From 0edc794c6a5bd5013f79f7519248010d2c91a73d Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sun, 31 Mar 2013 11:54:27 +0200 Subject: [PATCH] Fix for Lazav, Dimir Mastermind. Added two additional tests for Lazav. --- .../sets/gatecrash/LazavDimirMastermind.java | 55 +++++++----- .../cards/copy/LazavDimirMastermindTest.java | 83 ++++++++++++++++++- 2 files changed, 114 insertions(+), 24 deletions(-) diff --git a/Mage.Sets/src/mage/sets/gatecrash/LazavDimirMastermind.java b/Mage.Sets/src/mage/sets/gatecrash/LazavDimirMastermind.java index 5be68ed4254..e78388a2c4f 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/LazavDimirMastermind.java +++ b/Mage.Sets/src/mage/sets/gatecrash/LazavDimirMastermind.java @@ -27,10 +27,10 @@ */ package mage.sets.gatecrash; -import java.util.Iterator; import java.util.UUID; import mage.Constants; import mage.Constants.CardType; +import mage.Constants.Outcome; import mage.Constants.Rarity; import mage.Constants.Zone; import mage.MageInt; @@ -38,6 +38,7 @@ import mage.abilities.Ability; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.Effect; +import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.HexproofAbility; import mage.cards.Card; import mage.cards.CardImpl; @@ -107,9 +108,8 @@ class CreatureCardPutOpponentGraveyardTriggeredAbility extends TriggeredAbilityI } if (game.getOpponents(controllerId).contains(event.getPlayerId()) && card.getCardType().contains(CardType.CREATURE)) { - for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(card.getId())); - } + // store the card id to copy + game.getState().setValue(new StringBuilder("CardToCopy").append(getSourceId().toString()).toString(), card.getId()); return true; } } @@ -124,12 +124,17 @@ class CreatureCardPutOpponentGraveyardTriggeredAbility extends TriggeredAbilityI class LazavDimirEffect extends ContinuousEffectImpl { + protected UUID IdOfCopiedCard; + protected Card cardToCopy; + public LazavDimirEffect() { super(Constants.Duration.WhileOnBattlefield, Constants.Layer.CopyEffects_1, Constants.SubLayer.NA, Constants.Outcome.BecomeCreature); } public LazavDimirEffect(final LazavDimirEffect effect) { super(effect); + this.cardToCopy = effect.cardToCopy; + this.IdOfCopiedCard = effect.IdOfCopiedCard; } @Override @@ -139,47 +144,53 @@ class LazavDimirEffect extends ContinuousEffectImpl { @Override public boolean apply(Game game, Ability source) { - Card card = game.getCard(targetPointer.getFirst(game, source)); + Object object = game.getState().getValue(new StringBuilder("CardToCopy").append(source.getSourceId().toString()).toString()); + Card card = null; + if (object instanceof UUID) { + card = game.getCard((UUID) object); + } Permanent permanent = game.getPermanent(source.getSourceId()); if (card == null || permanent == null) { return false; } - permanent.getPower().setValue(card.getPower().getValue()); - permanent.getToughness().setValue(card.getToughness().getValue()); - permanent.getColor().setColor(card.getColor()); + if (IdOfCopiedCard == null || !IdOfCopiedCard.equals((UUID) object)) { + IdOfCopiedCard = (UUID) object; + cardToCopy = card.copy(); + cardToCopy.assignNewId(); + } + permanent.getPower().setValue(cardToCopy.getPower().getValue()); + permanent.getToughness().setValue(cardToCopy.getToughness().getValue()); + permanent.getColor().setColor(cardToCopy.getColor()); permanent.getManaCost().clear(); - permanent.getManaCost().add(card.getManaCost()); + permanent.getManaCost().add(cardToCopy.getManaCost()); permanent.getCardType().clear(); - for (CardType type : card.getCardType()) { + for (CardType type : cardToCopy.getCardType()) { if (!permanent.getCardType().contains(type)) { permanent.getCardType().add(type); } } permanent.getSubtype().clear(); - for (String type : card.getSubtype()) { + for (String type : cardToCopy.getSubtype()) { if (!permanent.getSubtype().contains(type)) { permanent.getSubtype().add(type); } } permanent.getSupertype().clear(); permanent.getSupertype().add("Legendary"); - for (String type : card.getSupertype()) { + for (String type : cardToCopy.getSupertype()) { if (!permanent.getSupertype().contains(type)) { permanent.getSupertype().add(type); } } - permanent.setExpansionSetCode(card.getExpansionSetCode()); - for (Iterator it = permanent.getAbilities().iterator();it.hasNext();) { - Ability ability = it.next(); - if (!(ability instanceof HexproofAbility) && !(ability instanceof CreatureCardPutOpponentGraveyardTriggeredAbility)) { - it.remove(); - } - } - for (Ability ability : card.getAbilities()) { + permanent.removeAllAbilities(source.getSourceId(), game); + permanent.addAbility(HexproofAbility.getInstance(), source.getSourceId(), game); + permanent.addAbility(new CreatureCardPutOpponentGraveyardTriggeredAbility(), source.getSourceId(), game); + + for (Ability ability : cardToCopy.getAbilities()) { if (!permanent.getAbilities().contains(ability)) { - permanent.addAbility(ability, source.getId(), game); + permanent.addAbility(ability, source.getSourceId(), game); } } return true; } -} \ No newline at end of file +} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/LazavDimirMastermindTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/LazavDimirMastermindTest.java index 2957afa0a02..7c16415cfd5 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/LazavDimirMastermindTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/LazavDimirMastermindTest.java @@ -9,6 +9,16 @@ import org.junit.Test; import org.mage.test.serverside.base.CardTestPlayerBase; /** + * + * Lazav, Dimir Mastermind + * + * Legendary Creature — Shapeshifter 3/3, UUBB + * Hexproof + * Whenever a creature card is put into an opponent's graveyard from anywhere, you may have + * Lazav, Dimir Mastermind become a copy of that card except its name is still + * Lazav, Dimir Mastermind, it's legendary in addition to its other types, and + * it gains hexproof and this ability. + * * @author LevelX2 */ public class LazavDimirMastermindTest extends CardTestPlayerBase { @@ -23,7 +33,7 @@ public class LazavDimirMastermindTest extends CardTestPlayerBase { addCard(Constants.Zone.LIBRARY, playerB, "Assault Griffin",5); skipInitShuffling(); - + activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target player puts the top card of his or her library into his or her graveyard.", playerB); setStopAt(1, Constants.PhaseStep.END_TURN); @@ -38,7 +48,7 @@ public class LazavDimirMastermindTest extends CardTestPlayerBase { } /** - * Tests copy simple creature + * Tests copy card with static abilitiy gaining ability to other permanents */ @Test public void testRatsHaveDeathtouch() { @@ -66,4 +76,73 @@ public class LazavDimirMastermindTest extends CardTestPlayerBase { Assert.assertTrue("Gutter Skulk should have deathtouch but hasn't", gutterSkulk.getAbilities().contains(DeathtouchAbility.getInstance())); } + + /** + * Tests copy Nightveil Specter + * + * Nightveil Specter + * Creature — Specter 2/3, {U/B}{U/B}{U/B} + * Flying + * Whenever Nightveil Specter deals combat damage to a player, that player exiles the top card of his or her library. + * You may play cards exiled with Nightveil Specter. + * + */ + @Test + public void testCopyNightveilSpecter() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Plains", 2); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Lazav, Dimir Mastermind", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Codex Shredder", 1); + + addCard(Constants.Zone.LIBRARY, playerB, "Silvercoat Lion",2); + addCard(Constants.Zone.LIBRARY, playerB, "Nightveil Specter",1); + skipInitShuffling(); + + activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target player puts the top card of his or her library into his or her graveyard.", playerB); + + attack(3, playerA, "Lazav, Dimir Mastermind"); + + castSpell(3, Constants.PhaseStep.POSTCOMBAT_MAIN, playerA, "Silvercoat Lion"); + + setStopAt(3, Constants.PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, "Lazav, Dimir Mastermind", 1); + assertPowerToughness(playerA, "Lazav, Dimir Mastermind", 2, 3); + + Permanent lazav = getPermanent("Lazav, Dimir Mastermind", playerA.getId()); + Assert.assertTrue(lazav.getAbilities().contains(FlyingAbility.getInstance())); + Assert.assertTrue(lazav.getSubtype().contains("Specter")); + Assert.assertTrue(lazav.getSupertype().contains("Legendary")); + + assertPermanentCount(playerA, "Silvercoat Lion", 1); + assertPowerToughness(playerA, "Silvercoat Lion", 2, 2); + + } + + @Test + public void testCopyMultipleTimes() { + addCard(Constants.Zone.BATTLEFIELD, playerA, "Lazav, Dimir Mastermind", 1); + addCard(Constants.Zone.BATTLEFIELD, playerA, "Codex Shredder", 1); + + addCard(Constants.Zone.LIBRARY, playerB, "Silvercoat Lion",2); + addCard(Constants.Zone.LIBRARY, playerB, "Nightveil Specter",1); + skipInitShuffling(); + + // Lazav becomes a Nightveil Specter + activateAbility(1, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target player puts the top card of his or her library into his or her graveyard.", playerB); + + // Lazav becomes a Silvercoat Lion + activateAbility(3, Constants.PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Target player puts the top card of his or her library into his or her graveyard.", playerB); + + setStopAt(3, Constants.PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, "Lazav, Dimir Mastermind", 1); + assertPowerToughness(playerA, "Lazav, Dimir Mastermind", 2, 2); + + Permanent lazav = getPermanent("Lazav, Dimir Mastermind", playerA.getId()); + Assert.assertTrue(lazav.getSubtype().contains("Cat")); + Assert.assertTrue(lazav.getSupertype().contains("Legendary")); + + } }