Browse Source

leveltable::get_level_from_exp

pbs
jake 5 years ago
parent
commit
27179f924b
  1. 22
      src/common/leveltable.rs

22
src/common/leveltable.rs

@ -76,6 +76,20 @@ impl CharacterLevelTable {
}
}
pub fn get_level_from_exp(&self, ch_class: CharacterClass, exp: u32) -> u32 {
if let Some(statlist) = self.table.get(&ch_class) {
statlist
.iter()
.filter(|stat| {
stat.exp <= exp
})
.count() as u32
}
else {
0
}
}
pub fn get_stats_from_exp(&self, ch_class: CharacterClass, exp: u32) -> (u32, CharacterStats) {
if let Some(statlist) = self.table.get(&ch_class) {
statlist
@ -110,4 +124,12 @@ mod test {
assert!(table.get_stats_from_exp(CharacterClass::FOmarl, 0) == (1, CharacterStats { hp: 20, atp: 13, mst: 53, evp: 35, dfp: 10, ata: 15, lck: 10 }));
assert!(table.get_stats_from_exp(CharacterClass::FOmarl, 1 << 17) == (36, CharacterStats { hp: 125, atp: 114, mst: 219, evp: 182, dfp: 42, ata: 213, lck: 10 }));
}
#[test]
fn test_levels() {
let table = CharacterLevelTable::new();
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 0) == 1);
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 3000) == 8);
assert!(table.get_level_from_exp(CharacterClass::FOmarl, 3200) == 9);
}
}
Loading…
Cancel
Save