1
0
Fork 0
mirror of https://github.com/correl/mage.git synced 2025-04-08 17:00:07 -09:00

[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.Map;
import mage.abilities.common.CanBeYourCommanderAbility;
import mage.abilities.keyword.PartnerAbility;
import mage.cards.Card;
import mage.cards.ExpansionSet;
import mage.cards.Sets;
@ -105,9 +106,10 @@ public class Commander extends Constructed {
@Override
public boolean validate(Deck deck) {
boolean valid = true;
FilterMana colorIdentity = new FilterMana();
if (deck.getCards().size() != 99) {
invalid.put("Deck", "Must contain 99 cards: has " + deck.getCards().size() + " cards");
if (deck.getCards().size() + deck.getSideboard().size() != 100) {
invalid.put("Deck", "Must contain 100 cards: has " + (deck.getCards().size() + deck.getSideboard().size()) + " cards");
valid = false;
}
@ -132,34 +134,48 @@ public class Commander extends Constructed {
}
}
if (deck.getSideboard().size() == 1) {
Card commander = (Card) deck.getSideboard().toArray()[0];
if (commander == null) {
invalid.put("Commander", "Commander invalid ");
return false;
}
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 {
if (deck.getSideboard().size() < 1 || deck.getSideboard().size() > 2) {
invalid.put("Commander", "Sideboard must contain only the commander(s)");
valid = false;
} else {
for (Card commander : deck.getSideboard()) {
if (bannedCommander.contains(commander.getName())) {
invalid.put("Commander", "Commander banned (" + commander.getName() + ")");
valid = false;
}
} else {
invalid.put("Commander", "Commander invalid (" + commander.getName() + ")");
if ((!commander.getCardType().contains(CardType.CREATURE) || !commander.getSupertype().contains("Legendary"))
&& (!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;
}
} else {
invalid.put("Commander", "Sideboard must contain only the commander");
}
for (Card card : deck.getCards()) {
if (!isSetAllowed(card.getExpansionSetCode())) {
if (!legalSets(card)) {

View file

@ -27,6 +27,8 @@
*/
package mage.cards.c;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility;
@ -71,28 +73,44 @@ public class CommandBeacon extends CardImpl {
}
class CommandBeaconEffect extends OneShotEffect {
CommandBeaconEffect() {
super(Outcome.ReturnToHand);
this.staticText = "Put your commander into your hand from the command zone";
}
CommandBeaconEffect(final CommandBeaconEffect effect) {
super(effect);
}
@Override
public CommandBeaconEffect copy() {
return new CommandBeaconEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Card commander = game.getCard(controller.getCommanderId());
if (commander != null && game.getState().getZone(commander.getId()) == Zone.COMMAND) {
controller.moveCards(commander, Zone.HAND, source, game);
List<Card> commandersInCommandZone = new ArrayList<>(1);
for (UUID commanderId : controller.getCommandersIds()) {
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;
}

View file

@ -127,17 +127,19 @@ class ConspiracyEffect extends ContinuousEffectImpl {
}
}
// commander in command zone
if (controller.getCommanderId() != null && game.getState().getZone(controller.getCommanderId()).equals(Zone.COMMAND)) {
Card card = game.getCard(controller.getCommanderId());
if (card.getCardType().contains(CardType.CREATURE)) {
setCreatureSubtype(card, choice, game);
for (UUID commanderId : controller.getCommandersIds()) {
if (game.getState().getZone(commanderId).equals(Zone.COMMAND)) {
Card card = game.getCard(commanderId);
if (card.getCardType().contains(CardType.CREATURE)) {
setCreatureSubtype(card, choice, game);
}
}
}
// creature spells you control
for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext();) {
StackObject stackObject = iterator.next();
if (stackObject instanceof Spell &&
stackObject.getControllerId().equals(source.getControllerId()) &&
stackObject.getControllerId().equals(source.getControllerId()) &&
stackObject.getCardType().contains(CardType.CREATURE)) {
Card card = ((Spell) stackObject).getCard();
setCreatureSubtype(card, choice, game);
@ -153,20 +155,20 @@ class ConspiracyEffect extends ContinuousEffectImpl {
}
return false;
}
private void setCreatureSubtype(MageObject object, String subtype, Game game) {
if (object != null) {
if (object instanceof Card) {
Card card = (Card) object;
setChosenSubtype(
game.getState().getCreateCardAttribute(card).getSubtype(),
game.getState().getCreateCardAttribute(card).getSubtype(),
subtype);
} else {
setChosenSubtype(object.getSubtype(game), subtype);
}
}
}
private void setChosenSubtype(List<String> subtype, String choice) {
if (subtype.size() != 1 || !subtype.contains(choice)) {
subtype.removeAll(CardRepository.instance.getCreatureTypes());

View file

@ -140,7 +140,7 @@ class KarnLiberatedEffect extends OneShotEffect {
if (card.getOwnerId().equals(player.getId()) && !card.isCopy() // no copies
&& !player.getSideboard().contains(card.getId())
&& !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.setZone(card.getId(), Zone.COMMAND);
} else {

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -76,16 +76,14 @@ public abstract class GameCommanderImpl extends GameImpl {
for (UUID playerId : state.getPlayerList(startingPlayerId)) {
Player player = getPlayer(playerId);
if (player != null) {
if (player.getSideboard().size() > 0) {
Card commander = getCard((UUID) player.getSideboard().toArray()[0]);
while (player.getSideboard().size() > 0) {
Card commander = this.getCard(player.getSideboard().iterator().next());
if (commander != null) {
player.setCommanderId(commander.getId());
player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
commander.getAbilities().setControllerId(player.getId());
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary));
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);
CommanderInfoWatcher watcher = new CommanderInfoWatcher(commander.getId(), CHECK_COMMANDER_DAMAGE);
getState().getWatchers().add(watcher);
@ -93,7 +91,6 @@ public abstract class GameCommanderImpl extends GameImpl {
}
}
}
}
this.getState().addAbility(ability, null);
super.init(choosingPlayerId);
@ -189,15 +186,17 @@ public abstract class GameCommanderImpl extends GameImpl {
@Override
protected boolean checkStateBasedActions() {
for (Player player : getPlayers().values()) {
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", player.getCommanderId());
if (damageWatcher == null) {
continue;
}
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
if (entrySet.getValue() > 20) {
Player opponent = getPlayer(entrySet.getKey());
if (opponent != null && !opponent.hasLost() && player.isInGame()) {
opponent.lost(this);
for (UUID commanderId : player.getCommandersIds()) {
CommanderInfoWatcher damageWatcher = (CommanderInfoWatcher) getState().getWatchers().get("CommanderCombatDamageWatcher", commanderId);
if (damageWatcher == null) {
continue;
}
for (Map.Entry<UUID, Integer> entrySet : damageWatcher.getDamageToPlayer().entrySet()) {
if (entrySet.getValue() > 20) {
Player opponent = getPlayer(entrySet.getKey());
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<>();
cards.add(commander);
this.loadCards(cards, playerId);
player.setCommanderId(commander.getId());
player.addCommanderId(commander.getId());
commander.moveToZone(Zone.COMMAND, null, this, true);
ability.addEffect(new CommanderReplacementEffect(commander.getId(), alsoHand, alsoLibrary));
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
*
* @param commanderId
* @param commandersIds
*/
void setCommanderId(UUID commanderId);
void addCommanderId(UUID commanderId);
/**
* Get the commanderId of the player
*
* @return
*/
UUID getCommanderId();
Set<UUID> getCommandersIds();
/**
* 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.predicate.Predicates;
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.command.CommandObject;
import mage.game.events.DamagePlayerEvent;
@ -153,7 +158,7 @@ public abstract class PlayerImpl implements Player, Serializable {
protected Cards sideboard;
protected Cards hand;
protected Graveyard graveyard;
protected UUID commanderId;
protected Set<UUID> commandersIds = new HashSet<>(0);
protected Abilities<Ability> abilities;
protected Counters counters;
protected int landsPlayed;
@ -273,7 +278,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.sideboard = player.sideboard.copy();
this.hand = player.hand.copy();
this.graveyard = player.graveyard.copy();
this.commanderId = player.commanderId;
this.commandersIds = player.commandersIds;
this.abilities = player.abilities.copy();
this.counters = player.counters.copy();
@ -359,7 +364,7 @@ public abstract class PlayerImpl implements Player, Serializable {
this.sideboard = player.getSideboard().copy();
this.hand = player.getHand().copy();
this.graveyard = player.getGraveyard().copy();
this.commanderId = player.getCommanderId();
this.commandersIds = player.getCommandersIds();
this.abilities = player.getAbilities().copy();
this.counters = player.getCounters().copy();
@ -3124,13 +3129,13 @@ public abstract class PlayerImpl implements Player, Serializable {
}
@Override
public void setCommanderId(UUID commanderId) {
this.commanderId = commanderId;
public void addCommanderId(UUID commanderId) {
this.commandersIds.add(commanderId);
}
@Override
public UUID getCommanderId() {
return this.commanderId;
public Set<UUID> getCommandersIds() {
return this.commandersIds;
}
@Override