From b19a799b835009b1712ee57c3db75f53981e7019 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Tue, 18 Sep 2018 10:57:30 -0400 Subject: [PATCH] Implemented Hatchery Spider --- .../src/mage/cards/h/HatcherySpider.java | 121 ++++++++++++++++++ Mage.Sets/src/mage/sets/GuildsOfRavnica.java | 1 + .../common/CastSourceTriggeredAbility.java | 10 +- 3 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 Mage.Sets/src/mage/cards/h/HatcherySpider.java diff --git a/Mage.Sets/src/mage/cards/h/HatcherySpider.java b/Mage.Sets/src/mage/cards/h/HatcherySpider.java new file mode 100644 index 0000000000..ac3d189cc3 --- /dev/null +++ b/Mage.Sets/src/mage/cards/h/HatcherySpider.java @@ -0,0 +1,121 @@ +package mage.cards.h; + +import java.util.UUID; +import mage.MageInt; +import mage.ObjectColor; +import mage.abilities.Ability; +import mage.abilities.dynamicvalue.common.CardsInControllerGraveyardCount; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.CastSourceTriggeredAbility; +import mage.constants.SubType; +import mage.abilities.keyword.ReachAbility; +import mage.cards.Card; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.cards.Cards; +import mage.cards.CardsImpl; +import mage.constants.CardType; +import mage.constants.ComparisonType; +import mage.constants.Outcome; +import mage.constants.Zone; +import mage.filter.FilterCard; +import mage.filter.StaticFilters; +import mage.filter.common.FilterPermanentCard; +import mage.filter.predicate.mageobject.ColorPredicate; +import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; +import mage.game.Game; +import mage.players.Player; +import mage.target.TargetCard; +import mage.target.common.TargetCardInLibrary; + +/** + * + * @author TheElk801 + */ +public final class HatcherySpider extends CardImpl { + + public HatcherySpider(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{G}{G}"); + + this.subtype.add(SubType.SPIDER); + this.power = new MageInt(5); + this.toughness = new MageInt(7); + + // Reach + this.addAbility(ReachAbility.getInstance()); + + // Undergrowth — When you cast this spell, reveal the top X cards of your library, where X is the number of creature cards in your graveyard. You may put a green permanent card with converted mana cost X or less from among them onto the battlefield. Put the rest on the bottom of your library in a random order. + this.addAbility(new CastSourceTriggeredAbility( + new HatcherySpiderEffect(), false, + "Undergrowth — " + )); + } + + public HatcherySpider(final HatcherySpider card) { + super(card); + } + + @Override + public HatcherySpider copy() { + return new HatcherySpider(this); + } +} + +class HatcherySpiderEffect extends OneShotEffect { + + public HatcherySpiderEffect() { + super(Outcome.Benefit); + this.staticText = "reveal the top X cards of your library, " + + "where X is the number of creature cards in your graveyard. " + + "You may put a green permanent card with converted mana cost " + + "X or less from among them onto the battlefield. " + + "Put the rest on the bottom of your library " + + "in a random order."; + } + + public HatcherySpiderEffect(final HatcherySpiderEffect effect) { + super(effect); + } + + @Override + public HatcherySpiderEffect copy() { + return new HatcherySpiderEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getFirstTarget()); + if (player == null) { + return false; + } + int xValue = new CardsInControllerGraveyardCount( + StaticFilters.FILTER_CARD_CREATURE + ).calculate(game, source, this); + FilterCard filter = new FilterPermanentCard( + "green permanent card with converted mana cost " + + xValue + " or less" + ); + filter.add(new ColorPredicate(ObjectColor.GREEN)); + filter.add(new ConvertedManaCostPredicate( + ComparisonType.FEWER_THAN, xValue + 1 + )); + TargetCard target = new TargetCardInLibrary(filter); + Cards cards = new CardsImpl( + player.getLibrary().getTopCards(game, xValue) + ); + if (player.chooseUse(outcome, "Put a card onto the battlefield?", source, game) + && player.choose(outcome, cards, target, game)) { + Card card = game.getCard(target.getFirstTarget()); + if (card != null + && player.moveCards(card, Zone.BATTLEFIELD, source, game)) { + cards.remove(card); + } + } + while (!cards.isEmpty()) { + Card card = cards.getRandom(game); + player.getLibrary().putOnBottom(card, game); + cards.remove(card); + } + return true; + } +} diff --git a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java index fe361a6e30..57139111bb 100644 --- a/Mage.Sets/src/mage/sets/GuildsOfRavnica.java +++ b/Mage.Sets/src/mage/sets/GuildsOfRavnica.java @@ -92,6 +92,7 @@ public final class GuildsOfRavnica extends ExpansionSet { cards.add(new SetCardInfo("Guild Summit", 41, Rarity.UNCOMMON, mage.cards.g.GuildSummit.class)); cards.add(new SetCardInfo("Haazda Marshal", 13, Rarity.UNCOMMON, mage.cards.h.HaazdaMarshal.class)); cards.add(new SetCardInfo("Hammer Dropper", 176, Rarity.COMMON, mage.cards.h.HammerDropper.class)); + cards.add(new SetCardInfo("Hatchery Spider", 132, Rarity.RARE, mage.cards.h.HatcherySpider.class)); cards.add(new SetCardInfo("Healer's Hawk", 14, Rarity.COMMON, mage.cards.h.HealersHawk.class)); cards.add(new SetCardInfo("House Guildmage", 177, Rarity.UNCOMMON, mage.cards.h.HouseGuildmage.class)); cards.add(new SetCardInfo("Hunted Witness", 15, Rarity.COMMON, mage.cards.h.HuntedWitness.class)); diff --git a/Mage/src/main/java/mage/abilities/effects/common/CastSourceTriggeredAbility.java b/Mage/src/main/java/mage/abilities/effects/common/CastSourceTriggeredAbility.java index 308c16b189..b9b552d762 100644 --- a/Mage/src/main/java/mage/abilities/effects/common/CastSourceTriggeredAbility.java +++ b/Mage/src/main/java/mage/abilities/effects/common/CastSourceTriggeredAbility.java @@ -1,4 +1,3 @@ - package mage.abilities.effects.common; import mage.MageObject; @@ -16,18 +15,25 @@ import mage.game.stack.Spell; public class CastSourceTriggeredAbility extends TriggeredAbilityImpl { public static final String SOURCE_CAST_SPELL_ABILITY = "sourceCastSpellAbility"; + private final String rulePrefix; public CastSourceTriggeredAbility(Effect effect) { this(effect, false); } public CastSourceTriggeredAbility(Effect effect, boolean optional) { + this(effect, optional, ""); + } + + public CastSourceTriggeredAbility(Effect effect, boolean optional, String rulePrefix) { super(Zone.STACK, effect, optional); this.ruleAtTheTop = true; + this.rulePrefix = rulePrefix; } public CastSourceTriggeredAbility(final CastSourceTriggeredAbility ability) { super(ability); + this.rulePrefix = ability.rulePrefix; } @Override @@ -59,6 +65,6 @@ public class CastSourceTriggeredAbility extends TriggeredAbilityImpl { @Override public String getRule() { - return "When you cast {source}, " + super.getRule(); + return rulePrefix + "When you cast this spell, " + super.getRule(); } }