diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 0b85e914fc0..00a814b5d62 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -21,8 +21,6 @@ import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; - import forge.GameCommand; import forge.card.CardStateName; import forge.card.CardType; @@ -636,11 +634,14 @@ public class GameAction { return affectedCards; } - public final Set checkStateEffects(final boolean runEvents) { + public final void checkStateEffects(final boolean runEvents) { + checkStateEffects(runEvents, new HashSet()); + } + public final void checkStateEffects(final boolean runEvents, final Set allAffectedCards) { // sol(10/29) added for Phase updates, state effects shouldn't be // checked during Spell Resolution (except when persist-returning if (game.getStack().isResolving()) { - return Collections.emptySet(); + return; } // final JFrame frame = Singletons.getView().getFrame(); @@ -649,7 +650,7 @@ public class GameAction { // } if (game.isGameOver()) { - return Collections.emptySet(); + return; } // Max: I don't know where to put this! - but since it's a state based action, it must be in check state effects @@ -662,9 +663,7 @@ public class GameAction { game.getStack().setFrozen(true); TrackableObject.freeze(); //prevent views flickering during while updating for state-based effects - // do this multiple times, sometimes creatures/permanents will survive - // when they shouldn't - final Set allAffectedCards = Sets.newHashSet(); + // do this multiple times, sometimes creatures/permanents will survive when they shouldn't for (int q = 0; q < 9; q++) { final Set affectedCards = checkStaticAbilities(false); boolean checkAgain = false; @@ -775,14 +774,12 @@ public class GameAction { checkGameOverCondition(); if (game.getAge() != GameStage.Play) { - return Collections.emptySet(); + return; } game.getTriggerHandler().resetActiveTriggers(); if (!refreeze) { game.getStack().unfreezeStack(); } - - return allAffectedCards; } private boolean stateBasedAction704_5n(Card c) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/EndTurnEffect.java b/forge-game/src/main/java/forge/game/ability/effects/EndTurnEffect.java index ee4c7e5eb51..fd2ea7e66c5 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/EndTurnEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/EndTurnEffect.java @@ -17,7 +17,6 @@ public class EndTurnEffect extends SpellAbilityEffect { */ @Override public void resolve(SpellAbility sa) { - Game game = sa.getActivatingPlayer().getGame(); // Steps taken from gatherer's rulings on Time Stop. // 1) All spells and abilities on the stack are exiled. This includes diff --git a/forge-game/src/main/java/forge/game/phase/PhaseHandler.java b/forge-game/src/main/java/forge/game/phase/PhaseHandler.java index 20eae859f10..6bd708ad002 100644 --- a/forge-game/src/main/java/forge/game/phase/PhaseHandler.java +++ b/forge-game/src/main/java/forge/game/phase/PhaseHandler.java @@ -19,8 +19,6 @@ package forge.game.phase; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; - import forge.card.mana.ManaCost; import forge.game.*; import forge.game.ability.AbilityFactory; @@ -852,6 +850,8 @@ public class PhaseHandler implements java.io.Serializable { // don't even offer priority, because it's untap of 1st turn now givePriorityToPlayer = false; + final Set allAffectedCards = new HashSet(); + // MAIN GAME LOOP while (!game.isGameOver()) { if (givePriorityToPlayer) { @@ -864,18 +864,18 @@ public class PhaseHandler implements java.io.Serializable { int loopCount = 0; do { - final Set allAffectedCards = Sets.newHashSet(); - boolean addedAnythingToStack = false; - do { + do { // Rule 704.3 Whenever a player would get priority, the game checks ... for state-based actions, - allAffectedCards.addAll(game.getAction().checkStateEffects(false)); + game.getAction().checkStateEffects(false, allAffectedCards); if (game.isGameOver()) { return; // state-based effects check could lead to game over } - addedAnythingToStack = game.getStack().addAllTriggeredAbilitiesToStack(); - } while (addedAnythingToStack); + } while (game.getStack().addAllTriggeredAbilitiesToStack()); //loop so long as something was added to stack - game.fireEvent(new GameEventCardStatsChanged(allAffectedCards)); + if (!allAffectedCards.isEmpty()) { + game.fireEvent(new GameEventCardStatsChanged(allAffectedCards)); + allAffectedCards.clear(); + } if (playerTurn.hasLost() && pPlayerPriority.equals(playerTurn) && pFirstPriority.equals(playerTurn)) { // If the active player has lost, and they have priority, set the next player to have priority