From d43cdba805fb3c49290b22563e58c169e0ed337b Mon Sep 17 00:00:00 2001 From: Noah Gleason Date: Fri, 6 Jul 2018 19:14:55 -0400 Subject: [PATCH] Implement Premature Burial --- .../src/mage/cards/p/PrematureBurial.java | 143 ++++++++++++++++++ Mage.Sets/src/mage/sets/TimeSpiral.java | 1 + 2 files changed, 144 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/p/PrematureBurial.java diff --git a/Mage.Sets/src/mage/cards/p/PrematureBurial.java b/Mage.Sets/src/mage/cards/p/PrematureBurial.java new file mode 100644 index 0000000000..9f35bb5888 --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PrematureBurial.java @@ -0,0 +1,143 @@ +package mage.cards.p; + +import mage.MageObject; +import mage.MageObjectReference; +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.effects.common.DestroyTargetEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.WatcherScope; +import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.game.Game; +import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; +import mage.target.common.TargetCreaturePermanent; +import mage.watchers.Watcher; + +import java.util.*; + +/** + * + * @author noahg + */ +public final class PrematureBurial extends CardImpl { + + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("nonblack creature that entered the battlefield since your last turn ended"); + + static { + filter.add(Predicates.not(new ColorPredicate(ObjectColor.BLACK))); + } + + public PrematureBurial(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.SORCERY}, "{1}{B}"); + + + // Destroy target nonblack creature that entered the battlefield since your last turn ended. + this.getSpellAbility().addEffect(new DestroyTargetEffect().setText("Destroy target nonblack creature that entered the battlefield since your last turn ended.")); + this.getSpellAbility().addTarget(new ETBSinceYourLastTurnTarget(filter)); + this.getSpellAbility().addWatcher(new ETBSinceYourLastTurnWatcher()); + } + + public PrematureBurial(final PrematureBurial card) { + super(card); + } + + @Override + public PrematureBurial copy() { + return new PrematureBurial(this); + } +} + +class ETBSinceYourLastTurnTarget extends TargetCreaturePermanent { + + public ETBSinceYourLastTurnTarget(FilterCreaturePermanent filter) { + super(filter); + this.targetName = "nonblack creature that entered the battlefield since your last turn ended"; + } + + public ETBSinceYourLastTurnTarget(ETBSinceYourLastTurnTarget target){ + super(target); + } + + @Override + public boolean canTarget(UUID controllerId, UUID id, Ability source, Game game) { + System.out.println("canTarget called"); + ETBSinceYourLastTurnWatcher watcher = (ETBSinceYourLastTurnWatcher) game.getState().getWatchers().get(ETBSinceYourLastTurnWatcher.class.getSimpleName()); + if (watcher != null){ + if (watcher.enteredSinceLastTurn(controllerId, new MageObjectReference(id, game))){ + System.out.println(game.getPermanent(id).getIdName()+" entered since the last turn."); + return super.canTarget(controllerId, id, source, game); + } + } + return false; + } + + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + MageObject targetSource = game.getObject(sourceId); + ETBSinceYourLastTurnWatcher watcher = (ETBSinceYourLastTurnWatcher) game.getState().getWatchers().get(ETBSinceYourLastTurnWatcher.class.getSimpleName()); + for (Permanent permanent: game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) { + if (permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) { + if(watcher.enteredSinceLastTurn(sourceControllerId, new MageObjectReference(permanent.getId(), game))) { + return true; + } + } + } + return false; + } + + @Override + public ETBSinceYourLastTurnTarget copy() { + return new ETBSinceYourLastTurnTarget(this); + } +} + +class ETBSinceYourLastTurnWatcher extends Watcher { + + private final Map> playerToETBMap; + + public ETBSinceYourLastTurnWatcher() { + super(ETBSinceYourLastTurnWatcher.class.getSimpleName(), WatcherScope.GAME); + this.playerToETBMap = new HashMap<>(); + } + + public ETBSinceYourLastTurnWatcher(ETBSinceYourLastTurnWatcher watcher) { + super(watcher); + this.playerToETBMap = new HashMap<>(); + for (UUID player : watcher.playerToETBMap.keySet()){ + this.playerToETBMap.put(player, new HashSet<>(watcher.playerToETBMap.get(player))); + } + } + + @Override + public void watch(GameEvent event, Game game) { + if (event.getType() == GameEvent.EventType.END_TURN_STEP_POST){ + System.out.println("End of turn for "+game.getPlayer(event.getPlayerId()).getName()); + playerToETBMap.put(event.getPlayerId(), new HashSet<>()); + } else if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD){ + Permanent etbPermanent = game.getPermanent(event.getTargetId()); + if (etbPermanent != null){ + System.out.println("nonnull permanent entered: "+etbPermanent.getIdName()); + for (UUID player : game.getPlayerList()){ + if (!playerToETBMap.containsKey(player)){ + playerToETBMap.put(player, new HashSet<>()); + } + playerToETBMap.get(player).add(new MageObjectReference(etbPermanent.getBasicMageObject(game), game)); + } + } + } + } + + public boolean enteredSinceLastTurn(UUID player, MageObjectReference mor){ + return playerToETBMap.get(player).contains(mor); + } + + @Override + public ETBSinceYourLastTurnWatcher copy() { + return new ETBSinceYourLastTurnWatcher(this); + } +} \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/TimeSpiral.java b/Mage.Sets/src/mage/sets/TimeSpiral.java index dd82083812..7a2d9fcc0c 100644 --- a/Mage.Sets/src/mage/sets/TimeSpiral.java +++ b/Mage.Sets/src/mage/sets/TimeSpiral.java @@ -212,6 +212,7 @@ public final class TimeSpiral extends ExpansionSet { cards.add(new SetCardInfo("Plains", 284, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Plains", 285, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Plunder", 174, Rarity.COMMON, mage.cards.p.Plunder.class)); + cards.add(new SetCardInfo("Premature Burial", 125, Rarity.UNCOMMON, mage.cards.p.PrematureBurial.class)); cards.add(new SetCardInfo("Primal Forcemage", 212, Rarity.UNCOMMON, mage.cards.p.PrimalForcemage.class)); cards.add(new SetCardInfo("Prismatic Lens", 262, Rarity.COMMON, mage.cards.p.PrismaticLens.class)); cards.add(new SetCardInfo("Psionic Sliver", 72, Rarity.RARE, mage.cards.p.PsionicSliver.class));