diff --git a/Cargo.toml b/Cargo.toml index 8c71f7d..d3bbacc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,3 +7,4 @@ edition = "2021" [dependencies] rand = "0.8.5" +anyhow = { version = "1.0.72", features = ["backtrace"] } \ No newline at end of file diff --git a/src/battle.rs b/src/battle.rs index 0ca9995..90b7aff 100644 --- a/src/battle.rs +++ b/src/battle.rs @@ -1,5 +1,5 @@ -use crate::unit::Unit; use crate::statistics::StatBlock; +use crate::unit::Unit; pub enum Field { City, @@ -45,24 +45,24 @@ pub struct BattleTeam { } impl BattleTeam { pub fn new(front: [Option; 3], back: [Option; 3]) -> Self { - Self { - front, - back, - } + Self { front, back } } } pub struct Battle { - view_team: BattleTeam, - oppose_team: BattleTeam, + teams: [BattleTeam; 2], field: Field, weather: Weather, } impl Battle { - pub fn new(view_team: BattleTeam, oppose_team: BattleTeam, field: Field, weather: Weather) -> Self { + pub fn new( + team1: BattleTeam, + team2: BattleTeam, + field: Field, + weather: Weather, + ) -> Self { Self { - view_team, - oppose_team, + teams: [team1, team2], field, weather, } @@ -78,8 +78,8 @@ impl Battle { Field::Chaos => { sb.add_intellect(5); sb.add_magick(5); - }, - _ => () + } + _ => (), }; sb } @@ -93,7 +93,7 @@ impl Battle { sb.add_strength(-5); sb.add_defense(-5); sb.add_intellect(-5); - }, + } Weather::Sun => sb.add_magick(-1), _ => (), }; @@ -106,7 +106,7 @@ impl Battle { sb.add_vitality(-10); sb.add_strength(-10); sb.add_dexterity(-10); - }, + } _ => (), }; sb diff --git a/src/equipment/comp.rs b/src/equipment/comp.rs index 4e80750..35af04b 100644 --- a/src/equipment/comp.rs +++ b/src/equipment/comp.rs @@ -76,8 +76,12 @@ impl Comp { mstorage: 16, gstorage: 8, stat_mods, - flavor: String::from("Handmade with love by Gideon Chiba, good luck out there trainee!"), - description: String::from("+1 Intellect, 1 spell slot, 16MiB of spell storage, 8GiB of program storage."), + flavor: String::from( + "Handmade with love by Gideon Chiba, good luck out there trainee!", + ), + description: String::from( + "+1 Intellect, 1 spell slot, 16MiB of spell storage, 8GiB of program storage.", + ), } } pub fn spiceworks_v3() -> Self { @@ -91,7 +95,9 @@ impl Comp { gstorage: 8, stat_mods, flavor: String::from("A heart is scratched into the side."), - description: String::from("+1 Magick, 2 spell slots, 16MiB of spell storage, 8GiB of program storage."), + description: String::from( + "+1 Magick, 2 spell slots, 16MiB of spell storage, 8GiB of program storage.", + ), } } @@ -119,7 +125,9 @@ impl Comp { gstorage: 16, stat_mods: StatBlock::new_zero(), flavor: String::from("Mass produced garbage."), - description: String::from("Five spell slots, 128MiB of spell storage, and 16GiB of program storage."), + description: String::from( + "Five spell slots, 128MiB of spell storage, and 16GiB of program storage.", + ), } } diff --git a/src/equipment/sword.rs b/src/equipment/sword.rs index a22eb3a..344b942 100644 --- a/src/equipment/sword.rs +++ b/src/equipment/sword.rs @@ -17,7 +17,9 @@ impl Sword { damage: 1u8, stat_mods: StatBlock::new_zero(), flavor: String::from("A basic bitch sword. It is completely useless."), - description: String::from("1 Attack Strength Sword. Literally the cheapest you can get."), + description: String::from( + "1 Attack Strength Sword. Literally the cheapest you can get.", + ), } } pub fn id(self) -> String { @@ -65,8 +67,12 @@ impl Sword { name: String::from("Sacred Blade"), damage: 58u8, stat_mods: buf, - flavor: String::from("Forged eons ago by master smiths and imbued with the magic of gods."), - description: String::from("+5 Strength. 58 Attack. The sacred sword of a religious cult."), + flavor: String::from( + "Forged eons ago by master smiths and imbued with the magic of gods.", + ), + description: String::from( + "+5 Strength. 58 Attack. The sacred sword of a religious cult.", + ), } } pub fn ceremonial_knife() -> Self { diff --git a/src/inventory.rs b/src/inventory.rs index 00b1c90..dfc80f0 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -1,6 +1,11 @@ -use crate::equipment::{sword::Sword, gun::Gun, comp::Comp, hat::Hat, shirt::Shirt, pants::Pants, shoes::Shoes}; +use anyhow::Result; -struct BagEquipment { +use crate::equipment::{ + comp::Comp, gun::Gun, hat::Hat, pants::Pants, shirt::Shirt, shoes::Shoes, sword::Sword, +}; + +#[derive(Debug, Clone)] +pub struct BagEquipment { swords: Option>, guns: Option>, comps: Option>, @@ -9,8 +14,143 @@ struct BagEquipment { pants: Option>, shoes: Option>, } - -struct Inventory { - equipment: Option, - +impl BagEquipment { + pub fn new() -> Self { + Self { + swords: None, + guns: None, + comps: None, + hats: None, + shirts: None, + pants: None, + shoes: None, + } + } + pub fn swords(&self) -> Option> { + self.swords.clone() + } + pub fn guns(&self) -> Option> { + self.guns.clone() + } + pub fn comps(&self) -> Option> { + self.comps.clone() + } + pub fn hats(&self) -> Option> { + self.hats.clone() + } + pub fn shirts(&self) -> Option> { + self.shirts.clone() + } + pub fn pants(&self) -> Option> { + self.pants.clone() + } + pub fn shoes(&self) -> Option> { + self.shoes.clone() + } + pub fn add_sword(&mut self, sword: Sword) -> Result<()> { + let mut swords = match self.clone().swords { + Some(s) => s, + None => Vec::new(), + }; + swords.push(sword); + self.swords = Some(swords); + Ok(()) + } + pub fn add_gun(&mut self, gun: Gun) -> Result<()> { + let mut guns = match self.clone().guns { + Some(g) => g, + None => Vec::new(), + }; + guns.push(gun); + self.guns = Some(guns); + Ok(()) + } + pub fn add_comp(&mut self, comp: Comp) -> Result<()> { + let mut comps = match self.clone().comps { + Some(c) => c, + None => Vec::new(), + }; + comps.push(comp); + self.comps = Some(comps); + Ok(()) + } + pub fn add_hat(&mut self, hat: Hat) -> Result<()> { + let mut hats = match self.clone().hats { + Some(h) => h, + None => Vec::new(), + }; + hats.push(hat); + self.hats = Some(hats); + Ok(()) + } + pub fn add_shirt(&mut self, shirt: Shirt) -> Result<()> { + let mut shirts = match self.clone().shirts { + Some(s) => s, + None => Vec::new(), + }; + shirts.push(shirt); + self.shirts = Some(shirts); + Ok(()) + } + pub fn add_pant(&mut self, pant: Pants) -> Result<()> { + let mut pants = match self.clone().pants { + Some(p) => p, + None => Vec::new(), + }; + pants.push(pant); + self.pants = Some(pants); + Ok(()) + } + pub fn add_shoe(&mut self, shoe: Shoes) -> Result<()> { + let mut shoes = match self.clone().shoes { + Some(s) => s, + None => Vec::new(), + }; + shoes.push(shoe); + self.shoes = Some(shoes); + Ok(()) + } + pub fn set_swords(&mut self, swords: Option>) -> Result<()> { + self.swords = swords; + Ok(()) + } + pub fn set_guns(&mut self, guns: Option>) -> Result<()> { + self.guns = guns; + Ok(()) + } + pub fn set_comps(&mut self, comps: Option>) -> Result<()> { + self.comps = comps; + Ok(()) + } + pub fn set_hats(&mut self, hats: Option>) -> Result<()> { + self.hats = hats; + Ok(()) + } + pub fn set_shirts(&mut self, shirts: Option>) -> Result<()> { + self.shirts = shirts; + Ok(()) + } + pub fn set_pants(&mut self, pants: Option>) -> Result<()> { + self.pants = pants; + Ok(()) + } + pub fn set_shoes(&mut self, shoes: Option>) -> Result<()> { + self.shoes = shoes; + Ok(()) + } +} + +pub struct Inventory { + equipment: Option, +} +impl Inventory { + pub fn new() -> Self { + Self { + equipment: None, + } + } + pub fn set_equipment(&mut self, equipment: Option) -> Result<()> { + self.equipment = equipment; + Ok(()) + } } diff --git a/src/lib.rs b/src/lib.rs index 78fa3bf..fc839c9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,7 @@ +pub mod battle; pub mod equipment; +pub mod inventory; pub mod magic; pub mod statistics; -pub mod unit; -pub mod inventory; pub mod status; -pub mod battle; +pub mod unit; diff --git a/src/status.rs b/src/status.rs index 756163a..50d6f1e 100644 --- a/src/status.rs +++ b/src/status.rs @@ -1,13 +1,13 @@ #[derive(Debug, Copy, Clone)] pub enum Status { - Poison, // hp slowly decreases - Static, // chance to miss turn - Freeze, // hp slowly decreases and chance to miss turn - Burn, // hp slowly decreases and unable to cast magic - Slow, // speed is halved - Confuse, // chance to hit random target (self included) - Stop, // miss turn - Haste, // speed is doubled - Faint, // close to death - Dead, // dead, cannot be revived + Poison, // hp slowly decreases + Static, // chance to miss turn + Freeze, // hp slowly decreases and chance to miss turn + Burn, // hp slowly decreases and unable to cast magic + Slow, // speed is halved + Confuse, // chance to hit random target (self included) + Stop, // miss turn + Haste, // speed is doubled + Faint, // close to death + Dead, // dead, cannot be revived } diff --git a/src/unit.rs b/src/unit.rs index 05d92e8..84f021e 100644 --- a/src/unit.rs +++ b/src/unit.rs @@ -1,4 +1,4 @@ -use crate::equipment::{EquipmentBlock, sword::Sword, gun::Gun}; +use crate::equipment::{gun::Gun, sword::Sword, EquipmentBlock}; use crate::statistics::StatBlock; use crate::status::Status; use rand::seq::SliceRandom; @@ -23,7 +23,7 @@ pub struct Unit { name: String, level: u8, exp: u32, - status: Option<(Option,Option)>, + status: Option<(Option, Option)>, gender: Gender, base_stats: StatBlock, hp: u16, @@ -72,7 +72,7 @@ impl Unit { pub fn shoot(&mut self) -> u32 { let equipment = self.clone().equipment().unwrap_or(EquipmentBlock::new()); match equipment.gun() { - Some(g) => { + Some(g) => { match g.clone().bullets() { Some(b) => { match g.ammo_count() { @@ -179,7 +179,7 @@ impl Unit { _ => { eprintln!("ERROR! human_battle_maniac() stat assign out of bounds!"); sb.add_vitality(1); - }, + } }; } let mut equip = EquipmentBlock::new(); @@ -220,7 +220,7 @@ impl Unit { _ => { eprintln!("ERROR! human_street_samurai() stat assign out of bounds!"); sb.add_vitality(1); - }, + } }; } let mut equip = EquipmentBlock::new();