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

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. #![allow(dead_code, unused_must_use)]
  2. use std::collections::{HashMap, BTreeMap};
  3. use serde::{Serialize, Deserialize};
  4. use std::fs::File;
  5. use std::io::Read;
  6. use crate::entity::item::weapon::WeaponType;
  7. use crate::entity::item::armor::ArmorType;
  8. use crate::entity::item::shield::ShieldType;
  9. use crate::entity::item::unit::UnitType;
  10. use crate::entity::item::mag::MagType;
  11. use crate::entity::item::tool::ToolType;
  12. use crate::entity::item::tech::Technique;
  13. lazy_static::lazy_static! {
  14. pub static ref WEAPON_STATS: HashMap<WeaponType, WeaponStats> = weapon_stats();
  15. pub static ref ARMOR_STATS: HashMap<ArmorType, ArmorStats> = armor_stats();
  16. pub static ref SHIELD_STATS: HashMap<ShieldType, ShieldStats> = shield_stats();
  17. pub static ref UNIT_STATS: BTreeMap<UnitType, UnitStats> = unit_stats();
  18. pub static ref TOOL_STATS: HashMap<ToolType, ToolStats> = tool_stats();
  19. pub static ref TECH_STATS: HashMap<Technique, TechStats> = tech_stats();
  20. }
  21. fn load_data_file<T: serde::de::DeserializeOwned>(path: &str) -> T {
  22. let mut f = File::open(path).unwrap();
  23. let mut s = String::new();
  24. f.read_to_string(&mut s);
  25. toml::from_str::<T>(s.as_str()).unwrap()
  26. }
  27. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  28. pub struct WeaponStats {
  29. pub grind: usize,
  30. pub atp_min: usize,
  31. pub atp_max: usize,
  32. pub shop_multiplier: f32,
  33. }
  34. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  35. pub struct ArmorStats {
  36. pub stars: u32,
  37. pub dfp: i32,
  38. pub evp: i32,
  39. pub dfp_modifier: u32,
  40. pub evp_modifier: u32,
  41. pub team_points: u32,
  42. pub level_req: u32,
  43. pub efr: i32,
  44. pub eic: i32,
  45. pub eth: i32,
  46. pub elt: i32,
  47. pub edk: i32,
  48. }
  49. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  50. pub struct ShieldStats {
  51. pub stars: u32,
  52. pub dfp: i32,
  53. pub evp: i32,
  54. pub dfp_modifier: u32,
  55. pub evp_modifier: u32,
  56. pub team_points: u32,
  57. pub level_req: u32,
  58. pub efr: i32,
  59. pub eic: i32,
  60. pub eth: i32,
  61. pub elt: i32,
  62. pub edk: i32,
  63. }
  64. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  65. pub struct UnitStats {
  66. pub stars: u32,
  67. pub stat: u32,
  68. pub amount: u32,
  69. pub team_points: u32,
  70. pub modifier: u32,
  71. }
  72. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  73. pub struct ToolStats {
  74. pub price: usize,
  75. }
  76. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  77. pub struct TechStats {
  78. pub price: usize,
  79. }
  80. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  81. pub struct MagStats {
  82. pub feed_table: u32,
  83. }
  84. #[derive(Debug, Copy, Clone, Serialize, Deserialize)]
  85. pub struct MagFeedStats {
  86. def: i8,
  87. pow: i8,
  88. dex: i8,
  89. mnd: i8,
  90. iq: i8,
  91. syn: i8,
  92. }
  93. #[derive(Debug)]
  94. pub struct MagFeedTable(HashMap<ToolType, MagFeedStats>);
  95. #[derive(Debug)]
  96. pub struct MagFeedTables(Vec<MagFeedTable>);
  97. pub fn weapon_stats() -> HashMap<WeaponType, WeaponStats> {
  98. let weapon_stats: HashMap<String, WeaponStats> = load_data_file("data/item_stats/weapon_stats.toml");
  99. weapon_stats.iter()
  100. .map(|(name, stats)| {
  101. (name.parse().unwrap(), *stats)
  102. }).collect()
  103. }
  104. pub fn armor_stats() -> HashMap<ArmorType, ArmorStats> {
  105. let armor_stats: HashMap<String, ArmorStats> = load_data_file("data/item_stats/armor_stats.toml");
  106. armor_stats.iter()
  107. .map(|(name, stats)| {
  108. (name.parse().unwrap(), *stats)
  109. }).collect()
  110. }
  111. pub fn shield_stats() -> HashMap<ShieldType, ShieldStats> {
  112. let shield_stats: HashMap<String, ShieldStats> = load_data_file("data/item_stats/shield_stats.toml");
  113. shield_stats.iter()
  114. .map(|(name, stats)| {
  115. (name.parse().unwrap(), *stats)
  116. }).collect()
  117. }
  118. pub fn unit_stats() -> BTreeMap<UnitType, UnitStats> {
  119. let unit_stats: BTreeMap<String, UnitStats> = load_data_file("data/item_stats/unit_stats.toml");
  120. unit_stats.iter()
  121. .map(|(name, stats)| {
  122. (name.parse().unwrap(), *stats)
  123. }).collect()
  124. }
  125. pub fn tool_stats() -> HashMap<ToolType, ToolStats> {
  126. let tool_stats: HashMap<String, ToolStats> = load_data_file("data/item_stats/tool_stats.toml");
  127. tool_stats.iter()
  128. .map(|(name, stats)| {
  129. (name.parse().unwrap(), *stats)
  130. }).collect()
  131. }
  132. pub fn tech_stats() -> HashMap<Technique, TechStats> {
  133. let tech_stats: HashMap<String, TechStats> = load_data_file("data/item_stats/tech_stats.toml");
  134. tech_stats.iter()
  135. .map(|(name, stats)| {
  136. (name.parse().unwrap(), *stats)
  137. }).collect()
  138. }
  139. pub fn mag_stats() -> HashMap<MagType, MagStats> {
  140. let mag_stats: BTreeMap<String, MagStats> = load_data_file("data/item_stats/mag_stats.toml");
  141. mag_stats.iter()
  142. .map(|(name, stats)| {
  143. (name.parse().unwrap(), *stats)
  144. }).collect()
  145. }
  146. pub fn mag_feed_tables() -> MagFeedTables {
  147. let mag_feed_tables: BTreeMap<String, Vec<BTreeMap<String, MagFeedStats>>> = load_data_file("data/item_stats/mag_feed_table.toml");
  148. MagFeedTables(mag_feed_tables.get("feedtable").unwrap().iter()
  149. .map(|feed_table| {
  150. MagFeedTable(feed_table.iter()
  151. .map(|(tool, feed_stats)| {
  152. (tool.parse().unwrap(), *feed_stats)
  153. }).collect())
  154. }).collect())
  155. }
  156. #[cfg(test)]
  157. mod test {
  158. use super::*;
  159. #[test]
  160. fn test_weapon_stats() {
  161. let wstat = weapon_stats();
  162. assert!(wstat.get(&WeaponType::MadamsUmbrella).unwrap().atp_max == 280);
  163. }
  164. #[test]
  165. fn test_armor_stats() {
  166. let astat = armor_stats();
  167. assert!(astat.get(&ArmorType::CrimsonCoat).unwrap().stars == 11);
  168. }
  169. #[test]
  170. fn test_shield_stats() {
  171. let sstat = shield_stats();
  172. assert!(sstat.get(&ShieldType::RedRing).unwrap().stars == 11);
  173. }
  174. #[test]
  175. fn test_unit_stats() {
  176. let ustat = unit_stats();
  177. assert!(ustat.get(&UnitType::ElfArm).unwrap().stars == 5);
  178. }
  179. #[test]
  180. fn test_tool_stats() {
  181. let tstat = tool_stats();
  182. assert!(tstat.get(&ToolType::Monomate).unwrap().price == 50);
  183. }
  184. #[test]
  185. fn test_tech_stats() {
  186. let tstat = tech_stats();
  187. assert!(tstat.get(&Technique::Reverser).unwrap().price == 5000);
  188. }
  189. #[test]
  190. fn test_mag_stats() {
  191. let mstats = mag_stats();
  192. assert!(mstats[&MagType::Sato].feed_table== 5);
  193. assert!(mstats[&MagType::Nidra].feed_table == 7);
  194. }
  195. #[test]
  196. fn test_mag_feed_tables() {
  197. let mfeed = mag_feed_tables();
  198. assert!(mfeed.0[7].0[&ToolType::Monomate].pow == 21);
  199. assert!(mfeed.0[5].0[&ToolType::MoonAtomizer].syn== 2);
  200. }
  201. }