elseware/src/ship/item_stats.rs

170 lines
4.3 KiB
Rust

#![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::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;
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()
}
struct WeaponStats {
}
#[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 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 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 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().into_iter()
.map(|feed_table| {
MagFeedTable(feed_table.into_iter()
.map(|(tool, feed_stats)| {
(tool.parse().unwrap(), *feed_stats)
}).collect())
}).collect())
}
#[cfg(test)]
mod test {
use super::*;
#[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_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);
}
}