From 792e23a0b0119472d6bdc1cb9476cd2f6bdb43c2 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 5 Aug 2014 14:48:36 +0200 Subject: [PATCH] * Steel Hellkite - Fixed that the activated ability of a Steel Hellkite copied with Phantasmal Image did not work. --- .../sets/scarsofmirrodin/SteelHellkite.java | 72 ++++--------------- .../test/cards/copy/PhantasmalImageTest.java | 43 +++++++++++ .../common/PlayerDamagedBySourceWatcher.java | 2 +- 3 files changed, 58 insertions(+), 59 deletions(-) diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java index a3128c3067f..3190efa5853 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/SteelHellkite.java @@ -27,7 +27,7 @@ */ package mage.sets.scarsofmirrodin; -import mage.constants.*; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.LimitedTimesPerTurnActivatedAbility; @@ -38,16 +38,15 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continious.BoostSourceEffect; import mage.abilities.keyword.FlyingAbility; import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.Zone; import mage.filter.common.FilterNonlandPermanent; import mage.game.Game; -import mage.game.events.DamagedPlayerEvent; -import mage.game.events.GameEvent; import mage.game.permanent.Permanent; -import mage.watchers.Watcher; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; +import mage.watchers.common.PlayerDamagedBySourceWatcher; /** * @author nantuko @@ -68,7 +67,6 @@ public class SteelHellkite extends CardImpl { // {X}: Destroy each nonland permanent with converted mana cost X whose controller was dealt combat damage by Steel Hellkite this turn. Activate this ability only once each turn. this.addAbility(new LimitedTimesPerTurnActivatedAbility(Zone.BATTLEFIELD, new SteelHellkiteDestroyEffect(), new ManaCostsImpl("{X}"))); - this.addWatcher(new SteelHellkiteWatcher()); } public SteelHellkite(final SteelHellkite card) { @@ -85,7 +83,7 @@ class SteelHellkiteDestroyEffect extends OneShotEffect { public SteelHellkiteDestroyEffect() { super(Outcome.DestroyPermanent); - staticText = "Destroy each nonland permanent with converted mana cost X whose controller was dealt combat damage by Steel Hellkite this turn"; + staticText = "Destroy each nonland permanent with converted mana cost X whose controller was dealt combat damage by {this} this turn"; } public SteelHellkiteDestroyEffect(final SteelHellkiteDestroyEffect effect) { @@ -99,57 +97,15 @@ class SteelHellkiteDestroyEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - SteelHellkiteWatcher watcher = (SteelHellkiteWatcher) game.getState().getWatchers().get("SteelHellkiteWatcher", source.getSourceId()); - if (watcher != null) { - int xValue = source.getManaCostsToPay().getX(); - for (UUID uuid : watcher.damagedPlayers) { - for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), uuid, game)) { - if (permanent.getControllerId().equals(uuid) && permanent.getManaCost().convertedManaCost() == xValue) { - permanent.destroy(source.getId(), game, false); - } + int xValue = source.getManaCostsToPay().getX(); + for (Permanent permanent: game.getBattlefield().getActivePermanents(new FilterNonlandPermanent(), source.getControllerId(), source.getSourceId(), game)) { + if (permanent.getManaCost().convertedManaCost() == xValue) { + PlayerDamagedBySourceWatcher watcher = (PlayerDamagedBySourceWatcher) game.getState().getWatchers().get("PlayerDamagedBySource", permanent.getControllerId()); + if (watcher != null && watcher.hasSourceDoneDamage(source.getSourceId(), game)) { + permanent.destroy(source.getSourceId(), game, false); } } } return true; } } - -class SteelHellkiteWatcher extends Watcher { - - public List damagedPlayers = new ArrayList(); - - public SteelHellkiteWatcher() { - super("SteelHellkiteWatcher", WatcherScope.CARD); - } - - public SteelHellkiteWatcher(final SteelHellkiteWatcher watcher) { - super(watcher); - damagedPlayers.addAll(watcher.damagedPlayers); - } - - @Override - public SteelHellkiteWatcher copy() { - return new SteelHellkiteWatcher(this); - } - - @Override - public void watch(GameEvent event, Game game) { - if (event.getType() == GameEvent.EventType.DAMAGED_PLAYER) { - DamagedPlayerEvent damageEvent = (DamagedPlayerEvent)event; - UUID sourceId = damageEvent.getSourceId(); - Permanent permanent = game.getPermanent(sourceId); - if (sourceId != null && permanent != null && permanent.getName().equals("Steel Hellkite")) { - if (!damagedPlayers.contains(event.getTargetId())) { - damagedPlayers.add(event.getTargetId()); - } - } - } - } - - @Override - public void reset() { - super.reset(); - damagedPlayers.clear(); - } - -} diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java index d478c38785a..ff537fe4ea8 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/copy/PhantasmalImageTest.java @@ -260,4 +260,47 @@ public class PhantasmalImageTest extends CardTestPlayerBase { assertLife(playerA, 18); } + /** + * I attack with a Phantasmal Image of Steel Hellkite. It deals damage. I activate + * it for zero. A.I. has Chalice of the Void set to one counter. The Chalice should + * be destroyed I think as in play it has a converted mana cost of zero but it is not. + */ + + @Test + public void testCopiedSteelHellkite() { + addCard(Zone.BATTLEFIELD, playerA, "Steel Hellkite"); + addCard(Zone.HAND, playerA, "Chalice of the Void"); + + + addCard(Zone.BATTLEFIELD, playerB, "Island", 2); + addCard(Zone.HAND, playerB, "Phantasmal Image"); + + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Chalice of the Void"); + setChoice(playerA, "X=0"); + + castSpell(2, PhaseStep.PRECOMBAT_MAIN, playerB, "Phantasmal Image"); + setChoice(playerB, "Steel Hellkite"); + + attack(4, playerB, "Steel Hellkite"); + + activateAbility(4, PhaseStep.POSTCOMBAT_MAIN, playerB, "{X}: Destroy each nonland permanent with converted mana cost X whose controller was dealt combat damage by {this} this turn. Activate this ability only once each turn."); + setChoice(playerB, "X=0"); + + + setStopAt(4, PhaseStep.END_TURN); + execute(); + + assertPermanentCount(playerA, "Steel Hellkite", 1); + assertPermanentCount(playerB, "Steel Hellkite", 1); + + assertLife(playerB, 20); + assertLife(playerA, 15); + + assertPermanentCount(playerA, "Chalice of the Void", 0); + assertGraveyardCount(playerA, "Chalice of the Void", 1); + + + + } } diff --git a/Mage/src/mage/watchers/common/PlayerDamagedBySourceWatcher.java b/Mage/src/mage/watchers/common/PlayerDamagedBySourceWatcher.java index 63ff552cb13..73020e7a5d4 100644 --- a/Mage/src/mage/watchers/common/PlayerDamagedBySourceWatcher.java +++ b/Mage/src/mage/watchers/common/PlayerDamagedBySourceWatcher.java @@ -44,7 +44,7 @@ import mage.watchers.Watcher; */ public class PlayerDamagedBySourceWatcher extends Watcher { - private Set damageSourceIds = new HashSet(); + private final Set damageSourceIds = new HashSet<>(); public PlayerDamagedBySourceWatcher(UUID playerId) { super("PlayerDamagedBySource", WatcherScope.PLAYER);