From 687c7a2b26089ed51cf4e6f93b005e4f342131e4 Mon Sep 17 00:00:00 2001 From: Noah Gleason Date: Sun, 1 Jul 2018 09:22:21 -0400 Subject: [PATCH] Implement Flash Foliage --- Mage.Sets/src/mage/cards/f/FlashFoliage.java | 101 +++++++++++++++++++ Mage.Sets/src/mage/sets/Dissension.java | 1 + 2 files changed, 102 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/f/FlashFoliage.java diff --git a/Mage.Sets/src/mage/cards/f/FlashFoliage.java b/Mage.Sets/src/mage/cards/f/FlashFoliage.java new file mode 100644 index 0000000000..2460dffc86 --- /dev/null +++ b/Mage.Sets/src/mage/cards/f/FlashFoliage.java @@ -0,0 +1,101 @@ +package mage.cards.f; + +import java.util.UUID; + +import mage.abilities.Ability; +import mage.abilities.common.CastOnlyDuringPhaseStepSourceAbility; +import mage.abilities.condition.common.AfterBlockersAreDeclaredCondition; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.DrawCardSourceControllerEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.TurnPhase; +import mage.game.Game; +import mage.game.combat.CombatGroup; +import mage.game.permanent.Permanent; +import mage.game.permanent.token.SaprolingToken; +import mage.game.permanent.token.Token; +import mage.players.Player; +import mage.target.common.FilterCreatureAttackingYou; +import mage.target.common.TargetCreaturePermanent; + +/** + * + * @author noahg + */ +public final class FlashFoliage extends CardImpl { + + public FlashFoliage(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{G}"); + + + // Cast Flash Foliage only during combat after blockers are declared. + this.addAbility(new CastOnlyDuringPhaseStepSourceAbility(TurnPhase.COMBAT, AfterBlockersAreDeclaredCondition.instance)); + + // Create a 1/1 green Saproling creature token that’s blocking target creature attacking you. + this.getSpellAbility().addEffect(new FlashFoliageEffect()); + this.getSpellAbility().addTarget(new TargetCreaturePermanent(new FilterCreatureAttackingYou())); + + // Draw a card. + this.getSpellAbility().addEffect(new DrawCardSourceControllerEffect(1)); + } + + public FlashFoliage(final FlashFoliage card) { + super(card); + } + + @Override + public FlashFoliage copy() { + return new FlashFoliage(this); + } +} + +class FlashFoliageEffect extends OneShotEffect { + + public FlashFoliageEffect() { + super(Outcome.Benefit); + this.staticText = "create a 1/1 green Saproling creature token that’s blocking target creature attacking you"; + } + + public FlashFoliageEffect(final FlashFoliageEffect effect) { + super(effect); + } + + @Override + public FlashFoliageEffect copy() { + return new FlashFoliageEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + + if (controller != null) { + Token token = new SaprolingToken(); + token.putOntoBattlefield(1, game, source.getSourceId(), source.getControllerId()); + Permanent attackingCreature = game.getPermanent(getTargetPointer().getFirst(game, source)); + if (attackingCreature != null && game.getState().getCombat() != null) { + // Possible ruling (see Aetherplasm) + // The token you created is blocking the attacking creature, + // even if the block couldn't legally be declared (for example, if that creature + // enters the battlefield tapped, or it can't block, or the attacking creature + // has protection from it) + CombatGroup combatGroup = game.getState().getCombat().findGroup(attackingCreature.getId()); + if (combatGroup != null) { + for (UUID tokenId : token.getLastAddedTokenIds()) { + Permanent saprolingToken = game.getPermanent(tokenId); + if (saprolingToken != null) { + combatGroup.addBlocker(tokenId, source.getControllerId(), game); + game.getCombat().addBlockingGroup(tokenId, attackingCreature.getId(), controller.getId(), game); + } + } + combatGroup.pickBlockerOrder(attackingCreature.getControllerId(), game); + } + } + return true; + } + return false; + } +} diff --git a/Mage.Sets/src/mage/sets/Dissension.java b/Mage.Sets/src/mage/sets/Dissension.java index 7fafc036ec..a8d1817105 100644 --- a/Mage.Sets/src/mage/sets/Dissension.java +++ b/Mage.Sets/src/mage/sets/Dissension.java @@ -75,6 +75,7 @@ public final class Dissension extends ExpansionSet { cards.add(new SetCardInfo("Experiment Kraj", 110, Rarity.RARE, mage.cards.e.ExperimentKraj.class)); cards.add(new SetCardInfo("Flame-Kin War Scout", 61, Rarity.UNCOMMON, mage.cards.f.FlameKinWarScout.class)); cards.add(new SetCardInfo("Flaring Flame-Kin", 62, Rarity.UNCOMMON, mage.cards.f.FlaringFlameKin.class)); + cards.add(new SetCardInfo("Flash Foliage", 85, Rarity.UNCOMMON, mage.cards.f.FlashFoliage.class)); cards.add(new SetCardInfo("Freewind Equenaut", 9, Rarity.COMMON, mage.cards.f.FreewindEquenaut.class)); cards.add(new SetCardInfo("Ghost Quarter", 173, Rarity.UNCOMMON, mage.cards.g.GhostQuarter.class)); cards.add(new SetCardInfo("Gnat Alley Creeper", 63, Rarity.UNCOMMON, mage.cards.g.GnatAlleyCreeper.class));