diff --git a/Mage.Sets/src/mage/cards/z/ZangiefTheRedCyclone.java b/Mage.Sets/src/mage/cards/z/ZangiefTheRedCyclone.java new file mode 100644 index 0000000000..de5330f1ea --- /dev/null +++ b/Mage.Sets/src/mage/cards/z/ZangiefTheRedCyclone.java @@ -0,0 +1,143 @@ +package mage.cards.z; + +import mage.MageInt; +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.common.DealsDamageToACreatureTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.condition.common.MyTurnCondition; +import mage.abilities.decorator.ConditionalContinuousEffect; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.SacrificeEffect; +import mage.abilities.effects.common.combat.MustBeBlockedByAtLeastOneSourceEffect; +import mage.abilities.effects.common.continuous.GainAbilitySourceEffect; +import mage.abilities.keyword.IndestructibleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.*; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.common.FilterNonlandPermanent; +import mage.filter.predicate.Predicates; +import mage.game.Game; +import mage.game.events.DamagedEvent; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.targetpointer.FixedTarget; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ZangiefTheRedCyclone extends CardImpl { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("a creature"); + + static { + filter.add(ZangiefTheRedCycloneWatcher::checkPermanent); + } + + public ZangiefTheRedCyclone(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{B}{R}{G}"); + + this.addSuperType(SuperType.LEGENDARY); + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.WARRIOR); + this.power = new MageInt(7); + this.toughness = new MageInt(4); + + // Zangief, the Red Cyclone must be blocked if able. + this.addAbility(new SimpleStaticAbility(new MustBeBlockedByAtLeastOneSourceEffect(Duration.WhileOnBattlefield))); + + // Iron Muscle—As long as it's your turn, Zangief has indestructible. + this.addAbility(new SimpleStaticAbility(new ConditionalContinuousEffect( + new GainAbilitySourceEffect(IndestructibleAbility.getInstance()), + MyTurnCondition.instance, "as long as it's your turn, {this} has indestructible" + )).withFlavorWord("Iron Muscle")); + + // Spinning Piledriver—Whenever Zangief deals damage to a creature, if that creature was dealt excess damage this turn, that creature's controller sacrifices a noncreature, nonland permanent. + this.addAbility(new DealsDamageToACreatureTriggeredAbility( + new ZangiefTheRedCycloneEffect(), false, false, true, filter + ).withFlavorWord("Spinning Piledriver"), new ZangiefTheRedCycloneWatcher()); + } + + private ZangiefTheRedCyclone(final ZangiefTheRedCyclone card) { + super(card); + } + + @Override + public ZangiefTheRedCyclone copy() { + return new ZangiefTheRedCyclone(this); + } +} + +class ZangiefTheRedCycloneEffect extends OneShotEffect { + + private static final FilterPermanent filter = new FilterNonlandPermanent("noncreature, nonland permanent"); + + static { + filter.add(Predicates.not(CardType.CREATURE.getPredicate())); + } + + ZangiefTheRedCycloneEffect() { + super(Outcome.Benefit); + staticText = "if that creature was dealt excess damage this turn, " + + "that creature's controller sacrifices a noncreature, nonland permanent"; + } + + private ZangiefTheRedCycloneEffect(final ZangiefTheRedCycloneEffect effect) { + super(effect); + } + + @Override + public ZangiefTheRedCycloneEffect copy() { + return new ZangiefTheRedCycloneEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Permanent permanent = game.getPermanentOrLKIBattlefield(getTargetPointer().getFirst(game, source)); + if (permanent == null) { + return false; + } + return new SacrificeEffect(filter, 1, "") + .setTargetPointer(new FixedTarget(permanent.getControllerId(), game)) + .apply(game, source); + } +} + +class ZangiefTheRedCycloneWatcher extends Watcher { + + private final Set morSet = new HashSet<>(); + + ZangiefTheRedCycloneWatcher() { + super(WatcherScope.GAME); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.DAMAGED_PERMANENT + && ((DamagedEvent) event).getExcess() >= 1) { + morSet.add(new MageObjectReference(event.getTargetId(), game)); + } + } + + @Override + public void reset() { + super.reset(); + morSet.clear(); + } + + static boolean checkPermanent(Permanent input, Game game) { + return game + .getState() + .getWatcher(ZangiefTheRedCycloneWatcher.class) + .morSet + .stream() + .anyMatch(mor -> mor.refersTo(input, game)); + } +} diff --git a/Mage/src/main/java/mage/abilities/common/DealsDamageToACreatureTriggeredAbility.java b/Mage/src/main/java/mage/abilities/common/DealsDamageToACreatureTriggeredAbility.java index 1dcc7f4ec6..7e1386d93e 100644 --- a/Mage/src/main/java/mage/abilities/common/DealsDamageToACreatureTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/common/DealsDamageToACreatureTriggeredAbility.java @@ -1,9 +1,9 @@ package mage.abilities.common; -import mage.constants.Zone; import mage.abilities.TriggeredAbilityImpl; import mage.abilities.effects.Effect; +import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.game.Game; import mage.game.events.DamagedEvent; @@ -12,7 +12,6 @@ import mage.game.permanent.Permanent; import mage.target.targetpointer.FixedTarget; /** - * * @author LevelX */ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl { @@ -43,7 +42,7 @@ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl public DealsDamageToACreatureTriggeredAbility copy() { return new DealsDamageToACreatureTriggeredAbility(this); } - + @Override public boolean checkEventType(GameEvent event, Game game) { return event.getType() == GameEvent.EventType.DAMAGED_PERMANENT; @@ -60,10 +59,8 @@ public class DealsDamageToACreatureTriggeredAbility extends TriggeredAbilityImpl } } if (setTargetPointer) { - for (Effect effect : this.getEffects()) { - effect.setTargetPointer(new FixedTarget(event.getTargetId(), game)); - effect.setValue("damage", event.getAmount()); - } + this.getEffects().setTargetPointer(new FixedTarget(event.getTargetId(), game)); + this.getEffects().setValue("damage", event.getAmount()); } return true; }