From 4024acdb28cf5be12f31875da2ea689159fb8b5a Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Thu, 24 Feb 2022 17:51:30 -0500 Subject: [PATCH] [NEM] reworked Kill Switch --- Mage.Sets/src/mage/cards/k/KillSwitch.java | 128 +++++++++++++++------ 1 file changed, 93 insertions(+), 35 deletions(-) diff --git a/Mage.Sets/src/mage/cards/k/KillSwitch.java b/Mage.Sets/src/mage/cards/k/KillSwitch.java index 16ecc2596f9..fb21fcfc698 100644 --- a/Mage.Sets/src/mage/cards/k/KillSwitch.java +++ b/Mage.Sets/src/mage/cards/k/KillSwitch.java @@ -1,57 +1,38 @@ - package mage.cards.k; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; -import mage.abilities.condition.common.SourceTappedBeforeUntapStepCondition; import mage.abilities.costs.common.TapSourceCost; -import mage.abilities.costs.mana.ManaCostsImpl; -import mage.abilities.decorator.ConditionalContinuousRuleModifyingEffect; -import mage.abilities.effects.Effect; -import mage.abilities.effects.common.DontUntapInControllersUntapStepAllEffect; -import mage.abilities.effects.common.TapAllEffect; +import mage.abilities.costs.mana.GenericManaCost; +import mage.abilities.effects.ContinuousRuleModifyingEffectImpl; +import mage.abilities.effects.OneShotEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Duration; -import mage.constants.TargetController; -import mage.constants.Zone; -import mage.filter.common.FilterArtifactPermanent; -import mage.filter.predicate.Predicates; -import mage.filter.predicate.permanent.PermanentIdPredicate; +import mage.constants.Outcome; +import mage.constants.PhaseStep; +import mage.filter.StaticFilters; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTargets; + +import java.util.List; +import java.util.UUID; /** - * * @author spjspj */ public final class KillSwitch extends CardImpl { - - //static { - // filter.add(AnotherPredicate.instance); - // } - public KillSwitch(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ARTIFACT},"{3}"); + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT}, "{3}"); // {2}, {tap}: Tap all other artifacts. They don't untap during their controllers' untap steps for as long as Kill Switch remains tapped. - FilterArtifactPermanent filter = new FilterArtifactPermanent(); - filter.add(Predicates.not(new PermanentIdPredicate(getId()))); - - SourceTappedBeforeUntapStepCondition condition = new SourceTappedBeforeUntapStepCondition(); - condition.setPermanentId(this.getId()); - Effect effect = new ConditionalContinuousRuleModifyingEffect( - new DontUntapInControllersUntapStepAllEffect(Duration.WhileOnBattlefield, TargetController.ANY, filter), - condition); - effect.setText("Artifacts tapped this way don't untap during their controllers' untap steps for as long as {this} remains tapped"); - - Effect effect2 = new TapAllEffect(filter); - effect2.setText("Tap all other artifacts"); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, effect2, new ManaCostsImpl("{2}")); + Ability ability = new SimpleActivatedAbility(new KillSwitchEffect(), new GenericManaCost(2)); ability.addCost(new TapSourceCost()); - ability.addEffect(effect); - this.addAbility(ability); + this.addAbility(ability); } private KillSwitch(final KillSwitch card) { @@ -63,3 +44,80 @@ public final class KillSwitch extends CardImpl { return new KillSwitch(this); } } + +class KillSwitchEffect extends OneShotEffect { + + KillSwitchEffect() { + super(Outcome.Benefit); + staticText = "tap all other artifacts. They don't untap during their controllers' " + + "untap steps for as long as {this} remains tapped"; + } + + private KillSwitchEffect(final KillSwitchEffect effect) { + super(effect); + } + + @Override + public KillSwitchEffect copy() { + return new KillSwitchEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + List permanents = game + .getBattlefield() + .getActivePermanents( + StaticFilters.FILTER_PERMANENT_ARTIFACT, + source.getControllerId(), source.getSourceId(), game + ); + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + if (sourcePermanent != null) { + permanents.remove(sourcePermanent); + game.addEffect(new KillSwitchUntapEffect().setTargetPointer(new FixedTargets(permanents, game)), source); + } + for (Permanent permanent : permanents) { + permanent.tap(source, game); + } + return true; + } +} + +class KillSwitchUntapEffect extends ContinuousRuleModifyingEffectImpl { + + KillSwitchUntapEffect() { + super(Duration.Custom, Outcome.Detriment); + } + + private KillSwitchUntapEffect(final KillSwitchUntapEffect effect) { + super(effect); + } + + @Override + public KillSwitchUntapEffect copy() { + return new KillSwitchUntapEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + return false; + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.UNTAP; + } + + @Override + public boolean applies(GameEvent event, Ability source, Game game) { + if (game.getTurn().getStepType() != PhaseStep.UNTAP) { + return false; + } + Permanent sourcePermanent = source.getSourcePermanentIfItStillExists(game); + if (sourcePermanent == null || !sourcePermanent.isTapped()) { + discard(); + return false; + } + return getTargetPointer().getTargets(game, source).contains(event.getTargetId()) + && game.isActivePlayer(game.getControllerId(event.getTargetId())); + } +}