slowly getting work done
This commit is contained in:
parent
ca10e900c8
commit
929e92769c
|
@ -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<Bullet>,
|
||||
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<Bullet> {
|
||||
self.bullets
|
||||
}
|
||||
pub fn ammo_count(self) -> u8 {
|
||||
self.ammo_count
|
||||
}
|
||||
pub fn stat_mods(self) -> StatBlock {
|
||||
self.stat_mods
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::equipment::{sword::Sword, gun::Gun, comp::Comp, hat::Hat, shirt::Shir
|
|||
|
||||
struct BagEquipment {
|
||||
swords: Option<Vec<Sword>>,
|
||||
guns: Option<Vec<Guns>>,
|
||||
guns: Option<Vec<Gun>>,
|
||||
comps: Option<Vec<Comp>>,
|
||||
hats: Option<Vec<Hat>>,
|
||||
shirts: Option<Vec<Shirt>>,
|
||||
|
|
34
src/unit.rs
34
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()
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue