Merge branch 'fixCommanderReplacement' into 'master'

commander LTB triggers before returning to command zone

Closes #1493

See merge request core-developers/forge!3565
This commit is contained in:
Hans Mackowiak
2021-01-14 13:29:48 +00:00
3 changed files with 38 additions and 1 deletions

View File

@@ -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<Card> 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);

View File

@@ -153,6 +153,8 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
private final Map<Card, Integer> 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<Card>, 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)) {

View File

@@ -3124,7 +3124,8 @@ public class Player extends GameEntity implements Comparable<Player> {
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 owners hand or library from anywhere, its owner may put it into the command zone instead.";
}
eff.addReplacementEffect(ReplacementHandler.parseReplacement(moved, eff, true));
}