From 267ae4f5591e683b659d8fd8c2fcfff8f7a439a5 Mon Sep 17 00:00:00 2001 From: magenoxx Date: Fri, 20 May 2011 21:02:29 +0400 Subject: [PATCH] Awesome bug fix (3h of debuging): 1. ReboundEffect was copied by Ascension. 2. Copied spells moved original spell to grave that caused later wrong changeZone event with from=GRAVEYARD to=GRAVEYARD instead of from=STACK to=GRAVEYARD. --- .../effects/common/CopyTargetSpellEffect.java | 1 + .../abilities/keyword/ReboundAbility.java | 17 +++++++++++-- Mage/src/mage/game/stack/Spell.java | 25 +++++++++++++------ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/CopyTargetSpellEffect.java b/Mage/src/mage/abilities/effects/common/CopyTargetSpellEffect.java index 2bf89862bf7..5621aeca4c3 100644 --- a/Mage/src/mage/abilities/effects/common/CopyTargetSpellEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyTargetSpellEffect.java @@ -55,6 +55,7 @@ public class CopyTargetSpellEffect extends OneShotEffect if (spell != null) { Spell copy = spell.copySpell(); copy.setControllerId(source.getControllerId()); + copy.setCopiedSpell(true); game.getStack().push(copy); copy.chooseNewTargets(game); return true; diff --git a/Mage/src/mage/abilities/keyword/ReboundAbility.java b/Mage/src/mage/abilities/keyword/ReboundAbility.java index 8a3e850228f..f84e8d72018 100644 --- a/Mage/src/mage/abilities/keyword/ReboundAbility.java +++ b/Mage/src/mage/abilities/keyword/ReboundAbility.java @@ -47,6 +47,7 @@ import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.stack.Spell; import mage.players.Player; +import org.apache.log4j.Logger; /** * This ability has no effect by default and will always return false on the call @@ -103,7 +104,7 @@ public class ReboundAbility extends TriggeredAbilityImpl { if ( event.getType() == EventType.SPELL_CAST && this.installReboundEffect ) { Spell spell = game.getStack().getSpell(event.getTargetId()); if (spell != null && spell.getSourceId().equals(this.getSourceId())) { - spell.getSpellAbility().addEffect(new ReboundEffect()); + spell.getSpellAbility().addEffect(new ReboundEffect(spell.getId())); this.installReboundEffect = false; } } @@ -131,16 +132,27 @@ public class ReboundAbility extends TriggeredAbilityImpl { */ class ReboundEffect extends OneShotEffect { - public ReboundEffect ( ) { + private Logger log = Logger.getLogger(ReboundEffect.class); + + private UUID originalId; + + public ReboundEffect(UUID originalId) { super(Outcome.Benefit); + this.originalId = originalId; } public ReboundEffect ( ReboundEffect effect ) { super(effect); + this.originalId = effect.originalId; } @Override public boolean apply(Game game, Ability source) { + if (!originalId.equals(source.getId())) { + log.warn("rebound was ignored. was it copied spell?"); + return false; + } + Card sourceCard = (Card)game.getObject(source.getSourceId()); ReboundEffectCastFromExileDelayedTrigger trigger = new ReboundEffectCastFromExileDelayedTrigger(sourceCard.getId(), sourceCard.getId()); trigger.setControllerId(source.getControllerId()); @@ -276,6 +288,7 @@ class ReboundCastSpellFromExileEffect extends OneShotEffect> implements StackObject, Card { private Card card; private SpellAbility ability; private UUID controllerId; + private boolean copiedSpell; public Spell(Card card, SpellAbility ability, UUID controllerId) { this.card = card; @@ -85,14 +86,18 @@ public class Spell> implements StackObject, Card { else result = true; - if (ability.getEffects().contains(ExileSpellEffect.getInstance())) - game.getExile().getPermanentExile().add(card); - else if (ability.getEffects().contains(ShuffleSpellEffect.getInstance())) { - card.moveToZone(Zone.LIBRARY, ability.getId(), game, false); - Player player = game.getPlayer(controllerId); - if (player != null) player.shuffleLibrary(game); - } else - card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false); + if (!copiedSpell) { + if (ability.getEffects().contains(ExileSpellEffect.getInstance())) + game.getExile().getPermanentExile().add(card); + else if (ability.getEffects().contains(ShuffleSpellEffect.getInstance())) { + card.moveToZone(Zone.LIBRARY, ability.getId(), game, false); + Player player = game.getPlayer(controllerId); + if (player != null) player.shuffleLibrary(game); + } else { + card.moveToZone(Zone.GRAVEYARD, ability.getId(), game, false); + } + } + return result; } //20091005 - 608.2b @@ -344,5 +349,9 @@ public class Spell> implements StackObject, Card { public void assignNewId() { throw new UnsupportedOperationException("Unsupported operation"); } + + public void setCopiedSpell(boolean isCopied) { + this.copiedSpell = isCopied; + } }