diff --git a/Mage.Sets/src/mage/cards/e/EaterOfTheDead.java b/Mage.Sets/src/mage/cards/e/EaterOfTheDead.java index 69da60ae3d..4c34144d75 100644 --- a/Mage.Sets/src/mage/cards/e/EaterOfTheDead.java +++ b/Mage.Sets/src/mage/cards/e/EaterOfTheDead.java @@ -1,6 +1,5 @@ package mage.cards.e; -import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; @@ -16,10 +15,12 @@ import mage.constants.Zone; import mage.filter.StaticFilters; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetCardInGraveyard; +import java.util.UUID; + /** - * * @author fireshoes */ public final class EaterOfTheDead extends CardImpl { @@ -31,7 +32,7 @@ public final class EaterOfTheDead extends CardImpl { this.toughness = new MageInt(4); // {0}: If Eater of the Dead is tapped, exile target creature card from a graveyard and untap Eater of the Dead. - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new EaterOfTheDeadEffect(), new GenericManaCost(0)); + Ability ability = new SimpleActivatedAbility(new EaterOfTheDeadEffect(), new GenericManaCost(0)); ability.addTarget(new TargetCardInGraveyard(StaticFilters.FILTER_CARD_CREATURE)); this.addAbility(ability); } @@ -49,28 +50,31 @@ public final class EaterOfTheDead extends CardImpl { class EaterOfTheDeadEffect extends OneShotEffect { EaterOfTheDeadEffect() { - super(Outcome.DestroyPermanent); + super(Outcome.Exile); staticText = "If {this} is tapped, exile target creature card from a graveyard and untap {this}"; } - EaterOfTheDeadEffect(final EaterOfTheDeadEffect effect) { + private EaterOfTheDeadEffect(final EaterOfTheDeadEffect effect) { super(effect); } @Override public boolean apply(Game game, Ability source) { - Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - Card card = game.getCard(source.getFirstTarget()); - if (sourcePermanent != null && sourcePermanent.isTapped() && card != null) { - card.moveToExile(null, "Eater of the Dead", source, game); - sourcePermanent.untap(game); + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentOrLKI(game); + if (player == null || permanent == null || !permanent.isTapped()) { + return false; } - return false; + Card card = game.getCard(source.getFirstTarget()); + if (card != null) { + player.moveCards(card, Zone.EXILED, source, game); + } + permanent.untap(game); + return true; } @Override public EaterOfTheDeadEffect copy() { return new EaterOfTheDeadEffect(this); } - } diff --git a/Mage.Sets/src/mage/cards/e/ElvishSpiritGuide.java b/Mage.Sets/src/mage/cards/e/ElvishSpiritGuide.java index 49e93e312d..c08d939ce6 100644 --- a/Mage.Sets/src/mage/cards/e/ElvishSpiritGuide.java +++ b/Mage.Sets/src/mage/cards/e/ElvishSpiritGuide.java @@ -1,4 +1,3 @@ - package mage.cards.e; import java.util.UUID; @@ -7,6 +6,7 @@ import mage.Mana; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; +import mage.abilities.costs.common.ExileSourceFromHandCost; import mage.abilities.mana.SimpleManaAbility; import mage.cards.Card; import mage.cards.CardImpl; @@ -44,40 +44,3 @@ public final class ElvishSpiritGuide extends CardImpl { return new ElvishSpiritGuide(this); } } - - -class ExileSourceFromHandCost extends CostImpl { - - public ExileSourceFromHandCost() { - this.text = "Exile {this} from your hand"; - } - - public ExileSourceFromHandCost(ExileSourceFromHandCost cost) { - super(cost); - } - - @Override - public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { - Card card = game.getCard(source.getSourceId()); - Player player = game.getPlayer(controllerId); - if (player != null && player.getHand().contains(source.getSourceId()) && card != null) { - paid = card.moveToExile(ability.getSourceId(), "from Hand", source, game); - } - return paid; - } - - @Override - public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { - Player player = game.getPlayer(controllerId); - if (player != null && player.getHand().contains(source.getSourceId())) { - return true; - } - return false; - } - - @Override - public ExileSourceFromHandCost copy() { - return new ExileSourceFromHandCost(this); - } - -} diff --git a/Mage.Sets/src/mage/cards/e/EndlessHorizons.java b/Mage.Sets/src/mage/cards/e/EndlessHorizons.java index 3dd419e869..41b66cf004 100644 --- a/Mage.Sets/src/mage/cards/e/EndlessHorizons.java +++ b/Mage.Sets/src/mage/cards/e/EndlessHorizons.java @@ -1,40 +1,36 @@ - package mage.cards.e; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.abilities.effects.SearchEffect; -import mage.cards.Card; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; +import mage.cards.*; import mage.constants.*; import mage.filter.FilterCard; -import mage.filter.common.FilterLandCard; -import mage.game.ExileZone; import mage.game.Game; +import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetCard; +import mage.target.common.TargetCardInExile; import mage.target.common.TargetCardInLibrary; import mage.util.CardUtil; +import java.util.Objects; +import java.util.UUID; + /** - * * @author jeffwadsworth */ public final class EndlessHorizons extends CardImpl { public EndlessHorizons(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{W}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{W}"); // When Endless Horizons enters the battlefield, search your library for any number of Plains cards and exile them. Then shuffle your library. this.addAbility(new EntersBattlefieldTriggeredAbility(new EndlessHorizonsEffect(), false)); // At the beginning of your upkeep, you may put a card you own exiled with Endless Horizons into your hand. - this.addAbility(new BeginningOfUpkeepTriggeredAbility(new EndlessHorizonsEffect2(), TargetController.YOU, true)); - + this.addAbility(new BeginningOfUpkeepTriggeredAbility(new EndlessHorizonsEffect2(), TargetController.YOU, false)); } private EndlessHorizons(final EndlessHorizons card) { @@ -47,20 +43,20 @@ public final class EndlessHorizons extends CardImpl { } } -class EndlessHorizonsEffect extends SearchEffect { +class EndlessHorizonsEffect extends OneShotEffect { - private static final FilterLandCard filter = new FilterLandCard("Plains card"); + private static final FilterCard filter = new FilterCard("Plains card"); static { filter.add(SubType.PLAINS.getPredicate()); } - public EndlessHorizonsEffect() { - super(new TargetCardInLibrary(0, Integer.MAX_VALUE, filter), Outcome.Neutral); + EndlessHorizonsEffect() { + super(Outcome.Neutral); this.staticText = "search your library for any number of Plains cards and exile them. Then shuffle your library"; } - public EndlessHorizonsEffect(final EndlessHorizonsEffect effect) { + private EndlessHorizonsEffect(final EndlessHorizonsEffect effect) { super(effect); } @@ -71,35 +67,39 @@ class EndlessHorizonsEffect extends SearchEffect { @Override public boolean apply(Game game, Ability source) { - Player you = game.getPlayer(source.getControllerId()); - if (you != null) { - if (you.searchLibrary(target, source, game)) { - UUID exileZone = CardUtil.getCardExileZoneId(game, source); - if (!target.getTargets().isEmpty()) { - for (UUID cardId : target.getTargets()) { - Card card = you.getLibrary().getCard(cardId, game); - if (card != null) { - card.moveToExile(exileZone, "Endless Horizons", source, game); - } - } - } - } - you.shuffleLibrary(source, game); - return true; - + Player player = game.getPlayer(source.getControllerId()); + Permanent permanent = source.getSourcePermanentOrLKI(game); + if (permanent == null || player == null) { + return false; } - return false; + TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter); + player.searchLibrary(target, source, game); + Cards cards = new CardsImpl(); + target.getTargets() + .stream() + .map(uuid -> player.getLibrary().getCard(uuid, game)) + .filter(Objects::nonNull) + .forEach(cards::add); + player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), permanent.getIdName()); + player.shuffleLibrary(source, game); + return true; } } class EndlessHorizonsEffect2 extends OneShotEffect { - public EndlessHorizonsEffect2() { + private static final FilterCard filter = new FilterCard(); + + static { + filter.add(TargetController.YOU.getOwnerPredicate()); + } + + EndlessHorizonsEffect2() { super(Outcome.ReturnToHand); this.staticText = "you may put a card you own exiled with {this} into your hand"; } - public EndlessHorizonsEffect2(final EndlessHorizonsEffect2 effect) { + private EndlessHorizonsEffect2(final EndlessHorizonsEffect2 effect) { super(effect); } @@ -111,22 +111,15 @@ class EndlessHorizonsEffect2 extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - ExileZone exZone = game.getExile().getExileZone(CardUtil.getCardExileZoneId(game, source)); - if (exZone != null) { - Card card = null; - if (exZone.size() > 1) { - TargetCard target = new TargetCard(Zone.EXILED, new FilterCard()); - controller.choose(outcome, exZone, target, game); - card = game.getCard(target.getFirstTarget()); - } else { - card = exZone.getRandom(game); - } - controller.moveCards(card, Zone.HAND, source, game); - } - return true; + if (controller == null) { + return false; } - return false; + TargetCard target = new TargetCardInExile( + 0, 1, filter, CardUtil.getExileZoneId(game, source) + ); + target.setNotTarget(true); + controller.choose(outcome, target, source.getSourceId(), game); + Card card = game.getCard(target.getFirstTarget()); + return card != null && controller.moveCards(card, Zone.HAND, source, game); } - } diff --git a/Mage.Sets/src/mage/cards/e/EscapePod.java b/Mage.Sets/src/mage/cards/e/EscapePod.java index e8e6cac66a..326850022a 100644 --- a/Mage.Sets/src/mage/cards/e/EscapePod.java +++ b/Mage.Sets/src/mage/cards/e/EscapePod.java @@ -1,24 +1,24 @@ - package mage.cards.e; -import java.util.UUID; -import mage.MageObject; import mage.abilities.Ability; import mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility; -import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.ReturnToBattlefieldUnderYourControlTargetEffect; +import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetControlledCreaturePermanent; import mage.target.targetpointer.FixedTarget; +import java.util.UUID; + /** - * * @author Styxo */ public final class EscapePod extends CardImpl { @@ -29,7 +29,6 @@ public final class EscapePod extends CardImpl { // Exile target creature you control. Return that card to the battlefield under your control at the beginning of the next end step. this.getSpellAbility().addEffect(new EscapePodEffect()); this.getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); - } private EscapePod(final EscapePod card) { @@ -44,34 +43,35 @@ public final class EscapePod extends CardImpl { class EscapePodEffect extends OneShotEffect { - public EscapePodEffect() { + EscapePodEffect() { super(Outcome.Detriment); - staticText = "Exile target creature you control. Return that card to the battlefield under your control at the beginning of the next end step"; + staticText = "Exile target creature you control. Return that card to the battlefield " + + "under your control at the beginning of the next end step"; } - public EscapePodEffect(final EscapePodEffect effect) { + private EscapePodEffect(final EscapePodEffect effect) { super(effect); } @Override public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getFirstTarget()); - MageObject sourceObject = game.getObject(source.getSourceId()); - if (permanent != null && sourceObject != null) { - if (permanent.moveToExile(source.getSourceId(), sourceObject.getIdName(), source, game)) { - Effect effect = new ReturnToBattlefieldUnderYourControlTargetEffect(); - effect.setText("Return that card to the battlefield under your control at the beginning of the next end step"); - effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game)); - game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source); - return true; - } + if (player == null || permanent == null) { + return false; } - return false; + Card card = permanent.getMainCard(); + player.moveCards(permanent, Zone.EXILED, source, game); + game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility( + new ReturnToBattlefieldUnderYourControlTargetEffect().setText( + "Return that card to the battlefield under your control at the beginning of the next end step" + ).setTargetPointer(new FixedTarget(card, game)) + ), source); + return true; } @Override public EscapePodEffect copy() { return new EscapePodEffect(this); } - } diff --git a/Mage.Sets/src/mage/cards/f/FinaleOfPromise.java b/Mage.Sets/src/mage/cards/f/FinaleOfPromise.java index 248f78245d..8958524bac 100644 --- a/Mage.Sets/src/mage/cards/f/FinaleOfPromise.java +++ b/Mage.Sets/src/mage/cards/f/FinaleOfPromise.java @@ -1,5 +1,6 @@ package mage.cards.f; +import mage.ApprovingObject; import mage.abilities.Ability; import mage.abilities.dynamicvalue.common.ManacostVariableValue; import mage.abilities.effects.ContinuousEffect; @@ -13,7 +14,6 @@ import mage.filter.FilterCard; import mage.filter.predicate.mageobject.ConvertedManaCostPredicate; import mage.game.Game; import mage.game.events.GameEvent; -import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; import mage.game.stack.Spell; import mage.players.Player; @@ -24,7 +24,6 @@ import mage.target.targetpointer.FixedTarget; import java.util.*; import java.util.stream.Collectors; -import mage.ApprovingObject; /** * @author JayDi85 @@ -192,8 +191,7 @@ class FinaleOfPromiseReplacementEffect extends ReplacementEffectImpl { if (controller != null) { Card card = game.getCard(getTargetPointer().getFirst(game, source)); if (card != null) { - card.moveToExile(null, "", source, game); - return true; + return controller.moveCards(card, Zone.EXILED, source, game); } } return false; diff --git a/Mage.Sets/src/mage/cards/f/FleshBlood.java b/Mage.Sets/src/mage/cards/f/FleshBlood.java index ae1807408a..e9d240ccd5 100644 --- a/Mage.Sets/src/mage/cards/f/FleshBlood.java +++ b/Mage.Sets/src/mage/cards/f/FleshBlood.java @@ -39,7 +39,6 @@ public final class FleshBlood extends SplitCard { getRightHalfCard().getSpellAbility().addTarget(new TargetControlledCreaturePermanent()); getRightHalfCard().getSpellAbility().addTarget(new TargetAnyTarget()); getRightHalfCard().getSpellAbility().addEffect(new BloodEffect()); - } private FleshBlood(final FleshBlood card) { @@ -65,19 +64,20 @@ class FleshEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); Card targetCard = game.getCard(source.getFirstTarget()); - if (targetCard != null) { - int power = targetCard.getPower().getValue(); - targetCard.moveToExile(null, null, source, game); - if (power > 0) { - Permanent targetCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget()); - if (targetCreature != null) { - targetCreature.addCounters(CounterType.P1P1.createInstance(power), source.getControllerId(), source, game); - } - } - return true; + if (player == null || targetCard == null) { + return false; } - return false; + int power = targetCard.getPower().getValue(); + player.moveCards(targetCard, Zone.EXILED, source, game); + if (power > 0) { + Permanent targetCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget()); + if (targetCreature != null) { + targetCreature.addCounters(CounterType.P1P1.createInstance(power), source.getControllerId(), source, game); + } + } + return true; } @Override diff --git a/Mage.Sets/src/mage/cards/f/Foresight.java b/Mage.Sets/src/mage/cards/f/Foresight.java index 0bb06df95b..1f4de70b52 100644 --- a/Mage.Sets/src/mage/cards/f/Foresight.java +++ b/Mage.Sets/src/mage/cards/f/Foresight.java @@ -1,25 +1,22 @@ - package mage.cards.f; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.delayed.AtTheBeginOfNextUpkeepDelayedTriggeredAbility; import mage.abilities.effects.SearchEffect; import mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect; import mage.abilities.effects.common.DrawCardSourceControllerEffect; -import mage.cards.Card; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; +import mage.cards.*; import mage.constants.CardType; import mage.constants.Outcome; -import mage.filter.FilterCard; +import mage.constants.Zone; +import mage.filter.StaticFilters; import mage.game.Game; import mage.players.Player; import mage.target.common.TargetCardInLibrary; +import java.util.UUID; + /** - * * @author TheElk801 */ public final class Foresight extends CardImpl { @@ -47,11 +44,11 @@ public final class Foresight extends CardImpl { class ForesightEffect extends SearchEffect { ForesightEffect() { - super(new TargetCardInLibrary(3, new FilterCard()), Outcome.Benefit); + super(new TargetCardInLibrary(3, StaticFilters.FILTER_CARD), Outcome.Benefit); staticText = "Search your library for three cards, exile them, then shuffle your library"; } - ForesightEffect(final ForesightEffect effect) { + private ForesightEffect(final ForesightEffect effect) { super(effect); } @@ -63,21 +60,19 @@ class ForesightEffect extends SearchEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - if (player != null && player.searchLibrary(target, source, game)) { - for (UUID targetId : getTargets()) { - Card card = player.getLibrary().getCard(targetId, game); - if (card != null) { - card.moveToExile(null, null, source, game); - } - } - player.shuffleLibrary(source, game); - return true; + if (player == null) { + return false; } - return false; + player.searchLibrary(target, source, game); + Cards cards = new CardsImpl(); + for (UUID targetId : target.getTargets()) { + Card card = player.getLibrary().getCard(targetId, game); + if (card != null) { + cards.add(card); + } + } + player.moveCards(cards, Zone.EXILED, source, game); + player.shuffleLibrary(source, game); + return true; } - - public List getTargets() { - return target.getTargets(); - } - } diff --git a/Mage.Sets/src/mage/cards/f/FracturedIdentity.java b/Mage.Sets/src/mage/cards/f/FracturedIdentity.java index 2ba73c21bb..00580a2f58 100644 --- a/Mage.Sets/src/mage/cards/f/FracturedIdentity.java +++ b/Mage.Sets/src/mage/cards/f/FracturedIdentity.java @@ -1,7 +1,5 @@ - package mage.cards.f; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateTokenCopyTargetEffect; @@ -9,13 +7,16 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; import mage.target.common.TargetNonlandPermanent; import mage.target.targetpointer.FixedTarget; +import java.util.UUID; + /** - * * @author spjspj */ public final class FracturedIdentity extends CardImpl { @@ -40,12 +41,12 @@ public final class FracturedIdentity extends CardImpl { class FracturedIdentityEffect extends OneShotEffect { - public FracturedIdentityEffect() { + FracturedIdentityEffect() { super(Outcome.Exile); this.staticText = "Exile target nonland permanent. Each player other than its controller creates a token that's a copy of it"; } - public FracturedIdentityEffect(final FracturedIdentityEffect effect) { + private FracturedIdentityEffect(final FracturedIdentityEffect effect) { super(effect); } @@ -56,17 +57,19 @@ class FracturedIdentityEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); Permanent permanent = game.getPermanent(source.getFirstTarget()); - if (permanent == null) { + if (player == null || permanent == null) { return false; } - - permanent.moveToExile(null, null, source, game); - UUID controllerId = permanent.getControllerId(); - for (UUID opponentId : game.getOpponents(controllerId)) { - CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(opponentId, null, false); - effect.setTargetPointer(new FixedTarget(permanent, game)); - effect.apply(game, source); + player.moveCards(permanent, Zone.EXILED, source, game); + for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) { + if (permanent.isControlledBy(playerId)) { + continue; + } + new CreateTokenCopyTargetEffect( + playerId, null, false + ).setTargetPointer(new FixedTarget(permanent, game)).apply(game, source); } return true; } diff --git a/Mage.Sets/src/mage/cards/f/FreeForAll.java b/Mage.Sets/src/mage/cards/f/FreeForAll.java index a338253390..77cef34a0e 100644 --- a/Mage.Sets/src/mage/cards/f/FreeForAll.java +++ b/Mage.Sets/src/mage/cards/f/FreeForAll.java @@ -1,14 +1,10 @@ - package mage.cards.f; -import java.util.List; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.BeginningOfUpkeepTriggeredAbility; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.cards.Cards; @@ -17,26 +13,28 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.TargetController; import mage.constants.Zone; -import mage.filter.common.FilterCreaturePermanent; +import mage.filter.StaticFilters; import mage.game.ExileZone; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; +import mage.util.CardUtil; + +import java.util.UUID; /** - * * @author L_J */ public final class FreeForAll extends CardImpl { public FreeForAll(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{3}{U}"); + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{3}{U}"); // When Free-for-All enters the battlefield, exile all creatures face down. this.addAbility(new EntersBattlefieldTriggeredAbility(new FreeForAllExileAllEffect())); // At the beginning of each player's upkeep, that player chooses a card exiled with Free-for-All at random and puts it onto the battlefield. - this.addAbility(new BeginningOfUpkeepTriggeredAbility(Zone.BATTLEFIELD, new FreeForAllReturnFromExileEffect(), TargetController.ANY, false, true)); + this.addAbility(new BeginningOfUpkeepTriggeredAbility(new FreeForAllReturnFromExileEffect(), TargetController.ANY, false)); // When Free-for-All leaves the battlefield, put all cards exiled with it into their owners' graveyards. this.addAbility(new LeavesBattlefieldTriggeredAbility(new FreeForAllLeavesBattlefieldEffect(), false)); @@ -54,12 +52,12 @@ public final class FreeForAll extends CardImpl { class FreeForAllExileAllEffect extends OneShotEffect { - public FreeForAllExileAllEffect() { + FreeForAllExileAllEffect() { super(Outcome.Exile); staticText = "exile all creatures face down"; } - public FreeForAllExileAllEffect(final FreeForAllExileAllEffect effect) { + private FreeForAllExileAllEffect(final FreeForAllExileAllEffect effect) { super(effect); } @@ -70,26 +68,32 @@ class FreeForAllExileAllEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - List permanents = game.getBattlefield().getActivePermanents(new FilterCreaturePermanent(), source.getControllerId(), source.getSourceId(), game); - for (Permanent permanent : permanents) { - Card card = game.getCard(permanent.getId()); - permanent.moveToExile(source.getSourceId(), "Free-for-All", source, game); - if (card != null) { - card.setFaceDown(true, game); - } + Player player = game.getPlayer(source.getControllerId()); + Permanent sourcePermanent = source.getSourcePermanentOrLKI(game); + if (player == null || sourcePermanent == null) { + return false; } + Cards cards = new CardsImpl(); + game.getBattlefield().getActivePermanents( + StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game + ).stream().forEach(cards::add); + player.moveCardsToExile(cards.getCards(game), source, game, false, CardUtil.getExileZoneId(game, source), sourcePermanent.getIdName()); + cards.getCards(game) + .stream() + .filter(card -> game.getState().getZone(card.getId()) == Zone.EXILED) + .forEach(card -> card.setFaceDown(true, game)); return true; } } class FreeForAllReturnFromExileEffect extends OneShotEffect { - public FreeForAllReturnFromExileEffect() { + FreeForAllReturnFromExileEffect() { super(Outcome.PutCardInPlay); - staticText = "that player chooses a card exiled with Free-for-All at random and puts it onto the battlefield"; + staticText = "that player chooses a card exiled with {this} at random and puts it onto the battlefield"; } - public FreeForAllReturnFromExileEffect(final FreeForAllReturnFromExileEffect effect) { + private FreeForAllReturnFromExileEffect(final FreeForAllReturnFromExileEffect effect) { super(effect); } @@ -100,27 +104,24 @@ class FreeForAllReturnFromExileEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Player player = game.getPlayer(targetPointer.getFirst(game, source)); - if (player != null) { - ExileZone exZone = game.getExile().getExileZone(source.getSourceId()); - if (exZone != null) { - Cards exiledCards = new CardsImpl(exZone.getCards(game)); - return player.moveCards(exiledCards.getRandom(game), Zone.BATTLEFIELD, source, game); - } - return true; + Player player = game.getPlayer(game.getActivePlayerId()); + ExileZone exZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)); + if (player == null || exZone == null || exZone.isEmpty()) { + return false; } - return false; + Cards exiledCards = new CardsImpl(exZone.getCards(game)); + return player.moveCards(exiledCards.getRandom(game), Zone.BATTLEFIELD, source, game); } } class FreeForAllLeavesBattlefieldEffect extends OneShotEffect { - public FreeForAllLeavesBattlefieldEffect() { + FreeForAllLeavesBattlefieldEffect() { super(Outcome.Detriment); this.staticText = "put all cards exiled with it into their owners' graveyards"; } - public FreeForAllLeavesBattlefieldEffect(final FreeForAllLeavesBattlefieldEffect effect) { + private FreeForAllLeavesBattlefieldEffect(final FreeForAllLeavesBattlefieldEffect effect) { super(effect); } @@ -132,13 +133,9 @@ class FreeForAllLeavesBattlefieldEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null) { - ExileZone exZone = game.getExile().getExileZone(source.getSourceId()); - if (exZone != null) { - return controller.moveCards(exZone.getCards(game), Zone.GRAVEYARD, source, game, false, false, true, null); - } - return true; - } - return false; + ExileZone exZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source)); + return controller != null + && exZone != null + && controller.moveCards(exZone.getCards(game), Zone.GRAVEYARD, source, game); } } diff --git a/Mage.Sets/src/mage/cards/f/FuneralPyre.java b/Mage.Sets/src/mage/cards/f/FuneralPyre.java index 937e819c97..62d11b91ee 100644 --- a/Mage.Sets/src/mage/cards/f/FuneralPyre.java +++ b/Mage.Sets/src/mage/cards/f/FuneralPyre.java @@ -1,7 +1,5 @@ - package mage.cards.f; -import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; @@ -9,27 +7,25 @@ import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.Outcome; +import mage.constants.Zone; import mage.game.Game; import mage.game.permanent.token.SpiritWhiteToken; -import mage.game.permanent.token.Token; import mage.players.Player; import mage.target.common.TargetCardInGraveyard; -import mage.util.CardUtil; + +import java.util.UUID; /** - * * @author jeffwadsworth */ public final class FuneralPyre extends CardImpl { public FuneralPyre(UUID ownerId, CardSetInfo setInfo) { super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{W}"); - // Exile target card from a graveyard. Its owner puts a 1/1 white Spirit creature token with flying onto the battlefield. this.getSpellAbility().addEffect(new FuneralPyreEffect()); this.getSpellAbility().addTarget(new TargetCardInGraveyard()); - } private FuneralPyre(final FuneralPyre card) { @@ -44,12 +40,13 @@ public final class FuneralPyre extends CardImpl { class FuneralPyreEffect extends OneShotEffect { - public FuneralPyreEffect() { + FuneralPyreEffect() { super(Outcome.Benefit); - this.staticText = "Exile target card from a graveyard. Its owner puts a 1/1 white Spirit creature token with flying onto the battlefield"; + this.staticText = "Exile target card from a graveyard. " + + "Its owner creates a 1/1 white Spirit creature token with flying"; } - public FuneralPyreEffect(final FuneralPyreEffect effect) { + private FuneralPyreEffect(final FuneralPyreEffect effect) { super(effect); } @@ -60,17 +57,16 @@ class FuneralPyreEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Card exiledCard = game.getCard(source.getTargets().getFirstTarget()); - if (exiledCard != null) { - UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), 0); - if (exiledCard.moveToExile(exileId, "Funeral Pyre", source, game)) { - Player owner = game.getPlayer(exiledCard.getOwnerId()); - if (owner != null) { - Token token = new SpiritWhiteToken(); - return token.putOntoBattlefield(1, game, source, owner.getId()); - } - } + Player player = game.getPlayer(source.getControllerId()); + Card exiledCard = game.getCard(source.getFirstTarget()); + if (player == null || exiledCard == null) { + return false; } - return false; + Player owner = game.getPlayer(exiledCard.getOwnerId()); + player.moveCards(exiledCard, Zone.EXILED, source, game); + if (owner != null) { + new SpiritWhiteToken().putOntoBattlefield(1, game, source, owner.getId()); + } + return true; } } diff --git a/Mage.Sets/src/mage/cards/s/SimianSpiritGuide.java b/Mage.Sets/src/mage/cards/s/SimianSpiritGuide.java index b54fc6f7e7..601da394f5 100644 --- a/Mage.Sets/src/mage/cards/s/SimianSpiritGuide.java +++ b/Mage.Sets/src/mage/cards/s/SimianSpiritGuide.java @@ -1,30 +1,24 @@ - package mage.cards.s; -import java.util.UUID; import mage.MageInt; import mage.Mana; -import mage.abilities.Ability; -import mage.abilities.costs.Cost; -import mage.abilities.costs.CostImpl; +import mage.abilities.costs.common.ExileSourceFromHandCost; import mage.abilities.mana.SimpleManaAbility; -import mage.cards.Card; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; import mage.constants.SubType; import mage.constants.Zone; -import mage.game.Game; -import mage.players.Player; + +import java.util.UUID; /** - * * @author Plopman */ public final class SimianSpiritGuide extends CardImpl { public SimianSpiritGuide(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.CREATURE},"{2}{R}"); + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{2}{R}"); this.subtype.add(SubType.APE); this.subtype.add(SubType.SPIRIT); @@ -44,40 +38,3 @@ public final class SimianSpiritGuide extends CardImpl { return new SimianSpiritGuide(this); } } - - -class ExileSourceFromHandCost extends CostImpl { - - public ExileSourceFromHandCost() { - this.text = "Exile {this} from your hand"; - } - - public ExileSourceFromHandCost(ExileSourceFromHandCost cost) { - super(cost); - } - - @Override - public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { - Card card = game.getCard(source.getSourceId()); - Player player = game.getPlayer(controllerId); - if (player != null && player.getHand().contains(source.getSourceId()) && card != null) { - paid = card.moveToExile(ability.getSourceId(), "from Hand", source, game); - } - return paid; - } - - @Override - public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { - Player player = game.getPlayer(controllerId); - if (player != null && player.getHand().contains(source.getSourceId())) { - return true; - } - return false; - } - - @Override - public ExileSourceFromHandCost copy() { - return new ExileSourceFromHandCost(this); - } - -} \ No newline at end of file diff --git a/Mage/src/main/java/mage/abilities/costs/common/ExileSourceFromHandCost.java b/Mage/src/main/java/mage/abilities/costs/common/ExileSourceFromHandCost.java new file mode 100644 index 0000000000..8d6ba5bc71 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/costs/common/ExileSourceFromHandCost.java @@ -0,0 +1,46 @@ +package mage.abilities.costs.common; + +import mage.abilities.Ability; +import mage.abilities.costs.Cost; +import mage.abilities.costs.CostImpl; +import mage.cards.Card; +import mage.constants.Zone; +import mage.game.Game; +import mage.players.Player; + +import java.util.UUID; + +/** + * @author TheElk801 + */ +public class ExileSourceFromHandCost extends CostImpl { + + public ExileSourceFromHandCost() { + this.text = "exile {this} from your hand"; + } + + private ExileSourceFromHandCost(ExileSourceFromHandCost cost) { + super(cost); + } + + @Override + public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) { + Player player = game.getPlayer(controllerId); + Card card = game.getCard(source.getSourceId()); + if (player != null && player.getHand().contains(source.getSourceId()) && card != null) { + paid = player.moveCards(card, Zone.EXILED, source, game); + } + return paid; + } + + @Override + public boolean canPay(Ability ability, Ability source, UUID controllerId, Game game) { + Player player = game.getPlayer(controllerId); + return player != null && player.getHand().contains(source.getSourceId()); + } + + @Override + public ExileSourceFromHandCost copy() { + return new ExileSourceFromHandCost(this); + } +}