Unstable Shapeshifter fixed some bugs and clean up.

This commit is contained in:
LevelX2 2016-11-01 01:19:52 +01:00
parent 0ed441b11f
commit 777025bea4
2 changed files with 21 additions and 6 deletions

View file

@ -34,6 +34,7 @@ import mage.abilities.common.EntersBattlefieldAllTriggeredAbility;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import static mage.cards.u.UnstableShapeshifter.filterAnotherCreature;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
@ -51,10 +52,10 @@ import mage.util.functions.EmptyApplyToPermanent;
*/ */
public class UnstableShapeshifter extends CardImpl { public class UnstableShapeshifter extends CardImpl {
private final static FilterCreaturePermanent filter = new FilterCreaturePermanent(); public final static FilterCreaturePermanent filterAnotherCreature = new FilterCreaturePermanent("another creature");
static { static {
filter.add(new AnotherPredicate()); filterAnotherCreature.add(new AnotherPredicate());
} }
public UnstableShapeshifter(UUID ownerId, CardSetInfo setInfo) { public UnstableShapeshifter(UUID ownerId, CardSetInfo setInfo) {
@ -64,8 +65,8 @@ public class UnstableShapeshifter extends CardImpl {
this.power = new MageInt(0); this.power = new MageInt(0);
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// Whenever another creature enters the battlefield under your control, you may have Renegade Doppelganger become a copy of that creature until end of turn. // Whenever another creature enters the battlefield, Unstable Shapeshifter becomes a copy of that creature and gains this ability.
this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new UnstableShapeshifterEffect(), filter, true, SetTargetPointer.PERMANENT, "")); this.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD, new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""));
} }
public UnstableShapeshifter(final UnstableShapeshifter card) { public UnstableShapeshifter(final UnstableShapeshifter card) {
@ -82,7 +83,7 @@ class UnstableShapeshifterEffect extends OneShotEffect {
public UnstableShapeshifterEffect() { public UnstableShapeshifterEffect() {
super(Outcome.Copy); super(Outcome.Copy);
this.staticText = "you may have {this} become a copy of that creature until end of turn"; this.staticText = "{this} becomes a copy of that creature and gains this ability";
} }
public UnstableShapeshifterEffect(final UnstableShapeshifterEffect effect) { public UnstableShapeshifterEffect(final UnstableShapeshifterEffect effect) {
@ -99,7 +100,9 @@ class UnstableShapeshifterEffect extends OneShotEffect {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
Permanent targetCreature = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); Permanent targetCreature = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source));
if (targetCreature != null && permanent != null) { if (targetCreature != null && permanent != null) {
game.copyPermanent(Duration.EndOfTurn, targetCreature, permanent.getId(), source, new EmptyApplyToPermanent()); Permanent blueprintPermanent = game.copyPermanent(Duration.Custom, targetCreature, permanent.getId(), source, new EmptyApplyToPermanent());
blueprintPermanent.addAbility(new EntersBattlefieldAllTriggeredAbility(Zone.BATTLEFIELD,
new UnstableShapeshifterEffect(), filterAnotherCreature, false, SetTargetPointer.PERMANENT, ""), game);
return true; return true;
} }
return false; return false;

View file

@ -1489,6 +1489,18 @@ public abstract class GameImpl implements Game, Serializable {
Ability newAbility = source.copy(); Ability newAbility = source.copy();
newEffect.init(newAbility, this); newEffect.init(newAbility, this);
// If there are already copy effects with dration = Custom to the same object, remove the existing effects because they no longer have any effect
if (Duration.Custom.equals(duration)) {
for (Effect effect : getState().getContinuousEffects().getLayeredEffects(this)) {
if (effect instanceof CopyEffect) {
CopyEffect copyEffect = (CopyEffect) effect;
// there is another copy effect that copies to the same permanent
if (copyEffect.getSourceId().equals(copyToPermanentId) && copyEffect.getDuration().equals(Duration.Custom)) {
copyEffect.discard();
}
}
}
}
state.addEffect(newEffect, newAbility); state.addEffect(newEffect, newAbility);
return newBluePrint; return newBluePrint;
} }