diff --git a/Mage.Sets/src/mage/sets/alarareborn/ArchitectsOfWill.java b/Mage.Sets/src/mage/sets/alarareborn/ArchitectsOfWill.java index 843fd2d832..39bac2325a 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/ArchitectsOfWill.java +++ b/Mage.Sets/src/mage/sets/alarareborn/ArchitectsOfWill.java @@ -121,7 +121,7 @@ class ArchitectsOfWillEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of target player's library")); target.setRequired(true); - while (cards.size() > 1) { + while (you.isInGame() && cards.size() > 1) { you.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/alarareborn/DefilerOfSouls.java b/Mage.Sets/src/mage/sets/alarareborn/DefilerOfSouls.java index acd1b23140..f3d6adbc9c 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/DefilerOfSouls.java +++ b/Mage.Sets/src/mage/sets/alarareborn/DefilerOfSouls.java @@ -111,7 +111,7 @@ class DefilerOfSoulsEffect extends OneShotEffect { //had, if thats the case this ability should fizzle. if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) { boolean abilityApplied = false; - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } diff --git a/Mage.Sets/src/mage/sets/alarareborn/SagesOfTheAnima.java b/Mage.Sets/src/mage/sets/alarareborn/SagesOfTheAnima.java index f60461d491..9b4b9bf0c3 100644 --- a/Mage.Sets/src/mage/sets/alarareborn/SagesOfTheAnima.java +++ b/Mage.Sets/src/mage/sets/alarareborn/SagesOfTheAnima.java @@ -123,7 +123,7 @@ class SagesOfTheAnimaReplacementEffect extends ReplacementEffectImpl { } TargetCard target = new TargetCard(Zone.PICK, new FilterCard()); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/apocalypse/GoblinRingleader.java b/Mage.Sets/src/mage/sets/apocalypse/GoblinRingleader.java index 0690d39bd9..5e74d33476 100644 --- a/Mage.Sets/src/mage/sets/apocalypse/GoblinRingleader.java +++ b/Mage.Sets/src/mage/sets/apocalypse/GoblinRingleader.java @@ -126,7 +126,7 @@ class GoblinRingleaderEffect extends OneShotEffect { } TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards2.size() > 0 && player.choose(Outcome.Detriment, cards2, target, game)) { + while (player.isInGame() && cards2.size() > 0 && player.choose(Outcome.Detriment, cards2, target, game)) { Card card = cards.get(target.getFirstTarget(), game); if (card != null) { cards2.remove(card); diff --git a/Mage.Sets/src/mage/sets/apocalypse/SylvanMessenger.java b/Mage.Sets/src/mage/sets/apocalypse/SylvanMessenger.java index 7376ccf396..667dd0a782 100644 --- a/Mage.Sets/src/mage/sets/apocalypse/SylvanMessenger.java +++ b/Mage.Sets/src/mage/sets/apocalypse/SylvanMessenger.java @@ -132,7 +132,7 @@ class SylvanMessengerEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards2.size() > 0 && player.choose(Outcome.Detriment, cards2, target, game)) { + while (player.isInGame() && cards2.size() > 0 && player.choose(Outcome.Detriment, cards2, target, game)) { Card card = cards2.get(target.getFirstTarget(), game); if (card != null) { cards2.remove(card); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/BrunaLightOfAlabaster.java b/Mage.Sets/src/mage/sets/avacynrestored/BrunaLightOfAlabaster.java index 5b7a2f76c1..59ae470521 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/BrunaLightOfAlabaster.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/BrunaLightOfAlabaster.java @@ -124,7 +124,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect { return false; } - while (player.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", game)) { + while (player.isInGame() && player.chooseUse(Outcome.Benefit, "Attach an Aura from the battlefield?", game)) { Target targetAura = new TargetPermanent(filterAura); if (player.choose(Outcome.Benefit, targetAura, source.getSourceId(), game)) { Permanent aura = game.getPermanent(targetAura.getFirstTarget()); @@ -139,7 +139,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect { } int count = player.getHand().count(filterAuraCard, game); - while (count > 0 && player.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", game)) { + while (player.isInGame() && count > 0 && player.chooseUse(Outcome.Benefit, "Attach an Aura from your hand?", game)) { TargetCard targetAura = new TargetCard(Zone.PICK, filterAuraCard); if (player.choose(Outcome.Benefit, player.getHand(), targetAura, game)) { Card aura = game.getCard(targetAura.getFirstTarget()); @@ -153,7 +153,7 @@ class BrunaLightOfAlabasterEffect extends OneShotEffect { } count = player.getGraveyard().count(filterAuraCard, game); - while (count > 0 && player.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", game)) { + while (player.isInGame() && count > 0 && player.chooseUse(Outcome.Benefit, "Attach an Aura from your graveyard?", game)) { TargetCard targetAura = new TargetCard(Zone.PICK, filterAuraCard); if (player.choose(Outcome.Benefit, player.getGraveyard(), targetAura, game)) { Card aura = game.getCard(targetAura.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/DescentIntoMadness.java b/Mage.Sets/src/mage/sets/avacynrestored/DescentIntoMadness.java index cc20920403..f8ee210797 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/DescentIntoMadness.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/DescentIntoMadness.java @@ -115,7 +115,7 @@ class DescentIntoMadnessEffect extends OneShotEffect { private void exileCards(Player player, int count, Ability source, Game game) { int amount = Math.min(count, player.getHand().size() + game.getBattlefield().getAllActivePermanents(player.getId()).size()); - while (amount > 0) { + while (player.isInGame() && amount > 0) { Target target = new TargetControlledPermanent(0, 1, filter, true); if (target.canChoose(player.getId(), game) && player.choose(Outcome.Exile, target, source.getSourceId(), game)) { diff --git a/Mage.Sets/src/mage/sets/avacynrestored/LairDelve.java b/Mage.Sets/src/mage/sets/avacynrestored/LairDelve.java index 588a9908dc..c907d612f6 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/LairDelve.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/LairDelve.java @@ -109,7 +109,7 @@ class LairDelveEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/avacynrestored/PrimalSurge.java b/Mage.Sets/src/mage/sets/avacynrestored/PrimalSurge.java index 94852a3af1..0e92aebdf4 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/PrimalSurge.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/PrimalSurge.java @@ -96,7 +96,7 @@ class PrimalSurgeEffect extends OneShotEffect { if (player.getLibrary().size() > 0) { Card card = player.getLibrary().removeFromTop(game); if (card != null) { - card.moveToExile(null, "", source.getId(), game); + card.moveToExile(null, "", source.getSourceId(), game); List cardType = card.getCardType(); if ((cardType.contains(CardType.ARTIFACT) || cardType.contains(CardType.CREATURE) || cardType.contains(CardType.ENCHANTMENT) || cardType.contains(CardType.LAND) @@ -114,7 +114,7 @@ class PrimalSurgeEffect extends OneShotEffect { } } } - } while (repeat); + } while (player.isInGame() && repeat); return true; } diff --git a/Mage.Sets/src/mage/sets/avacynrestored/RiteOfRuin.java b/Mage.Sets/src/mage/sets/avacynrestored/RiteOfRuin.java index 4ed42b25fa..db63e296ac 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/RiteOfRuin.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/RiteOfRuin.java @@ -93,22 +93,22 @@ class RiteOfRuinEffect extends OneShotEffect { return false; } - HashSet choices = new HashSet(); + HashSet choices = new HashSet<>(); choices.add("Artifacts"); choices.add("Creatures"); choices.add("Lands"); - LinkedList order = new LinkedList(); + LinkedList order = new LinkedList<>(); ChoiceImpl choice = new ChoiceImpl(true); choice.setChoices(choices); - while (controller.choose(Outcome.Sacrifice, choice, game) && choices.size() > 1) { + while (controller.isInGame() && controller.choose(Outcome.Sacrifice, choice, game) && choices.size() > 1) { order.add(getCardType(choice.getChoice())); choices.remove(choice.getChoice()); choice.clearChoice(); } order.add(getCardType(choices.iterator().next())); - LinkedList sacrifices = new LinkedList(); + LinkedList sacrifices = new LinkedList<>(); int count = 1; for (CardType cardType : order) { FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " permanent you control"); diff --git a/Mage.Sets/src/mage/sets/avacynrestored/StolenGoods.java b/Mage.Sets/src/mage/sets/avacynrestored/StolenGoods.java index 1b8f1371ae..de872b835a 100644 --- a/Mage.Sets/src/mage/sets/avacynrestored/StolenGoods.java +++ b/Mage.Sets/src/mage/sets/avacynrestored/StolenGoods.java @@ -109,7 +109,7 @@ class StolenGoodsEffect extends OneShotEffect { class StolenGoodsCastFromExileEffect extends AsThoughEffectImpl { - private UUID cardId; + private final UUID cardId; public StolenGoodsCastFromExileEffect(UUID cardId) { super(AsThoughEffectType.CAST, Duration.EndOfTurn, Outcome.Benefit); diff --git a/Mage.Sets/src/mage/sets/bornofthegods/OracleOfBones.java b/Mage.Sets/src/mage/sets/bornofthegods/OracleOfBones.java index 3b6b410047..72e12b17cb 100644 --- a/Mage.Sets/src/mage/sets/bornofthegods/OracleOfBones.java +++ b/Mage.Sets/src/mage/sets/bornofthegods/OracleOfBones.java @@ -113,7 +113,7 @@ class OracleOfBonesCastEffect extends OneShotEffect { controller.chooseUse(outcome, "Cast an instant or sorcery card from your hand without paying its mana cost?", game)) { Card cardToCast = null; boolean cancel = false; - while (!cancel) { + while (controller.isInGame() && !cancel) { if (controller.chooseTarget(outcome, target, source, game)) { cardToCast = game.getCard(target.getFirstTarget()); if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game)) { diff --git a/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java b/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java index df95fd7436..da15664213 100644 --- a/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java +++ b/Mage.Sets/src/mage/sets/bornofthegods/WhimsOfTheFates.java @@ -99,7 +99,7 @@ class WhimsOfTheFateEffect extends OneShotEffect { if (controller != null) { // Map of players and their piles (1,2,3) with values of UUID of the permanents - Map>> playerPermanents = new LinkedHashMap>>(); + Map>> playerPermanents = new LinkedHashMap<>(); PlayerList playerList = game.getState().getPlayerList(); while (!playerList.get().equals(source.getControllerId()) && controller.isInGame()) { diff --git a/Mage.Sets/src/mage/sets/championsofkamigawa/Squelch.java b/Mage.Sets/src/mage/sets/championsofkamigawa/Squelch.java index 7595a376fd..af1ab6578e 100644 --- a/Mage.Sets/src/mage/sets/championsofkamigawa/Squelch.java +++ b/Mage.Sets/src/mage/sets/championsofkamigawa/Squelch.java @@ -124,7 +124,7 @@ class ActivatedAbilityTarget extends TargetObject { @Override public Set possibleTargets(UUID sourceControllerId, Game game) { - Set possibleTargets = new HashSet(); + Set possibleTargets = new HashSet<>(); for (StackObject stackObject : game.getStack()) { if (stackObject.getStackAbility() != null && (stackObject.getStackAbility() instanceof ActivatedAbility) && game.getPlayer(sourceControllerId).getInRange().contains(stackObject.getStackAbility().getControllerId())) { possibleTargets.add(stackObject.getStackAbility().getId()); diff --git a/Mage.Sets/src/mage/sets/commander/AllianceOfArms.java b/Mage.Sets/src/mage/sets/commander/AllianceOfArms.java index 69f9bb3bfe..4f5a877ab4 100644 --- a/Mage.Sets/src/mage/sets/commander/AllianceOfArms.java +++ b/Mage.Sets/src/mage/sets/commander/AllianceOfArms.java @@ -118,7 +118,7 @@ class AllianceOfArmsEffect extends OneShotEffect { protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; - while (!payed) { + while (player.isInGame() && !payed) { xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); diff --git a/Mage.Sets/src/mage/sets/commander/CollectiveVoyage.java b/Mage.Sets/src/mage/sets/commander/CollectiveVoyage.java index 498be6c760..b1f83de646 100644 --- a/Mage.Sets/src/mage/sets/commander/CollectiveVoyage.java +++ b/Mage.Sets/src/mage/sets/commander/CollectiveVoyage.java @@ -127,7 +127,7 @@ class CollectiveVoyageEffect extends OneShotEffect { protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; - while (!payed) { + while (player.isInGame() && !payed) { xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); diff --git a/Mage.Sets/src/mage/sets/commander/MindsAglow.java b/Mage.Sets/src/mage/sets/commander/MindsAglow.java index cbb2c29ea7..83d23a6836 100644 --- a/Mage.Sets/src/mage/sets/commander/MindsAglow.java +++ b/Mage.Sets/src/mage/sets/commander/MindsAglow.java @@ -116,7 +116,7 @@ class MindsAglowEffect extends OneShotEffect { protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; - while (!payed) { + while (player.isInGame() && !payed) { xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); diff --git a/Mage.Sets/src/mage/sets/commander/SharedTrauma.java b/Mage.Sets/src/mage/sets/commander/SharedTrauma.java index eb84bb8371..7eb80a3f40 100644 --- a/Mage.Sets/src/mage/sets/commander/SharedTrauma.java +++ b/Mage.Sets/src/mage/sets/commander/SharedTrauma.java @@ -117,7 +117,7 @@ class SharedTraumaEffect extends OneShotEffect { protected static int playerPaysXGenericMana(Player player, Ability source, Game game) { int xValue = 0; boolean payed = false; - while (!payed) { + while (player.isInGame() && !payed) { xValue = player.announceXMana(0, Integer.MAX_VALUE, "How much mana will you pay?", game, source); if (xValue > 0) { Cost cost = new GenericManaCost(xValue); diff --git a/Mage.Sets/src/mage/sets/commander2013/EyeOfDoom.java b/Mage.Sets/src/mage/sets/commander2013/EyeOfDoom.java index 587433c8ef..91b2557441 100644 --- a/Mage.Sets/src/mage/sets/commander2013/EyeOfDoom.java +++ b/Mage.Sets/src/mage/sets/commander2013/EyeOfDoom.java @@ -105,7 +105,7 @@ class EyeOfDoomEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - List permanents = new ArrayList(); + List permanents = new ArrayList<>(); Target target = new TargetNonlandPermanent(); target.setRequired(true); target.setNotTarget(false); diff --git a/Mage.Sets/src/mage/sets/commander2013/LimDulsVault.java b/Mage.Sets/src/mage/sets/commander2013/LimDulsVault.java index 8b31e38aa1..bbb50e163f 100644 --- a/Mage.Sets/src/mage/sets/commander2013/LimDulsVault.java +++ b/Mage.Sets/src/mage/sets/commander2013/LimDulsVault.java @@ -116,7 +116,7 @@ class LimDulsVaultEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard(doAgain ? textBottom : textTop)); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java b/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java index 8e02d703a6..c8d5a643bb 100644 --- a/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java +++ b/Mage.Sets/src/mage/sets/commander2013/OrderOfSuccession.java @@ -97,7 +97,7 @@ class OrderOfSuccessionEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - Map playerCreature = new HashMap(); + Map playerCreature = new HashMap<>(); boolean left = source.getChoices().get(0).getChoice().equals("Left"); PlayerList playerList = game.getState().getPlayerList(); while (!playerList.get().equals(source.getControllerId()) && controller.isInGame()) { diff --git a/Mage.Sets/src/mage/sets/conflux/MaelstromArchangel.java b/Mage.Sets/src/mage/sets/conflux/MaelstromArchangel.java index 8367467e53..4a3c2ea771 100644 --- a/Mage.Sets/src/mage/sets/conflux/MaelstromArchangel.java +++ b/Mage.Sets/src/mage/sets/conflux/MaelstromArchangel.java @@ -110,7 +110,7 @@ class MaelstromArchangelCastEffect extends OneShotEffect { controller.chooseUse(outcome, "Cast a nonland card from your hand without paying its mana cost?", game)) { Card cardToCast = null; boolean cancel = false; - while (!cancel) { + while (controller.isInGame() && !cancel) { if (controller.chooseTarget(outcome, target, source, game)) { cardToCast = game.getCard(target.getFirstTarget()); if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game)) { diff --git a/Mage.Sets/src/mage/sets/darkascension/ArchdemonOfGreed.java b/Mage.Sets/src/mage/sets/darkascension/ArchdemonOfGreed.java index a810f8622d..e0f73b1d2e 100644 --- a/Mage.Sets/src/mage/sets/darkascension/ArchdemonOfGreed.java +++ b/Mage.Sets/src/mage/sets/darkascension/ArchdemonOfGreed.java @@ -92,7 +92,7 @@ public class ArchdemonOfGreed extends CardImpl { public ArchdemonOfGreedEffect() { super(Outcome.Damage); - this.staticText = "Sacrifice a Human. If you can't, tap Archdemon of Greed and it deals 9 damage to you."; + this.staticText = "Sacrifice a Human. If you can't, tap {this} and it deals 9 damage to you."; } public ArchdemonOfGreedEffect(final ArchdemonOfGreedEffect effect) { @@ -113,24 +113,24 @@ public class ArchdemonOfGreed extends CardImpl { Player player = game.getPlayer(source.getControllerId()); if (player != null) { TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false); + target.setRequired(true); // if they can pay the cost, then they must pay if (target.canChoose(player.getId(), game)) { - while (!target.isChosen() && target.canChoose(player.getId(), game)) { - player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); - } + player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); Permanent humanSacrifice = game.getPermanent(target.getFirstTarget()); - if (permanent != null) { + if (humanSacrifice != null) { // sacrifice the chosen card - return humanSacrifice.sacrifice(source.getId(), game); + return humanSacrifice.sacrifice(source.getSourceId(), game); } } else { permanent.tap(game); - player.damage(9, source.getId(), game, false, true); + player.damage(9, source.getSourceId(), game, false, true); } } + return true; } - return true; + return false; } } } diff --git a/Mage.Sets/src/mage/sets/darkascension/CallToTheKindred.java b/Mage.Sets/src/mage/sets/darkascension/CallToTheKindred.java index 6b497d6fae..a48b7a89ad 100644 --- a/Mage.Sets/src/mage/sets/darkascension/CallToTheKindred.java +++ b/Mage.Sets/src/mage/sets/darkascension/CallToTheKindred.java @@ -156,7 +156,7 @@ class CallToTheKindredEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/dragonsmaze/CatchRelease.java b/Mage.Sets/src/mage/sets/dragonsmaze/CatchRelease.java index 1f19e7a656..f8a01ff6a1 100644 --- a/Mage.Sets/src/mage/sets/dragonsmaze/CatchRelease.java +++ b/Mage.Sets/src/mage/sets/dragonsmaze/CatchRelease.java @@ -153,7 +153,7 @@ class ReleaseSacrificeEffect extends OneShotEffect { target5.setNotTarget(false); if (target1.canChoose(player.getId(), game)) { - while (!target1.isChosen() && target1.canChoose(player.getId(), game)) { + while (player.isInGame() && !target1.isChosen() && target1.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target1, source, game); } Permanent artifact = game.getPermanent(target1.getFirstTarget()); @@ -164,7 +164,7 @@ class ReleaseSacrificeEffect extends OneShotEffect { } if (target2.canChoose(player.getId(), game)) { - while (!target2.isChosen() && target2.canChoose(player.getId(), game)) { + while (player.isInGame() && !target2.isChosen() && target2.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target2, source, game); } Permanent creature = game.getPermanent(target2.getFirstTarget()); @@ -175,7 +175,7 @@ class ReleaseSacrificeEffect extends OneShotEffect { } if (target3.canChoose(player.getId(), game)) { - while (!target3.isChosen() && target3.canChoose(player.getId(), game)) { + while (player.isInGame() && !target3.isChosen() && target3.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target3, source, game); } Permanent enchantment = game.getPermanent(target3.getFirstTarget()); @@ -186,7 +186,7 @@ class ReleaseSacrificeEffect extends OneShotEffect { } if (target4.canChoose(player.getId(), game)) { - while (!target4.isChosen() && target4.canChoose(player.getId(), game)) { + while (player.isInGame() && !target4.isChosen() && target4.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target4, source, game); } Permanent land = game.getPermanent(target4.getFirstTarget()); @@ -197,7 +197,7 @@ class ReleaseSacrificeEffect extends OneShotEffect { } if (target5.canChoose(player.getId(), game)) { - while (!target5.isChosen() && target5.canChoose(player.getId(), game)) { + while (player.isInGame() && !target5.isChosen() && target5.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.Benefit, target5, source, game); } Permanent planeswalker = game.getPermanent(target5.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/eventide/Evershrike.java b/Mage.Sets/src/mage/sets/eventide/Evershrike.java index 6163812643..1f03aacab6 100644 --- a/Mage.Sets/src/mage/sets/eventide/Evershrike.java +++ b/Mage.Sets/src/mage/sets/eventide/Evershrike.java @@ -124,7 +124,7 @@ class EvershrikeEffect extends OneShotEffect { filterAuraCard.add(new AuraCardCanAttachToPermanentId(evershrikePermanent.getId())); filterAuraCard.add(new ConvertedManaCostPredicate(ComparisonType.LessThan, xAmount)); int count = you.getHand().count(filterAuraCard, game); - while (count > 0 && you.chooseUse(Outcome.Benefit, "Do you wish to put an Aura card from your hand onto Evershrike", game)) { + while (you.isInGame() && count > 0 && you.chooseUse(Outcome.Benefit, "Do you wish to put an Aura card from your hand onto Evershrike", game)) { TargetCard targetAura = new TargetCard(Zone.PICK, filterAuraCard); if (you.choose(Outcome.Benefit, you.getHand(), targetAura, game)) { Card aura = game.getCard(targetAura.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/exodus/Cataclysm.java b/Mage.Sets/src/mage/sets/exodus/Cataclysm.java index dfd2b22fbf..2edfde65e8 100644 --- a/Mage.Sets/src/mage/sets/exodus/Cataclysm.java +++ b/Mage.Sets/src/mage/sets/exodus/Cataclysm.java @@ -101,7 +101,7 @@ class CataclysmEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - List chosen = new ArrayList(); + List chosen = new ArrayList<>(); for (UUID playerId : game.getPlayerList()) { Player player = game.getPlayer(playerId); @@ -122,7 +122,7 @@ class CataclysmEffect extends OneShotEffect { target4.setNotTarget(true); if (target1.canChoose(player.getId(), game)) { - while (!target1.isChosen() && target1.canChoose(player.getId(), game)) { + while (player.isInGame() && !target1.isChosen() && target1.canChoose(player.getId(), game)) { player.choose(Outcome.Benefit, target1, source.getSourceId(), game); } Permanent artifact = game.getPermanent(target1.getFirstTarget()); @@ -133,7 +133,7 @@ class CataclysmEffect extends OneShotEffect { } if (target2.canChoose(player.getId(), game)) { - while (!target2.isChosen() && target2.canChoose(player.getId(), game)) { + while (player.isInGame() && !target2.isChosen() && target2.canChoose(player.getId(), game)) { player.choose(Outcome.Benefit, target2, source.getSourceId(), game); } Permanent creature = game.getPermanent(target2.getFirstTarget()); @@ -144,7 +144,7 @@ class CataclysmEffect extends OneShotEffect { } if (target3.canChoose(player.getId(), game)) { - while (!target3.isChosen() && target3.canChoose(player.getId(), game)) { + while (player.isInGame() && !target3.isChosen() && target3.canChoose(player.getId(), game)) { player.choose(Outcome.Benefit, target3, source.getSourceId(), game); } Permanent enchantment = game.getPermanent(target3.getFirstTarget()); @@ -155,7 +155,7 @@ class CataclysmEffect extends OneShotEffect { } if (target4.canChoose(player.getId(), game)) { - while (!target4.isChosen() && target4.canChoose(player.getId(), game)) { + while (player.isInGame() && !target4.isChosen() && target4.canChoose(player.getId(), game)) { player.choose(Outcome.Benefit, target4, source.getSourceId(), game); } Permanent land = game.getPermanent(target4.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/fifthdawn/DawnsReflection.java b/Mage.Sets/src/mage/sets/fifthdawn/DawnsReflection.java index 8a5eae51d1..e924d59bf5 100644 --- a/Mage.Sets/src/mage/sets/fifthdawn/DawnsReflection.java +++ b/Mage.Sets/src/mage/sets/fifthdawn/DawnsReflection.java @@ -138,10 +138,7 @@ class DawnsReflectionManaEffect extends ManaEffect { Mana mana = new Mana(); for(int i = 0; i < x; i++){ ChoiceColor choiceColor = new ChoiceColor(); - while (!controller.choose(Outcome.Benefit, choiceColor, game)) { - if (!controller.isInGame()) { - return false; - } + while (controller.isInGame() && !controller.choose(Outcome.Benefit, choiceColor, game)) { } if (choiceColor.getColor().isBlack()) { diff --git a/Mage.Sets/src/mage/sets/fifthedition/SylvanLibrary.java b/Mage.Sets/src/mage/sets/fifthedition/SylvanLibrary.java index 3f322c2b7a..39d53246d9 100644 --- a/Mage.Sets/src/mage/sets/fifthedition/SylvanLibrary.java +++ b/Mage.Sets/src/mage/sets/fifthedition/SylvanLibrary.java @@ -136,7 +136,7 @@ class SylvanLibraryEffect extends OneShotEffect { if (numberOfCardsToPutBack > 1) { TargetCard target2 = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of your library (last chosen will be on top)")); target2.setRequired(true); - while (cardsPutBack.size() > 1) { + while (controller.isInGame() && cardsPutBack.size() > 1) { controller.choose(Outcome.Benefit, cardsPutBack, target2, game); Card card = cardsPutBack.get(target2.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/gatecrash/DevourFlesh.java b/Mage.Sets/src/mage/sets/gatecrash/DevourFlesh.java index 7a18072e10..058f80d0c6 100644 --- a/Mage.Sets/src/mage/sets/gatecrash/DevourFlesh.java +++ b/Mage.Sets/src/mage/sets/gatecrash/DevourFlesh.java @@ -106,7 +106,7 @@ class DevourFleshSacrificeEffect extends OneShotEffect { if (realCount > 0) { Target target = new TargetControlledPermanent(1, 1, filter, true); target.setRequired(true); - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } Permanent permanent = game.getPermanent(target.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/iceage/GlacialChasm.java b/Mage.Sets/src/mage/sets/iceage/GlacialChasm.java index 5706397b82..30e7d20971 100644 --- a/Mage.Sets/src/mage/sets/iceage/GlacialChasm.java +++ b/Mage.Sets/src/mage/sets/iceage/GlacialChasm.java @@ -123,7 +123,7 @@ class SacrificeControllerEffect extends OneShotEffect{ //had, if thats the case this ability should fizzle. if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) { boolean abilityApplied = false; - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } diff --git a/Mage.Sets/src/mage/sets/innistrad/CreepingRenaissance.java b/Mage.Sets/src/mage/sets/innistrad/CreepingRenaissance.java index 7a5a39b13b..75b7400b2f 100644 --- a/Mage.Sets/src/mage/sets/innistrad/CreepingRenaissance.java +++ b/Mage.Sets/src/mage/sets/innistrad/CreepingRenaissance.java @@ -94,7 +94,8 @@ class CreepingRenaissanceEffect extends OneShotEffect { typeChoice.getChoices().add(CardType.LAND.toString()); typeChoice.getChoices().add(CardType.PLANESWALKER.toString()); - while (!controller.choose(Outcome.ReturnToHand, typeChoice, game)); + while (controller.isInGame() && !controller.choose(Outcome.ReturnToHand, typeChoice, game)) { + } String typeName = typeChoice.getChoice(); CardType chosenType = null; diff --git a/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java b/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java index 756467c89d..ff0dfde075 100644 --- a/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java +++ b/Mage.Sets/src/mage/sets/innistrad/DivineReckoning.java @@ -106,7 +106,7 @@ class DivineReckoningEffect extends OneShotEffect { Target target = new TargetControlledPermanent(1, 1, filter, false); target.setRequired(true); if (target.canChoose(player.getId(), game)) { - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Benefit, target, source.getSourceId(), game); } Permanent permanent = game.getPermanent(target.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/innistrad/GarrukTheVeilCursed.java b/Mage.Sets/src/mage/sets/innistrad/GarrukTheVeilCursed.java index 696fdf18fb..dbc6dc857f 100644 --- a/Mage.Sets/src/mage/sets/innistrad/GarrukTheVeilCursed.java +++ b/Mage.Sets/src/mage/sets/innistrad/GarrukTheVeilCursed.java @@ -159,7 +159,7 @@ class GarrukTheVeilCursedEffect extends OneShotEffect { Target target = new TargetControlledPermanent(1, 1, filterCreature, false); boolean sacrificed = false; if (target.canChoose(player.getId(), game)) { - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.choose(Outcome.Sacrifice, target, source.getSourceId(), game); } diff --git a/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java b/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java index caac40f3b3..bddcc031f6 100644 --- a/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java +++ b/Mage.Sets/src/mage/sets/innistrad/TrepanationBlade.java @@ -115,14 +115,14 @@ class TrepanationBladeDiscardEffect extends OneShotEffect { Card card = player.getLibrary().removeFromTop(game); if (card != null) { cards.add(card); - card.moveToZone(Zone.GRAVEYARD, source.getId(), game, false); + player.moveCardToGraveyardWithInfo(card, source.getSourceId(), game, Zone.LIBRARY); if (card.getCardType().contains(CardType.LAND)) { landFound = true; } } } - if (creature != null && !cards.isEmpty()) { + if (!cards.isEmpty()) { player.revealCards("Trepanation Blade", cards, game); game.getState().setValue(source.getSourceId().toString() + "_TrepanationBlade", cards.size()); return true; diff --git a/Mage.Sets/src/mage/sets/invasion/Opt.java b/Mage.Sets/src/mage/sets/invasion/Opt.java index 975648f929..471dda01c3 100644 --- a/Mage.Sets/src/mage/sets/invasion/Opt.java +++ b/Mage.Sets/src/mage/sets/invasion/Opt.java @@ -102,11 +102,11 @@ class OptEffect extends OneShotEffect { } TargetCard target1 = new TargetCard(Zone.PICK, filter1); // move cards to the bottom of the library - while (cards.size() > 0 && player.choose(Outcome.Detriment, cards, target1, game)) { + while (cards.size() > 0 && player.isInGame() && player.choose(Outcome.Detriment, cards, target1, game)) { Card card = cards.get(target1.getFirstTarget(), game); if (card != null) { cards.remove(card); - card.moveToZone(Zone.LIBRARY, source.getId(), game, false); + card.moveToZone(Zone.LIBRARY, source.getSourceId(), game, false); } target1.clearChosen(); } diff --git a/Mage.Sets/src/mage/sets/journeyintonyx/NessianGameWarden.java b/Mage.Sets/src/mage/sets/journeyintonyx/NessianGameWarden.java index e918ccf9e6..5afd4ba398 100644 --- a/Mage.Sets/src/mage/sets/journeyintonyx/NessianGameWarden.java +++ b/Mage.Sets/src/mage/sets/journeyintonyx/NessianGameWarden.java @@ -135,7 +135,7 @@ class NessianGameWardenEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/judgment/FlashOfInsight.java b/Mage.Sets/src/mage/sets/judgment/FlashOfInsight.java index 775982734d..a0ae6cd44d 100644 --- a/Mage.Sets/src/mage/sets/judgment/FlashOfInsight.java +++ b/Mage.Sets/src/mage/sets/judgment/FlashOfInsight.java @@ -143,7 +143,7 @@ class FlashOfInsightEffect extends OneShotEffect { .append(" card").append(cards.size() > 1 ? "s":"") .append(" on the bottom of his or her library").toString()); } - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/limitedalpha/NaturalSelection.java b/Mage.Sets/src/mage/sets/limitedalpha/NaturalSelection.java index 6470a23927..2ef7ae41f2 100644 --- a/Mage.Sets/src/mage/sets/limitedalpha/NaturalSelection.java +++ b/Mage.Sets/src/mage/sets/limitedalpha/NaturalSelection.java @@ -110,7 +110,7 @@ class NaturalSelectionEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the top of target player's library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { you.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/magic2010/MirrorOfFate.java b/Mage.Sets/src/mage/sets/magic2010/MirrorOfFate.java index 588ff70a74..38706a92ed 100644 --- a/Mage.Sets/src/mage/sets/magic2010/MirrorOfFate.java +++ b/Mage.Sets/src/mage/sets/magic2010/MirrorOfFate.java @@ -115,7 +115,7 @@ class MirrorOfFateEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on top of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/magic2010/WarpWorld.java b/Mage.Sets/src/mage/sets/magic2010/WarpWorld.java index 584c0fc306..96f2c63c7c 100644 --- a/Mage.Sets/src/mage/sets/magic2010/WarpWorld.java +++ b/Mage.Sets/src/mage/sets/magic2010/WarpWorld.java @@ -91,20 +91,20 @@ class WarpWorldEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - Map> permanentsOwned = new HashMap>(); + Map> permanentsOwned = new HashMap<>(); Collection permanents = game.getBattlefield().getAllPermanents(); for (Permanent permanent : permanents) { List list = permanentsOwned.get(permanent.getOwnerId()); if (list == null) { - list = new ArrayList(); + list = new ArrayList<>(); } list.add(permanent); permanentsOwned.put(permanent.getOwnerId(), list); } // shuffle permanents into owner's library - Map permanentsCount = new HashMap(); + Map permanentsCount = new HashMap<>(); PlayerList playerList = game.getPlayerList(); playerList.setCurrent(game.getActivePlayerId()); Player player = game.getPlayer(game.getActivePlayerId()); @@ -127,7 +127,7 @@ class WarpWorldEffect extends OneShotEffect { } while (!player.getId().equals(game.getActivePlayerId())); - Map cardsRevealed = new HashMap(); + Map cardsRevealed = new HashMap<>(); // draw cards and reveal them playerList.setCurrent(game.getActivePlayerId()); @@ -155,9 +155,9 @@ class WarpWorldEffect extends OneShotEffect { do { CardsImpl cards = cardsRevealed.get(player.getId()); for (Card card : cards.getCards(game)) { - if (card != null && card.getCardType().contains(CardType.ARTIFACT) + if (card != null && (card.getCardType().contains(CardType.ARTIFACT) || card.getCardType().contains(CardType.CREATURE) - || card.getCardType().contains(CardType.LAND)) { + || card.getCardType().contains(CardType.LAND))) { card.putOntoBattlefield(game, Zone.HAND, source.getSourceId(), player.getId()); cards.remove(card); } @@ -188,7 +188,7 @@ class WarpWorldEffect extends OneShotEffect { CardsImpl cards = cardsRevealed.get(player.getId()); for (Card card : cards.getCards(game)) { if (card != null) { - card.moveToZone(Zone.GRAVEYARD, source.getId(), game, false); + card.moveToZone(Zone.GRAVEYARD, source.getSourceId(), game, false); } } diff --git a/Mage.Sets/src/mage/sets/magic2011/MassPolymorph.java b/Mage.Sets/src/mage/sets/magic2011/MassPolymorph.java index 269d45cc9b..4f26f7e37a 100644 --- a/Mage.Sets/src/mage/sets/magic2011/MassPolymorph.java +++ b/Mage.Sets/src/mage/sets/magic2011/MassPolymorph.java @@ -95,10 +95,11 @@ class MassPolymorphEffect extends OneShotEffect { while (creatureCards.size() < count && player.getLibrary().size() > 0) { Card card = player.getLibrary().removeFromTop(game); revealed.add(card); - if (card.getCardType().contains(CardType.CREATURE)) + if (card.getCardType().contains(CardType.CREATURE)) { creatureCards.add(card); - else + } else { nonCreatureCards.add(card); + } } player.revealCards("Mass Polymorph", revealed, game); for (Card creatureCard: creatureCards.getCards(game)) { diff --git a/Mage.Sets/src/mage/sets/mirrodin/GoblinCharbelcher.java b/Mage.Sets/src/mage/sets/mirrodin/GoblinCharbelcher.java index 7323317bd0..ea2cd4b788 100644 --- a/Mage.Sets/src/mage/sets/mirrodin/GoblinCharbelcher.java +++ b/Mage.Sets/src/mage/sets/mirrodin/GoblinCharbelcher.java @@ -136,7 +136,7 @@ class GoblinCharbelcherEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/mirrodinbesieged/MitoticManipulation.java b/Mage.Sets/src/mage/sets/mirrodinbesieged/MitoticManipulation.java index 686b010ff2..48e6c701ef 100644 --- a/Mage.Sets/src/mage/sets/mirrodinbesieged/MitoticManipulation.java +++ b/Mage.Sets/src/mage/sets/mirrodinbesieged/MitoticManipulation.java @@ -132,7 +132,7 @@ class MitoticManipulationEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/modernmasters/PetalsOfInsight.java b/Mage.Sets/src/mage/sets/modernmasters/PetalsOfInsight.java index 549a19c232..444a6d6dc7 100644 --- a/Mage.Sets/src/mage/sets/modernmasters/PetalsOfInsight.java +++ b/Mage.Sets/src/mage/sets/modernmasters/PetalsOfInsight.java @@ -107,7 +107,7 @@ class PetalsOfInsightEffect extends OneShotEffect { if (player.chooseUse(outcome, "Put the cards on the bottom of your library in any order?", game)) { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/newphyrexia/PsychicSurgery.java b/Mage.Sets/src/mage/sets/newphyrexia/PsychicSurgery.java index 0244032e46..ae5eb8a65f 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/PsychicSurgery.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/PsychicSurgery.java @@ -146,7 +146,7 @@ class PsychicSurgeryEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on top of his library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/newphyrexia/ShrineOfPiercingVision.java b/Mage.Sets/src/mage/sets/newphyrexia/ShrineOfPiercingVision.java index 23dff2d5a9..3012892614 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/ShrineOfPiercingVision.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/ShrineOfPiercingVision.java @@ -141,7 +141,7 @@ class ShrineOfPiercingVisionEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/ninthedition/TeferisPuzzleBox.java b/Mage.Sets/src/mage/sets/ninthedition/TeferisPuzzleBox.java index f978a2a9fa..1206b06d64 100644 --- a/Mage.Sets/src/mage/sets/ninthedition/TeferisPuzzleBox.java +++ b/Mage.Sets/src/mage/sets/ninthedition/TeferisPuzzleBox.java @@ -96,7 +96,7 @@ class TeferisPuzzleBoxEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/odyssey/TaintedPact.java b/Mage.Sets/src/mage/sets/odyssey/TaintedPact.java index 24d2e9c0cc..5753c8c524 100644 --- a/Mage.Sets/src/mage/sets/odyssey/TaintedPact.java +++ b/Mage.Sets/src/mage/sets/odyssey/TaintedPact.java @@ -90,8 +90,8 @@ class TaintedPactEffect extends OneShotEffect{ if (player == null || sourceCard == null) { return false; } - Set names = new HashSet(); - while (player.getLibrary().size() > 0) { + Set names = new HashSet<>(); + while (player.isInGame() && player.getLibrary().size() > 0) { Card card = player.getLibrary().getFromTop(game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/planeshift/SunkenHope.java b/Mage.Sets/src/mage/sets/planeshift/SunkenHope.java index bb8051d7e7..38b181b449 100644 --- a/Mage.Sets/src/mage/sets/planeshift/SunkenHope.java +++ b/Mage.Sets/src/mage/sets/planeshift/SunkenHope.java @@ -103,7 +103,7 @@ class ReturnToHandEffect extends OneShotEffect { target.setRequired(true); if (target.canChoose(player.getId(), game)) { - while (!target.isChosen() && target.canChoose(player.getId(), game)) { + while (player.isInGame() && !target.isChosen() && target.canChoose(player.getId(), game)) { player.chooseTarget(Outcome.ReturnToHand, target, source, game); } diff --git a/Mage.Sets/src/mage/sets/ravnika/Mindmoil.java b/Mage.Sets/src/mage/sets/ravnika/Mindmoil.java index 5efad27654..7d02039eae 100644 --- a/Mage.Sets/src/mage/sets/ravnika/Mindmoil.java +++ b/Mage.Sets/src/mage/sets/ravnika/Mindmoil.java @@ -93,7 +93,7 @@ class MindmoilEffect extends OneShotEffect { } TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (you.isInGame() && cards.size() > 1) { you.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java b/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java index 3af50e4709..17576fda6e 100644 --- a/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java +++ b/Mage.Sets/src/mage/sets/returntoravnica/JaceArchitectOfThought.java @@ -306,7 +306,7 @@ class JaceArchitectOfThoughtEffect2 extends OneShotEffect { TargetCard targetCard = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); targetCard.setRequired(true); - while (cardsToLibrary.size() > 1) { + while (player.isInGame() && cardsToLibrary.size() > 1) { player.choose(Outcome.Neutral, cardsToLibrary, targetCard, game); Card card = cardsToLibrary.get(targetCard.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/HellcarverDemon.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/HellcarverDemon.java index 76be920943..8be15ed14e 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/HellcarverDemon.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/HellcarverDemon.java @@ -114,7 +114,7 @@ class HellcarverDemonEffect extends OneShotEffect { } } - while (player != null && player.chooseUse(Outcome.PlayForFree, "Cast another nonland card exiled with Hellcarver Demon without paying that card's mana cost?", game)) { + while (player != null && player.isInGame() && player.chooseUse(Outcome.PlayForFree, "Cast another nonland card exiled with Hellcarver Demon without paying that card's mana cost?", game)) { TargetCardInExile target = new TargetCardInExile(filter, source.getSourceId()); while (player.choose(Outcome.PlayForFree, game.getExile().getExileZone(source.getSourceId()), target, game)) { Card card = game.getCard(target.getFirstTarget()); diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/JaddiLifestrider.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/JaddiLifestrider.java index 590f026804..d6a3edc3d9 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/JaddiLifestrider.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/JaddiLifestrider.java @@ -100,15 +100,16 @@ class JaddiLifestriderEffect extends OneShotEffect { TargetCreaturePermanent target = new TargetCreaturePermanent(filter); while (true) { target.clearChosen(); - if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getId(), game)) { + if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.Tap, source.getControllerId(), source.getSourceId(), game)) { UUID creature = target.getFirstTarget(); if (creature != null) { game.getPermanent(creature).tap(game); tappedAmount++; } } - else + else { break; + } } if (tappedAmount > 0) { you.gainLife(tappedAmount * 2, game); diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/CloneShell.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/CloneShell.java index b95a86e1e9..a0c730339a 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/CloneShell.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/CloneShell.java @@ -126,7 +126,7 @@ class CloneShellEffect extends OneShotEffect { if (cards.size() > 0) { TargetCard target2 = new TargetCard(Zone.PICK, filter2); target2.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Benefit, cards, target2, game); Card card = cards.get(target2.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java b/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java index 9334c7d3d1..35999caa07 100644 --- a/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java +++ b/Mage.Sets/src/mage/sets/scarsofmirrodin/ShapeAnew.java @@ -106,10 +106,11 @@ public class ShapeAnew extends CardImpl { while (artifactCard == null && player.getLibrary().size() > 0) { Card card = player.getLibrary().removeFromTop(game); revealed.add(card); - if (card.getCardType().contains(CardType.ARTIFACT)) + if (card.getCardType().contains(CardType.ARTIFACT)) { artifactCard = card; - else + } else { nonArtifactCards.add(card); + } } player.revealCards("Shape Anew", revealed, game); if (artifactCard != null) { diff --git a/Mage.Sets/src/mage/sets/shardsofalara/GiftOfTheGargantuan.java b/Mage.Sets/src/mage/sets/shardsofalara/GiftOfTheGargantuan.java index 68100f13e1..e79861c0c0 100644 --- a/Mage.Sets/src/mage/sets/shardsofalara/GiftOfTheGargantuan.java +++ b/Mage.Sets/src/mage/sets/shardsofalara/GiftOfTheGargantuan.java @@ -143,7 +143,7 @@ class GiftOfTheGargantuanEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/tempest/ScrollRack.java b/Mage.Sets/src/mage/sets/tempest/ScrollRack.java index 579c89168f..cbc2d0a257 100644 --- a/Mage.Sets/src/mage/sets/tempest/ScrollRack.java +++ b/Mage.Sets/src/mage/sets/tempest/ScrollRack.java @@ -90,9 +90,10 @@ class ScrollRackEffect extends OneShotEffect { FilterCard filter = new FilterCard("card in your hand to exile"); FilterCard filter2 = new FilterCard("card exiled by Scroll Rack to put on top of library"); Player you = game.getPlayer(source.getControllerId()); - TargetCardInHand target = new TargetCardInHand(0, you.getHand().size(), filter); - int amountExiled = 0; + if (you != null) { + TargetCardInHand target = new TargetCardInHand(0, you.getHand().size(), filter); + int amountExiled = 0; if (target.canChoose(source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getId(), game)) { if (!target.getTargets().isEmpty()) { List targets = target.getTargets(); @@ -121,10 +122,8 @@ class ScrollRackEffect extends OneShotEffect { ExileZone scrollRackExileZone = game.getExile().getExileZone(source.getSourceId()); target2.setRequired(true); if (scrollRackExileZone != null) { - while (scrollRackExileZone.count(filter, game) > 1) { - if (you != null) { - you.lookAtCards("exiled cards with " + game.getCard(source.getSourceId()).getName(), scrollRackExileZone, game); - } + while (you.isInGame() && scrollRackExileZone.count(filter, game) > 1) { + you.lookAtCards("exiled cards with " + game.getCard(source.getSourceId()).getName(), scrollRackExileZone, game); you.choose(Outcome.Neutral, scrollRackExileZone, target2, game); Card card = game.getCard(target2.getFirstTarget()); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/tenth/Scalpelexis.java b/Mage.Sets/src/mage/sets/tenth/Scalpelexis.java index 16e823b257..faeaf9a9e1 100644 --- a/Mage.Sets/src/mage/sets/tenth/Scalpelexis.java +++ b/Mage.Sets/src/mage/sets/tenth/Scalpelexis.java @@ -95,7 +95,7 @@ class ScalpelexisEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player player = game.getPlayer(targetPointer.getFirst(game, source)); - List namesFiltered = new ArrayList(); + List namesFiltered = new ArrayList<>(); boolean doneOnce = false; while (checkDuplicatedNames(namesFiltered) || !doneOnce) { @@ -114,16 +114,18 @@ class ScalpelexisEffect extends OneShotEffect { } public boolean checkDuplicatedNames(List string) { - for (int i = 0; i < string.size()-1; i++) { + for (int i = 0; i < string.size() - 1; i++) { String stringToCheck = string.get(i); - if(stringToCheck == null) continue; //empty ignore - for (int j = i+1; j < string.size(); j++) { - String stringToCompare = string.get(j); - if (stringToCheck.equals(stringToCompare)){ - return true; - } + if (stringToCheck == null) { + continue; //empty ignore + } + for (int j = i + 1; j < string.size(); j++) { + String stringToCompare = string.get(j); + if (stringToCheck.equals(stringToCompare)) { + return true; } - } - return false; + } + } + return false; } } \ No newline at end of file diff --git a/Mage.Sets/src/mage/sets/theros/BowOfNylea.java b/Mage.Sets/src/mage/sets/theros/BowOfNylea.java index 2ed696deb0..41f8a176d0 100644 --- a/Mage.Sets/src/mage/sets/theros/BowOfNylea.java +++ b/Mage.Sets/src/mage/sets/theros/BowOfNylea.java @@ -153,7 +153,7 @@ class PutCardsFromGraveyardToLibraryEffect extends OneShotEffect { if (!cards.isEmpty()) { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("on bottom of your library (last chosen will be on bottom)")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/HarmonicConvergence.java b/Mage.Sets/src/mage/sets/urzaslegacy/HarmonicConvergence.java index 580d9c5a25..946c7c2281 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/HarmonicConvergence.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/HarmonicConvergence.java @@ -118,7 +118,7 @@ class HarmonicConvergenceEffect extends OneShotEffect { for (Permanent permanent : list) { cards.add(permanent); } - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Permanent permanent = game.getPermanent(target.getFirstTarget()); if (permanent != null) { diff --git a/Mage.Sets/src/mage/sets/urzaslegacy/RavenFamiliar.java b/Mage.Sets/src/mage/sets/urzaslegacy/RavenFamiliar.java index a3b2c8d224..a0f5895b9a 100644 --- a/Mage.Sets/src/mage/sets/urzaslegacy/RavenFamiliar.java +++ b/Mage.Sets/src/mage/sets/urzaslegacy/RavenFamiliar.java @@ -126,7 +126,7 @@ public class RavenFamiliar extends CardImpl { target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/visions/GoblinRecruiter.java b/Mage.Sets/src/mage/sets/visions/GoblinRecruiter.java index 2b28694ec2..13235082fe 100644 --- a/Mage.Sets/src/mage/sets/visions/GoblinRecruiter.java +++ b/Mage.Sets/src/mage/sets/visions/GoblinRecruiter.java @@ -122,7 +122,7 @@ class GoblinRecruiterEffect extends OneShotEffect { if (cards.size() > 1) { TargetCard targetCard = new TargetCard(Zone.LIBRARY, putOnTopOfLibraryFilter); targetCard.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Benefit, cards, targetCard, game); Card card = cards.get(targetCard.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/zendikar/MerfolkWayfinder.java b/Mage.Sets/src/mage/sets/zendikar/MerfolkWayfinder.java index 6c0591b4db..366bc28761 100644 --- a/Mage.Sets/src/mage/sets/zendikar/MerfolkWayfinder.java +++ b/Mage.Sets/src/mage/sets/zendikar/MerfolkWayfinder.java @@ -118,7 +118,7 @@ class MerfolkWayfinderEffect extends OneShotEffect { TargetCard target = new TargetCard(Zone.PICK, new FilterCard("card to put on the bottom of your library")); target.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Neutral, cards, target, game); Card card = cards.get(target.getFirstTarget(), game); if (card != null) { diff --git a/Mage.Sets/src/mage/sets/zendikar/SummoningTrap.java b/Mage.Sets/src/mage/sets/zendikar/SummoningTrap.java index fcf068795b..22d4f1fba1 100644 --- a/Mage.Sets/src/mage/sets/zendikar/SummoningTrap.java +++ b/Mage.Sets/src/mage/sets/zendikar/SummoningTrap.java @@ -198,7 +198,7 @@ class SummoningTrapEffect extends OneShotEffect { new FilterCard( "card to put on the bottom of your library")); target2.setRequired(true); - while (cards.size() > 1) { + while (player.isInGame() && cards.size() > 1) { player.choose(Outcome.Benefit, cards, target2, game); Card card = cards.get(target2.getFirstTarget(), game); diff --git a/Mage.Sets/src/mage/sets/zendikar/WorldQueller.java b/Mage.Sets/src/mage/sets/zendikar/WorldQueller.java index 6f76d2d2bc..4af2ef767c 100644 --- a/Mage.Sets/src/mage/sets/zendikar/WorldQueller.java +++ b/Mage.Sets/src/mage/sets/zendikar/WorldQueller.java @@ -86,7 +86,7 @@ public class WorldQueller extends CardImpl { class WorldQuellerEffect extends OneShotEffect { - private static final HashSet choice = new LinkedHashSet(); + private static final HashSet choice = new LinkedHashSet<>(); static { choice.add(CardType.ARTIFACT.toString()); @@ -115,13 +115,13 @@ class WorldQuellerEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - List chosen = new ArrayList(); + List chosen = new ArrayList<>(); Player you = game.getPlayer(source.getControllerId()); Permanent sourceCreature = game.getPermanent(source.getSourceId()); if (you != null && sourceCreature != null) { Choice choiceImpl = new ChoiceImpl(); choiceImpl.setChoices(choice); - while (!you.choose(Outcome.Neutral, choiceImpl, game)) {}; + while (you.isInGame() && !you.choose(Outcome.Neutral, choiceImpl, game)) {} CardType type = null; String choosenType = choiceImpl.getChoice(); @@ -142,51 +142,52 @@ class WorldQuellerEffect extends OneShotEffect { } else if (choosenType.equals(CardType.TRIBAL.toString())) { type = CardType.TRIBAL; } + if (type != null) { + FilterPermanent filter = new FilterControlledPermanent(new StringBuilder("permanent you control of type ").append(type.toString()).toString()); + filter.add(new CardTypePredicate(type)); - FilterPermanent filter = new FilterControlledPermanent(new StringBuilder("permanent you control of type ").append(type.toString()).toString()); - filter.add(new CardTypePredicate(type)); + TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false); + target.setRequired(true); + target.setNotTarget(true); - TargetPermanent target = new TargetControlledPermanent(1, 1, filter, false); - target.setRequired(true); - target.setNotTarget(true); - - // you always go first - if (target.canChoose(you.getId(), game)) { - while (!target.isChosen() && target.canChoose(you.getId(), game)) { - you.choose(Outcome.Sacrifice, target, source.getId(), game); - } - Permanent permanent = game.getPermanent(target.getFirstTarget()); - if (permanent != null) { - chosen.add(permanent); - } - } - - target.clearChosen(); - - // opponents follow - for (UUID playerId : game.getPlayerList()) { - if (playerId != you.getId()) { - Player player = game.getPlayer(playerId); - if (target.canChoose(playerId, game)) { - while (!target.isChosen() && target.canChoose(playerId, game)) { - player.choose(Outcome.Sacrifice, target, source.getId(), game); - } - Permanent permanent = game.getPermanent(target.getFirstTarget()); - if (permanent != null) { - chosen.add(permanent); - } - target.clearChosen(); + // you always go first + if (target.canChoose(you.getId(), game)) { + while (you.isInGame() && !target.isChosen() && target.canChoose(you.getId(), game)) { + you.choose(Outcome.Sacrifice, target, source.getId(), game); + } + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent != null) { + chosen.add(permanent); } } - } - // all chosen permanents are sacrificed together - for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { - if (chosen.contains(permanent)) { - permanent.sacrifice(source.getId(), game); + target.clearChosen(); + + // opponents follow + for (UUID playerId : game.getPlayerList()) { + if (playerId != you.getId()) { + Player player = game.getPlayer(playerId); + if (target.canChoose(playerId, game)) { + while (!target.isChosen() && target.canChoose(playerId, game)) { + player.choose(Outcome.Sacrifice, target, source.getId(), game); + } + Permanent permanent = game.getPermanent(target.getFirstTarget()); + if (permanent != null) { + chosen.add(permanent); + } + target.clearChosen(); + } + } } + + // all chosen permanents are sacrificed together + for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) { + if (chosen.contains(permanent)) { + permanent.sacrifice(source.getId(), game); + } + } + return true; } - return true; } return false; } diff --git a/Mage/src/mage/players/PlayerImpl.java b/Mage/src/mage/players/PlayerImpl.java index 78e5da9122..c3a1d89919 100644 --- a/Mage/src/mage/players/PlayerImpl.java +++ b/Mage/src/mage/players/PlayerImpl.java @@ -2254,10 +2254,17 @@ public abstract class PlayerImpl implements Player, Serializable { public boolean moveCardToLibraryWithInfo(Card card, UUID sourceId, Game game, Zone fromZone, boolean toTop, boolean withName) { boolean result = false; if (card.moveToZone(Zone.LIBRARY, sourceId, game, toTop)) { - game.informPlayers(new StringBuilder(this.getName()) - .append(" puts ").append(withName ? card.getName():"a card").append(" ") - .append(fromZone != null ? new StringBuilder("from ").append(fromZone.toString().toLowerCase(Locale.ENGLISH)).append(" "):"") - .append("to the ").append(toTop ? "top":"bottom").append(" of his or her library").toString()); + StringBuilder sb = new StringBuilder(this.getName()) + .append(" puts ").append(withName ? card.getName():"a card").append(" "); + if (fromZone != null) { + if (fromZone.equals(Zone.PICK)) { + sb.append("a picked card "); + } else { + sb.append("from ").append(fromZone.toString().toLowerCase(Locale.ENGLISH)).append(" "); + } + } + sb.append("to the ").append(toTop ? "top":"bottom").append(" of his or her library"); + game.informPlayers(sb.toString()); result = true; } return result;