From 8a9ced09ea0a53ca45159048e2b50a8d0be3ce22 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 23 Sep 2020 20:54:39 -0600 Subject: [PATCH] armor shop pricing --- src/ship/item_stats.rs | 3 +++ src/ship/shops/armor.rs | 44 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/ship/item_stats.rs b/src/ship/item_stats.rs index be39a90..953ecce 100644 --- a/src/ship/item_stats.rs +++ b/src/ship/item_stats.rs @@ -14,6 +14,9 @@ use crate::entity::item::tool::ToolType; lazy_static::lazy_static! { pub static ref WEAPON_STATS: HashMap = weapon_stats(); + pub static ref ARMOR_STATS: HashMap = armor_stats(); + pub static ref SHIELD_STATS: HashMap = shield_stats(); + pub static ref UNIT_STATS: BTreeMap = unit_stats(); } diff --git a/src/ship/shops/armor.rs b/src/ship/shops/armor.rs index 8944350..07e115b 100644 --- a/src/ship/shops/armor.rs +++ b/src/ship/shops/armor.rs @@ -11,14 +11,56 @@ use crate::ship::room::Difficulty; use crate::entity::item::armor::ArmorType; use crate::entity::item::shield::ShieldType; use crate::entity::item::unit::UnitType; +use crate::ship::shops::ShopItem; +use crate::ship::item_stats::{ARMOR_STATS, SHIELD_STATS, UNIT_STATS}; - +#[derive(Debug)] enum ShopArmor { Frame(ArmorType, usize), Barrier(ShieldType), Unit(UnitType), } +const ARMOR_MULTIPLIER: f32 = 0.799999952; +const SHIELD_MULTIPLIER: f32 = 1.5; +const UNIT_MULTIPLIER: f32 = 1000.0; + +impl ShopItem for ShopArmor { + fn price(&self) -> usize { + match self { + ShopArmor::Frame(frame, slot) => { + ARMOR_STATS.get(&frame) + .map(|frame_stats| { + let mut price = (frame_stats.dfp + frame_stats.evp) as f32; + price *= price; + price /= ARMOR_MULTIPLIER; + price += 70.0 * frame_stats.level_req as f32; + price += 70.0 * frame_stats.level_req as f32 * *slot as f32; + price as usize + }) + .unwrap_or(0) + }, + ShopArmor::Barrier(barrier) => { + SHIELD_STATS.get(&barrier) + .map(|barrier_stats| { + let mut price = (barrier_stats.dfp + barrier_stats.evp) as f32; + price *= price; + price /= SHIELD_MULTIPLIER; + price += 70.0 * barrier_stats.level_req as f32; + price as usize + }) + .unwrap_or(0) + }, + ShopArmor::Unit(unit) => { + UNIT_STATS.get(&unit) + .map(|unit_stats| { + (unit_stats.stars as f32 * UNIT_MULTIPLIER) as usize + }) + .unwrap_or(0) + } + } + } +} #[derive(Debug, Deserialize, Clone)]