From d97d15edc9fe253a658a618a0d1fdc6d2be6fa53 Mon Sep 17 00:00:00 2001 From: Daniel Bomar Date: Wed, 3 Nov 2021 09:05:43 -0500 Subject: [PATCH] [VOW] Implemented Cemetery Prowler --- .../src/mage/cards/c/CemeteryProwler.java | 142 ++++++++++++++++++ .../src/mage/sets/InnistradCrimsonVow.java | 1 + 2 files changed, 143 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/c/CemeteryProwler.java diff --git a/Mage.Sets/src/mage/cards/c/CemeteryProwler.java b/Mage.Sets/src/mage/cards/c/CemeteryProwler.java new file mode 100644 index 0000000000..d70f7aafbe --- /dev/null +++ b/Mage.Sets/src/mage/cards/c/CemeteryProwler.java @@ -0,0 +1,142 @@ +package mage.cards.c; + +import java.util.HashSet; +import java.util.UUID; +import mage.MageInt; +import mage.MageObject; +import mage.abilities.Ability; +import mage.abilities.SpellAbility; +import mage.abilities.common.EntersBattlefieldOrAttacksSourceTriggeredAbility; +import mage.abilities.common.SimpleStaticAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.cost.CostModificationEffectImpl; +import mage.cards.Card; +import mage.constants.*; +import mage.abilities.keyword.VigilanceAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.game.ExileZone; +import mage.game.Game; +import mage.players.Player; +import mage.target.common.TargetCardInGraveyard; +import mage.util.CardUtil; + +/** + * + * @author weirddan455 + */ +public final class CemeteryProwler extends CardImpl { + + public CemeteryProwler(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{1}{G}{G}"); + + this.subtype.add(SubType.WOLF); + this.power = new MageInt(3); + this.toughness = new MageInt(4); + + // Vigilance + this.addAbility(VigilanceAbility.getInstance()); + + // Whenever Cemetery Prowler enters the battlefield or attacks, exile a card from a graveyard. + this.addAbility(new EntersBattlefieldOrAttacksSourceTriggeredAbility(new CemeteryProwlerExileEffect())); + + // Spells you cast cost {1} less to cast for each card type they share with cards exiled with Cemetery Prowler. + this.addAbility(new SimpleStaticAbility(new CemeteryProwlerCostReductionEffect())); + } + + private CemeteryProwler(final CemeteryProwler card) { + super(card); + } + + @Override + public CemeteryProwler copy() { + return new CemeteryProwler(this); + } +} + +class CemeteryProwlerExileEffect extends OneShotEffect { + + public CemeteryProwlerExileEffect() { + super(Outcome.Exile); + staticText = "exile a card from a graveyard"; + } + + private CemeteryProwlerExileEffect(final CemeteryProwlerExileEffect effect) { + super(effect); + } + + @Override + public CemeteryProwlerExileEffect copy() { + return new CemeteryProwlerExileEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + TargetCardInGraveyard target = new TargetCardInGraveyard(); + target.setNotTarget(true); + controller.choose(outcome, target, source.getSourceId(), game); + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); + MageObject sourceObject = source.getSourceObject(game); + String exileName = sourceObject == null ? null : sourceObject.getIdName(); + return controller.moveCardsToExile(card, source, game, true, exileId, exileName); + } + } + return false; + } +} + +class CemeteryProwlerCostReductionEffect extends CostModificationEffectImpl { + + public CemeteryProwlerCostReductionEffect() { + super(Duration.WhileOnBattlefield, Outcome.Benefit, CostModificationType.REDUCE_COST); + staticText = "Spells you cast cost {1} less to cast for each card type they share with cards exiled with {this}"; + } + + private CemeteryProwlerCostReductionEffect(final CemeteryProwlerCostReductionEffect effect) { + super(effect); + } + + @Override + public CemeteryProwlerCostReductionEffect copy() { + return new CemeteryProwlerCostReductionEffect(this); + } + + @Override + public boolean apply(Game game, Ability source, Ability abilityToModify) { + if (abilityToModify instanceof SpellAbility) { + // sourceObjectZoneChangeCounter is not working here. Getting it from GameState works. + UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId())); + ExileZone exileZone = game.getExile().getExileZone(exileId); + Card castCard = ((SpellAbility) abilityToModify).getCharacteristics(game); + if (exileZone != null && castCard != null) { + HashSet cardTypes = new HashSet<>(); + for (UUID cardId : exileZone) { + Card card = game.getCard(cardId); + if (card != null) { + cardTypes.addAll(card.getCardType(game)); + } + } + int sharedTypes = 0; + for (CardType type : castCard.getCardType(game)) { + if (cardTypes.contains(type)) { + sharedTypes++; + } + } + if (sharedTypes > 0) { + CardUtil.reduceCost(abilityToModify, sharedTypes); + return true; + } + } + } + return false; + } + + @Override + public boolean applies(Ability abilityToModify, Ability source, Game game) { + return abilityToModify instanceof SpellAbility && abilityToModify.isControlledBy(source.getControllerId()); + } +} diff --git a/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java b/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java index 7512fde683..6317c45b04 100644 --- a/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java +++ b/Mage.Sets/src/mage/sets/InnistradCrimsonVow.java @@ -47,6 +47,7 @@ public final class InnistradCrimsonVow extends ExpansionSet { cards.add(new SetCardInfo("Bramble Wurm", 189, Rarity.UNCOMMON, mage.cards.b.BrambleWurm.class)); cards.add(new SetCardInfo("By Invitation Only", 5, Rarity.RARE, mage.cards.b.ByInvitationOnly.class)); cards.add(new SetCardInfo("Cemetery Protector", 6, Rarity.MYTHIC, mage.cards.c.CemeteryProtector.class)); + cards.add(new SetCardInfo("Cemetery Prowler", 191, Rarity.MYTHIC, mage.cards.c.CemeteryProwler.class)); cards.add(new SetCardInfo("Change of Fortune", 150, Rarity.RARE, mage.cards.c.ChangeOfFortune.class)); cards.add(new SetCardInfo("Clever Distraction", 9, Rarity.UNCOMMON, mage.cards.c.CleverDistraction.class)); cards.add(new SetCardInfo("Cloaked Cadet", 192, Rarity.UNCOMMON, mage.cards.c.CloakedCadet.class));