[Commander] Added possibility to cast Commander

This commit is contained in:
Plopman 2013-07-17 20:37:31 +02:00
parent e6847a472d
commit 9499c65fe6
4 changed files with 37 additions and 5 deletions

View file

@ -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<T extends CardImpl<T>> extends MageObjectImpl<T> implements Card {
@ -290,6 +291,7 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
case OUTSIDE:
game.getPlayer(ownerId).getSideboard().remove(this);
break;
case COMMAND:
case STACK:
case PICK:
break;
@ -313,6 +315,9 @@ public abstract class CardImpl<T extends CardImpl<T>> extends MageObjectImpl<T>
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<T extends CardImpl<T>> extends MageObjectImpl<T>
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());
}

View file

@ -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

View file

@ -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<T extends GameImpl<T>> implements Game, Serializable {
@ -305,6 +307,13 @@ public abstract class GameImpl<T extends GameImpl<T>> 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<T extends GameImpl<T>> 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

View file

@ -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<GameState> {
}
}
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);
}
}