From fb0d9c0f9ddf14681d95c301c9dd4c5a77c1cfce Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 15 Jun 2013 09:43:01 +0200 Subject: [PATCH] * Renegade Doppelganger - Fixed a bug that the copy effect did not end at end of turn and the copy was permanently renewed. --- .../RenegadeDoppelganger.java | 48 +++++++++++-------- .../abilities/effects/common/CopyEffect.java | 6 ++- Mage/src/mage/game/Game.java | 3 ++ Mage/src/mage/game/GameImpl.java | 7 ++- 4 files changed, 41 insertions(+), 23 deletions(-) diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/RenegadeDoppelganger.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/RenegadeDoppelganger.java index c904ed8f0e..0a50b71847 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/RenegadeDoppelganger.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/RenegadeDoppelganger.java @@ -27,12 +27,17 @@ */ package mage.sets.riseoftheeldrazi; -import mage.Constants.*; +import java.util.UUID; +import mage.Constants.CardType; +import mage.Constants.Duration; +import mage.Constants.Outcome; +import mage.Constants.Rarity; +import mage.Constants.Zone; import mage.MageInt; 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.cards.CardImpl; import mage.game.Game; import mage.game.events.GameEvent; @@ -40,7 +45,6 @@ import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; import mage.util.functions.EmptyApplyToPermanent; -import java.util.UUID; /** * @@ -106,32 +110,34 @@ class RenegadeDoppelgangerTriggeredAbility extends TriggeredAbilityImpl { +class RenegadeDoppelgangerEffect extends OneShotEffect { - RenegadeDoppelgangerEffect() { - super(Duration.EndOfTurn, Layer.CopyEffects_1, SubLayer.NA, Outcome.Copy); + public RenegadeDoppelgangerEffect() { + super(Outcome.Benefit); + this.staticText = "have {this} become a copy of that creature until end of turn"; } - RenegadeDoppelgangerEffect(final RenegadeDoppelgangerEffect effect) { + public RenegadeDoppelgangerEffect(final RenegadeDoppelgangerEffect effect) { super(effect); } - @Override - public boolean apply(Game game, Ability source) { - Permanent creature = game.getPermanent(targetPointer.getFirst(game, source)); - Permanent permanent = game.getPermanent(source.getSourceId()); - - if (creature == null || permanent == null) { - return false; - } - - game.copyPermanent(creature, permanent, source, new EmptyApplyToPermanent()); - - return true; - } - @Override public RenegadeDoppelgangerEffect copy() { return new RenegadeDoppelgangerEffect(this); } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanent(source.getSourceId()); + Permanent targetCreature = game.getPermanent(targetPointer.getFirst(game, source)); + if (targetCreature == null) { + targetCreature = (Permanent) game.getLastKnownInformation(getTargetPointer().getFirst(game, source), Zone.BATTLEFIELD); + } + if (targetCreature == null || permanent == null) { + return false; + } + + game.copyPermanent(Duration.EndOfTurn, targetCreature, permanent, source, new EmptyApplyToPermanent()); + return false; + } } diff --git a/Mage/src/mage/abilities/effects/common/CopyEffect.java b/Mage/src/mage/abilities/effects/common/CopyEffect.java index 45587d10ca..b027376300 100644 --- a/Mage/src/mage/abilities/effects/common/CopyEffect.java +++ b/Mage/src/mage/abilities/effects/common/CopyEffect.java @@ -50,7 +50,11 @@ public class CopyEffect extends ContinuousEffectImpl { private UUID sourceId; public CopyEffect(Permanent target, UUID sourceId) { - super(Duration.Custom, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); + this(Duration.Custom, target, sourceId); + } + + public CopyEffect(Duration duration, Permanent target, UUID sourceId) { + super(duration, Layer.CopyEffects_1, SubLayer.NA, Outcome.BecomeCreature); this.target = target; this.sourceId = sourceId; } diff --git a/Mage/src/mage/game/Game.java b/Mage/src/mage/game/Game.java index 4fff07e8f2..05ab8d9552 100644 --- a/Mage/src/mage/game/Game.java +++ b/Mage/src/mage/game/Game.java @@ -65,6 +65,7 @@ import mage.util.functions.ApplyToPermanent; import java.io.Serializable; import java.util.*; +import mage.Constants.Duration; public interface Game extends MageItem, Serializable { @@ -189,6 +190,8 @@ public interface Game extends MageItem, Serializable { * @param applier */ Permanent copyPermanent(Permanent copyFromPermanent, Permanent copyToPermanent, Ability source, ApplyToPermanent applier); + + Permanent copyPermanent(Duration duration, Permanent copyFromPermanent, Permanent copyToPermanent, Ability source, ApplyToPermanent applier); Card copyCard(Card cardToCopy, Ability source, UUID newController); diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index 5a9627f369..ff79d57165 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -997,6 +997,11 @@ public abstract class GameImpl> implements Game, Serializa @Override public Permanent copyPermanent(Permanent copyFromPermanent, Permanent copyToPermanent, Ability source, ApplyToPermanent applier) { + return copyPermanent(Duration.Custom, copyFromPermanent, copyToPermanent, source, applier); + } + + @Override + public Permanent copyPermanent(Duration duration, Permanent copyFromPermanent, Permanent copyToPermanent, Ability source, ApplyToPermanent applier) { Permanent permanent = copyFromPermanent.copy(); //getState().addCard(permanent); @@ -1009,7 +1014,7 @@ public abstract class GameImpl> implements Game, Serializa Ability newAbility = source.copy(); - CopyEffect newEffect = new CopyEffect(permanent, copyToPermanent.getId()); + CopyEffect newEffect = new CopyEffect(duration, permanent, copyToPermanent.getId()); newEffect.newId(); newEffect.setTimestamp(); newEffect.init(newAbility, this);