incomplete, need items, damage, etc
This commit is contained in:
parent
929e92769c
commit
10df4922aa
|
@ -7,3 +7,4 @@ edition = "2021"
|
|||
|
||||
[dependencies]
|
||||
rand = "0.8.5"
|
||||
anyhow = { version = "1.0.72", features = ["backtrace"] }
|
|
@ -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<BattleUnit>; 3], back: [Option<BattleUnit>; 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
|
||||
|
|
|
@ -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.",
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
152
src/inventory.rs
152
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<Vec<Sword>>,
|
||||
guns: Option<Vec<Gun>>,
|
||||
comps: Option<Vec<Comp>>,
|
||||
|
@ -9,8 +14,143 @@ struct BagEquipment {
|
|||
pants: Option<Vec<Pants>>,
|
||||
shoes: Option<Vec<Shoes>>,
|
||||
}
|
||||
|
||||
struct Inventory {
|
||||
equipment: Option<BagEquipment>,
|
||||
|
||||
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<Vec<Sword>> {
|
||||
self.swords.clone()
|
||||
}
|
||||
pub fn guns(&self) -> Option<Vec<Gun>> {
|
||||
self.guns.clone()
|
||||
}
|
||||
pub fn comps(&self) -> Option<Vec<Comp>> {
|
||||
self.comps.clone()
|
||||
}
|
||||
pub fn hats(&self) -> Option<Vec<Hat>> {
|
||||
self.hats.clone()
|
||||
}
|
||||
pub fn shirts(&self) -> Option<Vec<Shirt>> {
|
||||
self.shirts.clone()
|
||||
}
|
||||
pub fn pants(&self) -> Option<Vec<Pants>> {
|
||||
self.pants.clone()
|
||||
}
|
||||
pub fn shoes(&self) -> Option<Vec<Shoes>> {
|
||||
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<Vec<Sword>>) -> Result<()> {
|
||||
self.swords = swords;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_guns(&mut self, guns: Option<Vec<Gun>>) -> Result<()> {
|
||||
self.guns = guns;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_comps(&mut self, comps: Option<Vec<Comp>>) -> Result<()> {
|
||||
self.comps = comps;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_hats(&mut self, hats: Option<Vec<Hat>>) -> Result<()> {
|
||||
self.hats = hats;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_shirts(&mut self, shirts: Option<Vec<Shirt>>) -> Result<()> {
|
||||
self.shirts = shirts;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_pants(&mut self, pants: Option<Vec<Pants>>) -> Result<()> {
|
||||
self.pants = pants;
|
||||
Ok(())
|
||||
}
|
||||
pub fn set_shoes(&mut self, shoes: Option<Vec<Shoes>>) -> Result<()> {
|
||||
self.shoes = shoes;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Inventory {
|
||||
equipment: Option<BagEquipment>,
|
||||
}
|
||||
impl Inventory {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
equipment: None,
|
||||
}
|
||||
}
|
||||
pub fn set_equipment(&mut self, equipment: Option<BagEquipment>) -> Result<()> {
|
||||
self.equipment = equipment;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
10
src/unit.rs
10
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<Status>,Option<Status>)>,
|
||||
status: Option<(Option<Status>, Option<Status>)>,
|
||||
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();
|
||||
|
|
Loading…
Reference in a new issue