From 2dcc883b0afb5c73305c0d143c7cb85f13e5e8a9 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sat, 25 May 2019 11:00:48 -0400 Subject: [PATCH] Implemented Zhalfirin Decoy --- .../src/mage/cards/z/ZhalfirinDecoy.java | 108 ++++++++++++++++++ Mage.Sets/src/mage/sets/ModernHorizons.java | 1 + 2 files changed, 109 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/z/ZhalfirinDecoy.java diff --git a/Mage.Sets/src/mage/cards/z/ZhalfirinDecoy.java b/Mage.Sets/src/mage/cards/z/ZhalfirinDecoy.java new file mode 100644 index 0000000000..79e8507767 --- /dev/null +++ b/Mage.Sets/src/mage/cards/z/ZhalfirinDecoy.java @@ -0,0 +1,108 @@ +package mage.cards.z; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.ActivateIfConditionActivatedAbility; +import mage.abilities.condition.Condition; +import mage.abilities.costs.common.TapSourceCost; +import mage.abilities.effects.common.TapTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; +import mage.constants.WatcherScope; +import mage.constants.Zone; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.target.common.TargetCreaturePermanent; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class ZhalfirinDecoy extends CardImpl { + + public ZhalfirinDecoy(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{W}"); + + this.subtype.add(SubType.HUMAN); + this.subtype.add(SubType.SOLDIER); + this.power = new MageInt(1); + this.toughness = new MageInt(3); + + // {T}: Tap target creature. Activate this ability only if you had a creature enter the battlefield under your control this turn. + Ability ability = new ActivateIfConditionActivatedAbility( + Zone.BATTLEFIELD, new TapTargetEffect(), new TapSourceCost(), ZhalfirinDecoyCondition.instance + ); + ability.addTarget(new TargetCreaturePermanent()); + this.addAbility(ability, new ZhalfirinDecoyWatcher()); + } + + private ZhalfirinDecoy(final ZhalfirinDecoy card) { + super(card); + } + + @Override + public ZhalfirinDecoy copy() { + return new ZhalfirinDecoy(this); + } +} + +enum ZhalfirinDecoyCondition implements Condition { + instance; + + @Override + public boolean apply(Game game, Ability source) { + ZhalfirinDecoyWatcher watcher = game.getState().getWatcher(ZhalfirinDecoyWatcher.class); + return watcher != null && watcher.enteredCreatureForPlayer(source.getControllerId()); + } + + @Override + public String toString() { + return "you had a creature enter the battlefield under your control this turn"; + } +} + +class ZhalfirinDecoyWatcher extends Watcher { + + private final Set players = new HashSet<>(); + + ZhalfirinDecoyWatcher() { + super(WatcherScope.GAME); + } + + private ZhalfirinDecoyWatcher(final ZhalfirinDecoyWatcher watcher) { + super(watcher); + this.players.addAll(watcher.players); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ZONE_CHANGE) { + ZoneChangeEvent zEvent = (ZoneChangeEvent) event; + if (zEvent.getToZone() == Zone.BATTLEFIELD + && zEvent.getTarget().isCreature()) { + players.add(zEvent.getTarget().getControllerId()); + } + } + } + + @Override + public void reset() { + players.clear(); + } + + boolean enteredCreatureForPlayer(UUID playerId) { + return players.contains(playerId); + } + + @Override + public ZhalfirinDecoyWatcher copy() { + return new ZhalfirinDecoyWatcher(this); + } +} diff --git a/Mage.Sets/src/mage/sets/ModernHorizons.java b/Mage.Sets/src/mage/sets/ModernHorizons.java index 0864e1c593..0551aacb34 100644 --- a/Mage.Sets/src/mage/sets/ModernHorizons.java +++ b/Mage.Sets/src/mage/sets/ModernHorizons.java @@ -128,5 +128,6 @@ public final class ModernHorizons extends ExpansionSet { cards.add(new SetCardInfo("Waterlogged Grove", 249, Rarity.RARE, mage.cards.w.WaterloggedGrove.class)); cards.add(new SetCardInfo("Wing Shards", 38, Rarity.UNCOMMON, mage.cards.w.WingShards.class)); cards.add(new SetCardInfo("Wrenn and Six", 217, Rarity.MYTHIC, mage.cards.w.WrennAndSix.class)); + cards.add(new SetCardInfo("Zhalfirin Decoy", 39, Rarity.UNCOMMON, mage.cards.z.ZhalfirinDecoy.class)); } }