Much simpler way to implement DontUntapAsLongAsSourceTappedEffect.

This also works correctly when the source permanent untaps and then taps again.
This commit is contained in:
LoneFox 2015-09-29 15:11:01 +03:00
parent d9e1a72ad1
commit 705bdabafb

View file

@ -30,20 +30,22 @@ package mage.abilities.effects.common;
import java.util.UUID; import java.util.UUID;
import mage.abilities.Ability; 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.constants.Duration;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.events.GameEvent;
/** /**
* *
* @author LoneFox * @author LoneFox
*/ */
public class DontUntapAsLongAsSourceTappedEffect extends RestrictionEffect { public class DontUntapAsLongAsSourceTappedEffect extends ConditionalContinuousRuleModifyingEffect {
public DontUntapAsLongAsSourceTappedEffect() { 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."; 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 @Override
public boolean applies(Permanent permanent, Ability source, Game game) { public boolean applies(GameEvent event, Ability source, Game game) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); if(event.getType() == GameEvent.EventType.UNTAP && event.getTargetId().equals(source.getSourceId())) {
if(sourcePermanent != null && sourcePermanent.isTapped()) { effect.discard();
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;
}
}
} }
return false; return super.applies(event, source, game);
}
@Override
public boolean canBeUntapped(Permanent permanent, Ability source, Game game) {
return false;
} }
@Override @Override