From 49bce836f9bda8db1597d6316a41a23332877792 Mon Sep 17 00:00:00 2001 From: Grath <1895280+Grath@users.noreply.github.com> Date: Mon, 30 Sep 2024 22:08:58 -0400 Subject: [PATCH] Change Duration.UntilTheNextEndStep to statically end during the beginning of EndStep. --- .../abilities/effects/ContinuousEffect.java | 2 -- .../effects/ContinuousEffectImpl.java | 26 ++++--------------- .../abilities/effects/ContinuousEffects.java | 22 +++++++++++++--- .../effects/ContinuousEffectsList.java | 25 +++++++++++++++++- Mage/src/main/java/mage/game/GameState.java | 5 ++++ .../src/main/java/mage/game/turn/EndStep.java | 9 +++++++ 6 files changed, 61 insertions(+), 28 deletions(-) diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffect.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffect.java index 3b0cddcbf60..c1456292c37 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffect.java @@ -74,8 +74,6 @@ public interface ContinuousEffect extends Effect { boolean isYourNextEndStep(Game game); - boolean isTheNextEndStep(Game game); - boolean isYourNextUpkeepStep(Game game); @Override diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java index d09810fd2b9..c8a5b78dd0e 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectImpl.java @@ -56,11 +56,9 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu // until your next turn or until end of your next turn private UUID startingControllerId; // player to check for turn duration (can't different with real controller ability) - private UUID startingActivePlayerId; // Player whose turn the effect started on private boolean startingTurnWasActive; // effect started during related players turn and related players turn was already active private int effectStartingOnTurn = 0; // turn the effect started - private int effectStartingControllerEndStep = 0; - private int effectStartingActivePlayerEndStep = 0; + private int effectStartingEndStep = 0; private int nextTurnNumber = Integer.MAX_VALUE; // effect is waiting for a step during your next turn, we store it if found. // set to the turn number on your next turn. private int effectStartingStepNum = 0; // Some continuous are waiting for the next step of a kind. @@ -93,11 +91,9 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu this.affectedObjectList.addAll(effect.affectedObjectList); this.temporary = effect.temporary; this.startingControllerId = effect.startingControllerId; - this.startingActivePlayerId = effect.startingActivePlayerId; this.startingTurnWasActive = effect.startingTurnWasActive; this.effectStartingOnTurn = effect.effectStartingOnTurn; - this.effectStartingControllerEndStep = effect.effectStartingControllerEndStep; - this.effectStartingActivePlayerEndStep = effect.effectStartingActivePlayerEndStep; + this.effectStartingEndStep = effect.effectStartingEndStep; this.dependencyTypes = effect.dependencyTypes; this.dependendToTypes = effect.dependendToTypes; this.characterDefining = effect.characterDefining; @@ -255,12 +251,10 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu @Override public void setStartingControllerAndTurnNum(Game game, UUID startingController, UUID activePlayerId) { this.startingControllerId = startingController; - this.startingActivePlayerId = activePlayerId; this.startingTurnWasActive = activePlayerId != null && activePlayerId.equals(startingController); // you can't use "game" for active player cause it's called from tests/cheat too this.effectStartingOnTurn = game.getTurnNum(); - this.effectStartingControllerEndStep = EndStepCountWatcher.getCount(startingController, game); - this.effectStartingActivePlayerEndStep = EndStepCountWatcher.getCount(activePlayerId, game); + this.effectStartingEndStep = EndStepCountWatcher.getCount(startingController, game); this.effectStartingStepNum = game.getState().getStepNum(); } @@ -272,12 +266,7 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu @Override public boolean isYourNextEndStep(Game game) { - return EndStepCountWatcher.getCount(startingControllerId, game) > effectStartingControllerEndStep; - } - - @Override - public boolean isTheNextEndStep(Game game) { - return EndStepCountWatcher.getCount(startingActivePlayerId, game) > effectStartingActivePlayerEndStep; + return EndStepCountWatcher.getCount(startingControllerId, game) > effectStartingEndStep; } public boolean isEndCombatOfYourNextTurn(Game game) { @@ -302,14 +291,13 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu @Override public boolean isInactive(Ability source, Game game) { - // YOUR turn checks, players who left the game, and the next end step + // YOUR turn checks, players who left the game // until end of turn - must be checked on cleanup step, see rules 514.2 // other must checked here (active and leave players), see rules 800.4 switch (duration) { case UntilYourNextTurn: case UntilEndOfYourNextTurn: case UntilYourNextEndStep: - case UntilTheNextEndStep: case UntilEndCombatOfYourNextTurn: case UntilYourNextUpkeepStep: break; @@ -354,10 +342,6 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu return this.isYourNextEndStep(game); } break; - case UntilTheNextEndStep: - if (player != null && player.isInGame()) { - return this.isTheNextEndStep(game); - } case UntilEndCombatOfYourNextTurn: if (player != null && player.isInGame()) { return this.isEndCombatOfYourNextTurn(game); diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java index 35a309dff83..8dd4e6cf9ea 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffects.java @@ -120,8 +120,8 @@ public class ContinuousEffects implements Serializable { preventionEffects.removeEndOfCombatEffects(); requirementEffects.removeEndOfCombatEffects(); restrictionEffects.removeEndOfCombatEffects(); - for (ContinuousEffectsList asThoughtlist : asThoughEffectsMap.values()) { - asThoughtlist.removeEndOfCombatEffects(); + for (ContinuousEffectsList asThoughlist : asThoughEffectsMap.values()) { + asThoughlist.removeEndOfCombatEffects(); } costModificationEffects.removeEndOfCombatEffects(); spliceCardEffects.removeEndOfCombatEffects(); @@ -134,13 +134,27 @@ public class ContinuousEffects implements Serializable { preventionEffects.removeEndOfTurnEffects(game); requirementEffects.removeEndOfTurnEffects(game); restrictionEffects.removeEndOfTurnEffects(game); - for (ContinuousEffectsList asThoughtlist : asThoughEffectsMap.values()) { - asThoughtlist.removeEndOfTurnEffects(game); + for (ContinuousEffectsList asThoughlist : asThoughEffectsMap.values()) { + asThoughlist.removeEndOfTurnEffects(game); } costModificationEffects.removeEndOfTurnEffects(game); spliceCardEffects.removeEndOfTurnEffects(game); } + public synchronized void removeBeginningOfEndStepEffects(Game game) { + layeredEffects.removeBeginningOfEndStepEffects(game); + continuousRuleModifyingEffects.removeBeginningOfEndStepEffects(game); + replacementEffects.removeBeginningOfEndStepEffects(game); + preventionEffects.removeBeginningOfEndStepEffects(game); + requirementEffects.removeBeginningOfEndStepEffects(game); + restrictionEffects.removeBeginningOfEndStepEffects(game); + for (ContinuousEffectsList asThoughlist : asThoughEffectsMap.values()) { + asThoughlist.removeBeginningOfEndStepEffects(game); + } + costModificationEffects.removeBeginningOfEndStepEffects(game); + spliceCardEffects.removeBeginningOfEndStepEffects(game); + } + public synchronized void removeInactiveEffects(Game game) { layeredEffects.removeInactiveEffects(game); continuousRuleModifyingEffects.removeInactiveEffects(game); diff --git a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java index a75c476971b..0bcfbb6e00e 100644 --- a/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java +++ b/Mage/src/main/java/mage/abilities/effects/ContinuousEffectsList.java @@ -71,6 +71,29 @@ public class ContinuousEffectsList extends ArrayList } } + public void removeBeginningOfEndStepEffects(Game game) { + // calls every turn on beginning of end step + // rules 514.2 + for (Iterator i = this.iterator(); i.hasNext(); ) { + T entry = i.next(); + boolean canRemove; + switch (entry.getDuration()) { + case UntilTheNextEndStep: + canRemove = true; + break; + case UntilYourNextEndStep: + canRemove = entry.isYourNextEndStep(game); + break; + default: + canRemove = false; + } + if (canRemove) { + i.remove(); + effectAbilityMap.remove(entry.getId()); + } + } + } + public void removeEndOfCombatEffects() { for (Iterator i = this.iterator(); i.hasNext(); ) { T entry = i.next(); @@ -156,7 +179,6 @@ public class ContinuousEffectsList extends ArrayList case UntilEndOfYourNextTurn: case UntilEndCombatOfYourNextTurn: case UntilYourNextEndStep: - case UntilTheNextEndStep: case UntilYourNextUpkeepStep: // until your turn effects continue until real turn reached, their used it's own inactive method // 514.2 Second, the following actions happen simultaneously: all damage marked on permanents @@ -170,6 +192,7 @@ public class ContinuousEffectsList extends ArrayList } break; case EndOfTurn: + case UntilTheNextEndStep: // end of turn discards on cleanup steps // 514.2 break; diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index e9238b39ab5..889ec20af27 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -692,6 +692,11 @@ public class GameState implements Serializable, Copyable { game.applyEffects(); } + // remove beginning of end step effects + public void removeBoESEffects(Game game) { + effects.removeBeginningOfEndStepEffects(game); + } + public void removeTurnStartEffect(Game game) { delayed.removeStartOfNewTurn(game); } diff --git a/Mage/src/main/java/mage/game/turn/EndStep.java b/Mage/src/main/java/mage/game/turn/EndStep.java index d23ef87d7c8..26d32f20e17 100644 --- a/Mage/src/main/java/mage/game/turn/EndStep.java +++ b/Mage/src/main/java/mage/game/turn/EndStep.java @@ -3,8 +3,11 @@ package mage.game.turn; import mage.constants.PhaseStep; +import mage.game.Game; import mage.game.events.GameEvent.EventType; +import java.util.UUID; + /** * @author BetaSteward_at_googlemail.com */ @@ -26,4 +29,10 @@ public class EndStep extends Step { return new EndStep(this); } + @Override + public void beginStep(Game game, UUID activePlayerId) { + super.beginStep(game, activePlayerId); + + game.getState().removeBoESEffects(game); + } }