#![allow(dead_code, unused_must_use)] use std::collections::{HashMap, BTreeMap}; use serde::{Serialize, Deserialize}; use std::fs::File; use std::io::Read; use entity::item::weapon::WeaponType; use entity::item::armor::ArmorType; use entity::item::shield::ShieldType; use entity::item::unit::UnitType; use entity::item::mag::MagType; use entity::item::tool::ToolType; use entity::item::tech::Technique; lazy_static::lazy_static! { pub static ref WEAPON_STATS: HashMap = weapon_stats(); pub static ref ARMOR_STATS: HashMap = armor_stats(); pub static ref SHIELD_STATS: HashMap = shield_stats(); pub static ref UNIT_STATS: BTreeMap = unit_stats(); pub static ref TOOL_STATS: HashMap = tool_stats(); pub static ref TECH_STATS: HashMap = tech_stats(); } fn load_data_file(path: &str) -> T { let mut f = File::open(path).unwrap(); let mut s = String::new(); f.read_to_string(&mut s); toml::from_str::(s.as_str()).unwrap() } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct WeaponStats { pub grind: usize, pub atp_min: usize, pub atp_max: usize, pub shop_multiplier: f32, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct ArmorStats { pub stars: u32, pub dfp: i32, pub evp: i32, pub dfp_modifier: u32, pub evp_modifier: u32, pub team_points: u32, pub level_req: u32, pub efr: i32, pub eic: i32, pub eth: i32, pub elt: i32, pub edk: i32, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct ShieldStats { pub stars: u32, pub dfp: i32, pub evp: i32, pub dfp_modifier: u32, pub evp_modifier: u32, pub team_points: u32, pub level_req: u32, pub efr: i32, pub eic: i32, pub eth: i32, pub elt: i32, pub edk: i32, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct UnitStats { pub stars: u32, pub stat: u32, pub amount: u32, pub team_points: u32, pub modifier: u32, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct ToolStats { pub price: usize, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct TechStats { pub price: usize, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct MagStats { pub feed_table: u32, } #[derive(Debug, Copy, Clone, Serialize, Deserialize)] pub struct MagFeedStats { def: i8, pow: i8, dex: i8, mnd: i8, iq: i8, syn: i8, } #[derive(Debug)] pub struct MagFeedTable(HashMap); #[derive(Debug)] pub struct MagFeedTables(Vec); pub fn weapon_stats() -> HashMap { let weapon_stats: HashMap = load_data_file("data/item_stats/weapon_stats.toml"); weapon_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn armor_stats() -> HashMap { let armor_stats: HashMap = load_data_file("data/item_stats/armor_stats.toml"); armor_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn shield_stats() -> HashMap { let shield_stats: HashMap = load_data_file("data/item_stats/shield_stats.toml"); shield_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn unit_stats() -> BTreeMap { let unit_stats: BTreeMap = load_data_file("data/item_stats/unit_stats.toml"); unit_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn tool_stats() -> HashMap { let tool_stats: HashMap = load_data_file("data/item_stats/tool_stats.toml"); tool_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn tech_stats() -> HashMap { let tech_stats: HashMap = load_data_file("data/item_stats/tech_stats.toml"); tech_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn mag_stats() -> HashMap { let mag_stats: BTreeMap = load_data_file("data/item_stats/mag_stats.toml"); mag_stats.iter() .map(|(name, stats)| { (name.parse().unwrap(), *stats) }).collect() } pub fn mag_feed_tables() -> MagFeedTables { let mag_feed_tables: BTreeMap>> = load_data_file("data/item_stats/mag_feed_table.toml"); MagFeedTables(mag_feed_tables.get("feedtable").unwrap().iter() .map(|feed_table| { MagFeedTable(feed_table.iter() .map(|(tool, feed_stats)| { (tool.parse().unwrap(), *feed_stats) }).collect()) }).collect()) } #[cfg(test)] mod test { use super::*; #[test] fn test_weapon_stats() { let wstat = weapon_stats(); assert!(wstat.get(&WeaponType::MadamsUmbrella).unwrap().atp_max == 280); } #[test] fn test_armor_stats() { let astat = armor_stats(); assert!(astat.get(&ArmorType::CrimsonCoat).unwrap().stars == 11); } #[test] fn test_shield_stats() { let sstat = shield_stats(); assert!(sstat.get(&ShieldType::RedRing).unwrap().stars == 11); } #[test] fn test_unit_stats() { let ustat = unit_stats(); assert!(ustat.get(&UnitType::ElfArm).unwrap().stars == 5); } #[test] fn test_tool_stats() { let tstat = tool_stats(); assert!(tstat.get(&ToolType::Monomate).unwrap().price == 50); } #[test] fn test_tech_stats() { let tstat = tech_stats(); assert!(tstat.get(&Technique::Reverser).unwrap().price == 5000); } #[test] fn test_mag_stats() { let mstats = mag_stats(); assert!(mstats[&MagType::Sato].feed_table== 5); assert!(mstats[&MagType::Nidra].feed_table == 7); } #[test] fn test_mag_feed_tables() { let mfeed = mag_feed_tables(); assert!(mfeed.0[7].0[&ToolType::Monomate].pow == 21); assert!(mfeed.0[5].0[&ToolType::MoonAtomizer].syn== 2); } }