From 1dc305f3294311bbbf49d51d29771e431282c593 Mon Sep 17 00:00:00 2001 From: htrajan Date: Thu, 16 Apr 2020 19:21:54 -0700 Subject: [PATCH] -setStrictChooseMode and assertAllCommandsUsed in every test -store filter info in GameState -put instead of putIfAbsent --- .../cards/z/ZilorthaStrengthIncarnate.java | 2 +- .../iko/ZilorthaStrengthIncarnateTest.java | 29 +++++++++++++++---- Mage/src/main/java/mage/game/Game.java | 5 ---- Mage/src/main/java/mage/game/GameImpl.java | 21 +------------- Mage/src/main/java/mage/game/GameState.java | 15 ++++++++++ .../java/mage/game/combat/CombatGroup.java | 2 +- 6 files changed, 42 insertions(+), 32 deletions(-) diff --git a/Mage.Sets/src/mage/cards/z/ZilorthaStrengthIncarnate.java b/Mage.Sets/src/mage/cards/z/ZilorthaStrengthIncarnate.java index 4c5578c65b..6fc791ed35 100644 --- a/Mage.Sets/src/mage/cards/z/ZilorthaStrengthIncarnate.java +++ b/Mage.Sets/src/mage/cards/z/ZilorthaStrengthIncarnate.java @@ -61,7 +61,7 @@ class ZilorthaStrengthIncarnateEffect extends ContinuousEffectImpl { // Change the rule FilterCreaturePermanent filter = StaticFilters.FILTER_PERMANENT_CREATURE.copy(); filter.add(new ControllerIdPredicate(source.getControllerId())); - game.addPowerInsteadOfToughnessForDamageLethalityFilter(source.getSourceId(), filter); + game.getState().addPowerInsteadOfToughnessForDamageLethalityFilter(source.getSourceId(), filter); return true; } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/iko/ZilorthaStrengthIncarnateTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/iko/ZilorthaStrengthIncarnateTest.java index 58b02a0407..21818bf65c 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/iko/ZilorthaStrengthIncarnateTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/iko/ZilorthaStrengthIncarnateTest.java @@ -11,11 +11,6 @@ import org.mage.test.serverside.base.CardTestPlayerBase; */ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { - @After - public void after() { - assertAllCommandsUsed(); - } - @Test public void testNotPresent_combatDamageResolvesLethalityAsNormal() { addCard(Zone.BATTLEFIELD, playerA, "Savai Sabertooth"); @@ -24,7 +19,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { attack(1, playerA, "Savai Sabertooth"); block(1, playerB, "Drannith Healer", "Savai Sabertooth"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Savai Sabertooth", 1); assertGraveyardCount(playerB, "Drannith Healer", 1); @@ -39,7 +37,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { attack(1, playerA, "Savai Sabertooth"); block(1, playerB, "Drannith Healer", "Savai Sabertooth"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Savai Sabertooth", 0); assertGraveyardCount(playerB, "Drannith Healer", 1); @@ -58,7 +59,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { attack(1, playerA, "Aegis Turtle"); block(1, playerB, "Aegis Turtle", "Aegis Turtle"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Aegis Turtle", 0); assertGraveyardCount(playerB, "Aegis Turtle", 0); @@ -72,7 +76,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Spill", "Savai Sabertooth"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Savai Sabertooth", 1); assertGraveyardCount(playerB, "Flame Spill", 1); @@ -89,7 +96,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Flame Spill", "Savai Sabertooth"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Savai Sabertooth", 1); assertGraveyardCount(playerB, "Flame Spill", 1); @@ -114,7 +124,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Murder", "Zilortha, Strength Incarnate"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Zilortha, Strength Incarnate", 1); assertGraveyardCount(playerA, "Savai Sabertooth", 1); @@ -132,7 +145,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { attack(1, playerA, "Maned Serval"); block(1, playerB, "Maned Serval", "Maned Serval"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_COMBAT); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Maned Serval", 1); assertGraveyardCount(playerB, "Maned Serval", 1); @@ -152,7 +168,10 @@ public class ZilorthaStrengthIncarnateTest extends CardTestPlayerBase { castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Zilortha, Strength Incarnate"); + setStrictChooseMode(true); + setStopAt(1, PhaseStep.END_TURN); execute(); + assertAllCommandsUsed(); assertGraveyardCount(playerA, "Maned Serval", 1); assertGraveyardCount(playerB, "Maned Serval", 0); diff --git a/Mage/src/main/java/mage/game/Game.java b/Mage/src/main/java/mage/game/Game.java index fc96422d55..b41080c668 100644 --- a/Mage/src/main/java/mage/game/Game.java +++ b/Mage/src/main/java/mage/game/Game.java @@ -17,7 +17,6 @@ import mage.cards.decks.Deck; import mage.choices.Choice; import mage.constants.*; import mage.counters.Counters; -import mage.filter.common.FilterCreaturePermanent; import mage.game.combat.Combat; import mage.game.command.Commander; import mage.game.command.Emblem; @@ -487,8 +486,4 @@ public interface Game extends MageItem, Serializable { return getCommandersIds(player, CommanderCardType.ANY); } - void addPowerInsteadOfToughnessForDamageLethalityFilter(UUID source, FilterCreaturePermanent filter); - - List getActivePowerInsteadOfToughnessForDamageLethalityFilters(); - } diff --git a/Mage/src/main/java/mage/game/GameImpl.java b/Mage/src/main/java/mage/game/GameImpl.java index efa40d6f72..e367d7f763 100644 --- a/Mage/src/main/java/mage/game/GameImpl.java +++ b/Mage/src/main/java/mage/game/GameImpl.java @@ -70,9 +70,6 @@ import java.io.IOException; import java.io.Serializable; import java.util.*; import java.util.Map.Entry; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; public abstract class GameImpl implements Game, Serializable { @@ -149,8 +146,6 @@ public abstract class GameImpl implements Game, Serializable { // temporary store for income concede commands, don't copy private final LinkedList concedingPlayers = new LinkedList<>(); - private Map usePowerInsteadOfToughnessForDamageLethalityFilters = new HashMap<>(); - public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, Mulligan mulligan, int startLife, int startingSize) { this.id = UUID.randomUUID(); this.range = range; @@ -1897,7 +1892,7 @@ public abstract class GameImpl implements Game, Serializable { List legendary = new ArrayList<>(); List worldEnchantment = new ArrayList<>(); - List usePowerInsteadOfToughnessForDamageLethalityFilters = getActivePowerInsteadOfToughnessForDamageLethalityFilters(); + List usePowerInsteadOfToughnessForDamageLethalityFilters = getState().getActivePowerInsteadOfToughnessForDamageLethalityFilters(); for (Permanent perm : getBattlefield().getAllActivePermanents()) { if (perm.isCreature()) { //20091005 - 704.5f @@ -3320,18 +3315,4 @@ public abstract class GameImpl implements Game, Serializable { public Set getCommandersIds(Player player, CommanderCardType commanderCardType) { return player.getCommandersIds(); } - - @Override - public void addPowerInsteadOfToughnessForDamageLethalityFilter(UUID source, FilterCreaturePermanent filter) { - usePowerInsteadOfToughnessForDamageLethalityFilters.putIfAbsent(source, filter); - } - - @Override - public List getActivePowerInsteadOfToughnessForDamageLethalityFilters() { - return usePowerInsteadOfToughnessForDamageLethalityFilters.isEmpty() ? emptyList() : getBattlefield().getAllActivePermanents().stream() - .map(Card::getId) - .filter(usePowerInsteadOfToughnessForDamageLethalityFilters::containsKey) - .map(usePowerInsteadOfToughnessForDamageLethalityFilters::get) - .collect(Collectors.toList()); - } } diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index f9f344c666..604fe36b7e 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -10,6 +10,7 @@ import mage.cards.Card; import mage.cards.SplitCard; import mage.constants.Zone; import mage.designations.Designation; +import mage.filter.common.FilterCreaturePermanent; import mage.game.combat.Combat; import mage.game.combat.CombatGroup; import mage.game.command.Command; @@ -38,6 +39,8 @@ import java.io.Serializable; import java.util.*; import java.util.stream.Collectors; +import static java.util.Collections.emptyList; + /** * @author BetaSteward_at_googlemail.com *

@@ -96,6 +99,7 @@ public class GameState implements Serializable, Copyable { private Map zoneChangeCounter = new HashMap<>(); private Map copiedCards = new HashMap<>(); private int permanentOrderNumber; + private Map usePowerInsteadOfToughnessForDamageLethalityFilters = new HashMap<>(); private int applyEffectsCounter; // Upcounting number of each applyEffects execution @@ -1209,4 +1213,15 @@ public class GameState implements Serializable, Copyable { return applyEffectsCounter; } + public void addPowerInsteadOfToughnessForDamageLethalityFilter(UUID source, FilterCreaturePermanent filter) { + usePowerInsteadOfToughnessForDamageLethalityFilters.put(source, filter); + } + + public List getActivePowerInsteadOfToughnessForDamageLethalityFilters() { + return usePowerInsteadOfToughnessForDamageLethalityFilters.isEmpty() ? emptyList() : getBattlefield().getAllActivePermanents().stream() + .map(Card::getId) + .filter(usePowerInsteadOfToughnessForDamageLethalityFilters::containsKey) + .map(usePowerInsteadOfToughnessForDamageLethalityFilters::get) + .collect(Collectors.toList()); + } } diff --git a/Mage/src/main/java/mage/game/combat/CombatGroup.java b/Mage/src/main/java/mage/game/combat/CombatGroup.java index 85c83acd1b..d3d5926822 100644 --- a/Mage/src/main/java/mage/game/combat/CombatGroup.java +++ b/Mage/src/main/java/mage/game/combat/CombatGroup.java @@ -934,7 +934,7 @@ public class CombatGroup implements Serializable, Copyable { } public static int getLethalDamage(Permanent damagedPermanent, Game game) { - List usePowerInsteadOfToughnessForDamageLethalityFilters = game.getActivePowerInsteadOfToughnessForDamageLethalityFilters(); + List usePowerInsteadOfToughnessForDamageLethalityFilters = game.getState().getActivePowerInsteadOfToughnessForDamageLethalityFilters(); /* * for handling Zilortha, Strength Incarnate: * 2020-04-17