From 0ff02de485051fa0fc375a14b60c54ba02756f3c Mon Sep 17 00:00:00 2001 From: Bug Hunter Date: Thu, 14 Jan 2021 13:29:48 +0000 Subject: [PATCH] commander LTB triggers before returning to command zone --- .../src/main/java/forge/game/GameAction.java | 27 +++++++++++++++++++ .../src/main/java/forge/game/card/Card.java | 9 +++++++ .../main/java/forge/game/player/Player.java | 3 ++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 338d5a1100f..45e8ab183d3 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -33,6 +33,7 @@ import forge.game.keyword.KeywordInterface; import forge.game.mulligan.MulliganService; import forge.game.player.GameLossReason; import forge.game.player.Player; +import forge.game.player.PlayerActionConfirmMode; import forge.game.replacement.ReplacementEffect; import forge.game.replacement.ReplacementResult; import forge.game.replacement.ReplacementType; @@ -539,6 +540,10 @@ public class GameAction { AttachEffect.attachAuraOnIndirectEnterBattlefield(c); } + if (c.isCommander()) { + c.setMoveToCommandZone(true); + } + return c; } @@ -1048,6 +1053,17 @@ public class GameAction { checkAgain = true; } + if (game.getRules().hasAppliedVariant(GameType.Commander) && !checkAgain) { + Iterable cards = p.getCardsIn(ZoneType.Graveyard).threadSafeIterable(); + for (final Card c : cards) { + checkAgain |= stateBasedAction903_9a(c); + } + cards = p.getCardsIn(ZoneType.Exile).threadSafeIterable(); + for (final Card c : cards) { + checkAgain |= stateBasedAction903_9a(c); + } + } + if (handlePlaneswalkerRule(p, table)) { checkAgain = true; } @@ -1142,6 +1158,17 @@ public class GameAction { return checkAgain; } + private boolean stateBasedAction903_9a(Card c) { + if (c.isCommander() && c.canMoveToCommandZone()) { + c.setMoveToCommandZone(false); + if (c.getOwner().getController().confirmAction(c.getSpellPermanent(), PlayerActionConfirmMode.ChangeZoneToAltDestination, c.getName() + ": If a commander is in a graveyard or in exile and that card was put into that zone since the last time state-based actions were checked, its owner may put it into the command zone.")) { + moveTo(c.getOwner().getZone(ZoneType.Command), c, null); + return true; + } + } + return false; + } + private boolean stateBasedAction704_5r(Card c) { boolean checkAgain = false; final CounterType p1p1 = CounterType.get(CounterEnumType.P1P1); diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index c7c65583eab..4eaf337c326 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -153,6 +153,8 @@ public class Card extends GameEntity implements Comparable, IHasSVars { private final Map assignedDamageMap = Maps.newTreeMap(); private boolean isCommander = false; + private boolean canMoveToCommandZone = false; + private boolean startsGameInPlay = false; private boolean drawnThisTurn = false; private boolean becameTargetThisTurn = false; @@ -5999,6 +6001,13 @@ public class Card extends GameEntity implements Comparable, IHasSVars { view.updateCommander(this); } + public boolean canMoveToCommandZone() { + return canMoveToCommandZone; + } + public void setMoveToCommandZone(boolean b) { + canMoveToCommandZone = b; + } + public void setSplitStateToPlayAbility(final SpellAbility sa) { CardStateName stateName = sa.getCardState(); if (hasState(stateName)) { diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index acf40a3489e..877158b6a3f 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -3124,7 +3124,8 @@ public class Player extends GameEntity implements Comparable { if (game.getRules().hasAppliedVariant(GameType.TinyLeaders)) { moved += " | Destination$ Graveyard,Exile | Description$ If a commander would be put into its owner's graveyard or exile from anywhere, that player may put it into the command zone instead."; } else { - moved += " | Destination$ Graveyard,Exile,Hand,Library | Description$ If a commander would be exiled or put into hand, graveyard, or library from anywhere, that player may put it into the command zone instead."; + // rule 903.9b + moved += " | Destination$ Hand,Library | Description$ If a commander would be put into its owner’s hand or library from anywhere, its owner may put it into the command zone instead."; } eff.addReplacementEffect(ReplacementHandler.parseReplacement(moved, eff, true)); }