* Added "Duel Commander" format (fixes #436).

This commit is contained in:
LevelX2 2014-11-08 01:33:29 +01:00
parent 6f8de373ac
commit d7f100b24b
21 changed files with 280 additions and 167 deletions

View file

@ -54,17 +54,20 @@ import mage.players.Player;
public class CommanderReplacementEffect extends ReplacementEffectImpl {
private final UUID commanderId;
private final boolean alsoLibrary;
public CommanderReplacementEffect(UUID commanderId) {
public CommanderReplacementEffect(UUID commanderId, boolean alsoLibrary) {
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.";
this.commanderId = commanderId;
this.duration = Duration.EndOfGame;
this.alsoLibrary = alsoLibrary;
}
public CommanderReplacementEffect(final CommanderReplacementEffect effect) {
super(effect);
this.commanderId = effect.commanderId;
this.alsoLibrary = effect.alsoLibrary;
}
@Override
@ -112,7 +115,11 @@ public class CommanderReplacementEffect extends ReplacementEffectImpl {
@Override
public boolean applies(GameEvent event, Ability source, Game game) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && (((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD || ((ZoneChangeEvent)event).getToZone() == Zone.EXILED)) {
if (event.getType() == GameEvent.EventType.ZONE_CHANGE && (
((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());

View file

@ -41,7 +41,7 @@ public abstract class DeckValidator implements Serializable {
protected String name;
protected Map<String, String> invalid = new HashMap<String, String>();
protected Map<String, String> invalid = new HashMap<>();
public DeckValidator(String name) {
this.name = name;

View file

@ -57,23 +57,17 @@ public abstract class GameCommanderImpl extends GameImpl {
private final Map<UUID, Cards> mulliganedCards = new HashMap<>();
private final Set<CommanderCombatDamageWatcher> commanderCombatWatcher = new HashSet<>();
protected boolean alsoLibrary; // replace also commander going to library
public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
super(attackOption, range, freeMulligans);
public GameCommanderImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) {
super(attackOption, range, freeMulligans, startLife);
}
public GameCommanderImpl(final GameCommanderImpl game) {
super(game);
}
// MTG Rules 20121001
// 903.7. Once the starting player has been determined, each player sets his or her life total to 40 and
// draws a hand of seven cards.
@Override
public int getLife() {
return 40;
}
@Override
protected void init(UUID choosingPlayerId, GameOptions gameOptions) {
super.init(choosingPlayerId, gameOptions);
@ -87,10 +81,10 @@ 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()));
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoLibrary));
ability.addEffect(new CommanderCostModification(commander.getId()));
ability.addEffect(new CommanderManaReplacementEffect(player.getId(), commander.getSpellAbility().getManaCosts().getMana()));
getState().setValue(commander.getId() + "_castCount", new Integer(0));
getState().setValue(commander.getId() + "_castCount", 0);
CommanderCombatDamageWatcher watcher = new CommanderCombatDamageWatcher(commander.getId());
getState().getWatchers().add(watcher);
this.commanderCombatWatcher.add(watcher);
@ -135,16 +129,16 @@ public abstract class GameCommanderImpl extends GameImpl {
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
int used = usedFreeMulligans.get(player.getId());
if (used < freeMulligans ) {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(used+1));
usedFreeMulligans.put(player.getId(), used+1);
}
} else {
deduction = 0;{
}
usedFreeMulligans.put(player.getId(), new Integer(1));
usedFreeMulligans.put(player.getId(), 1);
}
}
player.drawCards(numCards - deduction, this);
@ -210,4 +204,9 @@ public abstract class GameCommanderImpl extends GameImpl {
public boolean isOpponent(Player player, UUID playerToCheck) {
return !player.getId().equals(playerToCheck);
}
public void setAlsoLibrary(boolean alsoLibrary) {
this.alsoLibrary = alsoLibrary;
}
}

View file

@ -194,12 +194,15 @@ public abstract class GameImpl implements Game, Serializable {
private boolean saveGame = false;
private int priorityTime;
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans) {
private final int startLife;
public GameImpl(MultiplayerAttackOption attackOption, RangeOfInfluence range, int freeMulligans, int startLife) {
this.id = UUID.randomUUID();
this.range = range;
this.freeMulligans = freeMulligans;
this.attackOption = attackOption;
this.state = new GameState();
this.startLife = startLife;
// this.actions = new LinkedList<MageAction>();
}
@ -235,6 +238,7 @@ public abstract class GameImpl implements Game, Serializable {
this.scopeRelevant = game.scopeRelevant;
this.priorityTime = game.priorityTime;
this.saveGame = game.saveGame;
this.startLife = game.startLife;
}
@Override
@ -2525,5 +2529,10 @@ public abstract class GameImpl implements Game, Serializable {
public UUID getStartingPlayerId() {
return startingPlayerId;
}
@Override
public int getLife() {
return startLife;
}
}

View file

@ -44,7 +44,6 @@ import mage.game.events.TableEvent;
import mage.game.events.TableEvent.EventType;
import mage.game.events.TableEventSource;
import mage.players.Player;
import mage.players.PlayerList;
import mage.util.DateFormat;
import org.apache.log4j.Logger;