* Finished card attribute change handling for color of cards (card subtype not supported yet) related to #408

This commit is contained in:
LevelX2 2015-06-10 14:00:37 +02:00
parent 199ff16c0c
commit 93dcf2d59f
6 changed files with 131 additions and 34 deletions

View file

@ -37,7 +37,6 @@ import mage.constants.SetType;
* @author LevelX2
*/
public class Conspiracy extends ExpansionSet {
private static final Conspiracy fINSTANCE = new Conspiracy();

View file

@ -54,6 +54,7 @@ public class CeruleanWisps extends CardImpl {
this.getSpellAbility().addTarget(new TargetCreaturePermanent());
this.getSpellAbility().addEffect(new BecomesColorTargetEffect(ObjectColor.BLUE, Duration.EndOfTurn));
this.getSpellAbility().addEffect(new UntapTargetEffect());
// Draw a card.
this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(1));
}

View file

@ -78,15 +78,15 @@ class DragonsClawAbility extends TriggeredAbilityImpl {
return new DragonsClawAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == EventType.SPELL_CAST;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getType() == EventType.SPELL_CAST) {
Spell spell = game.getStack().getSpell(event.getTargetId());
if (spell != null && spell.getColor(game).isRed()) {
return true;
}
}
return false;
Spell spell = game.getStack().getSpell(event.getTargetId());
return spell != null && spell.getColor(game).isRed();
}
@Override

View file

@ -75,6 +75,13 @@ public class PaintersServantTest extends CardTestPlayerBase {
Assert.assertEquals(true, silvercoatLion.getColor(currentGame).isWhite());
Assert.assertEquals(true, silvercoatLion.getColor(currentGame).isBlue());
for(Card card: playerA.getLibrary().getCards(currentGame)) {
Assert.assertEquals(card.getName() + " should be blue",true, card.getColor(currentGame).isBlue());
}
for(Card card: playerB.getLibrary().getCards(currentGame)) {
Assert.assertEquals(card.getName() + " should be blue",true, card.getColor(currentGame).isBlue());
}
for(Card card: playerA.getHand().getCards(currentGame)) {
Assert.assertEquals(true, card.getColor(currentGame).isRed());
Assert.assertEquals(true, card.getColor(currentGame).isBlue());
@ -131,6 +138,13 @@ public class PaintersServantTest extends CardTestPlayerBase {
Assert.assertEquals(true, silvercoatLion.getColor(currentGame).isWhite());
Assert.assertEquals(false, silvercoatLion.getColor(currentGame).isBlue());
for(Card card: playerA.getLibrary().getCards(currentGame)) {
Assert.assertEquals(card.getName() + " should not be blue",false, card.getColor(currentGame).isBlue());
}
for(Card card: playerB.getLibrary().getCards(currentGame)) {
Assert.assertEquals(card.getName() + " should not be blue",false, card.getColor(currentGame).isBlue());
}
for(Card card: playerA.getHand().getCards(currentGame)) {
Assert.assertEquals(true, card.getColor(currentGame).isRed());
Assert.assertEquals(false, card.getColor(currentGame).isBlue());
@ -154,4 +168,83 @@ public class PaintersServantTest extends CardTestPlayerBase {
}
/**
* 5/1/2008 While Painter's Servant is on the battlefield, an effect that
* changes an object's colors will overwrite Painter's Servant's effect. For
* example, casting Cerulean Wisps on a creature will turn it blue,
* regardless of the color chosen for Painter's Servant.
*/
@Test
public void testColorOverwrite() {
// As Painter's Servant enters the battlefield, choose a color.
// All cards that aren't on the battlefield, spells, and permanents are the chosen color in addition to their other colors.
addCard(Zone.HAND, playerA, "Painter's Servant", 1);
addCard(Zone.BATTLEFIELD, playerA, "Swamp", 2);
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
// Target creature becomes blue until end of turn. Untap that creature.
// Draw a card.
addCard(Zone.HAND, playerB, "Cerulean Wisps", 1); // Instant {U}
addCard(Zone.BATTLEFIELD, playerB, "Island", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Painter's Servant");
setChoice(playerA, "Red");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cerulean Wisps", "Silvercoat Lion", "Painter's Servant", StackClause.WHILE_NOT_ON_STACK);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Painter's Servant", 1);
Permanent silvercoatLion = getPermanent("Silvercoat Lion", playerA);
Assert.assertEquals(false, silvercoatLion.getColor(currentGame).isWhite());
Assert.assertEquals(false, silvercoatLion.getColor(currentGame).isRed());
Assert.assertEquals(true, silvercoatLion.getColor(currentGame).isBlue());
}
/**
* Check color of spells
*/
@Test
public void testColorSpell() {
// As Painter's Servant enters the battlefield, choose a color.
// All cards that aren't on the battlefield, spells, and permanents are the chosen color in addition to their other colors.
addCard(Zone.HAND, playerA, "Painter's Servant", 1);
// Draw two cards.
addCard(Zone.HAND, playerA, "Divination", 1); // {U}{2}
addCard(Zone.BATTLEFIELD, playerA, "Island", 5);
// Whenever a player casts a red spell, you may gain 1 life.
addCard(Zone.BATTLEFIELD, playerA, "Dragon's Claw");
addCard(Zone.BATTLEFIELD, playerA, "Silvercoat Lion");
// Target creature becomes blue until end of turn. Untap that creature.
// Draw a card.
addCard(Zone.HAND, playerB, "Cerulean Wisps", 1); // Instant {U}
addCard(Zone.BATTLEFIELD, playerB, "Island", 1);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Painter's Servant");
setChoice(playerA, "Red");
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, "Cerulean Wisps", "Silvercoat Lion", "Painter's Servant", StackClause.WHILE_NOT_ON_STACK);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Divination", NO_TARGET, "Painter's Servant", StackClause.WHILE_NOT_ON_STACK);
setStopAt(1, PhaseStep.BEGIN_COMBAT);
execute();
assertPermanentCount(playerA, "Painter's Servant", 1);
assertGraveyardCount(playerA, "Divination", 1);
assertGraveyardCount(playerB, "Cerulean Wisps", 1);
assertLife(playerA, 22); // + 1 from Cerulean Wisps + 1 from Divination
Permanent silvercoatLion = getPermanent("Silvercoat Lion", playerA);
Assert.assertEquals(false, silvercoatLion.getColor(currentGame).isWhite());
Assert.assertEquals(false, silvercoatLion.getColor(currentGame).isRed());
Assert.assertEquals(true, silvercoatLion.getColor(currentGame).isBlue());
}
}

View file

@ -803,7 +803,7 @@ public class ContinuousEffects implements Serializable {
}
}
// Must be called here for some effects to be able to work correctly
// TODO: add info which effects that need
// TODO: add info which effects need that call
game.applyEffects();
} while (true);
return caught;

View file

@ -41,8 +41,6 @@ import mage.constants.Layer;
import mage.constants.Outcome;
import mage.constants.SubLayer;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.game.stack.StackObject;
import mage.players.Player;
/**
@ -50,7 +48,7 @@ import mage.players.Player;
*/
public class BecomesColorTargetEffect extends ContinuousEffectImpl {
private final ObjectColor setColor;
private ObjectColor setColor;
/**
* Set the color of a spell or permanent
@ -76,49 +74,55 @@ public class BecomesColorTargetEffect extends ContinuousEffectImpl {
}
@Override
public boolean apply(Game game, Ability source) {
public void init(Ability source, Game game) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
boolean result = false;
ObjectColor objectColor;
return;
}
if (setColor == null) {
ChoiceColor choice = new ChoiceColor();
while (!choice.isChosen()) {
controller.choose(Outcome.PutManaInPool, choice, game);
if (!controller.isInGame()) {
return false;
return;
}
}
if (choice.getColor() != null) {
objectColor = choice.getColor();
setColor = choice.getColor();
} else {
return false;
return;
}
if (!game.isSimulation()) {
game.informPlayers(controller.getLogName() + " has chosen the color: " + objectColor.toString());
game.informPlayers(controller.getLogName() + " has chosen the color: " + setColor.toString());
}
} else {
objectColor = this.setColor;
}
super.init(source, game); //To change body of generated methods, choose Tools | Templates.
}
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
if (objectColor != null) {
if (setColor != null) {
boolean objectFound = false;
for (UUID targetId :targetPointer.getTargets(game, source)) {
MageObject o = game.getObject(targetId);
if (o != null) {
if (o instanceof Permanent || o instanceof StackObject) {
o.getColor(game).setColor(objectColor);
result = true;
}
MageObject targetObject = game.getObject(targetId);
if (targetObject != null) {
objectFound = true;
targetObject.getColor(game).setColor(setColor);
}
}
}
if (!result) {
if (this.getDuration().equals(Duration.Custom)) {
if (!objectFound && this.getDuration().equals(Duration.Custom)) {
this.discard();
}
return true;
} else {
throw new UnsupportedOperationException("No color set");
}
return result;
}
@Override