From 23a3d1212ec028f58d02eef4131d03219fa01c3a Mon Sep 17 00:00:00 2001 From: andy Date: Fri, 1 Sep 2023 12:56:41 -0300 Subject: [PATCH] match mag feed decrease behaviour with the client and fix test --- src/entity/item/mag.rs | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/entity/item/mag.rs b/src/entity/item/mag.rs index 17fa1b4..035f1e3 100644 --- a/src/entity/item/mag.rs +++ b/src/entity/item/mag.rs @@ -1029,10 +1029,30 @@ impl Mag { MAG_STATS.get(&self.mag).map(|stats| { MAG_FEEDING_TABLES.get(stats.feed_table).map(|feeding_table| { feeding_table.get(&tool).map(|feed_stats| { - self.def = std::cmp::max(std::cmp::max((self.def as i16) + feed_stats.def, 0) as u16, self.def()*100); - self.pow = std::cmp::max(std::cmp::max((self.pow as i16) + feed_stats.pow, 0) as u16, self.pow()*100); - self.dex = std::cmp::max(std::cmp::max((self.dex as i16) + feed_stats.dex, 0) as u16, self.dex()*100); - self.mnd = std::cmp::max(std::cmp::max((self.mnd as i16) + feed_stats.mnd, 0) as u16, self.mind()*100); + self.def = { + if (self.def as i16 + feed_stats.def) < ((self.def()*100) as i16) { + self.def + } else { + std::cmp::max(std::cmp::max((self.def as i16) + feed_stats.def, 0) as u16, self.def()*100) + }}; + self.pow = { + if (self.pow as i16 + feed_stats.pow) < ((self.pow()*100) as i16) { + self.pow + } else { + std::cmp::max(std::cmp::max((self.pow as i16) + feed_stats.pow, 0) as u16, self.pow()*100) + }}; + self.dex = { + if (self.dex as i16 + feed_stats.dex) < ((self.dex()*100) as i16) { + self.dex + } else { + std::cmp::max(std::cmp::max((self.dex as i16) + feed_stats.dex, 0) as u16, self.dex()*100) + }}; + self.mnd = { + if (self.mnd as i16 + feed_stats.mnd) < ((self.mind()*100) as i16) { + self.mnd + } else { + std::cmp::max(std::cmp::max((self.mnd as i16) + feed_stats.mnd, 0) as u16, self.mind()*100) + }}; self.iq = std::cmp::min(((self.iq as i16) + feed_stats.iq as i16) as u8, 200); self.synchro = std::cmp::min(((self.synchro as i8) + feed_stats.syn) as u8, 120); }) @@ -1188,7 +1208,7 @@ mod test { f.read_to_string(&mut s).unwrap(); let mut feed: HashMap>> = toml::from_str(&s).unwrap(); - let feed = feed.remove("feedtable".into()).unwrap(); + let feed = feed.remove("feedtable").unwrap(); let _feed = feed.into_iter() .map(|table| { table.into_iter() @@ -1219,7 +1239,7 @@ mod test { } assert!(mag == Mag { mag: MagType::Sato, - def: 507, + def: 509, pow: 5019, dex: 4505, mnd: 0,