From 488e7a9290c56529b1344ce02d44851af2e3dfda Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 25 Mar 2015 13:58:01 +0100 Subject: [PATCH] * Implemented latest Commander rule changes concerning zone changes. --- .../src/mage/game/CommanderDuelMatch.java | 6 +- .../mage/game/CommanderFreeForAllMatch.java | 6 +- .../src/mage/game/TinyLeadersDuelMatch.java | 2 +- .../CommanderReplacementEffect.java | 78 +++++++++++-------- Mage/src/mage/game/GameCommanderImpl.java | 10 +-- Mage/src/mage/game/GameTinyLeadersImpl.java | 10 +-- 6 files changed, 62 insertions(+), 50 deletions(-) diff --git a/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelMatch.java b/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelMatch.java index 1fa48a6133..f0b3a26118 100644 --- a/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelMatch.java +++ b/Mage.Server.Plugins/Mage.Game.CommanderDuel/src/mage/game/CommanderDuelMatch.java @@ -44,15 +44,15 @@ public class CommanderDuelMatch extends MatchImpl { @Override public void startGame() throws GameException { int startLife = 40; - boolean alsoLibrary = false; + boolean alsoHand = true; // Don't like it to compare but seems like it's complicated to do it in another way if (options.getDeckType().equals("Variant Magic - Duel Commander")) { startLife = 30; - alsoLibrary = true; + alsoHand = false; } CommanderDuel game = new CommanderDuel(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife); game.setStartMessage(this.createGameStartMessage()); - game.setAlsoLibrary(alsoLibrary); + game.setAlsoHand(alsoHand); initGame(game); games.add(game); } diff --git a/Mage.Server.Plugins/Mage.Game.CommanderFreeForAll/src/mage/game/CommanderFreeForAllMatch.java b/Mage.Server.Plugins/Mage.Game.CommanderFreeForAll/src/mage/game/CommanderFreeForAllMatch.java index 3e6caf776c..e8eb1bd46d 100644 --- a/Mage.Server.Plugins/Mage.Game.CommanderFreeForAll/src/mage/game/CommanderFreeForAllMatch.java +++ b/Mage.Server.Plugins/Mage.Game.CommanderFreeForAll/src/mage/game/CommanderFreeForAllMatch.java @@ -44,14 +44,14 @@ public class CommanderFreeForAllMatch extends MatchImpl { @Override public void startGame() throws GameException { int startLife = 40; - boolean alsoLibrary = false; + boolean alsoHand = true; if (options.getDeckType().equals("Variant Magic - Duel Commander")) { startLife = 30; - alsoLibrary = true; + alsoHand = false; } CommanderFreeForAll game = new CommanderFreeForAll(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife); game.setStartMessage(this.createGameStartMessage()); - game.setAlsoLibrary(alsoLibrary); + game.setAlsoHand(alsoHand); initGame(game); games.add(game); } diff --git a/Mage.Server.Plugins/Mage.Game.TinyLeadersDuel/src/mage/game/TinyLeadersDuelMatch.java b/Mage.Server.Plugins/Mage.Game.TinyLeadersDuel/src/mage/game/TinyLeadersDuelMatch.java index 6349384e7c..6ec787ca9d 100644 --- a/Mage.Server.Plugins/Mage.Game.TinyLeadersDuel/src/mage/game/TinyLeadersDuelMatch.java +++ b/Mage.Server.Plugins/Mage.Game.TinyLeadersDuel/src/mage/game/TinyLeadersDuelMatch.java @@ -50,7 +50,7 @@ public class TinyLeadersDuelMatch extends MatchImpl { game.setStartMessage(this.createGameStartMessage()); //Tucking a Tiny Leader is legal - game.setAlsoLibrary(false); + game.setAlsoHand(true); this.initGame(game); games.add(game); } diff --git a/Mage/src/mage/abilities/effects/common/continuous/CommanderReplacementEffect.java b/Mage/src/mage/abilities/effects/common/continuous/CommanderReplacementEffect.java index eab3273ce1..842ed2554a 100644 --- a/Mage/src/mage/abilities/effects/common/continuous/CommanderReplacementEffect.java +++ b/Mage/src/mage/abilities/effects/common/continuous/CommanderReplacementEffect.java @@ -54,20 +54,20 @@ import mage.players.Player; public class CommanderReplacementEffect extends ReplacementEffectImpl { private final UUID commanderId; - private final boolean alsoLibrary; + private final boolean alsoHand; - public CommanderReplacementEffect(UUID commanderId, boolean alsoLibrary) { + public CommanderReplacementEffect(UUID commanderId, boolean alsoHand) { super(Duration.WhileOnBattlefield, Outcome.Benefit); staticText = "If a commander would be put into its owner’s graveyard from anywhere, that player may put it into the command zone instead. If a commander would be put into the exile zone from anywhere, its owner may put it into the command zone instead."; this.commanderId = commanderId; this.duration = Duration.EndOfGame; - this.alsoLibrary = alsoLibrary; + this.alsoHand = alsoHand; } public CommanderReplacementEffect(final CommanderReplacementEffect effect) { super(effect); this.commanderId = effect.commanderId; - this.alsoLibrary = effect.alsoLibrary; + this.alsoHand = effect.alsoHand; } @Override @@ -81,7 +81,47 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl { } @Override - public boolean replaceEvent(GameEvent event, Ability source, Game game) { + public void init(Ability source, Game game) { + super.init(source, game); + if (commanderId == null) { + throw new IllegalArgumentException("commanderId has to be set"); + } + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + switch(((ZoneChangeEvent)event).getToZone()) { + case HAND: + if (!alsoHand) { + return false; + } + case GRAVEYARD: + case EXILED: + case LIBRARY: + if(commanderId.equals(event.getTargetId())){ + return true; + } + break; + case STACK: + Spell spell = game.getStack().getSpell(event.getTargetId()); + if (spell != null) { + if (commanderId.equals(spell.getSourceId())) { + return true; + } + } + break; + + } + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { if (((ZoneChangeEvent)event).getFromZone() == Zone.BATTLEFIELD) { Permanent permanent = ((ZoneChangeEvent)event).getTarget(); if (permanent != null) { @@ -114,32 +154,4 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl { } return false; } - @Override - public boolean checksEventType(GameEvent event, Game game) { - return event.getType() == GameEvent.EventType.ZONE_CHANGE; - } - - @Override - public boolean applies(GameEvent event, Ability source, Game game) { - if (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD || - ((ZoneChangeEvent)event).getToZone() == Zone.EXILED || - (alsoLibrary && ((ZoneChangeEvent)event).getToZone() == Zone.LIBRARY)) - { - if (commanderId != null) { - if (((ZoneChangeEvent)event).getFromZone().equals(Zone.STACK)) { - Spell spell = game.getStack().getSpell(event.getTargetId()); - if (spell != null) { - if (commanderId.equals(spell.getSourceId())) { - return true; - } - } - } - if(commanderId.equals(event.getTargetId())){ - return true; - } - } - } - return false; - } - } diff --git a/Mage/src/mage/game/GameCommanderImpl.java b/Mage/src/mage/game/GameCommanderImpl.java index d50f8adc3e..980dcc22ee 100644 --- a/Mage/src/mage/game/GameCommanderImpl.java +++ b/Mage/src/mage/game/GameCommanderImpl.java @@ -59,7 +59,7 @@ public abstract class GameCommanderImpl extends GameImpl { private final Map mulliganedCards = new HashMap<>(); private final Set commanderCombatWatcher = new HashSet<>(); - protected boolean alsoLibrary; // replace also commander going to library + protected boolean alsoHand; // replace also commander going to hand protected boolean startingPlayerSkipsDraw = true; public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) { @@ -68,7 +68,7 @@ public abstract class GameCommanderImpl extends GameImpl { public GameCommanderImpl(final GameCommanderImpl game) { super(game); - this.alsoLibrary = game.alsoLibrary; + this.alsoHand = game.alsoHand; this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw; } @@ -84,7 +84,7 @@ public abstract class GameCommanderImpl extends GameImpl { if (commander != null) { player.setCommanderId(commander.getId()); commander.moveToZone(Zone.COMMAND, null, this, true); - ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoLibrary)); + ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand)); ability.addEffect(new CommanderCostModification(commander.getId())); ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander))); getState().setValue(commander.getId() + "_castCount", 0); @@ -211,8 +211,8 @@ public abstract class GameCommanderImpl extends GameImpl { return !player.getId().equals(playerToCheck); } - public void setAlsoLibrary(boolean alsoLibrary) { - this.alsoLibrary = alsoLibrary; + public void setAlsoHand(boolean alsoHand) { + this.alsoHand = alsoHand; } } diff --git a/Mage/src/mage/game/GameTinyLeadersImpl.java b/Mage/src/mage/game/GameTinyLeadersImpl.java index 57f886fa72..06d1a7a217 100644 --- a/Mage/src/mage/game/GameTinyLeadersImpl.java +++ b/Mage/src/mage/game/GameTinyLeadersImpl.java @@ -59,7 +59,7 @@ import mage.watchers.common.CommanderInfoWatcher; */ public abstract class GameTinyLeadersImpl extends GameImpl{ - protected boolean alsoLibrary; // replace also commander going to library + protected boolean alsoHand; // replace also commander going to library protected boolean startingPlayerSkipsDraw = true; public GameTinyLeadersImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) { @@ -68,7 +68,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl{ public GameTinyLeadersImpl(final GameTinyLeadersImpl game) { super(game); - this.alsoLibrary = game.alsoLibrary; + this.alsoHand = game.alsoHand; this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw; } @@ -86,7 +86,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl{ this.loadCards(cards, playerId); player.setCommanderId(commander.getId()); commander.moveToZone(Zone.COMMAND, null, this, true); - ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoLibrary)); + ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand)); ability.addEffect(new CommanderCostModification(commander.getId())); ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander))); getState().setValue(commander.getId() + "_castCount", 0); @@ -152,8 +152,8 @@ public abstract class GameTinyLeadersImpl extends GameImpl{ return !player.getId().equals(playerToCheck); } - public void setAlsoLibrary(boolean alsoLibrary) { - this.alsoLibrary = alsoLibrary; + public void setAlsoHand(boolean alsoHand) { + this.alsoHand = alsoHand; } }