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