fix triage

This commit is contained in:
ntr 2019-12-19 15:41:03 +10:00
parent e4adb83060
commit 34b575fefc
3 changed files with 45 additions and 19 deletions

View File

@ -495,11 +495,13 @@ impl Construct {
self.effects = self.effects.clone().into_iter().filter_map(|mut effect| {
effect.duration = effect.duration.saturating_sub(1);
println!("{:?}", effect);
if effect.duration == 0 {
return None;
}
// info!("reduced effect {:?}", effect);
info!("reduced effect {:?}", effect);
return Some(effect);
}).collect::<Vec<ConstructEffect>>();

View File

@ -135,20 +135,6 @@ impl Game {
.unwrap()
}
pub fn update_construct(&mut self, construct: &mut Construct) -> &mut Game {
match self.players.iter_mut().find(|t| t.constructs.iter().any(|c| c.id == construct.id)) {
Some(player) => {
let index = player.constructs.iter().position(|t| t.id == construct.id).unwrap();
player.constructs.remove(index);
player.constructs.push(construct.clone());
player.constructs.sort_unstable_by_key(|c| c.id);
},
None => panic!("construct not in game"),
};
self
}
pub fn can_start(&self) -> bool {
return self.players.len() == self.player_num
&& self.players.iter().all(|t| t.constructs.len() == self.player_constructs)
@ -441,10 +427,12 @@ impl Game {
// temp vec of this round's resolving skills
// because need to check cooldown use before pushing them into the complete list
let mut r_animation_ms = 0;
println!("{:?}", self.stack);
while let Some(cast) = self.stack.pop() {
self.new_resolve(cast);
};
println!("processing durations");
self.progress_durations();
// go through the whole most recent round and modify delays of the resolutions
@ -2188,6 +2176,45 @@ mod tests {
}));
}
#[test]
fn triage_test() {
let mut game = create_2v2_test_game();
let player_id = game.players[0].id;
let source = game.players[0].constructs[0].id;
let target = game.players[1].constructs[0].id;
game.resolve(Cast::new(source, player_id, target, Skill::Strike));
game.resolve(Cast::new(source, player_id, target, Skill::Triage));
let last = game.resolutions.len() - 1;
let resolutions = &game.resolutions[last];
assert!(resolutions.iter().any(|r| match r.event {
Event::Healing { construct, colour, amount, overhealing: _, display: _ } =>
construct == target && amount > 0 && colour == Colour::Green,
_ => false,
}));
// it's hidden
// assert!(resolutions.iter().any(|r| match r.event {
// Event::Effect { construct, effect, duration: _, display: _ } =>
// construct == target && effect == Effect::Triaged,
// _ => false,
// }));
game.progress_durations(); // pretend it's a new turn
game = game.resolve_phase_start();
let last = game.resolutions.len() - 1;
let resolutions = &game.resolutions[last];
assert!(resolutions.iter().any(|r| match r.event {
Event::Healing { construct, colour, amount: _, overhealing, display: _ } =>
construct == target && overhealing > 0 && colour == Colour::Green,
_ => false,
}));
}
#[test]
fn counter_test() {
let mut game = create_2v2_test_game();

View File

@ -186,9 +186,6 @@ impl Cast {
Skill::TriageTick => triage_tick(self, game),
};
// actions.append(&mut rest);
// return actions;
}
}
@ -2208,7 +2205,7 @@ fn triage_tick(cast: Cast, game: &mut Game) {
Action::Heal {
construct: cast.target,
colour: Colour::Green,
amount: game.value(Value::TickDamage { construct: cast.target, effect: Effect::Electrocute }),
amount: game.value(Value::TickDamage { construct: cast.target, effect: Effect::Triage }),
}
);
game.action(cast,