shop_sell #65
| @ -12,47 +12,55 @@ use crate::entity::item::unit::{Unit, UnitType}; | ||||
| use crate::ship::shops::ShopItem; | ||||
| use crate::ship::item_stats::{ARMOR_STATS, SHIELD_STATS, UNIT_STATS}; | ||||
| 
 | ||||
| // #[derive(Debug)]
 | ||||
| // pub enum ArmorShopItem {
 | ||||
| //     Frame(ArmorType, usize), // slots
 | ||||
| //     Barrier(ShieldType),
 | ||||
| //     Unit(UnitType),
 | ||||
| // }
 | ||||
| 
 | ||||
| #[derive(Debug)] | ||||
| pub enum ArmorShopItem { | ||||
|     Frame(ArmorType, usize), // slots
 | ||||
|     Barrier(ShieldType), | ||||
|     Unit(UnitType), | ||||
|     Frame(Armor), // slots
 | ||||
|     Barrier(Shield), | ||||
|     Unit(Unit), | ||||
| } | ||||
| 
 | ||||
| const ARMOR_MULTIPLIER: f32 = 0.799_999_95; | ||||
| const SHIELD_MULTIPLIER: f32 = 1.5; | ||||
| const UNIT_MULTIPLIER: f32 = 1000.0; | ||||
| 
 | ||||
| // TODO: reduce the number of type casts?
 | ||||
| impl ShopItem for ArmorShopItem { | ||||
|     fn price(&self) -> usize { | ||||
|         match self { | ||||
|             ArmorShopItem::Frame(frame, slot) => { | ||||
|                 ARMOR_STATS.get(frame) | ||||
|             ArmorShopItem::Frame(frame) => { | ||||
|                 ARMOR_STATS.get(&frame.armor) | ||||
|                     .map(|frame_stats| { | ||||
|                         let mut price = (frame_stats.dfp + frame_stats.evp) as f32; | ||||
|                         let mut price = (frame_stats.dfp + frame_stats.evp + frame.dfp as i32 + frame.evp as i32) 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 += 70.0 * (frame_stats.level_req + 1) as f32; | ||||
|                         price += 70.0 * (frame_stats.level_req + 1) as f32 * frame.slots as f32; | ||||
|                         price as usize | ||||
|                     }) | ||||
|                     .unwrap_or(0xFFFF) | ||||
|             }, | ||||
|             ArmorShopItem::Barrier(barrier) => { | ||||
|                 SHIELD_STATS.get(barrier) | ||||
|                 SHIELD_STATS.get(&barrier.shield) | ||||
|                     .map(|barrier_stats| { | ||||
|                         let mut price = (barrier_stats.dfp + barrier_stats.evp) as f32; | ||||
|                         let mut price = (barrier_stats.dfp + barrier_stats.evp + barrier.dfp as i32 + barrier.evp as i32) as f32; | ||||
|                         price *= price; | ||||
|                         price /= SHIELD_MULTIPLIER; | ||||
|                         price += 70.0 * barrier_stats.level_req as f32; | ||||
|                         price += 70.0 * (barrier_stats.level_req + 1) as f32; | ||||
|                         price as usize | ||||
|                     }) | ||||
|                     .unwrap_or(0xFFFF) | ||||
|             }, | ||||
|             ArmorShopItem::Unit(unit) => { | ||||
|                 UNIT_STATS.get(unit) | ||||
|                 UNIT_STATS.get(&unit.unit) | ||||
|                     .map(|unit_stats| { | ||||
|                         (unit_stats.stars as f32 * UNIT_MULTIPLIER) as usize | ||||
|                         ((unit_stats.stars as f32 + unit.modifier_stars() as f32) * UNIT_MULTIPLIER) as usize | ||||
|                     }) | ||||
|                     .unwrap_or(0xFFFF) | ||||
|             } | ||||
| @ -65,24 +73,24 @@ impl ShopItem for ArmorShopItem { | ||||
| 
 | ||||
|     fn as_item(&self) -> ItemDetail { | ||||
|         match self { | ||||
|             ArmorShopItem::Frame(frame, slot) => { | ||||
|             ArmorShopItem::Frame(frame) => { | ||||
|                 ItemDetail::Armor(Armor { | ||||
|                     armor: *frame, | ||||
|                     armor: frame.armor, | ||||
|                     dfp: 0, | ||||
|                     evp: 0, | ||||
|                     slots: *slot as u8, | ||||
|                     slots: frame.slots as u8, | ||||
|                 }) | ||||
|             }, | ||||
|             ArmorShopItem::Barrier(barrier) => { | ||||
|                 ItemDetail::Shield(Shield { | ||||
|                     shield: *barrier, | ||||
|                     shield: barrier.shield, | ||||
|                     dfp: 0, | ||||
|                     evp: 0, | ||||
|                 }) | ||||
|             }, | ||||
|             ArmorShopItem::Unit(unit) => { | ||||
|                 ItemDetail::Unit(Unit { | ||||
|                     unit: *unit, | ||||
|                     unit: unit.unit, | ||||
|                     modifier: None, | ||||
|                 }) | ||||
|             }, | ||||
| @ -92,19 +100,19 @@ impl ShopItem for ArmorShopItem { | ||||
| 
 | ||||
| impl From<&Armor> for ArmorShopItem { | ||||
|     fn from(armor: &Armor) -> ArmorShopItem { | ||||
|         ArmorShopItem::Frame(armor.armor, armor.slots as usize) | ||||
|         ArmorShopItem::Frame(*armor) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl From<&Shield> for ArmorShopItem { | ||||
|     fn from(shield: &Shield) -> ArmorShopItem { | ||||
|         ArmorShopItem::Barrier(shield.shield) | ||||
|         ArmorShopItem::Barrier(*shield) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl From<&Unit> for ArmorShopItem { | ||||
|     fn from(unit: &Unit) -> ArmorShopItem { | ||||
|         ArmorShopItem::Unit(unit.unit) | ||||
|         ArmorShopItem::Unit(*unit) | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| @ -280,7 +288,12 @@ impl<R: Rng + SeedableRng> ArmorShop<R> { | ||||
|                 let frame_detail = tier.item.get(frame_choice.sample(&mut self.rng)).unwrap(); | ||||
|                 let slot = self.frame.slot_rate.get(slot_choice.sample(&mut self.rng)).unwrap(); | ||||
| 
 | ||||
|                 ArmorShopItem::Frame(frame_detail.item, slot.slot) | ||||
|                 ArmorShopItem::Frame(Armor { | ||||
|                     armor: frame_detail.item, | ||||
|                     dfp: 0, | ||||
|                     evp: 0, | ||||
|                     slots: slot.slot as u8, | ||||
|                 }) | ||||
|             }) | ||||
|             .collect() | ||||
|     } | ||||
| @ -297,7 +310,11 @@ impl<R: Rng + SeedableRng> ArmorShop<R> { | ||||
|             .map(|_| { | ||||
|                 let barrier_detail = tier.item.get(barrier_choice.sample(&mut self.rng)).unwrap(); | ||||
| 
 | ||||
|                 ArmorShopItem::Barrier(barrier_detail.item) | ||||
|                 ArmorShopItem::Barrier(Shield { | ||||
|                     shield: barrier_detail.item, | ||||
|                     dfp: 0, | ||||
|                     evp: 0, | ||||
|                 }) | ||||
|             }) | ||||
|             .collect() | ||||
|     } | ||||
| @ -313,7 +330,10 @@ impl<R: Rng + SeedableRng> ArmorShop<R> { | ||||
|                     .map(|_| { | ||||
|                         let unit_detail = tier.item.get(unit_choice.sample(&mut self.rng)).unwrap(); | ||||
| 
 | ||||
|                 ArmorShopItem::Unit(unit_detail.item) | ||||
|                 ArmorShopItem::Unit(Unit { | ||||
|                     unit: unit_detail.item, | ||||
|                     modifier: None, | ||||
|                 }) | ||||
|                     }) | ||||
|                     .collect() | ||||
|             }) | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user