Browse Source

weapon stats

pbs
jake 4 years ago
parent
commit
c13c071946
  1. 2165
      data/item_stats/weapon_stats.toml
  2. 29
      src/ship/item_stats.rs

2165
data/item_stats/weapon_stats.toml
File diff suppressed because it is too large
View File

29
src/ship/item_stats.rs

@ -4,6 +4,7 @@ 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;
@ -11,6 +12,11 @@ use crate::entity::item::mag::MagType;
use crate::entity::item::tool::ToolType;
lazy_static::lazy_static! {
pub static ref WEAPON_STATS: HashMap<WeaponType, WeaponStats> = weapon_stats();
}
fn load_data_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
let mut f = File::open(path).unwrap();
let mut s = String::new();
@ -20,8 +26,12 @@ fn load_data_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
}
struct WeaponStats {
#[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)]
@ -86,6 +96,15 @@ 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()
.inspect(|k| println!("{:?}", k))
.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()
@ -135,6 +154,12 @@ pub fn mag_feed_tables() -> MagFeedTables {
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();

Loading…
Cancel
Save