From d85583895cfffea054e4a9b1ae1a1a1cb112d381 Mon Sep 17 00:00:00 2001 From: Pcornat Date: Thu, 5 Feb 2026 14:08:47 +0100 Subject: [PATCH] Adding objects in Billy logic --- src/billy_objects.rs | 193 +++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 1 + src/sheet.rs | 2 +- 3 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 src/billy_objects.rs diff --git a/src/billy_objects.rs b/src/billy_objects.rs new file mode 100644 index 0000000..f133028 --- /dev/null +++ b/src/billy_objects.rs @@ -0,0 +1,193 @@ +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), + } + } +} diff --git a/src/lib.rs b/src/lib.rs index 8d3728f..eea7074 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,2 +1,3 @@ +pub mod billy_objects; pub mod gui; pub mod sheet; diff --git a/src/sheet.rs b/src/sheet.rs index 577dce5..1779c0a 100644 --- a/src/sheet.rs +++ b/src/sheet.rs @@ -14,7 +14,7 @@ pub enum Classe { } #[derive(Debug, Serialize, Deserialize)] -enum CharacteristicType { +pub enum CharacteristicType { Address(Characteristic), Stamina(Characteristic), Luck(Characteristic),