From c2b14522591c66b82cfaf6d355069463d0979fa5 Mon Sep 17 00:00:00 2001 From: drmDev Date: Fri, 1 Apr 2016 18:35:05 -0400 Subject: [PATCH] CreepingDread implementation. Updated cards-data to fix typo. --- .../shadowsoverinnistrad/CreepingDread.java | 164 ++++++++++++++++++ .../costs/common/DiscardTargetCost.java | 2 +- Utils/mtg-cards-data.txt | 2 +- 3 files changed, 166 insertions(+), 2 deletions(-) create mode 100644 Mage.Sets/src/mage/sets/shadowsoverinnistrad/CreepingDread.java diff --git a/Mage.Sets/src/mage/sets/shadowsoverinnistrad/CreepingDread.java b/Mage.Sets/src/mage/sets/shadowsoverinnistrad/CreepingDread.java new file mode 100644 index 0000000000..937bf1c3c8 --- /dev/null +++ b/Mage.Sets/src/mage/sets/shadowsoverinnistrad/CreepingDread.java @@ -0,0 +1,164 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package mage.sets.shadowsoverinnistrad; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import mage.abilities.Ability; +import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; +import mage.constants.Zone; +import mage.filter.FilterCard; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; + +/** + * + * @author escplan9 (Derek Monturo - dmontur1 at gmail dot com) + */ +public class CreepingDread extends CardImpl { + + public CreepingDread(UUID ownerId) { + super(ownerId, 104, "Creeping Dread", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{3}{B}"); + this.expansionSetCode = "SOI"; + + // At the beginning of your upkeep, each player discards a card. Each opponent who discarded a card that shares a card type with the card you discarded loses 3 life. + this.addAbility(new BeginningOfUpkeepTriggeredAbility(new CreepingDreadEffect(), TargetController.YOU, false)); + } + + public CreepingDread(final CreepingDread card) { + super(card); + } + + @Override + public CreepingDread copy() { + return new CreepingDread(this); + } +} + +class CreepingDreadEffect extends OneShotEffect { + + public CreepingDreadEffect() { + super(Outcome.Detriment); + this.staticText = "each player discards a card. Each opponent who discarded a card that shares a card type with the card you discarded loses 3 life."; + } + + public CreepingDreadEffect(final CreepingDreadEffect effect) { + super(effect); + } + + @Override + public CreepingDreadEffect copy() { + return new CreepingDreadEffect(this); + } + + /* + * When a spell or ability instructs each player to discard a card, + starting with the player whose turn it is and proceeding in turn order, + each player selects a card from his or her hand without revealing it, + sets it aside, and then all of those cards are revealed and discarded at once. + + http://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=409851 + */ + @Override + public boolean apply(Game game, Ability source) { + + // controller discards a card - store info on card type + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + + List typesChosen = new ArrayList<>(); + Map cardsChosen = new HashMap<>(); + if(!controller.getHand().isEmpty()) { + + TargetCard controllerTarget = new TargetCard(Zone.HAND, new FilterCard()); + if(controller.choose(Outcome.Discard, controller.getHand(), controllerTarget, game)) { + Card card = controller.getHand().get(controllerTarget.getFirstTarget(), game); + if (card != null) { + typesChosen = card.getCardType(); + cardsChosen.put(controller, card); + } + } + } + + ArrayList opponentsAffected = new ArrayList<>(); + for (UUID playerId : game.getOpponents(source.getControllerId())) { + Player opponent = game.getPlayer(playerId); + // opponent discards a card - if it is same card type as controller, add to opponentsAffected + if(!opponent.getHand().isEmpty()) { + TargetCard target = new TargetCard(Zone.HAND, new FilterCard()); + if(opponent.choose(Outcome.Discard, opponent.getHand(), target, game)) { + Card card = opponent.getHand().get(target.getFirstTarget(), game); + if (card != null) { + for (CardType cType : typesChosen) { + for (CardType oType : card.getCardType()) { + if (cType == oType) { + opponentsAffected.add(opponent); + break; + } + } + } + + cardsChosen.put(opponent, card); + } + } + } + } + + // each opponent who discarded a card of the same type loses 3 life + if (!opponentsAffected.isEmpty()) { + for(Player opponent : opponentsAffected) { + opponent.loseLife(3, game); + } + } + + // everyone discards the card at the same time + for (Map.Entry entry : cardsChosen.entrySet()) { + Player player = entry.getKey(); + Card cardChosen = entry.getValue(); + if (player != null && cardChosen != null) { + player.discard(cardChosen, source, game); + } + } + + return true; + } + + return false; + } +} \ No newline at end of file diff --git a/Mage/src/main/java/mage/abilities/costs/common/DiscardTargetCost.java b/Mage/src/main/java/mage/abilities/costs/common/DiscardTargetCost.java index d34f2c49c7..8f85ed8283 100644 --- a/Mage/src/main/java/mage/abilities/costs/common/DiscardTargetCost.java +++ b/Mage/src/main/java/mage/abilities/costs/common/DiscardTargetCost.java @@ -67,7 +67,7 @@ public class DiscardTargetCost extends CostImpl { @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { this.cards.clear(); - this.targets.clearChosen();; + this.targets.clearChosen(); Player player = game.getPlayer(controllerId); if (player == null) { return false; diff --git a/Utils/mtg-cards-data.txt b/Utils/mtg-cards-data.txt index b792a7780a..dcdbec82b3 100644 --- a/Utils/mtg-cards-data.txt +++ b/Utils/mtg-cards-data.txt @@ -57051,7 +57051,7 @@ Behind the Scenes|Shadows over Innistrad|100|U|{2}{B}|Enchantment|||Creature you Behold the Beyond|Shadows over Innistrad|101|M|{5}{B}{B}|Sorcery|||Discard your hand. Search your library for three cards and put those cards into your hand. Then shuffle your library.| Biting Rain|Shadows over Innistrad|102|U|{2}{B}{B}|Sorcery|||All creatures get -2/-2 until end of turn.$Madness {2}{B} (If you discard this card, discard it into exile. WHen you do, cast it for its madness cost or put it into your graveyard.)| Call the Bloodline|Shadows over Innistrad|103|U|{1}{B}|Enchantment|||{1}, Discard a card: Put a 1/1 black Vampire Knight token with lifelink onto the battlefield. Activate this ability only once each turn.| -Creeping Death|Shadows over Innistrad|104|U|{3}{B}|Enchantment|||At the beginning of your upkeep, each player discards a card. Each opponent who discarded a card that shares a card type with the card you discarded loses 3 life.| +Creeping Dread|Shadows over Innistrad|104|U|{3}{B}|Enchantment|||At the beginning of your upkeep, each player discards a card. Each opponent who discarded a card that shares a card type with the card you discarded loses 3 life.| Crow of Dark Tidings|Shadows over Innistrad|105|C|{2}{B}|Creature - Zombie Bird|2|2|Flying$When Crow of Dark Tidings enters the battlefield or dies, put the top two cards of your library into your graveyard.| Dead Weight|Shadows over Innistrad|106|C|{B}|Enchantment - Aura|||Enchant creature$Enchanted creature gets -2/-2.| Diregraf Colossus|Shadows over Innistrad|107|R|{2}{B}|Creature - Zombie Giant|2|2|Diregraf Colossus enters the battlefield with a +1/+1 counter on it for each Zombie card in your graveyard.$Whenever you cast a Zombie spell, put a 2/2 black Zombie creature token onto the battlefield tapped.|