From 47b92a5b801b7e6628c5c14bf296987c554ffe0a Mon Sep 17 00:00:00 2001 From: ntr Date: Tue, 10 Dec 2019 16:51:31 +1000 Subject: [PATCH] invert test --- core/src/construct.rs | 54 +++++++++++++++++++++---------------------- core/src/game.rs | 43 +++++++++++++++++++++++++++++++++- 2 files changed, 69 insertions(+), 28 deletions(-) diff --git a/core/src/construct.rs b/core/src/construct.rs index d612e62f..f162c8d3 100644 --- a/core/src/construct.rs +++ b/core/src/construct.rs @@ -482,8 +482,6 @@ impl Construct { } // Stats - - // fixme put everything through this fn pub fn stat(&self, stat: Stat) -> usize { match stat { Stat::RedLife => self.red_life.value, @@ -548,7 +546,7 @@ impl Construct { if self.is_ko() { return events; } let construct = self.id; - let modified_power = self.modified_amount(amount, Stat::RedDamageReceived); + let modified_amount = self.modified_amount(amount, Stat::RedDamageReceived); match self.affected(Effect::Invert) { false => { @@ -556,8 +554,8 @@ impl Construct { // eg 50 red_life 25 damage -> 0 remainder 25 mitigation // 50 red_life 100 damage -> 50 remainder 50 mitigation // 50 red_life 5 damage -> 0 remainder 5 mitigation - let remainder = modified_power.saturating_sub(self.red_life.value); - let mitigation = modified_power.saturating_sub(remainder); + let remainder = modified_amount.saturating_sub(self.red_life.value); + let mitigation = modified_amount.saturating_sub(remainder); // reduce red_life by mitigation amount self.red_life.reduce(mitigation); @@ -591,16 +589,18 @@ impl Construct { // 100 red healing // 50 red overhealing let current_green_life = self.stat(Stat::GreenLife); - self.green_life.increase(modified_power); + self.green_life.increase(modified_amount); let new_green_life = self.green_life.value; let green_healing = new_green_life - current_green_life; - let recharge = modified_power - green_healing; + let recharge = modified_amount - green_healing; let current_red_life = self.red_life.value; self.red_life.increase(recharge); 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 { @@ -618,7 +618,7 @@ impl Construct { construct, amount: recharge, overhealing, - colour: Colour::Blue + colour: Colour::Red } ); } @@ -634,12 +634,12 @@ impl Construct { if self.is_ko() { return events; } let construct = self.id; - let modified_power = self.modified_amount(amount, Stat::BlueDamageReceived); + let modified_amount = self.modified_amount(amount, Stat::BlueDamageReceived); match self.affected(Effect::Invert) { false => { - let remainder = modified_power.saturating_sub(self.blue_life.value); - let mitigation = modified_power.saturating_sub(remainder); + let remainder = modified_amount.saturating_sub(self.blue_life.value); + let mitigation = modified_amount.saturating_sub(remainder); // reduce blue_life by mitigation amount self.blue_life.reduce(mitigation); @@ -665,11 +665,11 @@ impl Construct { }, true => { let current_green_life = self.stat(Stat::GreenLife); - self.green_life.increase(modified_power); + self.green_life.increase(modified_amount); let new_green_life = self.green_life.value; let green_healing = new_green_life - current_green_life; - let recharge = modified_power - green_healing; + let recharge = modified_amount - green_healing; let current_blue_life = self.blue_life.value; self.blue_life.increase(recharge); let blue_healing = self.blue_life.value - current_blue_life; @@ -719,16 +719,16 @@ impl Construct { .map(|e| (e.effect, e.meta)) .collect::)>>(); - let modified_power = mods.iter() + let modified_amount = mods.iter() .fold(amount, |acc, fx| fx.0.apply(acc, fx.1)); match self.affected(Effect::Invert) { false => { let current_red_life = self.stat(Stat::RedLife); - self.red_life.increase(modified_power); + self.red_life.increase(modified_amount); let new_red_life = self.red_life.value; let healing = new_red_life - current_red_life; - let overhealing = modified_power - healing; + let overhealing = modified_amount - healing; if healing != 0 { events.push(Event::Healing { construct: self.id, amount: healing, overhealing, colour: Colour::Red }); @@ -736,8 +736,8 @@ impl Construct { }, true => { // Recharge takes a red and blue amount so check for them - let red_remainder = modified_power.saturating_sub(self.red_life.value); - let red_mitigation = modified_power.saturating_sub(red_remainder); + let red_remainder = modified_amount.saturating_sub(self.red_life.value); + let red_mitigation = modified_amount.saturating_sub(red_remainder); // reduce red_life by mitigation amount self.red_life.reduce(red_mitigation); @@ -769,17 +769,17 @@ impl Construct { .map(|e| (e.effect, e.meta)) .collect::)>>(); - let modified_power = mods.iter() + let modified_amount = mods.iter() .fold(amount, |acc, fx| fx.0.apply(acc, fx.1)); match self.affected(Effect::Invert) { false => { let current_green_life = self.stat(Stat::GreenLife); - self.green_life.increase(modified_power); + self.green_life.increase(modified_amount); let new_green_life = self.green_life.value; let healing = new_green_life - current_green_life; - let overhealing = modified_power - healing; + let overhealing = modified_amount - healing; events.push(Event::Healing { construct: self.id, @@ -791,7 +791,7 @@ impl Construct { true => { // there is no green shield (yet) let current_green_life = self.stat(Stat::GreenLife); - self.reduce_green_life(modified_power); + self.reduce_green_life(modified_amount); let delta = current_green_life - self.stat(Stat::GreenLife); events.push(Event::Damage { @@ -820,16 +820,16 @@ impl Construct { .map(|e| (e.effect, e.meta)) .collect::)>>(); - let modified_power = mods.iter() + let modified_amount = mods.iter() .fold(amount, |acc, fx| fx.0.apply(acc, fx.1)); match self.affected(Effect::Invert) { false => { let current_blue_life = self.stat(Stat::BlueLife); - self.blue_life.increase(modified_power); + self.blue_life.increase(modified_amount); let new_blue_life = self.blue_life.value; let healing = new_blue_life - current_blue_life; - let overhealing = modified_power - healing; + let overhealing = modified_amount - healing; if healing != 0 { events.push(Event::Healing { construct: self.id, amount: healing, overhealing, colour: Colour::Red }); @@ -837,8 +837,8 @@ impl Construct { }, true => { // Recharge takes a red and blue amount so check for them - let blue_remainder = modified_power.saturating_sub(self.blue_life.value); - let blue_mitigation = modified_power.saturating_sub(blue_remainder); + let blue_remainder = modified_amount.saturating_sub(self.blue_life.value); + let blue_mitigation = modified_amount.saturating_sub(blue_remainder); // reduce blue_life by mitigation amount self.blue_life.reduce(blue_mitigation); diff --git a/core/src/game.rs b/core/src/game.rs index 344353e9..abf3165c 100644 --- a/core/src/game.rs +++ b/core/src/game.rs @@ -1660,6 +1660,47 @@ mod tests { let target = game.players[1].constructs[0].id; game.resolve(Cast::new(source, player_id, target, Skill::Slay)); - println!("{:#?}", game.resolutions); + + 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::Red, + _ => false, + })); + + assert!(resolutions.iter().any(|r| match r.event { + Event::Damage { construct, colour, amount, mitigation: _, display: _ } => + construct == target && amount > 0 && colour == Colour::Red, + _ => false, + })); + } + + #[test] + fn invert_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::Invert)); + game.resolve(Cast::new(source, player_id, target, Skill::Strike)); + + 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: _ } => + construct == target && amount > 0 && colour == Colour::Green, + _ => false, + })); + + assert!(resolutions.iter().any(|r| match r.event { + Event::Healing { construct, colour, amount, overhealing: _ } => + construct == target && amount > 0 && colour == Colour::Red, + _ => false, + })); } }