From ee96531de5bb770c5b6e3e9678f46ba68661cc52 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 21 Oct 2016 00:15:41 +0200 Subject: [PATCH] * Fixed that a spell that becomes a permanent didn't had the colors of the spell (e.g. ERsatz Gnomes). --- Mage.Sets/src/mage/cards/e/ErsatzGnomes.java | 6 +- .../src/mage/cards/p/PaintersServant.java | 58 ++--------- .../cards/continuous/ErsatzGnomesTest.java | 99 +++++++++++++++++++ Mage/src/main/java/mage/ObjectColor.java | 25 ++++- Mage/src/main/java/mage/game/stack/Spell.java | 3 + 5 files changed, 135 insertions(+), 56 deletions(-) create mode 100644 Mage.Tests/src/test/java/org/mage/test/cards/continuous/ErsatzGnomesTest.java diff --git a/Mage.Sets/src/mage/cards/e/ErsatzGnomes.java b/Mage.Sets/src/mage/cards/e/ErsatzGnomes.java index 9aa42cb980e..59bedb0ea96 100644 --- a/Mage.Sets/src/mage/cards/e/ErsatzGnomes.java +++ b/Mage.Sets/src/mage/cards/e/ErsatzGnomes.java @@ -49,17 +49,17 @@ import mage.target.TargetSpell; public class ErsatzGnomes extends CardImpl { public ErsatzGnomes(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{3}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{3}"); this.subtype.add("Gnome"); this.power = new MageInt(1); this.toughness = new MageInt(1); - // {tap}: Target spell becomes colorless. + // {T}: Target spell becomes colorless. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesColorTargetEffect(new ObjectColor(), Duration.Custom), new TapSourceCost()); ability.addTarget(new TargetSpell()); this.addAbility(ability); - // {tap}: Target permanent becomes colorless until end of turn. + // {T}: Target permanent becomes colorless until end of turn. ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BecomesColorTargetEffect(new ObjectColor(), Duration.EndOfTurn), new TapSourceCost()); ability.addTarget(new TargetPermanent()); this.addAbility(ability); diff --git a/Mage.Sets/src/mage/cards/p/PaintersServant.java b/Mage.Sets/src/mage/cards/p/PaintersServant.java index 8fdb6e4750a..b84c9b18a61 100644 --- a/Mage.Sets/src/mage/cards/p/PaintersServant.java +++ b/Mage.Sets/src/mage/cards/p/PaintersServant.java @@ -59,7 +59,7 @@ import mage.sets.Commander; public class PaintersServant extends CardImpl { public PaintersServant(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT,CardType.CREATURE},"{2}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{2}"); this.subtype.add("Scarecrow"); this.power = new MageInt(1); @@ -97,24 +97,23 @@ class PaintersServantEffect extends ContinuousEffectImpl { if (color == null) { return false; } - String colorString = color.toString(); for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { - setObjectColor(perm, colorString, game); + perm.getColor(game).addColor(color); } // Stack for (MageObject object : game.getStack()) { if (object instanceof Spell) { - setObjectColor(object, colorString, game); + object.getColor(game).addColor(color); } } // Exile for (Card card : game.getExile().getAllCards(game)) { - setCardColor(card, colorString, game); + game.getState().getCreateCardAttribute(card).getColor().addColor(color); } // Command for (CommandObject commandObject : game.getState().getCommand()) { if (commandObject instanceof Commander) { - setObjectColor(commandObject, colorString, game); + commandObject.getColor(game).addColor(color); } } @@ -123,15 +122,15 @@ class PaintersServantEffect extends ContinuousEffectImpl { if (player != null) { // Hand for (Card card : player.getHand().getCards(game)) { - setCardColor(card, colorString, game); + game.getState().getCreateCardAttribute(card).getColor().addColor(color); } // Library for (Card card : player.getLibrary().getCards(game)) { - setCardColor(card, colorString, game); + game.getState().getCreateCardAttribute(card).getColor().addColor(color); } // Graveyard for (Card card : player.getGraveyard().getCards(game)) { - setCardColor(card, colorString, game); + game.getState().getCreateCardAttribute(card).getColor().addColor(color); } } } @@ -140,47 +139,6 @@ class PaintersServantEffect extends ContinuousEffectImpl { return false; } - protected static void setCardColor(Card card, String colorString, Game game) { - ObjectColor color = game.getState().getCreateCardAttribute(card).getColor(); - switch (colorString) { - case "W": - color.setWhite(true); - break; - case "B": - color.setBlack(true); - break; - case "U": - color.setBlue(true); - break; - case "G": - color.setGreen(true); - break; - case "R": - color.setRed(true); - break; - } - } - - protected static void setObjectColor(MageObject obj, String colorString, Game game) { - switch (colorString) { - case "W": - obj.getColor(game).setWhite(true); - break; - case "B": - obj.getColor(game).setBlack(true); - break; - case "U": - obj.getColor(game).setBlue(true); - break; - case "G": - obj.getColor(game).setGreen(true); - break; - case "R": - obj.getColor(game).setRed(true); - break; - } - } - @Override public PaintersServantEffect copy() { return new PaintersServantEffect(this); diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ErsatzGnomesTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ErsatzGnomesTest.java new file mode 100644 index 00000000000..5b1f330accc --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/continuous/ErsatzGnomesTest.java @@ -0,0 +1,99 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.cards.continuous; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import mage.game.permanent.Permanent; +import org.junit.Assert; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ +public class ErsatzGnomesTest extends CardTestPlayerBase { + + /** + * Ersatz Gnomes is incorrectly used I targeted a spell which is a permanent + * to colorless. When it enters the field its suppose to be colorless not go + * back to normal. It's colorless until it leaves the battlefield when you + * make a permanent spell colorless when you cast it. + */ + @Test + public void testColorlessSpellCreatesColorlessPermanent() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Zone.HAND, playerA, "Silvercoat Lion", 1); + + // {T}: Target spell becomes colorless. + // {T}: Target permanent becomes colorless until end of turn. + addCard(Zone.BATTLEFIELD, playerA, "Ersatz Gnomes"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target spell", "Silvercoat Lion"); + + setStopAt(1, PhaseStep.BEGIN_COMBAT); + execute(); + + assertPermanentCount(playerA, "Silvercoat Lion", 1); + assertTapped("Ersatz Gnomes", true); + Permanent lion = getPermanent("Silvercoat Lion", playerA); + Assert.assertTrue("Silvercoat lion has to be colorless", lion.getColor(currentGame).isColorless()); + } + + @Test + public void testColorlessSpellCreatesColorlessPermanentUntilItBattlefieldLeft() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 4); + addCard(Zone.HAND, playerA, "Silvercoat Lion", 1); + + // {T}: Target spell becomes colorless. + // {T}: Target permanent becomes colorless until end of turn. + addCard(Zone.BATTLEFIELD, playerA, "Ersatz Gnomes"); + + addCard(Zone.BATTLEFIELD, playerB, "Island", 1); + addCard(Zone.HAND, playerB, "Unsummon"); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Silvercoat Lion"); + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target spell", "Silvercoat Lion"); + + castSpell(1, PhaseStep.END_COMBAT, playerB, "Unsummon", "Silvercoat Lion"); + + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Silvercoat Lion"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerB, "Unsummon", 1); + assertPermanentCount(playerA, "Silvercoat Lion", 1); + assertTapped("Ersatz Gnomes", true); + Permanent lion = getPermanent("Silvercoat Lion", playerA); + Assert.assertTrue("Silvercoat lion has to be white", lion.getColor(currentGame).isWhite()); + } + +} diff --git a/Mage/src/main/java/mage/ObjectColor.java b/Mage/src/main/java/mage/ObjectColor.java index 60827481e64..4c4e1eb01fe 100644 --- a/Mage/src/main/java/mage/ObjectColor.java +++ b/Mage/src/main/java/mage/ObjectColor.java @@ -81,19 +81,20 @@ public class ObjectColor implements Serializable, Copyable, Compara red = color.red; green = color.green; } - + /** * Returns a new color which contains all of the colors of this ObjectColor * in addition to all of the colors of the other ObjectColor. + * * @param other The other ObjectColor to union with * @return A new color which is the union of this and other */ public ObjectColor union(ObjectColor other) { ObjectColor newColor = new ObjectColor(); newColor.white = white | other.white; - newColor.blue = blue | other.blue; + newColor.blue = blue | other.blue; newColor.black = black | other.black; - newColor.red = red | other.red; + newColor.red = red | other.red; newColor.green = green | other.green; return newColor; } @@ -146,6 +147,24 @@ public class ObjectColor implements Serializable, Copyable, Compara this.setWhite(color.isWhite()); } + public void addColor(ObjectColor color) { + if (color.isWhite()) { + setWhite(true); + } + if (color.isBlue()) { + setBlue(true); + } + if (color.isBlack()) { + setBlack(true); + } + if (color.isRed()) { + setRed(true); + } + if (color.isGreen()) { + setGreen(true); + } + } + public boolean isColorless() { return !(hasColor()); } diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index 69dfb83d4be..ed562d6b6cd 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -277,6 +277,9 @@ public class Spell extends StackObjImpl implements Card { } } else { updateOptionalCosts(0); + if (!getColor(game).equals(card.getColor(game))) { // if spell color was changed, the created permanent needs to be of that color + game.getState().getCreateCardAttribute(card).getColor().setColor(getColor(game)); + } return controller.moveCards(card, Zone.BATTLEFIELD, ability, game, false, faceDown, false, null); } }