|
|
@ -30,9 +30,8 @@ pub struct CharacterLevelTable { |
|
|
|
table: HashMap<CharacterClass, [CharacterLevelEntry; 200]>,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl CharacterLevelTable {
|
|
|
|
pub fn new() -> CharacterLevelTable {
|
|
|
|
impl Default for CharacterLevelTable {
|
|
|
|
fn default() -> CharacterLevelTable {
|
|
|
|
let file = File::open("data/char_stats.json").unwrap();
|
|
|
|
let json: Value = serde_json::from_reader(file).unwrap();
|
|
|
|
let mut table = HashMap::new();
|
|
|
@ -55,7 +54,7 @@ impl CharacterLevelTable { |
|
|
|
};
|
|
|
|
|
|
|
|
let mut statlist = [CharacterLevelEntry::default(); 200];
|
|
|
|
for (i, stat) in it.1.as_array().unwrap().into_iter().enumerate() {
|
|
|
|
for (i, stat) in it.1.as_array().unwrap().iter().enumerate() {
|
|
|
|
statlist[i] = CharacterLevelEntry {
|
|
|
|
hp: stat["hp"].as_i64().unwrap() as u32,
|
|
|
|
atp: stat["atp"].as_i64().unwrap() as u32,
|
|
|
@ -75,7 +74,9 @@ impl CharacterLevelTable { |
|
|
|
table: table,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
@ -120,14 +121,14 @@ mod test { |
|
|
|
use super::*;
|
|
|
|
#[test]
|
|
|
|
fn test_stat_levels() {
|
|
|
|
let table = CharacterLevelTable::new();
|
|
|
|
let table = CharacterLevelTable::default();
|
|
|
|
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();
|
|
|
|
let table = CharacterLevelTable::default();
|
|
|
|
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);
|
|
|
|