diff --git a/Mage.Sets/src/mage/sets/planarchaos/BrainGorgers.java b/Mage.Sets/src/mage/sets/planarchaos/BrainGorgers.java index 9ba3c089df..53fd0d565b 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/BrainGorgers.java +++ b/Mage.Sets/src/mage/sets/planarchaos/BrainGorgers.java @@ -29,6 +29,7 @@ package mage.sets.planarchaos; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.costs.common.SacrificeTargetCost; import mage.abilities.costs.mana.ManaCostsImpl; @@ -92,23 +93,26 @@ class BrainGorgersCounterSourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Spell spell = game.getStack().getSpell(source.getSourceId()); - if (spell != null) { + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject != null) { SacrificeTargetCost cost = new SacrificeTargetCost(new TargetControlledCreaturePermanent()); for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) { cost.clearPaid(); Player player = game.getPlayer(playerId); if (cost.canPay(source, source.getSourceId(), player.getId(), game) - && player.chooseUse(outcome, "Sacrifice a creature to counter " + spell.getIdName() + "?", source, game)) { + && player.chooseUse(outcome, "Sacrifice a creature to counter " + sourceObject.getIdName() + "?", source, game)) { if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { - game.informPlayers(player.getLogName() + " sacrifices a creature to counter " + spell.getIdName() + "."); - game.getStack().counter(spell.getId(), source.getSourceId(), game); + game.informPlayers(player.getLogName() + " sacrifices a creature to counter " + sourceObject.getIdName() + "."); + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null) { + game.getStack().counter(spell.getId(), source.getSourceId(), game); + } } } } return true; } return false; - } + } } diff --git a/Mage.Sets/src/mage/sets/planarchaos/DashHopes.java b/Mage.Sets/src/mage/sets/planarchaos/DashHopes.java index 561fbbc9e8..d061e582a9 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/DashHopes.java +++ b/Mage.Sets/src/mage/sets/planarchaos/DashHopes.java @@ -28,6 +28,7 @@ package mage.sets.planarchaos; import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.costs.common.PayLifeCost; import mage.abilities.effects.OneShotEffect; @@ -88,17 +89,20 @@ class DashHopesCounterSourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Spell spell = game.getStack().getSpell(source.getSourceId()); - if (spell != null) { + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject != null) { PayLifeCost cost = new PayLifeCost(5); for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) { Player player = game.getPlayer(playerId); cost.clearPaid(); if (cost.canPay(source, source.getSourceId(), player.getId(), game) - && player.chooseUse(outcome, "Pay 5 life to counter " + spell.getIdName() + "?", source, game)) { + && player.chooseUse(outcome, "Pay 5 life to counter " + sourceObject.getIdName() + "?", source, game)) { if (cost.pay(source, game, source.getSourceId(), player.getId(), false)) { - game.informPlayers(player.getLogName() + " pays 5 life to counter " + spell.getIdName() + "."); - game.getStack().counter(spell.getId(), source.getSourceId(), game); + game.informPlayers(player.getLogName() + " pays 5 life to counter " + sourceObject.getIdName() + "."); + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null) { + game.getStack().counter(spell.getId(), source.getSourceId(), game); + } } } } diff --git a/Mage.Sets/src/mage/sets/planarchaos/Phantasmagorian.java b/Mage.Sets/src/mage/sets/planarchaos/Phantasmagorian.java index 966f1d2a12..31778c3669 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/Phantasmagorian.java +++ b/Mage.Sets/src/mage/sets/planarchaos/Phantasmagorian.java @@ -29,6 +29,7 @@ package mage.sets.planarchaos; import java.util.UUID; import mage.MageInt; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.common.SimpleActivatedAbility; @@ -44,7 +45,6 @@ import mage.constants.Zone; import mage.filter.FilterCard; import mage.game.Game; import mage.game.stack.Spell; -import mage.game.stack.StackObject; import mage.players.Player; import mage.target.common.TargetCardInHand; @@ -81,7 +81,7 @@ public class Phantasmagorian extends CardImpl { class CounterSourceEffect extends OneShotEffect { public CounterSourceEffect() { - super(Outcome.Detriment); + super(Outcome.AIDontUseIt); } public CounterSourceEffect(final CounterSourceEffect effect) { @@ -95,25 +95,20 @@ class CounterSourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - - StackObject spell = null; - for (StackObject objet : game.getStack()) { - if (objet instanceof Spell && objet.getSourceId().equals(source.getSourceId())) { - spell = objet; - } - } - if (spell != null) { + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject != null) { DiscardTargetCost cost = new DiscardTargetCost(new TargetCardInHand(3, 3, new FilterCard())); - for (UUID uuid : game.getPlayerList()) { - Player player = game.getPlayer(uuid); + for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) { + Player player = game.getPlayer(playerId); cost.clearPaid(); if (cost.canPay(source, source.getSourceId(), player.getId(), game) - && player.chooseUse(Outcome.Detriment, "Discard three cards to counter " + spell.getName() + "?", source, game)) { - - if (cost.pay(source, game, source.getSourceId(), uuid, false)) { - game.informPlayers(player.getLogName() + " discards 3 cards to counter " + spell.getName() + "."); - game.getStack().counter(spell.getId(), source.getSourceId(), game); - return true; + && player.chooseUse(outcome, "Discard three cards to counter " + sourceObject.getIdName() + "?", source, game)) { + if (cost.pay(source, game, source.getSourceId(), playerId, false)) { + game.informPlayers(player.getLogName() + " discards 3 cards to counter " + sourceObject.getIdName() + "."); + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null) { + game.getStack().counter(spell.getId(), source.getSourceId(), game); + } } } } diff --git a/Mage.Sets/src/mage/sets/planarchaos/TemporalExtortion.java b/Mage.Sets/src/mage/sets/planarchaos/TemporalExtortion.java index ea806b6198..c1a25134a5 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/TemporalExtortion.java +++ b/Mage.Sets/src/mage/sets/planarchaos/TemporalExtortion.java @@ -28,6 +28,7 @@ package mage.sets.planarchaos; import java.util.UUID; +import mage.MageObject; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CastSourceTriggeredAbility; @@ -85,15 +86,18 @@ class TemporalExtortionCounterSourceEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Spell spell = game.getStack().getSpell(source.getSourceId()); - if (spell != null) { + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject != null) { for (UUID playerId : game.getState().getPlayerList(source.getControllerId())) { Player player = game.getPlayer(playerId); - if (player.chooseUse(outcome, "Pay half your life, rounded up to counter " + spell.getIdName() + "?", source, game)) { + if (player.chooseUse(outcome, "Pay half your life, rounded up to counter " + sourceObject.getIdName() + "?", source, game)) { Integer amount = (int) Math.ceil(player.getLife() / 2f); player.loseLife(amount, game); - game.informPlayers(player.getLogName() + " pays half his or her life, rounded up to counter " + spell.getIdName() + "."); - game.getStack().counter(spell.getId(), source.getSourceId(), game); + game.informPlayers(player.getLogName() + " pays half his or her life, rounded up to counter " + sourceObject.getIdName() + "."); + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null) { + game.getStack().counter(spell.getId(), source.getSourceId(), game); + } } } return true; diff --git a/Mage/src/mage/abilities/costs/common/DiscardTargetCost.java b/Mage/src/mage/abilities/costs/common/DiscardTargetCost.java index 3cb460452a..5ba87b8191 100644 --- a/Mage/src/mage/abilities/costs/common/DiscardTargetCost.java +++ b/Mage/src/mage/abilities/costs/common/DiscardTargetCost.java @@ -68,6 +68,7 @@ public class DiscardTargetCost extends CostImpl { @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana) { this.cards.clear(); + this.targets.clear(); Player player = game.getPlayer(controllerId); if (player == null) { return false; @@ -94,7 +95,8 @@ public class DiscardTargetCost extends CostImpl { @Override public void clearPaid() { super.clearPaid(); - cards.clear(); + this.cards.clear(); + this.targets.clear(); } @Override