From 34b575fefc81d049c5296598321d9b1f895c57fd Mon Sep 17 00:00:00 2001 From: ntr Date: Thu, 19 Dec 2019 15:41:03 +1000 Subject: [PATCH] fix triage --- core/src/construct.rs | 4 +++- core/src/game.rs | 55 ++++++++++++++++++++++++++++++++----------- core/src/skill.rs | 5 +--- 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/core/src/construct.rs b/core/src/construct.rs index 1e8b94d6..632f7631 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -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::>(); diff --git a/core/src/game.rs b/core/src/game.rs index 6ce8bdab..4f41e766 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -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(); diff --git a/core/src/skill.rs b/core/src/skill.rs index 59588d25..be9ecc36 100644 --- a/core/src/skill.rs +++ b/core/src/skill.rs @@ -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,