* Implemented latest Commander rule changes concerning zone changes.

This commit is contained in:
LevelX2 2015-03-25 13:58:01 +01:00
parent 2f2ce63ca2
commit 488e7a9290
6 changed files with 62 additions and 50 deletions

View file

@ -44,15 +44,15 @@ public class CommanderDuelMatch extends MatchImpl {
@Override @Override
public void startGame() throws GameException { public void startGame() throws GameException {
int startLife = 40; 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 // 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")) { if (options.getDeckType().equals("Variant Magic - Duel Commander")) {
startLife = 30; startLife = 30;
alsoLibrary = true; alsoHand = false;
} }
CommanderDuel game = new CommanderDuel(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife); CommanderDuel game = new CommanderDuel(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife);
game.setStartMessage(this.createGameStartMessage()); game.setStartMessage(this.createGameStartMessage());
game.setAlsoLibrary(alsoLibrary); game.setAlsoHand(alsoHand);
initGame(game); initGame(game);
games.add(game); games.add(game);
} }

View file

@ -44,14 +44,14 @@ public class CommanderFreeForAllMatch extends MatchImpl {
@Override @Override
public void startGame() throws GameException { public void startGame() throws GameException {
int startLife = 40; int startLife = 40;
boolean alsoLibrary = false; boolean alsoHand = true;
if (options.getDeckType().equals("Variant Magic - Duel Commander")) { if (options.getDeckType().equals("Variant Magic - Duel Commander")) {
startLife = 30; startLife = 30;
alsoLibrary = true; alsoHand = false;
} }
CommanderFreeForAll game = new CommanderFreeForAll(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife); CommanderFreeForAll game = new CommanderFreeForAll(options.getAttackOption(), options.getRange(), options.getFreeMulligans(), startLife);
game.setStartMessage(this.createGameStartMessage()); game.setStartMessage(this.createGameStartMessage());
game.setAlsoLibrary(alsoLibrary); game.setAlsoHand(alsoHand);
initGame(game); initGame(game);
games.add(game); games.add(game);
} }

View file

@ -50,7 +50,7 @@ public class TinyLeadersDuelMatch extends MatchImpl {
game.setStartMessage(this.createGameStartMessage()); game.setStartMessage(this.createGameStartMessage());
//Tucking a Tiny Leader is legal //Tucking a Tiny Leader is legal
game.setAlsoLibrary(false); game.setAlsoHand(true);
this.initGame(game); this.initGame(game);
games.add(game); games.add(game);
} }

View file

@ -54,20 +54,20 @@ import mage.players.Player;
public class CommanderReplacementEffect extends ReplacementEffectImpl { public class CommanderReplacementEffect extends ReplacementEffectImpl {
private final UUID commanderId; 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); super(Duration.WhileOnBattlefield, Outcome.Benefit);
staticText = "If a commander would be put into its owners 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."; staticText = "If a commander would be put into its owners 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.commanderId = commanderId;
this.duration = Duration.EndOfGame; this.duration = Duration.EndOfGame;
this.alsoLibrary = alsoLibrary; this.alsoHand = alsoHand;
} }
public CommanderReplacementEffect(final CommanderReplacementEffect effect) { public CommanderReplacementEffect(final CommanderReplacementEffect effect) {
super(effect); super(effect);
this.commanderId = effect.commanderId; this.commanderId = effect.commanderId;
this.alsoLibrary = effect.alsoLibrary; this.alsoHand = effect.alsoHand;
} }
@Override @Override
@ -81,7 +81,47 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
} }
@Override @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) { if (((ZoneChangeEvent)event).getFromZone() == Zone.BATTLEFIELD) {
Permanent permanent = ((ZoneChangeEvent)event).getTarget(); Permanent permanent = ((ZoneChangeEvent)event).getTarget();
if (permanent != null) { if (permanent != null) {
@ -114,32 +154,4 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
} }
return false; 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;
}
} }

View file

@ -59,7 +59,7 @@ public abstract class GameCommanderImpl extends GameImpl {
private final Map<UUID, Cards> mulliganedCards = new HashMap<>(); private final Map<UUID, Cards> mulliganedCards = new HashMap<>();
private final Set<CommanderInfoWatcher> commanderCombatWatcher = new HashSet<>(); private final Set<CommanderInfoWatcher> 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; protected boolean startingPlayerSkipsDraw = true;
public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) { 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) { public GameCommanderImpl(final GameCommanderImpl game) {
super(game); super(game);
this.alsoLibrary = game.alsoLibrary; this.alsoHand = game.alsoHand;
this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw; this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw;
} }
@ -84,7 +84,7 @@ public abstract class GameCommanderImpl extends GameImpl {
if (commander != null) { if (commander != null) {
player.setCommanderId(commander.getId()); player.setCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true); 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 CommanderCostModification(commander.getId()));
ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander))); ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
getState().setValue(commander.getId() + "_castCount", 0); getState().setValue(commander.getId() + "_castCount", 0);
@ -211,8 +211,8 @@ public abstract class GameCommanderImpl extends GameImpl {
return !player.getId().equals(playerToCheck); return !player.getId().equals(playerToCheck);
} }
public void setAlsoLibrary(boolean alsoLibrary) { public void setAlsoHand(boolean alsoHand) {
this.alsoLibrary = alsoLibrary; this.alsoHand = alsoHand;
} }
} }

View file

@ -59,7 +59,7 @@ import mage.watchers.common.CommanderInfoWatcher;
*/ */
public abstract class GameTinyLeadersImpl extends GameImpl{ 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; protected boolean startingPlayerSkipsDraw = true;
public GameTinyLeadersImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) { 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) { public GameTinyLeadersImpl(final GameTinyLeadersImpl game) {
super(game); super(game);
this.alsoLibrary = game.alsoLibrary; this.alsoHand = game.alsoHand;
this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw; this.startingPlayerSkipsDraw = game.startingPlayerSkipsDraw;
} }
@ -86,7 +86,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl{
this.loadCards(cards, playerId); this.loadCards(cards, playerId);
player.setCommanderId(commander.getId()); player.setCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true); 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 CommanderCostModification(commander.getId()));
ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander))); ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
getState().setValue(commander.getId() + "_castCount", 0); getState().setValue(commander.getId() + "_castCount", 0);
@ -152,8 +152,8 @@ public abstract class GameTinyLeadersImpl extends GameImpl{
return !player.getId().equals(playerToCheck); return !player.getId().equals(playerToCheck);
} }
public void setAlsoLibrary(boolean alsoLibrary) { public void setAlsoHand(boolean alsoHand) {
this.alsoLibrary = alsoLibrary; this.alsoHand = alsoHand;
} }
} }