diff --git a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java index 3737ba42519..7a9aa0eee78 100644 --- a/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java +++ b/Mage.Server.Plugins/Mage.Player.AI.MA/src/mage/player/ai/SimulatedPlayer2.java @@ -45,7 +45,6 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.VariableManaCost; import mage.abilities.effects.Effect; import mage.cards.Card; -import mage.choices.Choice; import mage.constants.AbilityType; import mage.game.Game; import mage.game.combat.Combat; @@ -452,9 +451,6 @@ public class SimulatedPlayer2 extends ComputerPlayer { newNode.getTargets().add(targetId); } } - for (Choice choice : ability.getChoices()) { - newNode.getChoices().add(choice.getChoice()); - } parent.children.add(newNode); } diff --git a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java index bbdd0ce9724..743c6a65445 100644 --- a/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java +++ b/Mage.Server.Plugins/Mage.Player.AIMinimax/src/mage/player/ai/SimulatedPlayer.java @@ -35,7 +35,6 @@ import mage.abilities.SpellAbility; import mage.abilities.TriggeredAbility; import mage.abilities.common.PassAbility; import mage.abilities.costs.mana.GenericManaCost; -import mage.choices.Choice; import mage.game.Game; import mage.game.combat.Combat; import mage.game.events.GameEvent; @@ -270,9 +269,6 @@ public class SimulatedPlayer extends ComputerPlayer { newNode.getTargets().add(targetId); } } - for (Choice choice: ability.getChoices()) { - newNode.getChoices().add(choice.getChoice()); - } parent.children.add(newNode); } diff --git a/Mage.Sets/src/mage/sets/betrayersofkamigawa/PetalmaneBaku.java b/Mage.Sets/src/mage/sets/betrayersofkamigawa/PetalmaneBaku.java index 1bd98974269..30e824dc0de 100644 --- a/Mage.Sets/src/mage/sets/betrayersofkamigawa/PetalmaneBaku.java +++ b/Mage.Sets/src/mage/sets/betrayersofkamigawa/PetalmaneBaku.java @@ -32,23 +32,17 @@ import mage.MageInt; import mage.Mana; import mage.abilities.Ability; import mage.abilities.common.SpellCastControllerTriggeredAbility; -import mage.abilities.costs.Cost; import mage.abilities.costs.common.RemoveVariableCountersSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.common.CountersCount; import mage.abilities.dynamicvalue.common.RemovedCountersForCostValue; -import mage.abilities.effects.common.ManaEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect; -import mage.abilities.mana.BasicManaAbility; import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; -import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.Rarity; import mage.counters.CounterType; import mage.filter.common.FilterSpiritOrArcaneCard; -import mage.game.Game; -import mage.players.Player; /** * @author LevelX2 @@ -88,76 +82,4 @@ public class PetalmaneBaku extends CardImpl { public PetalmaneBaku copy() { return new PetalmaneBaku(this); } - - private class PetalmaneBakuManaAbility extends BasicManaAbility { - - PetalmaneBakuManaAbility() { - super(new PetalmaneBakuManaEffect()); - this.addChoice(new ChoiceColor()); - } - - PetalmaneBakuManaAbility(final PetalmaneBakuManaAbility ability) { - super(ability); - } - - @Override - public PetalmaneBakuManaAbility copy() { - return new PetalmaneBakuManaAbility(this); - } - } - - private class PetalmaneBakuManaEffect extends ManaEffect { - - PetalmaneBakuManaEffect() { - super(); - staticText = "Add X mana of any one color to your mana pool"; - } - - PetalmaneBakuManaEffect(final PetalmaneBakuManaEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); - Player player = game.getPlayer(source.getControllerId()); - - if (player != null && choice != null) { - int numberOfMana = 0; - for (Cost cost : source.getCosts()) { - if (cost instanceof RemoveVariableCountersSourceCost) { - numberOfMana = ((RemoveVariableCountersSourceCost) cost).getAmount(); - } - } - if (choice.getColor().isBlack()) { - player.getManaPool().addMana(new Mana(0, 0, 0, 0, numberOfMana, 0, 0, 0), game, source); - return true; - } else if (choice.getColor().isBlue()) { - player.getManaPool().addMana(new Mana(0, 0, numberOfMana, 0, 0, 0, 0, 0), game, source); - return true; - } else if (choice.getColor().isRed()) { - player.getManaPool().addMana(new Mana(numberOfMana, 0, 0, 0, 0, 0, 0, 0), game, source); - return true; - } else if (choice.getColor().isGreen()) { - player.getManaPool().addMana(new Mana(0, numberOfMana, 0, 0, 0, 0, 0, 0), game, source); - return true; - } else if (choice.getColor().isWhite()) { - player.getManaPool().addMana(new Mana(0, 0, 0, numberOfMana, 0, 0, 0, 0), game, source); - return true; - } - } - return false; - } - - @Override - public Mana getMana(Game game, Ability source) { - return null; - } - - @Override - public PetalmaneBakuManaEffect copy() { - return new PetalmaneBakuManaEffect(this); - } - } - } diff --git a/Mage.Sets/src/mage/sets/commander2013/MarathWillOfTheWild.java b/Mage.Sets/src/mage/sets/commander2013/MarathWillOfTheWild.java index 4562b903d45..f24bb796b41 100644 --- a/Mage.Sets/src/mage/sets/commander2013/MarathWillOfTheWild.java +++ b/Mage.Sets/src/mage/sets/commander2013/MarathWillOfTheWild.java @@ -27,11 +27,13 @@ */ package mage.sets.commander2013; +import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.Mode; import mage.abilities.common.EntersBattlefieldAbility; import mage.abilities.common.SimpleActivatedAbility; +import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; import mage.abilities.costs.VariableCost; import mage.abilities.costs.mana.ManaCostsImpl; @@ -56,9 +58,6 @@ import mage.players.Player; import mage.target.common.TargetCreatureOrPlayer; import mage.target.common.TargetCreaturePermanent; -import java.util.UUID; -import mage.abilities.costs.Cost; - /** * * @author LevelX2 @@ -109,7 +108,7 @@ public class MarathWillOfTheWild extends CardImpl { } @Override - public void adjustChoices(Ability ability, Game game) { + public void adjustCosts(Ability ability, Game game) { if (ability instanceof SimpleActivatedAbility && ability.getModes().size() == 3) { Permanent sourcePermanent = game.getPermanent(ability.getSourceId()); if (sourcePermanent != null) { @@ -124,7 +123,6 @@ public class MarathWillOfTheWild extends CardImpl { } } } - } public MarathWillOfTheWild(final MarathWillOfTheWild card) { diff --git a/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java b/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java index 4bade00c62d..351c8c32e60 100644 --- a/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java +++ b/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java @@ -35,6 +35,7 @@ import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.continuous.GainControlTargetEffect; import mage.cards.CardImpl; +import mage.choices.Choice; import mage.choices.ChoiceLeftOrRight; import mage.constants.CardType; import mage.constants.Duration; @@ -62,7 +63,6 @@ public class OrderOfSuccession extends CardImpl { // Choose left or right. Starting with you and proceeding in the chosen direction, each player chooses a creature controlled by the next player in that direction. Each player gains control of the creature he or she chose. - this.getSpellAbility().addChoice(new ChoiceLeftOrRight()); this.getSpellAbility().addEffect(new OrderOfSuccessionEffect()); } @@ -96,8 +96,10 @@ class OrderOfSuccessionEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Map playerCreature = new HashMap<>(); - boolean left = source.getChoices().get(0).getChoice().equals("Left"); + Map playerCreature = new HashMap<>(2); + Choice choice = new ChoiceLeftOrRight(); + controller.choose(Outcome.Neutral, choice, game); + boolean left = choice.getChoice().equals("Left"); PlayerList playerList = game.getState().getPlayerList().copy(); // set playerlist to controller while (!playerList.get().equals(source.getControllerId()) && controller.canRespond()) { diff --git a/Mage.Sets/src/mage/sets/commander2013/SpringjackPasture.java b/Mage.Sets/src/mage/sets/commander2013/SpringjackPasture.java index 410e73111f9..9fc3ec0ab0e 100644 --- a/Mage.Sets/src/mage/sets/commander2013/SpringjackPasture.java +++ b/Mage.Sets/src/mage/sets/commander2013/SpringjackPasture.java @@ -35,21 +35,17 @@ import mage.abilities.costs.common.SacrificeXTargetCost; import mage.abilities.costs.common.TapSourceCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.dynamicvalue.common.GetXValue; -import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.CreateTokenEffect; import mage.abilities.effects.common.GainLifeEffect; import mage.abilities.mana.ColorlessManaAbility; +import mage.abilities.mana.DynamicManaAbility; import mage.cards.CardImpl; -import mage.choices.ChoiceColor; import mage.constants.CardType; -import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.predicate.mageobject.SubtypePredicate; -import mage.game.Game; import mage.game.permanent.token.GoatToken; -import mage.players.Player; /** * @@ -77,8 +73,12 @@ public class SpringjackPasture extends CardImpl { this.addAbility(ability); // {tap}, Sacrifice X Goats: Add X mana of any one color to your mana pool. You gain X life. - ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new SpringjackPastureEffect(), new TapSourceCost()); - ability.addChoice(new ChoiceColor()); + ability = new DynamicManaAbility( + new Mana(0,0,0,0,0,0,1,0), + new GetXValue(), + new TapSourceCost(), + "Add X mana of any one color to your mana pool", + true); ability.addCost(new SacrificeXTargetCost(filter)); ability.addEffect(new GainLifeEffect(new GetXValue())); this.addAbility(ability); @@ -94,43 +94,3 @@ public class SpringjackPasture extends CardImpl { return new SpringjackPasture(this); } } - -class SpringjackPastureEffect extends OneShotEffect { - - public SpringjackPastureEffect() { - super(Outcome.Benefit); - staticText = "Add X mana of any one color to your mana pool"; - } - - public SpringjackPastureEffect(final SpringjackPastureEffect effect) { - super(effect); - } - - @Override - public boolean apply(Game game, Ability source) { - Player you = game.getPlayer(source.getControllerId()); - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); - if (you != null && choice != null) { - int count = new GetXValue().calculate(game, source, this); - if (choice.getColor().isBlack()) { - you.getManaPool().addMana(new Mana(0, 0, 0, 0, count, 0, 0, 0), game, source); - } else if (choice.getColor().isBlue()) { - you.getManaPool().addMana(new Mana(0, 0, count, 0, 0, 0, 0, 0), game, source); - } else if (choice.getColor().isRed()) { - you.getManaPool().addMana(new Mana(count, 0, 0, 0, 0, 0, 0, 0), game, source); - } else if (choice.getColor().isGreen()) { - you.getManaPool().addMana(new Mana(0, count, 0, 0, 0, 0, 0, 0), game, source); - } else if (choice.getColor().isWhite()) { - you.getManaPool().addMana(new Mana(0, 0, 0, count, 0, 0, 0, 0), game, source); - } - return true; - - } - return false; - } - - @Override - public SpringjackPastureEffect copy() { - return new SpringjackPastureEffect(this); - } -} diff --git a/Mage.Sets/src/mage/sets/gatecrash/AngelicSkirmisher.java b/Mage.Sets/src/mage/sets/gatecrash/AngelicSkirmisher.java index cab75c5c867..a79dba31179 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/AngelicSkirmisher.java +++ b/Mage.Sets/src/mage/sets/gatecrash/AngelicSkirmisher.java @@ -30,12 +30,6 @@ package mage.sets.gatecrash; import java.util.HashSet; import java.util.Set; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Rarity; -import mage.constants.Duration; -import mage.constants.Outcome; -import mage.constants.TargetController; import mage.MageInt; import mage.abilities.Ability; import mage.abilities.common.BeginningOfCombatTriggeredAbility; @@ -48,6 +42,11 @@ import mage.abilities.keyword.VigilanceAbility; import mage.cards.CardImpl; import mage.choices.Choice; import mage.choices.ChoiceImpl; +import mage.constants.CardType; +import mage.constants.Duration; +import mage.constants.Outcome; +import mage.constants.Rarity; +import mage.constants.TargetController; import mage.filter.common.FilterControlledCreaturePermanent; import mage.game.Game; import mage.game.permanent.Permanent; @@ -59,16 +58,6 @@ import mage.players.Player; */ public class AngelicSkirmisher extends CardImpl { - private static final Choice abilityChoice = new ChoiceImpl(true); - private static final Set abilityChoices = new HashSet(); - static { - abilityChoice.setMessage("Choose ability for your creatures"); - abilityChoices.add("First strike"); - abilityChoices.add("Vigilance"); - abilityChoices.add("Lifelink"); - abilityChoice.setChoices(abilityChoices); - } - public AngelicSkirmisher(UUID ownerId) { super(ownerId, 3, "Angelic Skirmisher", Rarity.RARE, new CardType[]{CardType.CREATURE}, "{4}{W}{W}"); this.expansionSetCode = "GTC"; @@ -82,7 +71,6 @@ public class AngelicSkirmisher extends CardImpl { // At the beginning of each combat, choose first strike, vigilance or lifelink. Creatures you control gain that ability until end of turn. Ability ability = new BeginningOfCombatTriggeredAbility(new AngelicSkirmisherEffect(), TargetController.ANY, false); - ability.addChoice(abilityChoice); this.addAbility(ability); } @@ -108,17 +96,30 @@ class AngelicSkirmisherEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Choice abilityChoice = source.getChoices().get(0); + Player controller = game.getPlayer(source.getControllerId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId()); - if (controller != null && sourcePermanent != null && abilityChoice != null && abilityChoice.isChosen()) { + if (controller != null && sourcePermanent != null) { + Choice abilityChoice = new ChoiceImpl(true); + Set abilityChoices = new HashSet<>(3); + abilityChoice.setMessage("Choose ability for your creatures"); + abilityChoices.add("First strike"); + abilityChoices.add("Vigilance"); + abilityChoices.add("Lifelink"); + abilityChoice.setChoices(abilityChoices); Ability ability = null; - if (abilityChoice.getChoice().equals("First strike")) { - ability = FirstStrikeAbility.getInstance(); - } else if (abilityChoice.getChoice().equals("Vigilance")) { - ability = VigilanceAbility.getInstance(); - } else if (abilityChoice.getChoice().equals("Lifelink")) { - ability = LifelinkAbility.getInstance(); + switch (abilityChoice.getChoice()) { + case "First strike": + ability = FirstStrikeAbility.getInstance(); + break; + case "Vigilance": + ability = VigilanceAbility.getInstance(); + break; + case "Lifelink": + ability = LifelinkAbility.getInstance(); + break; + default: + break; } if (ability != null) { GainAbilityControlledEffect effect = new GainAbilityControlledEffect(ability, Duration.EndOfTurn, new FilterControlledCreaturePermanent()); diff --git a/Mage.Sets/src/mage/sets/invasion/Void.java b/Mage.Sets/src/mage/sets/invasion/Void.java index a5bbfe476ed..822ead1a827 100644 --- a/Mage.Sets/src/mage/sets/invasion/Void.java +++ b/Mage.Sets/src/mage/sets/invasion/Void.java @@ -28,17 +28,17 @@ package mage.sets.invasion; import java.util.HashSet; +import java.util.Set; import java.util.UUID; - -import mage.constants.CardType; -import mage.constants.Outcome; -import mage.constants.Rarity; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; import mage.cards.Card; import mage.cards.CardImpl; import mage.choices.Choice; import mage.choices.ChoiceImpl; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.Rarity; import mage.filter.Filter; import mage.filter.FilterCard; import mage.filter.predicate.Predicates; @@ -59,16 +59,7 @@ public class Void extends CardImpl { super(ownerId, 287, "Void", Rarity.RARE, new CardType[]{CardType.SORCERY}, "{3}{B}{R}"); this.expansionSetCode = "INV"; - // Choose a number. Destroy all artifacts and creatures with converted mana cost equal to that number. Then target player reveals his or her hand and discards all nonland cards with converted mana cost equal to the number. - Choice numberChoice = new ChoiceImpl(); - HashSet numbers = new HashSet(); - for (int i = 0; i <= 30; i++) { - numbers.add(Integer.toString(i)); - } - numberChoice.setChoices(numbers); - numberChoice.setMessage("Choose a number"); - this.getSpellAbility().addChoice(numberChoice); this.getSpellAbility().addTarget(new TargetPlayer()); this.getSpellAbility().addEffect(new VoidEffect()); @@ -102,28 +93,38 @@ class VoidEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - int number = Integer.parseInt(source.getChoices().get(0).getChoice()); - for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { - if ((permanent.getCardType().contains(CardType.ARTIFACT) || permanent.getCardType().contains(CardType.CREATURE)) - && permanent.getConvertedManaCost() == number) { - permanent.destroy(source.getSourceId(), game, false); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + Choice numberChoice = new ChoiceImpl(); + Set numbers = new HashSet<>(16); + for (int i = 0; i <= 15; i++) { + numbers.add(Integer.toString(i)); } - } - FilterCard filterCard = new FilterCard(); - filterCard.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal, number)); - filterCard.add(Predicates.not(new CardTypePredicate(CardType.LAND))); - - Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); - if (targetPlayer != null) { - targetPlayer.revealCards("Void", targetPlayer.getHand(), game); - for (Card card : targetPlayer.getHand().getCards(game)) { - if (filterCard.match(card, game)) { - targetPlayer.discard(card, source, game); + numberChoice.setChoices(numbers); + numberChoice.setMessage("Choose a number"); + controller.choose(Outcome.DestroyPermanent, numberChoice, game); + int number = Integer.parseInt(numberChoice.getChoice()); + for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) { + if ((permanent.getCardType().contains(CardType.ARTIFACT) || permanent.getCardType().contains(CardType.CREATURE)) + && permanent.getConvertedManaCost() == number) { + permanent.destroy(source.getSourceId(), game, false); } } - } else { - return false; + FilterCard filterCard = new FilterCard(); + filterCard.add(new ConvertedManaCostPredicate(Filter.ComparisonType.Equal, number)); + filterCard.add(Predicates.not(new CardTypePredicate(CardType.LAND))); + + Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source)); + if (targetPlayer != null) { + targetPlayer.revealCards("Void", targetPlayer.getHand(), game); + for (Card card : targetPlayer.getHand().getCards(game)) { + if (filterCard.match(card, game)) { + targetPlayer.discard(card, source, game); + } + } + } + return true; } - return true; + return false; } } diff --git a/Mage.Sets/src/mage/sets/invasion/WashOut.java b/Mage.Sets/src/mage/sets/invasion/WashOut.java index e418c5c55c5..24167f8c37a 100644 --- a/Mage.Sets/src/mage/sets/invasion/WashOut.java +++ b/Mage.Sets/src/mage/sets/invasion/WashOut.java @@ -44,6 +44,7 @@ import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.permanent.ControllerPredicate; import mage.game.Game; import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -52,6 +53,7 @@ import mage.game.permanent.Permanent; public class WashOut extends CardImpl { private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("creature an opponent controls"); + static { filter.add(new ControllerPredicate(TargetController.OPPONENT)); } @@ -60,9 +62,7 @@ public class WashOut extends CardImpl { super(ownerId, 87, "Wash Out", Rarity.UNCOMMON, new CardType[]{CardType.SORCERY}, "{3}{U}"); this.expansionSetCode = "INV"; - // Return all permanents of the color of your choice to their owners' hands. - this.getSpellAbility().addChoice(new ChoiceColor()); this.getSpellAbility().addEffect(new WashOutEffect()); } @@ -90,15 +90,19 @@ class WashOutEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - FilterPermanent filter = new FilterPermanent(); - ObjectColor color = ((ChoiceColor) source.getChoices().get(0)).getColor(); - if (color != null) { - filter.add(new ColorPredicate(color)); - - for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { - permanent.moveToZone(Zone.HAND, source.getSourceId(), game, true); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choice = new ChoiceColor(); + controller.choose(Outcome.ReturnToHand, choice, game); + ObjectColor color = choice.getColor(); + if (color != null) { + FilterPermanent filter = new FilterPermanent(); + filter.add(new ColorPredicate(color)); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) { + permanent.moveToZone(Zone.HAND, source.getSourceId(), game, true); + } + return true; } - return true; } return false; } diff --git a/Mage.Sets/src/mage/sets/judgment/PrismaticStrands.java b/Mage.Sets/src/mage/sets/judgment/PrismaticStrands.java index 17482f7c54a..14b1fdbf946 100644 --- a/Mage.Sets/src/mage/sets/judgment/PrismaticStrands.java +++ b/Mage.Sets/src/mage/sets/judgment/PrismaticStrands.java @@ -32,12 +32,14 @@ import mage.MageObject; import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.costs.common.TapTargetCost; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.FlashbackAbility; import mage.cards.CardImpl; import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.TimingRule; import mage.filter.common.FilterControlledCreaturePermanent; @@ -46,6 +48,7 @@ import mage.filter.predicate.mageobject.ColorPredicate; import mage.filter.predicate.permanent.TappedPredicate; import mage.game.Game; import mage.game.events.GameEvent; +import mage.players.Player; import mage.target.common.TargetControlledCreaturePermanent; /** @@ -65,8 +68,7 @@ public class PrismaticStrands extends CardImpl { this.expansionSetCode = "JUD"; // Prevent all damage that sources of the color of your choice would deal this turn. - this.getSpellAbility().addEffect(new PrismaticStrandsEffect(Duration.EndOfTurn, Integer.MAX_VALUE, false)); - this.getSpellAbility().addChoice(new ChoiceColor()); + this.getSpellAbility().addEffect(new PrismaticStrandsEffect()); // Flashback-Tap an untapped white creature you control. this.addAbility(new FlashbackAbility(new TapTargetCost(new TargetControlledCreaturePermanent(1,1,filter,false)), TimingRule.INSTANT)); @@ -82,16 +84,48 @@ public class PrismaticStrands extends CardImpl { } } -class PrismaticStrandsEffect extends PreventionEffectImpl { - - public PrismaticStrandsEffect(Duration duration, int amount, boolean onlyCombat) { - super(duration, amount, onlyCombat, false); +class PrismaticStrandsEffect extends OneShotEffect { + + PrismaticStrandsEffect() { + super(Outcome.PreventDamage); this.staticText = "Prevent all damage that sources of the color of your choice would deal this turn"; } - - public PrismaticStrandsEffect(PrismaticStrandsEffect effect) { + + PrismaticStrandsEffect(final PrismaticStrandsEffect effect) { super(effect); } + + @Override + public PrismaticStrandsEffect copy() { + return new PrismaticStrandsEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choice = new ChoiceColor(); + controller.choose(Outcome.PreventDamage, choice, game); + game.addEffect(new PrismaticStrandsPreventionEffect(choice.getColor()), source); + return true; + } + return false; + } +} + +class PrismaticStrandsPreventionEffect extends PreventionEffectImpl { + + private final ObjectColor color; + + PrismaticStrandsPreventionEffect(ObjectColor color) { + super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false); + this.color = color; + } + + PrismaticStrandsPreventionEffect(PrismaticStrandsPreventionEffect effect) { + super(effect); + this.color = effect.color; + } @Override public boolean apply(Game game, Ability source) { @@ -104,9 +138,8 @@ class PrismaticStrandsEffect extends PreventionEffectImpl { if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER) || event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) || event.getType().equals(GameEvent.EventType.DAMAGE_PLANESWALKER)) { - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); MageObject sourceObject = game.getObject(event.getSourceId()); - if (sourceObject != null && choice != null && sourceObject.getColor(game).shares(choice.getColor())) { + if (sourceObject != null && sourceObject.getColor(game).shares(this.color)) { return true; } } @@ -115,7 +148,7 @@ class PrismaticStrandsEffect extends PreventionEffectImpl { } @Override - public PrismaticStrandsEffect copy() { - return new PrismaticStrandsEffect(this); + public PrismaticStrandsPreventionEffect copy() { + return new PrismaticStrandsPreventionEffect(this); } -} \ No newline at end of file +} diff --git a/Mage.Sets/src/mage/sets/khansoftarkir/NecropolisFiend.java b/Mage.Sets/src/mage/sets/khansoftarkir/NecropolisFiend.java index 0e2c9859f7c..7aa53001fbe 100644 --- a/Mage.Sets/src/mage/sets/khansoftarkir/NecropolisFiend.java +++ b/Mage.Sets/src/mage/sets/khansoftarkir/NecropolisFiend.java @@ -87,7 +87,7 @@ public class NecropolisFiend extends CardImpl { } @Override - public void adjustChoices(Ability ability, Game game) { + public void adjustCosts(Ability ability, Game game) { if (ability instanceof SimpleActivatedAbility) { Player controller = game.getPlayer(ability.getControllerId()); if (controller != null) { @@ -101,7 +101,7 @@ public class NecropolisFiend extends CardImpl { } @Override - public void adjustCosts(Ability ability, Game game) { + public void adjustTargets(Ability ability, Game game) { if (ability instanceof SimpleActivatedAbility) { int xValue = ability.getManaCostsToPay().getX(); for(Cost cost: ability.getCosts()) { diff --git a/Mage.Sets/src/mage/sets/magic2015/AvacynGuardianAngel.java b/Mage.Sets/src/mage/sets/magic2015/AvacynGuardianAngel.java index e8b4d1ce9dd..30e7e579789 100644 --- a/Mage.Sets/src/mage/sets/magic2015/AvacynGuardianAngel.java +++ b/Mage.Sets/src/mage/sets/magic2015/AvacynGuardianAngel.java @@ -30,9 +30,11 @@ package mage.sets.magic2015; import java.util.UUID; import mage.MageInt; import mage.MageObject; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.mana.ManaCostsImpl; +import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.PreventionEffectImpl; import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.VigilanceAbility; @@ -40,12 +42,14 @@ import mage.cards.CardImpl; import mage.choices.ChoiceColor; import mage.constants.CardType; import mage.constants.Duration; +import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterCreaturePermanent; import mage.filter.predicate.permanent.AnotherPredicate; import mage.game.Game; import mage.game.events.GameEvent; +import mage.players.Player; import mage.target.TargetPlayer; import mage.target.common.TargetCreaturePermanent; @@ -76,17 +80,15 @@ public class AvacynGuardianAngel extends CardImpl { this.addAbility(VigilanceAbility.getInstance()); // {1}{W}: Prevent all damage that would be dealt to another target creature this turn by sources of the color of your choice. Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new AvacynGuardianAngelPreventToCreatureEffect(Duration.EndOfTurn, Integer.MAX_VALUE, false), - new ManaCostsImpl("{1}{W}")); - ability.addChoice(new ChoiceColor()); + new AvacynGuardianAngelPreventToCreatureEffect(), + new ManaCostsImpl<>("{1}{W}")); ability.addTarget(new TargetCreaturePermanent(filter)); this.addAbility(ability); // {5}{W}{W}: Prevent all damage that would be dealt to target player this turn by sources of the color of your choice. ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, - new AvacynGuardianAngelPreventToPlayerEffect(Duration.EndOfTurn, Integer.MAX_VALUE, false), - new ManaCostsImpl("{5}{W}{W}")); - ability.addChoice(new ChoiceColor()); + new AvacynGuardianAngelPreventToPlayerEffect(), + new ManaCostsImpl<>("{5}{W}{W}")); ability.addTarget(new TargetPlayer()); this.addAbility(ability); } @@ -101,18 +103,49 @@ public class AvacynGuardianAngel extends CardImpl { } } -class AvacynGuardianAngelPreventToCreatureEffect extends PreventionEffectImpl { - - public AvacynGuardianAngelPreventToCreatureEffect(Duration duration, int amount, boolean onlyCombat) { - super(duration, amount, onlyCombat, false); +class AvacynGuardianAngelPreventToCreatureEffect extends OneShotEffect { + + AvacynGuardianAngelPreventToCreatureEffect() { + super(Outcome.PreventDamage); this.staticText = "Prevent all damage that would be dealt to another target creature this turn by sources of the color of your choice"; } - - public AvacynGuardianAngelPreventToCreatureEffect(AvacynGuardianAngelPreventToCreatureEffect effect) { + + AvacynGuardianAngelPreventToCreatureEffect(final AvacynGuardianAngelPreventToCreatureEffect effect) { super(effect); } + + @Override + public AvacynGuardianAngelPreventToCreatureEffect copy() { + return new AvacynGuardianAngelPreventToCreatureEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choice = new ChoiceColor(); + if (controller.choose(Outcome.PreventDamage, choice, game)) { + game.addEffect(new AvacynGuardianAngelPreventToCreaturePreventionEffect(choice.getColor()), source); + return true; + } + } + return false; + } +} +class AvacynGuardianAngelPreventToCreaturePreventionEffect extends PreventionEffectImpl { + + private final ObjectColor color; + AvacynGuardianAngelPreventToCreaturePreventionEffect(ObjectColor color) { + super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false); + this.color = color; + } + + AvacynGuardianAngelPreventToCreaturePreventionEffect(AvacynGuardianAngelPreventToCreaturePreventionEffect effect) { + super(effect); + this.color = effect.color; + } @Override public boolean apply(Game game, Ability source) { @@ -124,9 +157,8 @@ class AvacynGuardianAngelPreventToCreatureEffect extends PreventionEffectImpl { if (super.applies(event, source, game)) { if (event.getType().equals(GameEvent.EventType.DAMAGE_CREATURE) && event.getTargetId().equals(getTargetPointer().getFirst(game, source))) { - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); MageObject sourceObject = game.getObject(event.getSourceId()); - if (sourceObject != null && choice != null && sourceObject.getColor(game).shares(choice.getColor())) { + if (sourceObject != null && sourceObject.getColor(game).shares(this.color)) { return true; } } @@ -135,21 +167,54 @@ class AvacynGuardianAngelPreventToCreatureEffect extends PreventionEffectImpl { } @Override - public AvacynGuardianAngelPreventToCreatureEffect copy() { - return new AvacynGuardianAngelPreventToCreatureEffect(this); + public AvacynGuardianAngelPreventToCreaturePreventionEffect copy() { + return new AvacynGuardianAngelPreventToCreaturePreventionEffect(this); } } -class AvacynGuardianAngelPreventToPlayerEffect extends PreventionEffectImpl { - - public AvacynGuardianAngelPreventToPlayerEffect(Duration duration, int amount, boolean onlyCombat) { - super(duration, amount, onlyCombat, false); +class AvacynGuardianAngelPreventToPlayerEffect extends OneShotEffect { + + AvacynGuardianAngelPreventToPlayerEffect() { + super(Outcome.PreventDamage); this.staticText = "Prevent all damage that would be dealt to target player this turn by sources of the color of your choice"; } - - public AvacynGuardianAngelPreventToPlayerEffect(AvacynGuardianAngelPreventToPlayerEffect effect) { + + AvacynGuardianAngelPreventToPlayerEffect(final AvacynGuardianAngelPreventToPlayerEffect effect) { super(effect); } + + @Override + public AvacynGuardianAngelPreventToPlayerEffect copy() { + return new AvacynGuardianAngelPreventToPlayerEffect(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ChoiceColor choice = new ChoiceColor(); + if (controller.choose(Outcome.PreventDamage, choice, game)) { + game.addEffect(new AvacynGuardianAngelPreventToPlayerPreventionEffect(choice.getColor()), source); + return true; + } + } + return false; + } +} + +class AvacynGuardianAngelPreventToPlayerPreventionEffect extends PreventionEffectImpl { + + private final ObjectColor color; + + AvacynGuardianAngelPreventToPlayerPreventionEffect(ObjectColor color) { + super(Duration.EndOfTurn, Integer.MAX_VALUE, false, false); + this.color = color; + } + + AvacynGuardianAngelPreventToPlayerPreventionEffect(AvacynGuardianAngelPreventToPlayerPreventionEffect effect) { + super(effect); + this.color = effect.color; + } @Override public boolean apply(Game game, Ability source) { @@ -161,9 +226,8 @@ class AvacynGuardianAngelPreventToPlayerEffect extends PreventionEffectImpl { if (super.applies(event, source, game)) { if (event.getType().equals(GameEvent.EventType.DAMAGE_PLAYER) && event.getTargetId().equals(getTargetPointer().getFirst(game, source))) { - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); MageObject sourceObject = game.getObject(event.getSourceId()); - if (sourceObject != null && choice != null && sourceObject.getColor(game).shares(choice.getColor())) { + if (sourceObject != null && sourceObject.getColor(game).shares(this.color)) { return true; } } @@ -172,7 +236,7 @@ class AvacynGuardianAngelPreventToPlayerEffect extends PreventionEffectImpl { } @Override - public AvacynGuardianAngelPreventToPlayerEffect copy() { - return new AvacynGuardianAngelPreventToPlayerEffect(this); + public AvacynGuardianAngelPreventToPlayerPreventionEffect copy() { + return new AvacynGuardianAngelPreventToPlayerPreventionEffect(this); } } diff --git a/Mage.Sets/src/mage/sets/mercadianmasques/FoodChain.java b/Mage.Sets/src/mage/sets/mercadianmasques/FoodChain.java index 5ed1c7f832b..0610159baf4 100644 --- a/Mage.Sets/src/mage/sets/mercadianmasques/FoodChain.java +++ b/Mage.Sets/src/mage/sets/mercadianmasques/FoodChain.java @@ -30,6 +30,7 @@ package mage.sets.mercadianmasques; import java.util.UUID; import mage.ConditionalMana; import mage.Mana; +import mage.ObjectColor; import mage.abilities.Ability; import mage.abilities.costs.Cost; import mage.abilities.costs.common.ExileTargetCost; @@ -41,6 +42,7 @@ import mage.cards.Card; import mage.cards.CardImpl; import mage.choices.ChoiceColor; import mage.constants.CardType; +import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.Zone; import mage.filter.common.FilterControlledCreaturePermanent; @@ -58,10 +60,8 @@ public class FoodChain extends CardImpl { super(ownerId, 246, "Food Chain", Rarity.RARE, new CardType[]{CardType.ENCHANTMENT}, "{2}{G}"); this.expansionSetCode = "MMQ"; - // Exile a creature you control: Add X mana of any one color to your mana pool, where X is the exiled creature's converted mana cost plus one. Spend this mana only to cast creature spells. Ability ability = new SimpleManaAbility(Zone.BATTLEFIELD, new FoodChainManaEffect(), new ExileTargetCost(new TargetControlledCreaturePermanent(1, 1, new FilterControlledCreaturePermanent("a creature you control"), true))); - ability.addChoice(new ChoiceColor()); this.addAbility(ability); } @@ -76,6 +76,7 @@ public class FoodChain extends CardImpl { } class FoodChainManaBuilder extends ConditionalManaBuilder { + @Override public ConditionalMana build(Object... options) { return new CreatureCastConditionalMana(this.mana); @@ -88,55 +89,58 @@ class FoodChainManaBuilder extends ConditionalManaBuilder { } class FoodChainManaEffect extends ManaEffect { - + FoodChainManaEffect() { this.staticText = "Add X mana of any one color to your mana pool, where X is the exiled creature's converted mana cost plus one. Spend this mana only to cast creature spells."; } - + FoodChainManaEffect(final FoodChainManaEffect effect) { super(effect); } - + @Override public FoodChainManaEffect copy() { return new FoodChainManaEffect(this); } - + @Override public boolean apply(Game game, Ability source) { - int manaCostExiled = 0; - for (Cost cost: source.getCosts()) { - if (cost.isPaid() && cost instanceof ExileTargetCost) { - for (Card card : ((ExileTargetCost) cost).getPermanents()) { - manaCostExiled += card.getConvertedManaCost(); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + int manaCostExiled = 0; + for (Cost cost : source.getCosts()) { + if (cost.isPaid() && cost instanceof ExileTargetCost) { + for (Card card : ((ExileTargetCost) cost).getPermanents()) { + manaCostExiled += card.getConvertedManaCost(); + } } } + ChoiceColor choice = new ChoiceColor(); + controller.choose(Outcome.PutManaInPool, choice, game); + ObjectColor chosenColor = choice.getColor(); + Mana mana = null; + if (chosenColor.isBlack()) { + mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build(); + } + else if (chosenColor.isBlue()) { + mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build(); + } + else if (chosenColor.isRed()) { + mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build(); + } + else if (chosenColor.isGreen()) { + mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build(); + } + else if (chosenColor.isWhite()) { + mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build(); + } + if (mana != null) { + checkToFirePossibleEvents(mana, game, source); + controller.getManaPool().addMana(mana, game, source); + return true; + } } - - ChoiceColor choice = (ChoiceColor) source.getChoices().get(0); - Mana mana = null; - if (choice.getColor().isBlack()) { - mana = new FoodChainManaBuilder().setMana(Mana.BlackMana(manaCostExiled + 1), source, game).build(); - } - else if (choice.getColor().isBlue()) { - mana = new FoodChainManaBuilder().setMana(Mana.BlueMana(manaCostExiled + 1), source, game).build(); - } - else if (choice.getColor().isRed()) { - mana = new FoodChainManaBuilder().setMana(Mana.RedMana(manaCostExiled + 1), source, game).build(); - } - else if (choice.getColor().isGreen()) { - mana = new FoodChainManaBuilder().setMana(Mana.GreenMana(manaCostExiled + 1), source, game).build(); - } - else if (choice.getColor().isWhite()) { - mana = new FoodChainManaBuilder().setMana(Mana.WhiteMana(manaCostExiled + 1), source, game).build(); - } - - Player player = game.getPlayer(source.getControllerId()); - if (player != null && mana != null) { - checkToFirePossibleEvents(mana, game, source); - player.getManaPool().addMana(mana, game, source); - return true; - } + return false; } @@ -145,5 +149,4 @@ class FoodChainManaEffect extends ManaEffect { return null; } - } diff --git a/Mage.Sets/src/mage/sets/modernmasters/RiftElemental.java b/Mage.Sets/src/mage/sets/modernmasters/RiftElemental.java index b0eae0d4f4e..04d74582e25 100644 --- a/Mage.Sets/src/mage/sets/modernmasters/RiftElemental.java +++ b/Mage.Sets/src/mage/sets/modernmasters/RiftElemental.java @@ -27,41 +27,32 @@ */ package mage.sets.modernmasters; -import java.util.HashSet; -import java.util.List; -import java.util.Set; import java.util.UUID; import mage.MageInt; import mage.abilities.Ability; -import mage.abilities.ActivatedAbility; import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.costs.Cost; import mage.abilities.costs.CostImpl; -import mage.abilities.costs.common.RemoveCounterCost; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.common.continuous.BoostSourceEffect; -import mage.abilities.keyword.SuspendAbility; import mage.cards.Card; import mage.cards.CardImpl; -import mage.choices.Choice; -import mage.choices.ChoiceImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; import mage.constants.Rarity; import mage.constants.TargetController; import mage.constants.Zone; -import mage.counters.Counter; import mage.counters.CounterType; -import mage.filter.FilterCard; -import mage.filter.predicate.mageobject.AbilityPredicate; -import mage.filter.predicate.other.CounterCardPredicate; +import mage.filter.common.FilterPermanentOrSuspendedCard; import mage.filter.predicate.other.OwnerPredicate; +import mage.filter.predicate.permanent.ControllerPredicate; +import mage.filter.predicate.permanent.CounterPredicate; 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.TargetControlledCreaturePermanent; +import mage.target.Target; +import mage.target.common.TargetPermanentOrSuspendedCard; /** * @@ -69,13 +60,6 @@ import mage.target.common.TargetControlledCreaturePermanent; */ public class RiftElemental extends CardImpl { - private static final FilterCard filter = new FilterCard("suspended card you own"); - static { - filter.add(new CounterCardPredicate(CounterType.TIME)); - filter.add(new AbilityPredicate(SuspendAbility.class)); - filter.add(new OwnerPredicate(TargetController.YOU)); - } - public RiftElemental(UUID ownerId) { super(ownerId, 127, "Rift Elemental", Rarity.COMMON, new CardType[]{CardType.CREATURE}, "{R}"); this.expansionSetCode = "MMA"; @@ -85,30 +69,11 @@ public class RiftElemental extends CardImpl { this.toughness = new MageInt(1); // {1}{R}, Remove a time counter from a permanent you control or suspended card you own: Rift Elemental gets +2/+0 until end of turn. - Choice targetChoice = new ChoiceImpl(); - targetChoice.setMessage("Choose what to target"); - targetChoice.getChoices().add("Permanent"); - targetChoice.getChoices().add("Suspended Card"); - Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(2,0,Duration.EndOfTurn), new ManaCostsImpl("{1}{R}")); - ability.addChoice(targetChoice); - ability.addCost(new RemoveCounterFromCardCost(new TargetCardInExile(1,1,filter, null, true), CounterType.TIME)); + Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostSourceEffect(2, 0, Duration.EndOfTurn), new ManaCostsImpl<>("{1}{R}")); + ability.addCost(new RiftElementalCost()); this.addAbility(ability); } - @Override - public void adjustCosts(Ability ability, Game game) { - if (ability instanceof ActivatedAbility && !ability.getChoices().isEmpty()) { - ability.getCosts().clear(); - Choice targetChoice = ability.getChoices().get(0); - if (targetChoice.getChoice().equals("Permanent")) { - ability.addCost(new RemoveCounterCost(new TargetControlledCreaturePermanent(), CounterType.TIME)); - } - if (targetChoice.getChoice().equals("Suspended Card")) { - ability.addCost(new RemoveCounterFromCardCost(new TargetCardInExile(1,1,filter, null, true), CounterType.TIME)); - } - } - } - public RiftElemental(final RiftElemental card) { super(card); } @@ -119,88 +84,55 @@ public class RiftElemental extends CardImpl { } } -class RemoveCounterFromCardCost extends CostImpl { +class RiftElementalCost extends CostImpl { - private TargetCard target; - private String name; - private CounterType counterTypeToRemove; - - public RemoveCounterFromCardCost(TargetCard target) { - this(target, null); + private static final FilterPermanentOrSuspendedCard filter = new FilterPermanentOrSuspendedCard("permanent you control with a time counter or suspended card you own"); + static { + filter.getPermanentFilter().add(new ControllerPredicate(TargetController.YOU)); + filter.getPermanentFilter().add(new CounterPredicate(CounterType.TIME)); + filter.getCardFilter().add(new OwnerPredicate(TargetController.YOU)); } - public RemoveCounterFromCardCost(TargetCard target, CounterType counterTypeToRemove) { - this.target = target; - this.counterTypeToRemove = counterTypeToRemove; - text = setText(); + RiftElementalCost() { + text = "Remove a time counter from a permanent you control or suspended card you own"; } - public RemoveCounterFromCardCost(final RemoveCounterFromCardCost cost) { + RiftElementalCost(final RiftElementalCost cost) { super(cost); - this.target = cost.target.copy(); - this.name = cost.name; } @Override public boolean pay(Ability ability, Game game, UUID sourceId, UUID controllerId, boolean noMana, Cost costToPay) { paid = false; Player controller = game.getPlayer(controllerId); - if (target.choose(Outcome.UnboostCreature, controllerId, sourceId, game)) { - for (UUID targetId: (List)target.getTargets()) { - Card card = game.getCard(targetId); - if (card != null) { - if (card.getCounters(game).size() > 0 && (counterTypeToRemove == null || card.getCounters(game).containsKey(counterTypeToRemove))) { - String counterName = null; - if (counterTypeToRemove != null) { - counterName = counterTypeToRemove.getName(); - } else { - if (card.getCounters(game).size() > 1 && counterTypeToRemove == null) { - Choice choice = new ChoiceImpl(true); - Set choices = new HashSet(); - for (Counter counter : card.getCounters(game).values()) { - if (card.getCounters(game).getCount(counter.getName()) > 0) { - choices.add(counter.getName()); - } - } - choice.setChoices(choices); - choice.setMessage("Choose a counter to remove from " + card.getName()); - controller.choose(Outcome.UnboostCreature, choice, game); - counterName = choice.getChoice(); - } else { - for (Counter counter : card.getCounters(game).values()) { - if (counter.getCount() > 0) { - counterName = counter.getName(); - } - } - } - } - if (counterName != null) { - card.removeCounters(counterName, 1, game); - if (card.getCounters(game).getCount(counterName) == 0 ){ - card.getCounters(game).removeCounter(counterName); - } - this.paid = true; - game.informPlayers(new StringBuilder(controller.getLogName()).append(" removes a ").append(counterName).append(" counter from ").append(card.getName()).toString()); - } + if (controller != null) { + Target target = new TargetPermanentOrSuspendedCard(filter, true); + if (target.choose(Outcome.Neutral, controllerId, sourceId, game)) { + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent != null) { + permanent.removeCounters(CounterType.TIME.createInstance(), game); + this.paid = true; + } + else { + Card card = game.getCard(target.getFirstTarget()); + if (card != null) { + card.removeCounters(CounterType.TIME.createInstance(), game); + this.paid = true; } } } } - target.clearChosen(); return paid; } @Override public boolean canPay(Ability ability, UUID sourceId, UUID controllerId, Game game) { - return target.canChoose(controllerId, game); - } - - private String setText() { - return "Remove a time counter from a permanent you control or suspended card you own"; + Target target = new TargetPermanentOrSuspendedCard(filter, true); + return target.canChoose(sourceId, controllerId, game); } @Override - public RemoveCounterFromCardCost copy() { - return new RemoveCounterFromCardCost(this); + public RiftElementalCost copy() { + return new RiftElementalCost(this); } } diff --git a/Mage.Sets/src/mage/sets/planarchaos/FuryCharm.java b/Mage.Sets/src/mage/sets/planarchaos/FuryCharm.java index 85047a8b093..d74b87261b1 100644 --- a/Mage.Sets/src/mage/sets/planarchaos/FuryCharm.java +++ b/Mage.Sets/src/mage/sets/planarchaos/FuryCharm.java @@ -30,7 +30,6 @@ package mage.sets.planarchaos; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.Mode; -import mage.abilities.SpellAbility; import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.DestroyTargetEffect; @@ -40,8 +39,6 @@ import mage.abilities.keyword.SuspendAbility; import mage.abilities.keyword.TrampleAbility; import mage.cards.Card; import mage.cards.CardImpl; -import mage.choices.Choice; -import mage.choices.ChoiceImpl; import mage.constants.CardType; import mage.constants.Duration; import mage.constants.Outcome; @@ -52,10 +49,9 @@ import mage.filter.predicate.mageobject.AbilityPredicate; import mage.filter.predicate.other.CounterCardPredicate; import mage.game.Game; import mage.game.permanent.Permanent; -import mage.target.Target; import mage.target.common.TargetArtifactPermanent; -import mage.target.common.TargetCardInExile; import mage.target.common.TargetCreaturePermanent; +import mage.target.common.TargetPermanentOrSuspendedCard; /** * @@ -73,7 +69,6 @@ public class FuryCharm extends CardImpl { super(ownerId, 100, "Fury Charm", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{1}{R}"); this.expansionSetCode = "PLC"; - // Choose one - this.getSpellAbility().getModes().setMinModes(1); this.getSpellAbility().getModes().setMaxModes(1); @@ -92,34 +87,9 @@ public class FuryCharm extends CardImpl { this.getSpellAbility().getModes().addMode(mode); // or remove two time counters from target permanent or suspended card. mode = new Mode(); - Choice targetChoice = new ChoiceImpl(); - targetChoice.setMessage("Choose what to target"); - targetChoice.getChoices().add("Permanent"); - targetChoice.getChoices().add("Suspended Card"); - mode.getChoices().add(targetChoice); + mode.getTargets().add(new TargetPermanentOrSuspendedCard()); mode.getEffects().add(new FuryCharmRemoveCounterEffect()); this.getSpellAbility().getModes().addMode(mode); - - - - } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - for(Effect effect :ability.getEffects()) { - if (effect instanceof FuryCharmRemoveCounterEffect) { - Choice targetChoice = ability.getChoices().get(0); - if (targetChoice.getChoice().equals("Permanent")) { - ability.addTarget(new TargetCreaturePermanent()); - } - if (targetChoice.getChoice().equals("Suspended Card")) { - Target target = new TargetCardInExile(1,1, filter, null, true); - ability.addTarget(target); - } - } - } - } } public FuryCharm(final FuryCharm card) { @@ -152,12 +122,12 @@ class FuryCharmRemoveCounterEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanent(this.getTargetPointer().getFirst(game, source)); if (permanent != null) { - permanent.removeCounters(CounterType.TIME.getName(), 2, game); + permanent.removeCounters(CounterType.TIME.getName(), 2, game); return true; } Card card = game.getCard(this.getTargetPointer().getFirst(game, source)); if (card != null) { - card.removeCounters(CounterType.TIME.getName(), 2, game); + card.removeCounters(CounterType.TIME.getName(), 2, game); return true; } return false; diff --git a/Mage.Sets/src/mage/sets/timespiral/Clockspinning.java b/Mage.Sets/src/mage/sets/timespiral/Clockspinning.java index 4000e5a0db3..468523e97e7 100644 --- a/Mage.Sets/src/mage/sets/timespiral/Clockspinning.java +++ b/Mage.Sets/src/mage/sets/timespiral/Clockspinning.java @@ -31,13 +31,10 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; import mage.abilities.Ability; -import mage.abilities.SpellAbility; -import mage.abilities.effects.Effect; import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.common.counter.AddCountersTargetEffect; import mage.abilities.effects.common.counter.RemoveCounterTargetEffect; import mage.abilities.keyword.BuybackAbility; -import mage.abilities.keyword.SuspendAbility; import mage.cards.Card; import mage.cards.CardImpl; import mage.choices.Choice; @@ -46,18 +43,10 @@ import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.Rarity; import mage.counters.Counter; -import mage.counters.CounterType; -import mage.filter.FilterCard; -import mage.filter.FilterPermanent; -import mage.filter.predicate.mageobject.AbilityPredicate; -import mage.filter.predicate.other.CounterCardPredicate; -import mage.filter.predicate.permanent.CounterAnyPredicate; import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; -import mage.target.Target; -import mage.target.TargetPermanent; -import mage.target.common.TargetCardInExile; +import mage.target.common.TargetPermanentOrSuspendedCard; import mage.target.targetpointer.FixedTarget; /** @@ -74,39 +63,10 @@ public class Clockspinning extends CardImpl { this.addAbility(new BuybackAbility("{3}")); // Choose a counter on target permanent or suspended card. Remove that counter from that permanent or card or put another of those counters on it. - Choice targetChoice = new ChoiceImpl(); - targetChoice.setMessage("Choose what to target"); - targetChoice.getChoices().add("Permanent"); - targetChoice.getChoices().add("Suspended Card"); - - this.getSpellAbility().addChoice(targetChoice); + this.getSpellAbility().addTarget(new TargetPermanentOrSuspendedCard()); this.getSpellAbility().addEffect(new ClockspinningAddOrRemoveCounterEffect()); } - - @Override - public void adjustTargets(Ability ability, Game game) { - if (ability instanceof SpellAbility) { - for (Effect effect : ability.getEffects()) { - if (effect instanceof ClockspinningAddOrRemoveCounterEffect) { - Choice targetChoice = ability.getChoices().get(0); - if (targetChoice.getChoice().equals("Permanent")) { - FilterPermanent filter = new FilterPermanent("target permanent with a counter"); - filter.add(new CounterAnyPredicate()); - ability.addTarget(new TargetPermanent(filter)); - } - if (targetChoice.getChoice().equals("Suspended Card")) { - FilterCard suspendFilter = new FilterCard("suspended card"); - suspendFilter.add(new AbilityPredicate(SuspendAbility.class)); - suspendFilter.add(new CounterCardPredicate(CounterType.TIME)); - - Target target = new TargetCardInExile(1, 1, suspendFilter, null, true); - ability.addTarget(target); - } - } - } - } - } - + public Clockspinning(final Clockspinning card) { super(card); } @@ -121,7 +81,7 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect { ClockspinningAddOrRemoveCounterEffect() { super(Outcome.Removal); - this.staticText = "Remove or add a counter from a target suspended card or a target permanent"; + this.staticText = "Choose a counter on target permanent or suspended card. Remove that counter from that permanent or card or put another of those counters on it"; } ClockspinningAddOrRemoveCounterEffect(final ClockspinningAddOrRemoveCounterEffect effect) { @@ -139,7 +99,7 @@ class ClockspinningAddOrRemoveCounterEffect extends OneShotEffect { String counterName = null; if (permanent.getCounters().size() > 1) { Choice choice = new ChoiceImpl(true); - Set choices = new HashSet<>(); + Set choices = new HashSet<>(2); for (Counter counter : permanent.getCounters().values()) { if (permanent.getCounters().getCount(counter.getName()) > 0) { choices.add(counter.getName()); diff --git a/Mage.Sets/src/mage/sets/urzassaga/CarpetOfFlowers.java b/Mage.Sets/src/mage/sets/urzassaga/CarpetOfFlowers.java index aebbed1641e..8b8907f87e7 100644 --- a/Mage.Sets/src/mage/sets/urzassaga/CarpetOfFlowers.java +++ b/Mage.Sets/src/mage/sets/urzassaga/CarpetOfFlowers.java @@ -59,7 +59,6 @@ public class CarpetOfFlowers extends CardImpl { super(ownerId, 240, "Carpet of Flowers", Rarity.UNCOMMON, new CardType[]{CardType.ENCHANTMENT}, "{G}"); this.expansionSetCode = "USG"; - // At the beginning of each of your main phases, if you haven't added mana to your mana pool with this ability this turn, you may add up to X mana of any one color to your mana pool, where X is the number of Islands target opponent controls. this.addAbility(new CarpetOfFlowersTriggeredAbility()); } @@ -74,17 +73,14 @@ public class CarpetOfFlowers extends CardImpl { } } - - class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl { - public CarpetOfFlowersTriggeredAbility() { + CarpetOfFlowersTriggeredAbility() { super(Zone.BATTLEFIELD, new CarpetOfFlowersEffect(), true); - this.addChoice(new ChoiceColor()); this.addTarget(new TargetOpponent()); } - public CarpetOfFlowersTriggeredAbility(final CarpetOfFlowersTriggeredAbility ability) { + CarpetOfFlowersTriggeredAbility(final CarpetOfFlowersTriggeredAbility ability) { super(ability); } @@ -106,34 +102,29 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl { @Override public boolean checkInterveningIfClause(Game game) { - Boolean activated = (Boolean)game.getState().getValue(this.originalId.toString() + "addMana"); - if (activated == null) - { + Boolean activatedThisTurn = (Boolean) game.getState().getValue(this.originalId.toString() + "addMana"); + if (activatedThisTurn == null) { return true; } - else - { - return !activated; + else { + return !activatedThisTurn; } } - - @Override public boolean resolve(Game game) { boolean value = super.resolve(game); - if(value == true) - { + if (value == true) { game.getState().setValue(this.originalId.toString() + "addMana", Boolean.TRUE); } return value; } - + @Override public void reset(Game game) { game.getState().setValue(this.originalId.toString() + "addMana", Boolean.FALSE); } - + @Override public String getRule() { StringBuilder sb = new StringBuilder("At the beginning of each of your main phases, if you haven't added mana to your mana pool with this ability this turn"); @@ -142,9 +133,8 @@ class CarpetOfFlowersTriggeredAbility extends TriggeredAbilityImpl { } - class CarpetOfFlowersEffect extends ManaEffect { - + private static final FilterControlledPermanent filter = new FilterControlledPermanent("Island "); static { @@ -164,19 +154,18 @@ class CarpetOfFlowersEffect extends ManaEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - if (controller != null){ + if (controller != null) { ChoiceColor choice = new ChoiceColor(); while (!choice.isChosen()) { - controller.choose(Outcome.Protect, choice, game); + controller.choose(Outcome.Benefit, choice, game); if (!controller.canRespond()) { return false; } } int countMax = game.getBattlefield().count(filter, source.getSourceId(), source.getTargets().getFirstTarget(), game); ChoiceImpl choiceCount = new ChoiceImpl(true); - LinkedHashSet set = new LinkedHashSet<>(); - for(int i = 0; i <= countMax; i++) - { + LinkedHashSet set = new LinkedHashSet<>(countMax + 1); + for (int i = 0; i <= countMax; i++) { set.add(Integer.toString(i)); } choiceCount.setChoices(set); @@ -201,8 +190,7 @@ class CarpetOfFlowersEffect extends ManaEffect { case "White": mana.setWhite(count); break; - case "Colorless": - mana.setGeneric(count); + default: break; } checkToFirePossibleEvents(mana, game, source); diff --git a/Mage/src/main/java/mage/MageObject.java b/Mage/src/main/java/mage/MageObject.java index f65a6e2a39d..545ba0dd156 100644 --- a/Mage/src/main/java/mage/MageObject.java +++ b/Mage/src/main/java/mage/MageObject.java @@ -44,8 +44,6 @@ public interface MageObject extends MageItem, Serializable { MageInt getToughness(); - void adjustChoices(Ability ability, Game game); - void adjustCosts(Ability ability, Game game); void adjustTargets(Ability ability, Game game); diff --git a/Mage/src/main/java/mage/MageObjectImpl.java b/Mage/src/main/java/mage/MageObjectImpl.java index ff6fd515573..ebb8fc674f9 100644 --- a/Mage/src/main/java/mage/MageObjectImpl.java +++ b/Mage/src/main/java/mage/MageObjectImpl.java @@ -173,10 +173,6 @@ public abstract class MageObjectImpl implements MageObject { return 0; } - @Override - public void adjustChoices(Ability ability, Game game) { - } - @Override public void adjustCosts(Ability ability, Game game) { } diff --git a/Mage/src/main/java/mage/abilities/Ability.java b/Mage/src/main/java/mage/abilities/Ability.java index c96470730ee..6592de44e72 100644 --- a/Mage/src/main/java/mage/abilities/Ability.java +++ b/Mage/src/main/java/mage/abilities/Ability.java @@ -37,8 +37,6 @@ import mage.abilities.costs.mana.ManaCost; import mage.abilities.costs.mana.ManaCosts; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; -import mage.choices.Choice; -import mage.choices.Choices; import mage.constants.AbilityType; import mage.constants.AbilityWord; import mage.constants.EffectType; @@ -248,20 +246,6 @@ public interface Ability extends Controllable, Serializable { */ void addTarget(Target target); - /** - * Choices - * - * @return - */ - Choices getChoices(); - - /** - * TODO: Javadoc me - * - * @param choice - */ - void addChoice(Choice choice); - /** * Retrieves the {@link Zone} that this ability is active within. * diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index 17cdcf4e8c0..b03bf8bbff4 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -54,8 +54,6 @@ import mage.abilities.effects.common.DynamicManaEffect; import mage.abilities.keyword.FlashbackAbility; import mage.abilities.mana.ManaAbility; import mage.cards.Card; -import mage.choices.Choice; -import mage.choices.Choices; import mage.constants.AbilityType; import mage.constants.AbilityWord; import mage.constants.EffectType; @@ -271,19 +269,7 @@ public abstract class AbilityImpl implements Ability { if (this.abilityType.equals(AbilityType.SPELL)) { game.getContinuousEffects().applySpliceEffects(this, game); } - - if (sourceObject != null) { - sourceObject.adjustChoices(this, game); - } - // TODO: Because all (non targeted) choices have to be done during resolution - // this has to be removed, if all using effects are changed - for (Mode mode : this.getModes().getSelectedModes()) { - if (mode.getChoices().size() > 0 && mode.getChoices().choose(game, this) == false) { - logger.debug("activate failed - choice"); - return false; - } - } - + // if ability can be cast for no mana, clear the mana costs now, because additional mana costs must be paid. // For Flashback ability can be set X before, so the X costs have to be restored for the flashbacked ability if (noMana) { @@ -687,11 +673,6 @@ public abstract class AbilityImpl implements Ability { return typedEffects; } - @Override - public Choices getChoices() { - return getModes().getMode().getChoices(); - } - @Override public Zone getZone() { return zone; @@ -840,13 +821,6 @@ public abstract class AbilityImpl implements Ability { } } - @Override - public void addChoice(Choice choice) { - if (choice != null) { - getChoices().add(choice); - } - } - @Override public Targets getTargets() { return getModes().getMode().getTargets(); @@ -1121,9 +1095,6 @@ public abstract class AbilityImpl implements Ability { } } } - for (Choice choice : this.getChoices()) { - sb.append(" - ").append(choice.getMessage()).append(": ").append(choice.getChoice()); - } return sb.toString(); } diff --git a/Mage/src/main/java/mage/abilities/Mode.java b/Mage/src/main/java/mage/abilities/Mode.java index 6476050ef91..26942355841 100644 --- a/Mage/src/main/java/mage/abilities/Mode.java +++ b/Mage/src/main/java/mage/abilities/Mode.java @@ -30,7 +30,6 @@ package mage.abilities; import java.io.Serializable; import java.util.UUID; import mage.abilities.effects.Effects; -import mage.choices.Choices; import mage.target.Targets; /** @@ -41,20 +40,17 @@ public class Mode implements Serializable { protected UUID id; protected Targets targets; - protected Choices choices; protected Effects effects; public Mode() { this.id = UUID.randomUUID(); this.targets = new Targets(); - this.choices = new Choices(); this.effects = new Effects(); } public Mode(Mode mode) { this.id = mode.id; this.targets = mode.targets.copy(); - this.choices = mode.choices.copy(); this.effects = mode.effects.copy(); } @@ -70,10 +66,6 @@ public class Mode implements Serializable { return targets; } - public Choices getChoices() { - return choices; - } - public Effects getEffects() { return effects; } diff --git a/Mage/src/main/java/mage/abilities/SpellAbility.java b/Mage/src/main/java/mage/abilities/SpellAbility.java index b1e6905fdea..a0c89bea84a 100644 --- a/Mage/src/main/java/mage/abilities/SpellAbility.java +++ b/Mage/src/main/java/mage/abilities/SpellAbility.java @@ -143,7 +143,6 @@ public class SpellAbility extends ActivatedAbilityImpl { } public void clear() { - getChoices().clearChosen(); getTargets().clearChosen(); this.manaCosts.clearPaid(); this.costs.clearPaid(); diff --git a/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java b/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java index e52e69072d6..a5ba79f9c8c 100644 --- a/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/AwakenAbility.java @@ -72,7 +72,6 @@ public class AwakenAbility extends SpellAbility { this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); - this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); this.addTarget(new TargetControlledPermanent(new FilterControlledLandPermanent(filterMessage))); diff --git a/Mage/src/main/java/mage/abilities/keyword/RetraceAbility.java b/Mage/src/main/java/mage/abilities/keyword/RetraceAbility.java index b70b599206a..4032bfe9646 100644 --- a/Mage/src/main/java/mage/abilities/keyword/RetraceAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/RetraceAbility.java @@ -50,7 +50,6 @@ public class RetraceAbility extends SpellAbility { this.addCost(cost); this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); - this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); diff --git a/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java index c3b66f5195b..7696744cf09 100644 --- a/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/SurgeAbility.java @@ -53,7 +53,6 @@ public class SurgeAbility extends SpellAbility { this.getCosts().addAll(card.getSpellAbility().getCosts().copy()); this.getEffects().addAll(card.getSpellAbility().getEffects().copy()); this.getTargets().addAll(card.getSpellAbility().getTargets().copy()); - this.getChoices().addAll(card.getSpellAbility().getChoices().copy()); this.spellAbilityType = SpellAbilityType.BASE_ALTERNATE; this.timing = card.getSpellAbility().getTiming(); this.setRuleAtTheTop(true); diff --git a/Mage/src/main/java/mage/filter/common/FilterPermanentOrSuspendedCard.java b/Mage/src/main/java/mage/filter/common/FilterPermanentOrSuspendedCard.java new file mode 100644 index 00000000000..7779b083ace --- /dev/null +++ b/Mage/src/main/java/mage/filter/common/FilterPermanentOrSuspendedCard.java @@ -0,0 +1,117 @@ +/* + * + * 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.filter.common; + +import java.util.UUID; +import mage.abilities.keyword.SuspendAbility; +import mage.cards.Card; +import mage.counters.CounterType; +import mage.filter.FilterCard; +import mage.filter.FilterImpl; +import mage.filter.FilterInPlay; +import mage.filter.FilterPermanent; +import mage.filter.predicate.mageobject.AbilityPredicate; +import mage.filter.predicate.other.CounterCardPredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; + +/** + * + * @author emerald000 + */ +public class FilterPermanentOrSuspendedCard extends FilterImpl implements FilterInPlay { + + protected FilterCard cardFilter; + protected FilterPermanent permanentFilter; + + public FilterPermanentOrSuspendedCard() { + this("permanent or suspended card"); + } + + public FilterPermanentOrSuspendedCard(String name) { + super(name); + permanentFilter = new FilterPermanent(); + cardFilter = new FilterCard(); + cardFilter.add(new AbilityPredicate(SuspendAbility.class)); + cardFilter.add(new CounterCardPredicate(CounterType.TIME)); + } + + public FilterPermanentOrSuspendedCard(final FilterPermanentOrSuspendedCard filter) { + super(filter); + this.permanentFilter = filter.permanentFilter.copy(); + this.cardFilter = filter.cardFilter.copy(); + } + + @Override + public boolean checkObjectClass(Object object) { + return true; + } + + @Override + public boolean match(Object o, Game game) { + if (o instanceof Permanent) { + return permanentFilter.match((Permanent) o, game); + } else if (o instanceof Card) { + return cardFilter.match((Card) o, game); + } + return false; + } + + @Override + public boolean match(Object o, UUID sourceId, UUID playerId, Game game) { + if (o instanceof Permanent) { + return permanentFilter.match((Permanent) o, sourceId, playerId, game); + } else if (o instanceof Card) { + return cardFilter.match((Card) o, sourceId, playerId, game); + } + return false; + } + + public FilterPermanent getPermanentFilter() { + return this.permanentFilter; + } + + public FilterCard getCardFilter() { + return this.cardFilter; + } + + public void setPermanentFilter(FilterPermanent permanentFilter) { + this.permanentFilter = permanentFilter; + } + + public void setSpellFilter(FilterCard cardFilter) { + this.cardFilter = cardFilter; + } + + @Override + public FilterPermanentOrSuspendedCard copy() { + return new FilterPermanentOrSuspendedCard(this); + } +} diff --git a/Mage/src/main/java/mage/game/GameState.java b/Mage/src/main/java/mage/game/GameState.java index acbcb8db002..205af9e108d 100644 --- a/Mage/src/main/java/mage/game/GameState.java +++ b/Mage/src/main/java/mage/game/GameState.java @@ -56,7 +56,6 @@ import mage.abilities.effects.ContinuousEffects; import mage.abilities.effects.Effect; import mage.cards.Card; import mage.cards.SplitCard; -import mage.choices.Choice; import mage.constants.Zone; import mage.game.combat.Combat; import mage.game.combat.CombatGroup; @@ -322,12 +321,6 @@ public class GameState implements Serializable, Copyable { sb.append(target.getTargets()); } } - if (!mode.getChoices().isEmpty()) { - sb.append("choices"); - for (Choice choice : mode.getChoices()) { - sb.append(choice.getChoice()); - } - } } } @@ -380,12 +373,6 @@ public class GameState implements Serializable, Copyable { sb.append(target.getTargets()); } } - if (!mode.getChoices().isEmpty()) { - sb.append("choices"); - for (Choice choice : mode.getChoices()) { - sb.append(choice.getChoice()); - } - } } } diff --git a/Mage/src/main/java/mage/game/command/Commander.java b/Mage/src/main/java/mage/game/command/Commander.java index 77560f1901c..0f6c5e3183b 100644 --- a/Mage/src/main/java/mage/game/command/Commander.java +++ b/Mage/src/main/java/mage/game/command/Commander.java @@ -165,10 +165,6 @@ public class Commander implements CommandObject { return card.getToughness(); } - @Override - public void adjustChoices(Ability ability, Game game) { - } - @Override public void adjustCosts(Ability ability, Game game) { } diff --git a/Mage/src/main/java/mage/game/command/Emblem.java b/Mage/src/main/java/mage/game/command/Emblem.java index b9d5cf6e931..e7d3044495f 100644 --- a/Mage/src/main/java/mage/game/command/Emblem.java +++ b/Mage/src/main/java/mage/game/command/Emblem.java @@ -174,10 +174,6 @@ public class Emblem implements CommandObject { return MageInt.EmptyMageInt; } - @Override - public void adjustChoices(Ability ability, Game game) { - } - @Override public void adjustCosts(Ability ability, Game game) { } diff --git a/Mage/src/main/java/mage/game/permanent/PermanentCard.java b/Mage/src/main/java/mage/game/permanent/PermanentCard.java index c4249c66334..be56b4b2d35 100644 --- a/Mage/src/main/java/mage/game/permanent/PermanentCard.java +++ b/Mage/src/main/java/mage/game/permanent/PermanentCard.java @@ -249,11 +249,6 @@ public class PermanentCard extends PermanentImpl { card.adjustCosts(ability, game); } - @Override - public void adjustChoices(Ability ability, Game game) { - card.adjustChoices(ability, game); - } - @Override public ManaCosts getManaCost() { if (faceDown) { // face down permanent has always {0} mana costs diff --git a/Mage/src/main/java/mage/game/stack/Spell.java b/Mage/src/main/java/mage/game/stack/Spell.java index 16c0b19978b..869365da3d2 100644 --- a/Mage/src/main/java/mage/game/stack/Spell.java +++ b/Mage/src/main/java/mage/game/stack/Spell.java @@ -647,13 +647,6 @@ public class Spell extends StackObjImpl implements Card { return copy; } - @Override - public void adjustChoices(Ability ability, Game game) { - if (card != null) { - card.adjustChoices(ability, game); - } - } - @Override public void adjustCosts(Ability ability, Game game) { if (card != null) { diff --git a/Mage/src/main/java/mage/game/stack/StackAbility.java b/Mage/src/main/java/mage/game/stack/StackAbility.java index ee04b6eeb2d..15cb0d4a0f2 100644 --- a/Mage/src/main/java/mage/game/stack/StackAbility.java +++ b/Mage/src/main/java/mage/game/stack/StackAbility.java @@ -49,8 +49,6 @@ import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.Effect; import mage.abilities.effects.Effects; import mage.cards.Card; -import mage.choices.Choice; -import mage.choices.Choices; import mage.constants.AbilityType; import mage.constants.AbilityWord; import mage.constants.CardType; @@ -307,15 +305,6 @@ public class StackAbility extends StackObjImpl implements Ability { return ability.getFirstTarget(); } - @Override - public Choices getChoices() { - return ability.getChoices(); - } - - @Override - public void addChoice(Choice choice) { - } - @Override public ManaCosts getManaCosts() { return ability.getManaCosts(); @@ -354,14 +343,6 @@ public class StackAbility extends StackObjImpl implements Ability { this.expansionSetCode = expansionSetCode; } - @Override - public void adjustChoices(Ability ability, Game game) { - Card card = game.getCard(ability.getSourceId()); - if (card != null) { - card.adjustChoices(ability, game); - } - } - @Override public void adjustCosts(Ability ability, Game game) { Card card = game.getCard(ability.getSourceId()); diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index f6ee154bc4f..fba36c72602 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2812,8 +2812,6 @@ public abstract class PlayerImpl implements Player, Serializable { } else { addTargetOptions(options, ability, 0, game); } - } else if (ability.getChoices().getUnchosen().size() > 0) { - addChoiceOptions(options, ability, 0, game); } else if (ability.getCosts().getTargets().getUnchosen().size() > 0) { addCostTargetOptions(options, ability, 0, game); } @@ -2834,8 +2832,6 @@ public abstract class PlayerImpl implements Player, Serializable { } else { addTargetOptions(options, newOption, 0, game); } - } else if (newOption.getChoices().getUnchosen().size() > 0) { - addChoiceOptions(options, newOption, 0, game); } else if (newOption.getCosts().getTargets().getUnchosen().size() > 0) { addCostTargetOptions(options, newOption, 0, game); } else { @@ -2863,22 +2859,6 @@ public abstract class PlayerImpl implements Player, Serializable { } if (targetNum < option.getTargets().size() - 2) { addTargetOptions(options, newOption, targetNum + 1, game); - } else if (option.getChoices().size() > 0) { - addChoiceOptions(options, newOption, 0, game); - } else if (option.getCosts().getTargets().size() > 0) { - addCostTargetOptions(options, newOption, 0, game); - } else { - options.add(newOption); - } - } - } - - private void addChoiceOptions(List options, Ability option, int choiceNum, Game game) { - for (String choice : option.getChoices().get(choiceNum).getChoices()) { - Ability newOption = option.copy(); - newOption.getChoices().get(choiceNum).setChoice(choice); - if (choiceNum < option.getChoices().size() - 1) { - addChoiceOptions(options, newOption, choiceNum + 1, game); } else if (option.getCosts().getTargets().size() > 0) { addCostTargetOptions(options, newOption, 0, game); } else { diff --git a/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java b/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java new file mode 100644 index 00000000000..eb036c7c86e --- /dev/null +++ b/Mage/src/main/java/mage/target/common/TargetPermanentOrSuspendedCard.java @@ -0,0 +1,177 @@ +/* + * + * 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.target.common; + +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import mage.MageObject; +import mage.abilities.Ability; +import mage.cards.Card; +import mage.constants.Zone; +import mage.filter.Filter; +import mage.filter.common.FilterPermanentOrSuspendedCard; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.target.TargetImpl; + +/** + * + * @author emerald000 + */ +public class TargetPermanentOrSuspendedCard extends TargetImpl { + + protected FilterPermanentOrSuspendedCard filter; + + public TargetPermanentOrSuspendedCard() { + this(new FilterPermanentOrSuspendedCard(), false); + } + + public TargetPermanentOrSuspendedCard(FilterPermanentOrSuspendedCard filter, boolean notTarget) { + super(notTarget); + this.filter = filter; + this.zone = Zone.ALL; + this.targetName = filter.getMessage(); + this.minNumberOfTargets = 1; + this.maxNumberOfTargets = 1; + } + + public TargetPermanentOrSuspendedCard(final TargetPermanentOrSuspendedCard target) { + super(target); + this.filter = target.filter.copy(); + } + + @Override + public Filter getFilter() { + return this.filter; + } + + @Override + public TargetPermanentOrSuspendedCard copy() { + return new TargetPermanentOrSuspendedCard(this); + } + + @Override + public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) { + MageObject sourceObject = game.getObject(sourceId); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { + if (permanent.canBeTargetedBy(sourceObject, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { + return true; + } + } + for (Card card : game.getExile().getAllCards(game)) { + if (filter.match(card, sourceId, sourceControllerId, game)) { + return true; + } + } + return false; + } + + @Override + public Set possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) { + Set possibleTargets = new HashSet<>(20); + MageObject sourceObject = game.getObject(sourceId); + for (Permanent permanent : game.getBattlefield().getActivePermanents(filter.getPermanentFilter(), sourceControllerId, game)) { + if (permanent.canBeTargetedBy(sourceObject, sourceControllerId, game) && filter.match(permanent, sourceId, sourceControllerId, game)) { + possibleTargets.add(permanent.getId()); + } + } + for (Card card : game.getExile().getAllCards(game)) { + if (filter.match(card, sourceId, sourceControllerId, game)) { + possibleTargets.add(card.getId()); + } + } + return possibleTargets; + } + + @Override + public boolean canTarget(UUID id, Game game) { + Permanent permanent = game.getPermanent(id); + if (permanent != null) { + return filter.match(permanent, game); + } + Card card = game.getExile().getCard(id, game); + if (card != null) { + return filter.match(card, game); + } + return false; + } + + @Override + public boolean canTarget(UUID id, Ability source, Game game) { + Permanent permanent = game.getPermanent(id); + if (permanent != null) { + if (source != null) { + MageObject targetSource = game.getObject(source.getSourceId()); + return permanent.canBeTargetedBy(targetSource, source.getControllerId(), game) + && filter.match(permanent, source.getSourceId(), source.getControllerId(), game); + } else { + return filter.match(permanent, game); + } + } + Card card = game.getExile().getCard(id, game); + if (card != null) { + return filter.match(card, game); + } + return false; + } + + @Override + public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) { + return this.canTarget(id, source, game); + } + + @Override + public boolean canChoose(UUID sourceControllerId, Game game) { + return this.canChoose(null, sourceControllerId, game); + } + + @Override + public Set possibleTargets(UUID sourceControllerId, Game game) { + return this.possibleTargets(null, sourceControllerId, game); + } + + @Override + public String getTargetedName(Game game) { + StringBuilder sb = new StringBuilder(""); + for (UUID targetId : this.getTargets()) { + Permanent permanent = game.getPermanent(targetId); + if (permanent != null) { + sb.append(permanent.getLogName()).append(" "); + } else { + Card card = game.getExile().getCard(targetId, game); + if (card != null) { + sb.append(card.getLogName()).append(" "); + } + } + } + return sb.toString(); + } +}