From 6e0a99c610d195c1bccd0578a770aafa23f075a6 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Fri, 28 Nov 2014 09:02:28 +0100 Subject: [PATCH] * Fixed that some Obstinate Baloth, Loxodon Smiter and Wilt Leafe Liege that caused "Discard" event to trigger twice if they were discarded (fixes #607). Some minor reworks. --- .../mage/sets/magic2011/ObstinateBaloth.java | 1 - .../sets/returntoravnica/LoxodonSmiter.java | 1 - .../sets/returntoravnica/RestInPeace.java | 54 ++++++++++--------- .../mage/sets/shadowmoor/WiltLeafLiege.java | 6 +-- .../effects/ContinuousEffectImpl.java | 4 ++ Mage/src/mage/players/PlayerImpl.java | 8 +-- 6 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java index c1df44587dc..5894870ab7c 100644 --- a/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java +++ b/Mage.Sets/src/mage/sets/magic2011/ObstinateBaloth.java @@ -118,7 +118,6 @@ class ObstinateBalothEffect extends ReplacementEffectImpl { Player owner = game.getPlayer(card.getOwnerId()); if (owner != null) { if (owner.putOntoBattlefieldWithInfo(card, game, Zone.HAND, source.getSourceId())) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, card.getId(), source.getSourceId(), owner.getId())); return true; } } diff --git a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java index 23794a4faf4..0fa9d430eb0 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/LoxodonSmiter.java @@ -117,7 +117,6 @@ class LoxodonSmiterEffect extends ReplacementEffectImpl { Player player = game.getPlayer(card.getOwnerId()); if (player != null) { if (card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId())) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, card.getId(), source.getSourceId(), player.getId())); return true; } } diff --git a/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java b/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java index 0624152a50f..90608a99464 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/RestInPeace.java @@ -28,11 +28,6 @@ package mage.sets.returntoravnica; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; -import mage.constants.Zone; import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.SimpleStaticAbility; @@ -40,7 +35,11 @@ import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.ReplacementEffectImpl; import mage.cards.Card; 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.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; @@ -109,19 +108,22 @@ class RestInPeaceExileAllEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - for (UUID playerId : game.getPlayerList()) { - Player player = game.getPlayer(playerId); - if (player != null) { - for (UUID cid : player.getGraveyard().copy()) { - Card c = game.getCard(cid); - if (c != null) { - c.moveToExile(null, null, source.getSourceId(), game); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + for (UUID playerId : controller.getInRange()) { + Player player = game.getPlayer(playerId); + if (player != null) { + for (UUID cid : player.getGraveyard().copy()) { + Card card = game.getCard(cid); + if (card != null) { + controller.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, Zone.GRAVEYARD); + } } } - } + return true; } - return true; + return false; } } @@ -148,16 +150,20 @@ class RestInPeaceReplacementEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - if (((ZoneChangeEvent)event).getFromZone() == Zone.BATTLEFIELD) { - Permanent permanent = ((ZoneChangeEvent)event).getTarget(); - if (permanent != null) { - return permanent.moveToExile(null, "", source.getSourceId(), game); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + if (((ZoneChangeEvent)event).getFromZone() == Zone.BATTLEFIELD) { + Permanent permanent = ((ZoneChangeEvent)event).getTarget(); + if (permanent != null) { + return controller.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD); + } } - } - else { - Card card = game.getCard(event.getTargetId()); - if (card != null) { - return card.moveToExile(null, "", source.getSourceId(), game); + else { + Card card = game.getCard(event.getTargetId()); + if (card != null) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + return controller.moveCardToExileWithInfo(card, null, "", source.getSourceId(), game, zEvent.getFromZone()); + } } } return false; @@ -168,4 +174,4 @@ class RestInPeaceReplacementEffect extends ReplacementEffectImpl { return event.getType() == GameEvent.EventType.ZONE_CHANGE && ((ZoneChangeEvent)event).getToZone() == Zone.GRAVEYARD; } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java b/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java index d8ff079fff5..58bf49f57c6 100644 --- a/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java +++ b/Mage.Sets/src/mage/sets/shadowmoor/WiltLeafLiege.java @@ -132,10 +132,8 @@ class WiltLeafLiegeEffect extends ReplacementEffectImpl { if (card != null) { Player player = game.getPlayer(card.getOwnerId()); if (player != null) { - if (card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId())) { - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.DISCARDED_CARD, card.getId(), source.getSourceId(), player.getId())); - return true; - } + card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId()); + return true; } } return false; diff --git a/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java index bb7311b98fc..9310d100d43 100644 --- a/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java +++ b/Mage/src/mage/abilities/effects/ContinuousEffectImpl.java @@ -145,6 +145,10 @@ public abstract class ContinuousEffectImpl extends EffectImpl implements Continu return discarded; } + /** + * Sets the discarded state of the effect. So it + * will be removed on next check. + */ @Override public void discard() { this.discarded = true; diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 850a2ee0872..4b6aa3a9596 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -714,10 +714,10 @@ public abstract class PlayerImpl implements Player, Serializable { 701.7c If a card is discarded, but an effect causes it to be put into a hidden zone instead of into its owner’s graveyard without being revealed, all values of that card’s characteristics are considered to be undefined. - TODOD: - If a card is discarded this way to pay a cost that specifies a characteristic - about the discarded card, that cost payment is illegal; the game returns to - the moment before the cost was paid (see rule 717, "Handling Illegal Actions"). + TODO: + If a card is discarded this way to pay a cost that specifies a characteristic + about the discarded card, that cost payment is illegal; the game returns to + the moment before the cost was paid (see rule 717, "Handling Illegal Actions"). */ if (card != null) { // write info to game log first so game log infos from triggered or replacement effects follow in the game log