From 705bdabafbfb47de85f9d24a4d1ca065bdb93d86 Mon Sep 17 00:00:00 2001 From: LoneFox Date: Tue, 29 Sep 2015 15:11:01 +0300 Subject: [PATCH] Much simpler way to implement DontUntapAsLongAsSourceTappedEffect. This also works correctly when the source permanent untaps and then taps again. --- .../DontUntapAsLongAsSourceTappedEffect.java | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/Mage/src/mage/abilities/effects/common/DontUntapAsLongAsSourceTappedEffect.java b/Mage/src/mage/abilities/effects/common/DontUntapAsLongAsSourceTappedEffect.java index b6ee8a4061..f84dc06cee 100644 --- a/Mage/src/mage/abilities/effects/common/DontUntapAsLongAsSourceTappedEffect.java +++ b/Mage/src/mage/abilities/effects/common/DontUntapAsLongAsSourceTappedEffect.java @@ -30,20 +30,22 @@ package mage.abilities.effects.common; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.effects.RestrictionEffect; +import mage.abilities.condition.common.SourceTappedCondition; +import mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect; +import mage.abilities.effects.common.DontUntapInControllersUntapStepTargetEffect; import mage.constants.Duration; import mage.game.Game; -import mage.game.permanent.Permanent; +import mage.game.events.GameEvent; /** * * @author LoneFox */ -public class DontUntapAsLongAsSourceTappedEffect extends RestrictionEffect { +public class DontUntapAsLongAsSourceTappedEffect extends ConditionalContinuousRuleModifyingEffect { public DontUntapAsLongAsSourceTappedEffect() { - super(Duration.WhileOnBattlefield); + super(new DontUntapInControllersUntapStepTargetEffect(Duration.Custom), SourceTappedCondition.getInstance()); staticText = "It doesn't untap during its controller's untap step for as long as {source} remains tapped."; } @@ -52,23 +54,11 @@ public class DontUntapAsLongAsSourceTappedEffect extends RestrictionEffect { } @Override - public boolean applies(Permanent permanent, Ability source, Game game) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if(sourcePermanent != null && sourcePermanent.isTapped()) { - String name = sourcePermanent.getName(); - if(sourcePermanent.getConnectedCards(name).size() > 0) { - UUID target = sourcePermanent.getConnectedCards(name).get(0); - if(target != null && target.equals(permanent.getId())) { - return true; - } - } + public boolean applies(GameEvent event, Ability source, Game game) { + if(event.getType() == GameEvent.EventType.UNTAP && event.getTargetId().equals(source.getSourceId())) { + effect.discard(); } - return false; - } - - @Override - public boolean canBeUntapped(Permanent permanent, Ability source, Game game) { - return false; + return super.applies(event, source, game); } @Override