hp stats
This commit is contained in:
parent
d8c4ff987c
commit
4806a087e3
@ -41,15 +41,15 @@ impl Battle {
|
||||
}
|
||||
|
||||
pub fn finished(&self) -> bool {
|
||||
self.cryps().iter().any(|c| c.hp == 0)
|
||||
self.cryps().iter().any(|c| c.is_ko())
|
||||
}
|
||||
|
||||
pub fn winner(&self) -> Option<&Cryp> {
|
||||
if self.cryps().iter().all(|c| c.hp == 0) {
|
||||
if self.cryps().iter().all(|c| c.is_ko()) {
|
||||
return None
|
||||
}
|
||||
|
||||
match self.cryps().iter().find(|c| c.hp > 0) {
|
||||
match self.cryps().iter().find(|c| !c.is_ko()) {
|
||||
Some(w) => Some(w),
|
||||
None => panic!("no winner found {:?}", self),
|
||||
}
|
||||
|
||||
51
src/cryp.rs
51
src/cryp.rs
@ -12,31 +12,23 @@ pub struct Stat {
|
||||
value: u64,
|
||||
}
|
||||
|
||||
type Dmg = Stat;
|
||||
type Def = Stat;
|
||||
type Stam = Stat;
|
||||
type Hp = Stat;
|
||||
|
||||
impl Stat {
|
||||
fn roll(&self) -> Roll {
|
||||
let mut rng = thread_rng();
|
||||
let roll: u64 = rng.gen();
|
||||
return Roll { roll, result: self.value & roll };
|
||||
}
|
||||
}
|
||||
|
||||
impl Hp {
|
||||
fn dmg(&mut self, dmg: u64) -> Hp {
|
||||
Hp {
|
||||
value: self.value.saturating_sub(dmg)
|
||||
}
|
||||
fn reduce(&mut self, dmg: u64) -> &mut Stat {
|
||||
self.value = self.value.saturating_sub(dmg);
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
fn print_roll(r: &Roll) {
|
||||
println!("{:?}", r.att);
|
||||
// println!("{:?}", r.att);
|
||||
println!("{:064b} &", r.roll);
|
||||
println!("{:064b}", r.value);
|
||||
// println!("{:064b}", r.value);
|
||||
println!("{:064b} - {:?}", r.result, r.result);
|
||||
println!("");
|
||||
}
|
||||
@ -51,10 +43,10 @@ pub struct Cryp {
|
||||
pub id: Uuid,
|
||||
// todo
|
||||
// make attributes hold this value
|
||||
pub dmg: Dmg,
|
||||
pub def: Def,
|
||||
pub stam: Stam,
|
||||
pub hp: Hp,
|
||||
pub dmg: Stat,
|
||||
pub def: Stat,
|
||||
pub stam: Stat,
|
||||
pub hp: Stat,
|
||||
pub xp: u64,
|
||||
pub lvl: u8,
|
||||
pub name: String,
|
||||
@ -70,10 +62,10 @@ impl Cryp {
|
||||
let id = Uuid::new_v4();
|
||||
return Cryp {
|
||||
id,
|
||||
dmg: Dmg { value: 0},
|
||||
def: Def { value: 0},
|
||||
stam: Stam { value: 0},
|
||||
hp: Hp { value: 0},
|
||||
dmg: Stat { value: 0},
|
||||
def: Stat { value: 0},
|
||||
stam: Stat { value: 0},
|
||||
hp: Stat { value: 0},
|
||||
lvl: 0,
|
||||
xp: 0,
|
||||
name: String::new()
|
||||
@ -124,10 +116,10 @@ impl Cryp {
|
||||
|
||||
self.xp = lvl_as_two_pwr;
|
||||
|
||||
self.dmg = Dmg { value: rng.gen_range(1, max) };
|
||||
self.def = Def { value: rng.gen_range(1, max) };
|
||||
self.stam = Stam { value: rng.gen_range(1, max) };
|
||||
self.hp = self.stam;
|
||||
self.dmg = Stat { value: rng.gen_range(1, max) };
|
||||
self.def = Stat { value: rng.gen_range(1, max) };
|
||||
self.stam = Stat { value: rng.gen_range(1, max) };
|
||||
self.hp = Stat { value: self.stam.value };
|
||||
self
|
||||
}
|
||||
|
||||
@ -135,17 +127,22 @@ impl Cryp {
|
||||
let final_dmg = opp_t.dmg.result.saturating_sub(plr_t.def.result);
|
||||
let blocked = opp_t.dmg.result.saturating_sub(final_dmg);
|
||||
|
||||
self.hp.reduce(final_dmg);
|
||||
|
||||
println!("{:?} deals {:?} dmg to {:?} ({:?} blocked / {:?} hp remaining)"
|
||||
,opp.name
|
||||
,final_dmg
|
||||
,self.name
|
||||
,blocked
|
||||
,hp);
|
||||
,self.hp.value);
|
||||
|
||||
self.hp = hp;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn is_ko(&self) -> bool {
|
||||
self.hp.value == 0
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user