diff --git a/core/src/construct.rs b/core/src/construct.rs index f162c8d3..7191c832 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -533,6 +533,8 @@ impl Construct { } pub fn damage(&mut self, amount: usize, colour: Colour) -> Vec { + if self.is_ko() { return vec![Event::TargetKo { construct: self.id }] } + match colour { Colour::Red => self.deal_red_damage(amount), Colour::Blue => self.deal_blue_damage(amount), @@ -543,7 +545,6 @@ impl Construct { fn deal_red_damage(&mut self, amount: usize) -> Vec { let mut events = vec![]; - if self.is_ko() { return events; } let construct = self.id; let modified_amount = self.modified_amount(amount, Stat::RedDamageReceived); @@ -599,8 +600,6 @@ impl Construct { let red_healing = self.red_life.value - current_red_life; let overhealing = recharge - red_healing; - println!("{:?} {:?} {:?} {:?}", recharge, green_healing, red_healing, self.red_life); - if green_healing > 0 { events.push( Event::Healing { @@ -630,8 +629,6 @@ impl Construct { fn deal_blue_damage(&mut self, amount: usize) -> Vec { let mut events = vec![]; - - if self.is_ko() { return events; } let construct = self.id; let modified_amount = self.modified_amount(amount, Stat::BlueDamageReceived); @@ -712,7 +709,6 @@ impl Construct { fn red_healing(&mut self, amount: usize) -> Vec { let mut events = vec![]; - if self.is_ko() { return events; } let mods = self.effects.iter() .filter(|e| e.effect.modifications().contains(&Stat::RedHealingReceived)) @@ -762,7 +758,6 @@ impl Construct { fn green_healing(&mut self, amount: usize) -> Vec { let mut events = vec![]; - if self.is_ko() { return events; } let mods = self.effects.iter() .filter(|e| e.effect.modifications().contains(&Stat::GreenHealingReceived)) @@ -813,7 +808,6 @@ impl Construct { fn blue_healing(&mut self, amount: usize) -> Vec { let mut events = vec![]; - if self.is_ko() { return events; } let mods = self.effects.iter() .filter(|e| e.effect.modifications().contains(&Stat::BlueHealingReceived)) @@ -862,7 +856,7 @@ impl Construct { } pub fn effect_add(&mut self, effect: ConstructEffect) -> Vec { - if self.is_ko() { return vec![] } + if self.is_ko() { return vec![Event::TargetKo { construct: self.id }] } if self.affected(Effect::Banish) { panic!("banish immunity not fixt yet") } @@ -889,7 +883,7 @@ impl Construct { } pub fn effect_remove(&mut self, effect: Effect) -> Vec { - if self.is_ko() { return vec![] } + if self.is_ko() { return vec![Event::TargetKo { construct: self.id }] } if let Some(p) = self.effects.iter().position(|ce| ce.effect == effect) { self.effects.remove(p); @@ -905,7 +899,7 @@ impl Construct { pub fn remove_all(&mut self) -> Vec { let mut removals = vec![]; - if self.is_ko() { return removals } + if self.is_ko() { return vec![Event::TargetKo { construct: self.id }] } while let Some(ce) = self.effects.pop() { removals.push(Event::Removal { @@ -919,7 +913,7 @@ impl Construct { } pub fn damage_trigger_casts(&mut self, cast: &Cast, event: &Event) -> Vec { - if self.is_ko() { return vec![] } + if self.is_ko() { return vec![] } match event { Event::Damage { construct, colour, amount, mitigation, display: _ } => { diff --git a/core/src/game.rs b/core/src/game.rs index 170862e3..66e39805 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -423,8 +423,8 @@ impl Game { |c| c.effects .iter() .cloned() - .filter_map(|e| e.tick)) - .collect::>(); + .filter_map(|e| e.tick) + ).collect::>(); // add them to the stack self.stack.append(&mut ticks); @@ -902,6 +902,7 @@ pub enum Event { Inversion { construct: Uuid }, Reflection { construct: Uuid }, Ko { construct: Uuid }, + TargetKo { construct: Uuid }, CooldownIncrease { construct: Uuid, turns: usize }, CooldownDecrease { construct: Uuid, turns: usize }, @@ -1636,8 +1637,6 @@ mod tests { let target = game.players[1].constructs[0].id; game.add_skill(player_id, source, target, Skill::Attack).unwrap(); game = game.resolve_phase_start(); - - println!("{:?}", game); } #[test] @@ -1648,8 +1647,6 @@ mod tests { let target = game.players[1].constructs[0].id; game.resolve(Cast::new(source, player_id, target, Skill::Bash)); - - println!("{:?}", game.resolutions); } #[test] @@ -1713,19 +1710,20 @@ mod tests { game.resolve(Cast::new(source, player_id, target, Skill::Siphon)); + // assert!(resolutions.iter().any(|r| match r.event { + // Event::Damage { construct, colour, amount, mitigation: _, display: _ } => + // construct == target && amount > 0 && colour == Colour::Blue, + // _ => false, + // })); + + // assert!(resolutions.iter().any(|r| match r.event { + // Event::Healing { construct, colour, amount, overhealing: _ } => + // construct == source && amount > 0 && colour == Colour::Green, + // _ => false, + // })); + 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::Damage { construct, colour, amount, mitigation: _, display: _ } => - construct == target && amount > 0 && colour == Colour::Blue, - _ => false, - })); - - assert!(resolutions.iter().any(|r| match r.event { - Event::Healing { construct, colour, amount, overhealing: _ } => - construct == source && amount > 0 && colour == Colour::Green, - _ => false, - })); + println!("{:#?}", resolutions); } }