diff --git a/src/ship/ship.rs b/src/ship/ship.rs index b986648..7c7bc59 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -303,7 +303,7 @@ impl ItemShops { ItemShops { weapon_shop: weapon_shop, tool_shop: ToolShop::new(), - armor_shop: ArmorShop::new(), + armor_shop: ArmorShop::default(), } } } diff --git a/src/ship/shops/armor.rs b/src/ship/shops/armor.rs index 2a6314f..789db56 100644 --- a/src/ship/shops/armor.rs +++ b/src/ship/shops/armor.rs @@ -19,7 +19,7 @@ pub enum ArmorShopItem { Unit(UnitType), } -const ARMOR_MULTIPLIER: f32 = 0.799999952; +const ARMOR_MULTIPLIER: f32 = 0.799_999_95; const SHIELD_MULTIPLIER: f32 = 1.5; const UNIT_MULTIPLIER: f32 = 1000.0; @@ -27,7 +27,7 @@ impl ShopItem for ArmorShopItem { fn price(&self) -> usize { match self { ArmorShopItem::Frame(frame, slot) => { - ARMOR_STATS.get(&frame) + ARMOR_STATS.get(frame) .map(|frame_stats| { let mut price = (frame_stats.dfp + frame_stats.evp) as f32; price *= price; @@ -39,7 +39,7 @@ impl ShopItem for ArmorShopItem { .unwrap_or(0xFFFF) }, ArmorShopItem::Barrier(barrier) => { - SHIELD_STATS.get(&barrier) + SHIELD_STATS.get(barrier) .map(|barrier_stats| { let mut price = (barrier_stats.dfp + barrier_stats.evp) as f32; price *= price; @@ -50,7 +50,7 @@ impl ShopItem for ArmorShopItem { .unwrap_or(0xFFFF) }, ArmorShopItem::Unit(unit) => { - UNIT_STATS.get(&unit) + UNIT_STATS.get(unit) .map(|unit_stats| { (unit_stats.stars as f32 * UNIT_MULTIPLIER) as usize }) @@ -236,8 +236,8 @@ pub struct ArmorShop { rng: R, } -impl ArmorShop { - pub fn new() -> ArmorShop { +impl Default for ArmorShop { + fn default() -> ArmorShop { ArmorShop { frame: load_frame_table(), barrier: load_barrier_table(), @@ -245,7 +245,9 @@ impl ArmorShop { rng: R::from_entropy(), } } +} +impl ArmorShop { fn generate_frame_list(&mut self, character_level: usize) -> Vec { let tier = self.frame.frame.iter() .filter(|t| t.level <= character_level) @@ -297,7 +299,7 @@ impl ArmorShop { }) .collect() }) - .unwrap_or(Vec::new()) + .unwrap_or_else(Vec::new) } pub fn generate_armor_list(&mut self, character_level: usize) -> Vec { @@ -316,12 +318,12 @@ mod test { #[test] fn test_loading_tool_shop() { - ArmorShop::::new(); + ArmorShop::::default(); } #[test] fn test_generating_some_armor() { - let mut fs = ArmorShop::::new(); + let mut fs = ArmorShop::::default(); for i in 0..200 { fs.generate_armor_list(i); }