combat log"

This commit is contained in:
ntr
2018-10-09 15:34:11 +11:00
parent 08b830320a
commit a42ef53c6d
4 changed files with 50 additions and 15 deletions
+7 -2
View File
@@ -16,6 +16,7 @@ use cryp::Cryp;
pub struct Battle {
pub a: Cryp,
pub b: Cryp,
pub log: Vec<String>,
}
impl Battle {
@@ -23,6 +24,7 @@ impl Battle {
return Battle {
a: a.clone(),
b: b.clone(),
log: vec![],
};
}
@@ -35,12 +37,15 @@ impl Battle {
panic!("{:?} is finished", self);
}
let a_turn = self.a.turn();
let b_turn = self.b.turn();
let mut a_turn = self.a.turn();
let mut b_turn = self.b.turn();
self.a.assign_dmg(&self.b, &a_turn, &b_turn);
self.b.assign_dmg(&self.a, &b_turn, &a_turn);
self.log.append(&mut a_turn.log);
self.log.append(&mut b_turn.log);
self
}
+13 -11
View File
@@ -38,25 +38,25 @@ impl Stat {
self
}
fn roll(&self, c: &Cryp) -> Roll {
fn roll(&self, c: &Cryp, log: &mut Vec<String>) -> Roll {
let mut rng = thread_rng();
let base: u64 = rng.gen();
let mut roll = Roll { kind: self.kind, base, result: base };
println!("{:?}", self.kind);
println!("{:064b} <- base roll", base);
log.push(format!("{:?}", self.kind));
log.push(format!("{:064b} <- base roll", base));
// apply skills
roll = c.skills.iter().fold(roll, |roll, s| s.apply(roll));
// finally combine with stat
println!("{:064b} <- finalised", roll.result);
log.push(format!("{:064b} <- finalised", roll.result));
roll.result = roll.result & self.value;
println!("{:064b} & <- attribute roll", self.value);
println!("{:064b} = {:?}", roll.result, roll.result);
println!("");
log.push(format!("{:064b} & <- attribute roll", self.value));
log.push(format!("{:064b} = {:?}", roll.result, roll.result));
log.push(format!(""));
return roll;
}
@@ -70,6 +70,7 @@ impl Stat {
pub struct Turn {
pub dmg: Roll,
pub def: Roll,
pub log: Vec<String>,
}
#[derive(Debug,Clone,Serialize,Deserialize)]
@@ -143,11 +144,12 @@ impl Cryp {
}
pub fn turn(&self) -> Turn {
// println!("{:?}'s turn:", c.name);
let dmg = self.dmg.roll(self);
let def = self.def.roll(self);
let mut log = vec![format!("{:?}'s turn:", self.name)];
return Turn { dmg, def }
let dmg = self.dmg.roll(self, &mut log);
let def = self.def.roll(self, &mut log);
return Turn { dmg, def, log }
}
pub fn create(mut self) -> Cryp {