From 93dcf2d59f6dc2020e03bb3dba2e6cc49be590b4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Wed, 10 Jun 2015 14:00:37 +0200 Subject: [PATCH] * Finished card attribute change handling for color of cards (card subtype not supported yet) related to #408 --- Mage.Sets/src/mage/sets/Conspiracy.java | 1 - .../mage/sets/shadowmoor/CeruleanWisps.java | 1 + .../mage/sets/tenthedition/DragonsClaw.java | 14 +-- .../cards/continuous/PaintersServantTest.java | 93 +++++++++++++++++++ .../abilities/effects/ContinuousEffects.java | 2 +- .../continuous/BecomesColorTargetEffect.java | 54 ++++++----- 6 files changed, 131 insertions(+), 34 deletions(-) diff --git a/Mage.Sets/src/mage/sets/Conspiracy.java b/Mage.Sets/src/mage/sets/Conspiracy.java index cb0ad96e7c7..1cf7af1408a 100644 --- a/Mage.Sets/src/mage/sets/Conspiracy.java +++ b/Mage.Sets/src/mage/sets/Conspiracy.java @@ -37,7 +37,6 @@ import mage.constants.SetType; * @author LevelX2 */ - public class Conspiracy extends ExpansionSet { private static final Conspiracy fINSTANCE = new Conspiracy(); diff --git a/Mage.Sets/src/mage/sets/shadowmoor/CeruleanWisps.java b/Mage.Sets/src/mage/sets/shadowmoor/CeruleanWisps.java index dcecf07ef75..c3b478e635c 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/CeruleanWisps.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/CeruleanWisps.java @@ -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)); } diff --git a/Mage.Sets/src/mage/sets/tenthedition/DragonsClaw.java b/Mage.Sets/src/mage/sets/tenthedition/DragonsClaw.java index 3fb21d7d48c..86a28f2dd3c 100644 --- a/Mage.Sets/src/mage/sets/tenthedition/DragonsClaw.java +++ b/Mage.Sets/src/mage/sets/tenthedition/DragonsClaw.java @@ -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 diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/PaintersServantTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/PaintersServantTest.java index 9ad87ebb8c5..2a45bf0f4a6 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/PaintersServantTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/PaintersServantTest.java @@ -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()); + + + } + + } diff --git a/Mage/src/mage/abilities/effects/ContinuousEffects.java b/Mage/src/mage/abilities/effects/ContinuousEffects.java index 561f1facc32..0b2c1fbe43b 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffects.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffects.java @@ -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; diff --git a/Mage/src/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java b/Mage/src/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java index b93a7cfff53..975beaa6e71 100644 --- a/Mage/src/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/continuous/BecomesColorTargetEffect.java @@ -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