Browse Source

lint src/ship/shop/armor.rs

jake 4 years ago
committed by andy
parent
commit
bf525bee71
  1. 2
      src/ship/ship.rs
  2. 20
      src/ship/shops/armor.rs

2
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(),
}
}
}

20
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<R: Rng + SeedableRng> {
rng: R,
}
impl<R: Rng + SeedableRng> ArmorShop<R> {
pub fn new() -> ArmorShop<R> {
impl<R: Rng + SeedableRng> Default for ArmorShop<R> {
fn default() -> ArmorShop<R> {
ArmorShop {
frame: load_frame_table(),
barrier: load_barrier_table(),
@ -245,7 +245,9 @@ impl<R: Rng + SeedableRng> ArmorShop<R> {
rng: R::from_entropy(),
}
}
}
impl<R: Rng + SeedableRng> ArmorShop<R> {
fn generate_frame_list(&mut self, character_level: usize) -> Vec<ArmorShopItem> {
let tier = self.frame.frame.iter()
.filter(|t| t.level <= character_level)
@ -297,7 +299,7 @@ impl<R: Rng + SeedableRng> ArmorShop<R> {
})
.collect()
})
.unwrap_or(Vec::new())
.unwrap_or_else(Vec::new)
}
pub fn generate_armor_list(&mut self, character_level: usize) -> Vec<ArmorShopItem> {
@ -316,12 +318,12 @@ mod test {
#[test]
fn test_loading_tool_shop() {
ArmorShop::<rand_chacha::ChaCha20Rng>::new();
ArmorShop::<rand_chacha::ChaCha20Rng>::default();
}
#[test]
fn test_generating_some_armor() {
let mut fs = ArmorShop::<rand_chacha::ChaCha20Rng>::new();
let mut fs = ArmorShop::<rand_chacha::ChaCha20Rng>::default();
for i in 0..200 {
fs.generate_armor_list(i);
}

Loading…
Cancel
Save