* Soulflayer - Fixed a bug that Soulflayer had abilities from previous casts when leaving and returning to battlefield.

This commit is contained in:
LevelX2 2015-02-20 02:18:00 +01:00
parent 306a0874dd
commit d07d3228a1

View file

@ -32,6 +32,7 @@ import java.util.List;
import java.util.Set; import java.util.Set;
import java.util.UUID; import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.MageObjectReference;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
@ -59,6 +60,7 @@ import mage.constants.SubLayer;
import mage.constants.Zone; import mage.constants.Zone;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.util.CardUtil;
/** /**
* *
@ -95,10 +97,11 @@ public class Soulflayer extends CardImpl {
class SoulflayerEffect extends ContinuousEffectImpl implements SourceEffect { class SoulflayerEffect extends ContinuousEffectImpl implements SourceEffect {
private Set<Ability> abilitiesToAdd; private Set<Ability> abilitiesToAdd;
private MageObjectReference objectReference = null;
public SoulflayerEffect() { public SoulflayerEffect() {
super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility); super(Duration.WhileOnBattlefield, Layer.AbilityAddingRemovingEffects_6, SubLayer.NA, Outcome.AddAbility);
staticText = "If a creature card with flying was exiled with Soulflayer's delve ability, Soulflayer has flying. The same is true for first strike, double strike, deathtouch, haste, hexproof, indestructible, lifelink, reach, trample, and vigilance"; staticText = "If a creature card with flying was exiled with {this}'s delve ability, {this} has flying. The same is true for first strike, double strike, deathtouch, haste, hexproof, indestructible, lifelink, reach, trample, and vigilance";
abilitiesToAdd = null; abilitiesToAdd = null;
} }
@ -108,6 +111,7 @@ class SoulflayerEffect extends ContinuousEffectImpl implements SourceEffect {
this.abilitiesToAdd = new HashSet<>(); this.abilitiesToAdd = new HashSet<>();
this.abilitiesToAdd.addAll(effect.abilitiesToAdd); this.abilitiesToAdd.addAll(effect.abilitiesToAdd);
} }
this.objectReference = effect.objectReference;
} }
@Override @Override
@ -119,11 +123,11 @@ class SoulflayerEffect extends ContinuousEffectImpl implements SourceEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(source.getSourceId()); Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) { if (permanent != null) {
if (abilitiesToAdd == null) { if (objectReference == null || !objectReference.refersTo(permanent)) {
for (Ability ability :permanent.getAbilities()) {
if (ability instanceof DelveAbility) {
List<Card> delvedCards = ((DelveAbility) ability).getDelvedCards();
abilitiesToAdd = new HashSet<>(); abilitiesToAdd = new HashSet<>();
this.objectReference = new MageObjectReference(permanent);
String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game, true);
List<Card> delvedCards = (List<Card>) game.getState().getValue(keyString);
if (delvedCards != null) { if (delvedCards != null) {
for(Card card: delvedCards) { for(Card card: delvedCards) {
if (!card.getCardType().contains(CardType.CREATURE)) { if (!card.getCardType().contains(CardType.CREATURE)) {
@ -167,8 +171,6 @@ class SoulflayerEffect extends ContinuousEffectImpl implements SourceEffect {
} }
} }
} }
}
}
for (Ability ability: abilitiesToAdd) { for (Ability ability: abilitiesToAdd) {
permanent.addAbility(ability, source.getSourceId(), game); permanent.addAbility(ability, source.getSourceId(), game);
} }