use crate::billy_objects::Weapons::*; use crate::sheet::CharacteristicType; use crate::sheet::CharacteristicType::*; use serde::{Deserialize, Serialize}; pub trait GenericObject { fn add_armor(&self) -> u32 { 0 } fn add_critique(&self) -> u32 { 0 } fn add_damage(&self) -> u32 { 0 } fn add_materiel(&self, in_type: &CharacteristicType) -> i32; } #[derive(Debug, Serialize, Deserialize)] pub enum Weapons { Sword, Lance, Morgenstern, Bow, } #[derive(Debug, Serialize, Deserialize)] pub enum Equipments { Chainmail, CookingPot, PamphletTourist, MedicKit, } #[derive(Debug, Serialize, Deserialize)] pub enum Tools { Fourche, Dagger, RockClimbingKit, SackOfGrain, } #[derive(Debug, Serialize, Deserialize)] pub enum Objects { Weapons(Weapons), Equipments(Equipments), Tools(Tools), } impl GenericObject for Weapons { fn add_damage(&self) -> u32 { if let Morgenstern = &self { 1 } else { 0 } } fn add_materiel(&self, in_type: &CharacteristicType) -> i32 { match self { Sword => { if let Skill(_) = &in_type { 4 } else { 0 } } Lance => match in_type { Address(_) => 1, Skill(_) => 3, _ => 0, }, Morgenstern => match in_type { Stamina(_) | Skill(_) => 1, _ => 0, }, Bow => match in_type { Address(_) => 1, Skill(_) => 3, _ => 0, }, } } } impl GenericObject for Equipments { fn add_armor(&self) -> u32 { match self { Equipments::Chainmail => 2, Equipments::CookingPot => 1, _ => 0, } } fn add_materiel(&self, in_type: &CharacteristicType) -> i32 { match self { Equipments::Chainmail => match in_type { Address(_) | Skill(_) => -1, Stamina(_) => 1, _ => 0, }, Equipments::CookingPot => { if let Stamina(_) = in_type { 2 } else { 0 } } Equipments::PamphletTourist => { if let Luck(_) = in_type { 4 } else { 0 } } Equipments::MedicKit => { if let Luck(_) = in_type { 1 } else { 0 } } } } } impl GenericObject for Tools { fn add_critique(&self) -> u32 { if let Tools::Dagger = &self { 6 } else { 0 } } fn add_materiel(&self, in_type: &CharacteristicType) -> i32 { match self { Tools::Fourche => match in_type { Stamina(_) => 3, Skill(_) => 1, _ => 0, }, Tools::Dagger => { if let Skill(_) = in_type { 1 } else { 0 } } Tools::RockClimbingKit => { if let Address(_) = in_type { 1 } else { 0 } } Tools::SackOfGrain => match in_type { Stamina(_) | Luck(_) => 2, _ => 0, }, } } } impl GenericObject for Objects { fn add_armor(&self) -> u32 { todo!() } fn add_critique(&self) -> u32 { match self { Objects::Weapons(a) => a.add_critique(), Objects::Equipments(a) => a.add_critique(), Objects::Tools(a) => a.add_critique(), } } fn add_damage(&self) -> u32 { match self { Objects::Weapons(a) => a.add_damage(), Objects::Equipments(a) => a.add_damage(), Objects::Tools(a) => a.add_damage(), } } fn add_materiel(&self, in_type: &CharacteristicType) -> i32 { match self { Objects::Weapons(a) => a.add_materiel(in_type), Objects::Equipments(a) => a.add_materiel(in_type), Objects::Tools(a) => a.add_materiel(in_type), } } }