[C16] Implemented Partner ability.

This commit is contained in:
emerald000 2016-11-01 22:59:39 -04:00
parent dfc72a9adb
commit c38f96ae55
13 changed files with 161 additions and 127 deletions

View file

@ -33,6 +33,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import mage.abilities.common.CanBeYourCommanderAbility; import mage.abilities.common.CanBeYourCommanderAbility;
import mage.abilities.keyword.PartnerAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.ExpansionSet; import mage.cards.ExpansionSet;
import mage.cards.Sets; import mage.cards.Sets;
@ -105,9 +106,10 @@ public class Commander extends Constructed {
@Override @Override
public boolean validate(Deck deck) { public boolean validate(Deck deck) {
boolean valid = true; boolean valid = true;
FilterMana colorIdentity = new FilterMana();
if (deck.getCards().size() != 99) { if (deck.getCards().size() + deck.getSideboard().size() != 100) {
invalid.put("Deck", "Must contain 99 cards: has " + deck.getCards().size() + " cards"); invalid.put("Deck", "Must contain 100 cards: has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
valid = false; valid = false;
} }
@ -132,34 +134,48 @@ public class Commander extends Constructed {
} }
} }
if (deck.getSideboard().size() == 1) { if (deck.getSideboard().size() < 1 || deck.getSideboard().size() > 2) {
Card commander = (Card) deck.getSideboard().toArray()[0]; invalid.put("Commander", "Sideboard must contain only the commander(s)");
if (commander == null) { valid = false;
invalid.put("Commander", "Commander invalid "); } else {
return false; for (Card commander : deck.getSideboard()) {
} if (bannedCommander.contains(commander.getName())) {
if ((commander.getCardType().contains(CardType.CREATURE) && commander.getSupertype().contains("Legendary"))
|| (commander.getCardType().contains(CardType.PLANESWALKER) && commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
if (!bannedCommander.contains(commander.getName())) {
FilterMana color = CardUtil.getColorIdentity(commander);
for (Card card : deck.getCards()) {
if (!cardHasValidColor(color, card)) {
invalid.put(card.getName(), "Invalid color (" + commander.getName() + ")");
valid = false;
}
}
} else {
invalid.put("Commander", "Commander banned (" + commander.getName() + ")"); invalid.put("Commander", "Commander banned (" + commander.getName() + ")");
valid = false; valid = false;
} }
} else { if ((!commander.getCardType().contains(CardType.CREATURE) || !commander.getSupertype().contains("Legendary"))
invalid.put("Commander", "Commander invalid (" + commander.getName() + ")"); && (!commander.getCardType().contains(CardType.PLANESWALKER) || !commander.getAbilities().contains(CanBeYourCommanderAbility.getInstance()))) {
invalid.put("Commander", "Commander invalid (" + commander.getName() + ")");
valid = false;
}
if (deck.getSideboard().size() == 2 && !commander.getAbilities().contains(PartnerAbility.getInstance())) {
invalid.put("Commander", "Commander without Partner (" + commander.getName() + ")");
valid = false;
}
FilterMana commanderColor = CardUtil.getColorIdentity(commander);
if (commanderColor.isWhite()) {
colorIdentity.setWhite(true);
}
if (commanderColor.isBlue()) {
colorIdentity.setBlue(true);
}
if (commanderColor.isBlack()) {
colorIdentity.setBlack(true);
}
if (commanderColor.isRed()) {
colorIdentity.setRed(true);
}
if (commanderColor.isGreen()) {
colorIdentity.setGreen(true);
}
}
}
for (Card card : deck.getCards()) {
if (!cardHasValidColor(colorIdentity, card)) {
invalid.put(card.getName(), "Invalid color (" + colorIdentity.toString() + ")");
valid = false; valid = false;
} }
} else {
invalid.put("Commander", "Sideboard must contain only the commander");
} }
for (Card card : deck.getCards()) { for (Card card : deck.getCards()) {
if (!isSetAllowed(card.getExpansionSetCode())) { if (!isSetAllowed(card.getExpansionSetCode())) {
if (!legalSets(card)) { if (!legalSets(card)) {

View file

@ -27,6 +27,8 @@
*/ */
package mage.cards.c; package mage.cards.c;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -90,9 +92,25 @@ class CommandBeaconEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Card commander = game.getCard(controller.getCommanderId()); List<Card> commandersInCommandZone = new ArrayList<>(1);
if (commander != null && game.getState().getZone(commander.getId()) == Zone.COMMAND) { for (UUID commanderId : controller.getCommandersIds()) {
controller.moveCards(commander, Zone.HAND, source, game); Card commander = game.getCard(commanderId);
if (commander != null && game.getState().getZone(commander.getId()) == Zone.COMMAND) {
commandersInCommandZone.add(commander);
}
}
if (commandersInCommandZone.size() == 1) {
controller.moveCards(commandersInCommandZone.get(0), Zone.HAND, source, game);
}
else if (commandersInCommandZone.size() == 2) {
Card firstCommander = commandersInCommandZone.get(0);
Card secondCommander = commandersInCommandZone.get(1);
if (controller.chooseUse(Outcome.ReturnToHand, "Return which commander to hand?", null, firstCommander.getName(), secondCommander.getName(), source, game)) {
controller.moveCards(firstCommander, Zone.HAND, source, game);
}
else {
controller.moveCards(secondCommander, Zone.HAND, source, game);
}
} }
return true; return true;
} }

View file

@ -127,10 +127,12 @@ class ConspiracyEffect extends ContinuousEffectImpl {
} }
} }
// commander in command zone // commander in command zone
if (controller.getCommanderId() != null && game.getState().getZone(controller.getCommanderId()).equals(Zone.COMMAND)) { for (UUID commanderId : controller.getCommandersIds()) {
Card card = game.getCard(controller.getCommanderId()); if (game.getState().getZone(commanderId).equals(Zone.COMMAND)) {
if (card.getCardType().contains(CardType.CREATURE)) { Card card = game.getCard(commanderId);
setCreatureSubtype(card, choice, game); if (card.getCardType().contains(CardType.CREATURE)) {
setCreatureSubtype(card, choice, game);
}
} }
} }
// creature spells you control // creature spells you control

View file

@ -140,7 +140,7 @@ class KarnLiberatedEffect extends OneShotEffect {
if (card.getOwnerId().equals(player.getId()) && !card.isCopy() // no copies if (card.getOwnerId().equals(player.getId()) && !card.isCopy() // no copies
&& !player.getSideboard().contains(card.getId()) && !player.getSideboard().contains(card.getId())
&& !cards.contains(card)) { // not the exiled cards && !cards.contains(card)) { // not the exiled cards
if (card.getId().equals(player.getCommanderId())) { if (player.getCommandersIds().contains(card.getId())) {
game.addCommander(new Commander(card)); game.addCommander(new Commander(card));
game.setZone(card.getId(), Zone.COMMAND); game.setZone(card.getId(), Zone.COMMAND);
} else { } else {

View file

@ -119,7 +119,7 @@ class OpalPalaceWatcher extends Watcher {
for (UUID playerId : game.getPlayerList()) { for (UUID playerId : game.getPlayerList()) {
Player player = game.getPlayer(playerId); Player player = game.getPlayer(playerId);
if (player != null) { if (player != null) {
if (player.getCommanderId() != null && player.getCommanderId().equals(card.getId())) { if (player.getCommandersIds().contains(card.getId())) {
commanderId.add(card.getId()); commanderId.add(card.getId());
break; break;
} }

View file

@ -131,10 +131,12 @@ class TeferiMageOfZhalfirAddFlashEffect extends ContinuousEffectImpl {
} }
} }
// commander in command zone // commander in command zone
if (controller.getCommanderId() != null && game.getState().getZone(controller.getCommanderId()).equals(Zone.COMMAND)) { for (UUID commanderId : controller.getCommandersIds()) {
Card card = game.getCard(controller.getCommanderId()); if (game.getState().getZone(commanderId).equals(Zone.COMMAND)) {
if (card.getCardType().contains(CardType.CREATURE)) { Card card = game.getCard(commanderId);
game.getState().addOtherAbility(card, FlashAbility.getInstance()); if (card.getCardType().contains(CardType.CREATURE)) {
game.getState().addOtherAbility(card, FlashAbility.getInstance());
}
} }
} }
return true; return true;

View file

@ -27,6 +27,7 @@
*/ */
package mage.abilities.condition.common; package mage.abilities.condition.common;
import java.util.UUID;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.condition.Condition; import mage.abilities.condition.Condition;
import mage.game.Game; import mage.game.Game;
@ -56,8 +57,12 @@ public class CommanderInPlayCondition implements Condition {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Permanent commander = game.getPermanent(controller.getCommanderId()); for (UUID commanderId : controller.getCommandersIds()) {
return commander != null && commander.getControllerId().equals(source.getControllerId()); Permanent commander = game.getPermanent(commanderId);
if (commander != null && commander.getControllerId().equals(source.getControllerId())) {
return true;
}
}
} }
return false; return false;
} }

View file

@ -28,6 +28,7 @@
package mage.abilities.mana; package mage.abilities.mana;
import java.util.List; import java.util.List;
import java.util.UUID;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.costs.Cost; import mage.abilities.costs.Cost;
@ -49,20 +50,16 @@ import mage.util.CardUtil;
*/ */
public class CommanderColorIdentityManaAbility extends ManaAbility { public class CommanderColorIdentityManaAbility extends ManaAbility {
private FilterMana commanderMana;
public CommanderColorIdentityManaAbility() { public CommanderColorIdentityManaAbility() {
super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(), new TapSourceCost()); super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(), new TapSourceCost());
} }
public CommanderColorIdentityManaAbility(Cost cost) { public CommanderColorIdentityManaAbility(Cost cost) {
super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(), cost); super(Zone.BATTLEFIELD, new CommanderIdentityManaEffect(), cost);
commanderMana = null;
} }
public CommanderColorIdentityManaAbility(final CommanderColorIdentityManaAbility ability) { public CommanderColorIdentityManaAbility(final CommanderColorIdentityManaAbility ability) {
super(ability); super(ability);
this.commanderMana = ability.commanderMana;
} }
@Override @Override
@ -75,30 +72,27 @@ public class CommanderColorIdentityManaAbility extends ManaAbility {
if (netMana.isEmpty() && game != null) { if (netMana.isEmpty() && game != null) {
Player controller = game.getPlayer(getControllerId()); Player controller = game.getPlayer(getControllerId());
if (controller != null) { if (controller != null) {
if (commanderMana == null) { for (UUID commanderId : controller.getCommandersIds()) {
Card commander = game.getCard(controller.getCommanderId()); Card commander = game.getCard(commanderId);
if (commander != null) { if (commander != null) {
commanderMana = CardUtil.getColorIdentity(commander); FilterMana commanderMana = CardUtil.getColorIdentity(commander);
} else { if (commanderMana.isBlack()) {
// In formats other than Commander, Command Tower's ability produces no mana. netMana.add(new Mana(ColoredManaSymbol.B));
commanderMana = new FilterMana(); }
if (commanderMana.isBlue()) {
netMana.add(new Mana(ColoredManaSymbol.U));
}
if (commanderMana.isGreen()) {
netMana.add(new Mana(ColoredManaSymbol.G));
}
if (commanderMana.isRed()) {
netMana.add(new Mana(ColoredManaSymbol.R));
}
if (commanderMana.isWhite()) {
netMana.add(new Mana(ColoredManaSymbol.W));
}
} }
} }
if (commanderMana.isBlack()) {
netMana.add(new Mana(ColoredManaSymbol.B));
}
if (commanderMana.isBlue()) {
netMana.add(new Mana(ColoredManaSymbol.U));
}
if (commanderMana.isGreen()) {
netMana.add(new Mana(ColoredManaSymbol.G));
}
if (commanderMana.isRed()) {
netMana.add(new Mana(ColoredManaSymbol.R));
}
if (commanderMana.isWhite()) {
netMana.add(new Mana(ColoredManaSymbol.W));
}
} }
} }
return netMana; return netMana;
@ -113,17 +107,13 @@ public class CommanderColorIdentityManaAbility extends ManaAbility {
class CommanderIdentityManaEffect extends ManaEffect { class CommanderIdentityManaEffect extends ManaEffect {
private FilterMana commanderMana;
public CommanderIdentityManaEffect() { public CommanderIdentityManaEffect() {
super(); super();
this.staticText = "Add to your mana pool one mana of any color in your commander's color identity"; this.staticText = "Add to your mana pool one mana of any color in your commander's color identity";
commanderMana = null;
} }
public CommanderIdentityManaEffect(final CommanderIdentityManaEffect effect) { public CommanderIdentityManaEffect(final CommanderIdentityManaEffect effect) {
super(effect); super(effect);
this.commanderMana = effect.commanderMana;
} }
@Override @Override
@ -135,31 +125,28 @@ class CommanderIdentityManaEffect extends ManaEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
if (commanderMana == null) {
Card commander = game.getCard(controller.getCommanderId());
if (commander != null) {
commanderMana = CardUtil.getColorIdentity(commander);
} else {
// In formats other than Commander, Command Tower's ability produces no mana.
commanderMana = new FilterMana();
}
}
Choice choice = new ChoiceImpl(); Choice choice = new ChoiceImpl();
choice.setMessage("Pick a mana color"); choice.setMessage("Pick a mana color");
if (commanderMana.isBlack()) { for (UUID commanderId : controller.getCommandersIds()) {
choice.getChoices().add("Black"); Card commander = game.getCard(commanderId);
} if (commander != null) {
if (commanderMana.isRed()) { FilterMana commanderMana = CardUtil.getColorIdentity(commander);
choice.getChoices().add("Red"); if (commanderMana.isWhite()) {
} choice.getChoices().add("White");
if (commanderMana.isBlue()) { }
choice.getChoices().add("Blue"); if (commanderMana.isBlue()) {
} choice.getChoices().add("Blue");
if (commanderMana.isGreen()) { }
choice.getChoices().add("Green"); if (commanderMana.isBlack()) {
} choice.getChoices().add("Black");
if (commanderMana.isWhite()) { }
choice.getChoices().add("White"); if (commanderMana.isRed()) {
choice.getChoices().add("Red");
}
if (commanderMana.isGreen()) {
choice.getChoices().add("Green");
}
}
} }
if (choice.getChoices().size() > 0) { if (choice.getChoices().size() > 0) {
if (choice.getChoices().size() == 1) { if (choice.getChoices().size() == 1) {

View file

@ -22,7 +22,7 @@ public class CommanderPredicate implements Predicate<Permanent> {
Player owner = game.getPlayer(input.getOwnerId()); Player owner = game.getPlayer(input.getOwnerId());
return input.getCardType().contains(CardType.CREATURE) return input.getCardType().contains(CardType.CREATURE)
&& owner != null && owner != null
&& input.getId().equals(owner.getCommanderId()); && input.getId().equals(owner.getCommandersIds());
} }
@Override @Override

View file

@ -76,16 +76,14 @@ public abstract class GameCommanderImpl extends GameImpl {
for (UUID playerId : state.getPlayerList(startingPlayerId)) { for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId); Player player = getPlayer(playerId);
if (player != null) { if (player != null) {
if (player.getSideboard().size() > 0) { while (player.getSideboard().size() > 0) {
Card commander = getCard((UUID) player.getSideboard().toArray()[0]); Card commander = this.getCard(player.getSideboard().iterator().next());
if (commander != null) { if (commander != null) {
player.setCommanderId(commander.getId()); player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true); commander.moveToZone(Zone.COMMAND, null, this, true);
commander.getAbilities().setControllerId(player.getId()); commander.getAbilities().setControllerId(player.getId());
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary)); ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary));
ability.addEffect(new CommanderCostModification(commander.getId())); ability.addEffect(new CommanderCostModification(commander.getId()));
// Commander rule #4 was removed Jan. 18, 2016
// ability.addEffect(new CommanderManaReplacementEffect(player.getId(), CardUtil.getColorIdentity(commander)));
getState().setValue(commander.getId() + "_castCount", 0); getState().setValue(commander.getId() + "_castCount", 0);
CommanderInfoWatcher watcher = new CommanderInfoWatcher(commander.getId(), CHECK_COMMANDER_DAMAGE); CommanderInfoWatcher watcher = new CommanderInfoWatcher(commander.getId(), CHECK_COMMANDER_DAMAGE);
getState().getWatchers().add(watcher); getState().getWatchers().add(watcher);
@ -93,7 +91,6 @@ public abstract class GameCommanderImpl extends GameImpl {
} }
} }
} }
} }
this.getState().addAbility(ability, null); this.getState().addAbility(ability, null);
super.init(choosingPlayerId); super.init(choosingPlayerId);
@ -189,15 +186,17 @@ public abstract class GameCommanderImpl extends GameImpl {
@Override @Override
protected boolean checkStateBasedActions() { protected boolean checkStateBasedActions() {
for (Player player : getPlayers().values()) { for (Player player : getPlayers().values()) {
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId()); for (UUID commanderId : player.getCommandersIds()) {
if (damageWatcher == null) { CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", commanderId);
continue; if (damageWatcher == null) {
} continue;
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) { }
if (entrySet.getValue() > 20) { for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
Player opponent = getPlayer(entrySet.getKey()); if (entrySet.getValue() > 20) {
if (opponent != null && !opponent.hasLost() && player.isInGame()) { Player opponent = getPlayer(entrySet.getKey());
opponent.lost(this); if (opponent != null && !opponent.hasLost() && player.isInGame()) {
opponent.lost(this);
}
} }
} }
} }

View file

@ -83,7 +83,7 @@ public abstract class GameTinyLeadersImpl extends GameImpl {
Set<Card> cards = new HashSet<>(); Set<Card> cards = new HashSet<>();
cards.add(commander); cards.add(commander);
this.loadCards(cards, playerId); this.loadCards(cards, playerId);
player.setCommanderId(commander.getId()); player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true); commander.moveToZone(Zone.COMMAND, null, this, true);
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary)); ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary));
ability.addEffect(new CommanderCostModification(commander.getId())); ability.addEffect(new CommanderCostModification(commander.getId()));

View file

@ -645,16 +645,16 @@ public interface Player extends MageItem, Copyable<Player> {
/** /**
* Set the commanderId of the player * Set the commanderId of the player
* *
* @param commanderId * @param commandersIds
*/ */
void setCommanderId(UUID commanderId); void addCommanderId(UUID commanderId);
/** /**
* Get the commanderId of the player * Get the commanderId of the player
* *
* @return * @return
*/ */
UUID getCommanderId(); Set<UUID> getCommandersIds();
/** /**
* Moves cards from one zone to another * Moves cards from one zone to another

View file

@ -105,7 +105,12 @@ import mage.filter.common.FilterCreatureForCombat;
import mage.filter.common.FilterCreatureForCombatBlock; import mage.filter.common.FilterCreatureForCombatBlock;
import mage.filter.predicate.Predicates; import mage.filter.predicate.Predicates;
import mage.filter.predicate.permanent.PermanentIdPredicate; import mage.filter.predicate.permanent.PermanentIdPredicate;
import mage.game.*; import mage.game.ExileZone;
import mage.game.Game;
import mage.game.Graveyard;
import mage.game.Table;
import mage.game.ZoneChangeInfo;
import mage.game.ZonesHandler;
import mage.game.combat.CombatGroup; import mage.game.combat.CombatGroup;
import mage.game.command.CommandObject; import mage.game.command.CommandObject;
import mage.game.events.DamagePlayerEvent; import mage.game.events.DamagePlayerEvent;
@ -153,7 +158,7 @@ public abstract class PlayerImpl implements Player, Serializable {
protected Cards sideboard; protected Cards sideboard;
protected Cards hand; protected Cards hand;
protected Graveyard graveyard; protected Graveyard graveyard;
protected UUID commanderId; protected Set<UUID> commandersIds = new HashSet<>(0);
protected Abilities<Ability> abilities; protected Abilities<Ability> abilities;
protected Counters counters; protected Counters counters;
protected int landsPlayed; protected int landsPlayed;
@ -273,7 +278,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.sideboard = player.sideboard.copy(); this.sideboard = player.sideboard.copy();
this.hand = player.hand.copy(); this.hand = player.hand.copy();
this.graveyard = player.graveyard.copy(); this.graveyard = player.graveyard.copy();
this.commanderId = player.commanderId; this.commandersIds = player.commandersIds;
this.abilities = player.abilities.copy(); this.abilities = player.abilities.copy();
this.counters = player.counters.copy(); this.counters = player.counters.copy();
@ -359,7 +364,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.sideboard = player.getSideboard().copy(); this.sideboard = player.getSideboard().copy();
this.hand = player.getHand().copy(); this.hand = player.getHand().copy();
this.graveyard = player.getGraveyard().copy(); this.graveyard = player.getGraveyard().copy();
this.commanderId = player.getCommanderId(); this.commandersIds = player.getCommandersIds();
this.abilities = player.getAbilities().copy(); this.abilities = player.getAbilities().copy();
this.counters = player.getCounters().copy(); this.counters = player.getCounters().copy();
@ -3124,13 +3129,13 @@ public abstract class PlayerImpl implements Player, Serializable {
} }
@Override @Override
public void setCommanderId(UUID commanderId) { public void addCommanderId(UUID commanderId) {
this.commanderId = commanderId; this.commandersIds.add(commanderId);
} }
@Override @Override
public UUID getCommanderId() { public Set<UUID> getCommandersIds() {
return this.commanderId; return this.commandersIds;
} }
@Override @Override