You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

238 lines
6.5 KiB

#![allow(dead_code, unused_must_use)]
use std::collections::{HashMap, BTreeMap};
use serde::{Serialize, Deserialize};
use std::fs::File;
use std::io::Read;
use crate::entity::item::weapon::WeaponType;
use crate::entity::item::armor::ArmorType;
use crate::entity::item::shield::ShieldType;
use crate::entity::item::unit::UnitType;
use crate::entity::item::mag::MagType;
use crate::entity::item::tool::ToolType;
use crate::entity::item::tech::Technique;
lazy_static::lazy_static! {
pub static ref WEAPON_STATS: HashMap<WeaponType, WeaponStats> = weapon_stats();
pub static ref ARMOR_STATS: HashMap<ArmorType, ArmorStats> = armor_stats();
pub static ref SHIELD_STATS: HashMap<ShieldType, ShieldStats> = shield_stats();
pub static ref UNIT_STATS: BTreeMap<UnitType, UnitStats> = unit_stats();
pub static ref TOOL_STATS: HashMap<ToolType, ToolStats> = tool_stats();
pub static ref TECH_STATS: HashMap<Technique, TechStats> = tech_stats();
}
fn load_data_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
let mut f = File::open(path).unwrap();
let mut s = String::new();
f.read_to_string(&mut s);
toml::from_str::<T>(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<ToolType, MagFeedStats>);
#[derive(Debug)]
pub struct MagFeedTables(Vec<MagFeedTable>);
pub fn weapon_stats() -> HashMap<WeaponType, WeaponStats> {
let weapon_stats: HashMap<String, WeaponStats> = 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<ArmorType, ArmorStats> {
let armor_stats: HashMap<String, ArmorStats> = 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<ShieldType, ShieldStats> {
let shield_stats: HashMap<String, ShieldStats> = 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<UnitType, UnitStats> {
let unit_stats: BTreeMap<String, UnitStats> = 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<ToolType, ToolStats> {
let tool_stats: HashMap<String, ToolStats> = 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<Technique, TechStats> {
let tech_stats: HashMap<String, TechStats> = 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<MagType, MagStats> {
let mag_stats: BTreeMap<String, MagStats> = 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<String, Vec<BTreeMap<String, MagFeedStats>>> = 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);
}
}