From 929e92769c9bd4aab2b0e67c47b5d216f441730f Mon Sep 17 00:00:00 2001 From: Ren Kararou Date: Fri, 25 Aug 2023 18:13:45 -0500 Subject: [PATCH] slowly getting work done --- src/equipment/gun.rs | 16 ++++++++++++---- src/equipment/mod.rs | 16 ++++++++-------- src/inventory.rs | 2 +- src/unit.rs | 34 +++++++++++++++++++++++++++++++++- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/equipment/gun.rs b/src/equipment/gun.rs index b88a348..f6a79ac 100644 --- a/src/equipment/gun.rs +++ b/src/equipment/gun.rs @@ -9,8 +9,8 @@ pub struct Bullet { impl Bullet { pub fn new() -> Self { Self { - id: "BULLET_BLANK", - name: "BLANK", + id: String::from("BULLET_BLANK"), + name: String::from("BLANK"), attack: 0, } } @@ -26,8 +26,8 @@ impl Bullet { pub fn normal() -> Self { Self { - id: "BULLET_NORMAL", - name: "Normal Bullet", + id: String::from("BULLET_NORMAL"), + name: String::from("Normal Bullet"), attack: 5, } } @@ -40,6 +40,7 @@ pub struct Gun { stat_mods: StatBlock, attack: u8, bullets: Option, + ammo_count: u8, mag_size: u8, description: String, flavor: String, @@ -52,6 +53,7 @@ impl Gun { stat_mods: StatBlock::new_zero(), attack: 0, bullets: None, + ammo_count: 0, mag_size: 0, description: String::from("A cheap toy."), flavor: String::from("Don't walk into a gun fight with this."), @@ -60,6 +62,12 @@ impl Gun { pub fn attack(self) -> u8 { self.attack } + pub fn bullets(self) -> Option { + self.bullets + } + pub fn ammo_count(self) -> u8 { + self.ammo_count + } pub fn stat_mods(self) -> StatBlock { self.stat_mods } diff --git a/src/equipment/mod.rs b/src/equipment/mod.rs index 663cc2e..cabe87b 100644 --- a/src/equipment/mod.rs +++ b/src/equipment/mod.rs @@ -1,10 +1,10 @@ -mod comp; -mod gun; -mod hat; -mod pants; -mod shirt; -mod shoes; -mod sword; +pub mod comp; +pub mod gun; +pub mod hat; +pub mod pants; +pub mod shirt; +pub mod shoes; +pub mod sword; use crate::statistics::StatBlock; @@ -96,7 +96,7 @@ impl EquipmentBlock { pub fn bonuses(self) -> StatBlock { let mut stats = StatBlock::new_zero(); stats += self.sword.unwrap_or(sword::Sword::new()).stat_mods(); - stats += self.gun.uwrap_or(gun::Gun::new()).stat_mods(); + stats += self.gun.unwrap_or(gun::Gun::new()).stat_mods(); stats += self.comp.unwrap_or(comp::Comp::new()).stat_mods(); stats += self.head.unwrap_or(hat::Hat::new()).stat_mods(); stats += self.chest.unwrap_or(shirt::Shirt::new()).stat_mods(); diff --git a/src/inventory.rs b/src/inventory.rs index ad52a20..00b1c90 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -2,7 +2,7 @@ use crate::equipment::{sword::Sword, gun::Gun, comp::Comp, hat::Hat, shirt::Shir struct BagEquipment { swords: Option>, - guns: Option>, + guns: Option>, comps: Option>, hats: Option>, shirts: Option>, diff --git a/src/unit.rs b/src/unit.rs index 84a4075..05d92e8 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -1,4 +1,4 @@ -use crate::equipment::EquipmentBlock; +use crate::equipment::{EquipmentBlock, sword::Sword, gun::Gun}; use crate::statistics::StatBlock; use crate::status::Status; use rand::seq::SliceRandom; @@ -60,6 +60,38 @@ impl Unit { pub fn gender(self) -> Gender { self.gender } + pub fn strike(self) -> u32 { + // accuracy and crit chance are calculated in the battle engine + let mut rng = rand::thread_rng(); + let extra: u32 = rng.gen_range(1..3); + let stren: u32 = self.clone().stats().strength().try_into().unwrap_or(0); + let equipment: EquipmentBlock = self.clone().equipment().unwrap_or(EquipmentBlock::new()); + let swdam = equipment.sword().unwrap_or(Sword::new()).damage(); + (extra * stren) + u32::from(swdam) + } + pub fn shoot(&mut self) -> u32 { + let equipment = self.clone().equipment().unwrap_or(EquipmentBlock::new()); + match equipment.gun() { + Some(g) => { + match g.clone().bullets() { + Some(b) => { + match g.ammo_count() { + 0 => 0, // TODO: Reload mechanics + _ => { + let mut rng = rand::thread_rng(); + let extra: u32 = rng.gen_range(5..25); + // TODO: Decrement ammo by one + let dmg: u32 = b.attack().try_into().unwrap_or(0); + dmg + extra + } + } + } + None => 0, + } + } + None => 0, + } + } pub fn stats(self) -> StatBlock { self.base_stats + self.stat_bonus() }