From a54bb5024ac09f976f83961d766c1c4ae85f93ed Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Mon, 1 Apr 2019 14:53:23 -0400 Subject: [PATCH] Implemented Gideon's Triumph --- .../src/mage/cards/g/GideonsTriumph.java | 121 ++++++++++++++++++ Mage.Sets/src/mage/sets/WarOfTheSpark.java | 1 + 2 files changed, 122 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/g/GideonsTriumph.java diff --git a/Mage.Sets/src/mage/cards/g/GideonsTriumph.java b/Mage.Sets/src/mage/cards/g/GideonsTriumph.java new file mode 100644 index 00000000000..b8a7b117de9 --- /dev/null +++ b/Mage.Sets/src/mage/cards/g/GideonsTriumph.java @@ -0,0 +1,121 @@ +package mage.cards.g; + +import mage.MageObjectReference; +import mage.abilities.Ability; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.SacrificeEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.constants.WatcherScope; +import mage.filter.FilterPermanent; +import mage.filter.common.FilterControlledPlaneswalkerPermanent; +import mage.filter.predicate.Predicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.common.TargetOpponent; +import mage.watchers.Watcher; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class GideonsTriumph extends CardImpl { + + public GideonsTriumph(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{1}{W}"); + + // Target opponent sacrifices a creature that attacked or blocked this turn. If you control a Gideon planeswalker, that player sacrifices two of those creatures instead. + this.getSpellAbility().addEffect(new GideonsTriumphEffect()); + this.getSpellAbility().addTarget(new TargetOpponent()); + } + + private GideonsTriumph(final GideonsTriumph card) { + super(card); + } + + @Override + public GideonsTriumph copy() { + return new GideonsTriumph(this); + } +} + +class GideonsTriumphEffect extends OneShotEffect { + + private static final FilterControlledPlaneswalkerPermanent filter + = new FilterControlledPlaneswalkerPermanent(SubType.GIDEON); + private static final FilterPermanent filter2 + = new FilterPermanent("creature that attacked or blocked this turn"); + + GideonsTriumphEffect() { + super(Outcome.Benefit); + staticText = "Target opponent sacrifices a creature that attacked or blocked this turn. " + + "If you control a Gideon planeswalker, that player sacrifices two of those creatures instead."; + } + + private GideonsTriumphEffect(final GideonsTriumphEffect effect) { + super(effect); + } + + @Override + public GideonsTriumphEffect copy() { + return new GideonsTriumphEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + int count = 1; + if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) { + count++; + } + return new SacrificeEffect(filter2, count, "Target opponent").apply(game, source); + } +} + +enum GideonsTriumphCondition implements Predicate { + instance; + + @Override + public boolean apply(Permanent input, Game game) { + GideonsTriumphWatcher watcher = game.getState().getWatcher(GideonsTriumphWatcher.class); + return input.isCreature() && watcher.attackedOrBlockedThisTurn(input, game); + } +} + +class GideonsTriumphWatcher extends Watcher { + + private final Set attackedOrBlockedThisTurnCreatures = new HashSet<>(); + + public GideonsTriumphWatcher() { + super(WatcherScope.GAME); + } + + private GideonsTriumphWatcher(final GideonsTriumphWatcher watcher) { + super(watcher); + this.attackedOrBlockedThisTurnCreatures.addAll(watcher.attackedOrBlockedThisTurnCreatures); + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.ATTACKER_DECLARED || event.getType() == GameEvent.EventType.BLOCKER_DECLARED) { + this.attackedOrBlockedThisTurnCreatures.add(new MageObjectReference(event.getSourceId(), game)); + } + } + + boolean attackedOrBlockedThisTurn(Permanent permanent, Game game) { + return this.attackedOrBlockedThisTurnCreatures.contains(new MageObjectReference(permanent, game)); + } + + + @Override + public GideonsTriumphWatcher copy() { + return new GideonsTriumphWatcher(this); + } + +} diff --git a/Mage.Sets/src/mage/sets/WarOfTheSpark.java b/Mage.Sets/src/mage/sets/WarOfTheSpark.java index e3a6d322297..d53ebf384f5 100644 --- a/Mage.Sets/src/mage/sets/WarOfTheSpark.java +++ b/Mage.Sets/src/mage/sets/WarOfTheSpark.java @@ -39,6 +39,7 @@ public final class WarOfTheSpark extends ExpansionSet { cards.add(new SetCardInfo("Forest", 262, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Forest", 263, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Forest", 264, Rarity.LAND, mage.cards.basiclands.Forest.class, NON_FULL_USE_VARIOUS)); + cards.add(new SetCardInfo("Gideon's Triumph", 15, Rarity.UNCOMMON, mage.cards.g.GideonsTriumph.class)); cards.add(new SetCardInfo("Herald of the Dreadhorde", 93, Rarity.COMMON, mage.cards.h.HeraldOfTheDreadhorde.class)); cards.add(new SetCardInfo("Honor the God-Pharaoh", 132, Rarity.COMMON, mage.cards.h.HonorTheGodPharaoh.class)); cards.add(new SetCardInfo("Ignite the Beacon", 18, Rarity.RARE, mage.cards.i.IgniteTheBeacon.class));