diff --git a/Mage/src/mage/cards/CardImpl.java b/Mage/src/mage/cards/CardImpl.java index 1f607acb50..20aba69541 100644 --- a/Mage/src/mage/cards/CardImpl.java +++ b/Mage/src/mage/cards/CardImpl.java @@ -50,6 +50,7 @@ import org.apache.log4j.Logger; import java.lang.reflect.Constructor; import java.util.*; import mage.constants.SpellAbilityType; +import mage.game.command.Commander; public abstract class CardImpl> extends MageObjectImpl implements Card { @@ -290,6 +291,7 @@ public abstract class CardImpl> extends MageObjectImpl case OUTSIDE: game.getPlayer(ownerId).getSideboard().remove(this); break; + case COMMAND: case STACK: case PICK: break; @@ -313,6 +315,9 @@ public abstract class CardImpl> extends MageObjectImpl case EXILED: game.getExile().getPermanentExile().add(this); break; + case COMMAND: + game.addCommander(new Commander(this)); + break; case LIBRARY: if (flag) { game.getPlayer(ownerId).getLibrary().putOnTop(this, game); @@ -369,6 +374,10 @@ public abstract class CardImpl> extends MageObjectImpl case OUTSIDE: game.getPlayer(ownerId).getSideboard().remove(this); break; + + case COMMAND: + game.getState().getCommand().remove((Commander)game.getObject(objectId)); + break; default: //logger.warning("moveToZone, not fully implemented: from="+event.getFromZone() + ", to="+event.getToZone()); } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 5eedb6188c..0ce2366e99 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -66,6 +66,7 @@ import mage.util.functions.ApplyToPermanent; import java.io.Serializable; import java.util.*; +import mage.game.command.Commander; public interface Game extends MageItem, Serializable { @@ -174,6 +175,7 @@ public interface Game extends MageItem, Serializable { void emptyManaPools(); void addEffect(ContinuousEffect continuousEffect, Ability source); void addEmblem(Emblem emblem, Ability source); + void addCommander(Commander commander); void addPermanent(Permanent permanent); // priority methods diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 06368c5daf..2a5dd3974c 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -90,7 +90,9 @@ import java.io.IOException; import java.io.Serializable; import java.util.*; import java.util.Map.Entry; +import mage.abilities.common.CastCommanderAbility; import mage.filter.predicate.permanent.ControllerIdPredicate; +import mage.game.command.Commander; public abstract class GameImpl> implements Game, Serializable { @@ -305,6 +307,13 @@ public abstract class GameImpl> implements Game, Serializa return item; } } + + for (CommandObject commandObject : state.getCommand()) { + if (commandObject instanceof Commander && commandObject.getId().equals(objectId)) { + return commandObject; + } + } + object = getCard(objectId); if (object == null) { @@ -998,7 +1007,18 @@ public abstract class GameImpl> implements Game, Serializa for (Ability ability : newEmblem.getAbilities()) { ability.setSourceId(newEmblem.getId()); } - state.addEmblem(newEmblem); + state.addCommandObject(newEmblem); + } + + + @Override + public void addCommander(Commander commander){ + state.addCommandObject(commander); + for(Ability ability : commander.getAbilities()){ + if(ability instanceof CastCommanderAbility){ + state.addOtherAbility(commander.getId(), (CastCommanderAbility)ability); + } + } } @Override diff --git a/Mage/src/mage/game/GameState.java b/Mage/src/mage/game/GameState.java index 90267668d1..14e4ac659b 100644 --- a/Mage/src/mage/game/GameState.java +++ b/Mage/src/mage/game/GameState.java @@ -42,6 +42,7 @@ import mage.choices.Choice; import mage.game.combat.Combat; import mage.game.combat.CombatGroup; import mage.game.command.Command; +import mage.game.command.CommandObject; import mage.game.command.Emblem; import mage.game.events.GameEvent; import mage.game.permanent.Battlefield; @@ -501,10 +502,10 @@ public class GameState implements Serializable, Copyable { } } - public void addEmblem(Emblem emblem) { - getCommand().add(emblem); - for (Ability ability: emblem.getAbilities()) { - addAbility(ability, emblem); + public void addCommandObject(CommandObject commandObject) { + getCommand().add(commandObject); + for (Ability ability: commandObject.getAbilities()) { + addAbility(ability, commandObject); } }