From fc754372bd4f586a9c75f1fb2e43d0717a515e37 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 01:09:35 +0100 Subject: [PATCH 01/11] Implemented Panglacial Wurm --- .../WhileSearchingPlayFromLibraryAbility.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 Mage/src/main/java/mage/abilities/common/WhileSearchingPlayFromLibraryAbility.java diff --git a/Mage/src/main/java/mage/abilities/common/WhileSearchingPlayFromLibraryAbility.java b/Mage/src/main/java/mage/abilities/common/WhileSearchingPlayFromLibraryAbility.java new file mode 100644 index 0000000000..4de0428289 --- /dev/null +++ b/Mage/src/main/java/mage/abilities/common/WhileSearchingPlayFromLibraryAbility.java @@ -0,0 +1,67 @@ +/* + * Copyright 2011 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.abilities.common; + +import mage.abilities.MageSingleton; +import mage.abilities.StaticAbility; + +import java.io.ObjectStreamException; + +import mage.constants.AbilityType; +import mage.constants.Zone; + +/** + * @author L_J + */ +public class WhileSearchingPlayFromLibraryAbility extends StaticAbility implements MageSingleton { + + private static final WhileSearchingPlayFromLibraryAbility instance = new WhileSearchingPlayFromLibraryAbility(); + + private Object readResolve() throws ObjectStreamException { + return instance; + } + + public static WhileSearchingPlayFromLibraryAbility getInstance() { + return instance; + } + + private WhileSearchingPlayFromLibraryAbility() { + super(AbilityType.STATIC, Zone.LIBRARY); + } + + @Override + public String getRule() { + return "While you're searching your library, you may cast {this} from your library."; + } + + @Override + public WhileSearchingPlayFromLibraryAbility copy() { + return instance; + } + +} From 22e149057323cacef74486509277a3785e7e2e85 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 01:11:25 +0100 Subject: [PATCH 02/11] Implemented Panglacial Wurm --- .../src/mage/cards/p/PanglacialWurm.java | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Mage.Sets/src/mage/cards/p/PanglacialWurm.java diff --git a/Mage.Sets/src/mage/cards/p/PanglacialWurm.java b/Mage.Sets/src/mage/cards/p/PanglacialWurm.java new file mode 100644 index 0000000000..889eba921a --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PanglacialWurm.java @@ -0,0 +1,66 @@ +/* + * 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.cards.p; + +import java.util.UUID; +import mage.MageInt; +import mage.abilities.common.WhileSearchingPlayFromLibraryAbility; +import mage.abilities.keyword.TrampleAbility; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.SubType; + +/** + * + * @author L_J + */ +public class PanglacialWurm extends CardImpl { + + public PanglacialWurm(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.CREATURE}, "{5}{G}{G}"); + this.subtype.add(SubType.WURM); + this.power = new MageInt(9); + this.toughness = new MageInt(5); + + // Trample + this.addAbility(TrampleAbility.getInstance()); + + // While you're searching your library, you may cast Panglacial Wurm from your library. + this.addAbility(WhileSearchingPlayFromLibraryAbility.getInstance()); + } + + public PanglacialWurm(final PanglacialWurm card) { + super(card); + } + + @Override + public PanglacialWurm copy() { + return new PanglacialWurm(this); + } +} From 4acb6ba6d209b60ed841015aec17c5bb8544066a Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 01:12:50 +0100 Subject: [PATCH 03/11] Implemented Panglacial Wurm --- Mage.Sets/src/mage/sets/Coldsnap.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Mage.Sets/src/mage/sets/Coldsnap.java b/Mage.Sets/src/mage/sets/Coldsnap.java index 5d924af0ca..1709fb4e29 100644 --- a/Mage.Sets/src/mage/sets/Coldsnap.java +++ b/Mage.Sets/src/mage/sets/Coldsnap.java @@ -139,6 +139,7 @@ public class Coldsnap extends ExpansionSet { cards.add(new SetCardInfo("Ohran Viper", 115, Rarity.RARE, mage.cards.o.OhranViper.class)); cards.add(new SetCardInfo("Ohran Yeti", 93, Rarity.COMMON, mage.cards.o.OhranYeti.class)); cards.add(new SetCardInfo("Orcish Bloodpainter", 94, Rarity.COMMON, mage.cards.o.OrcishBloodpainter.class)); + cards.add(new SetCardInfo("Panglacial Wurm", 116, Rarity.RARE, mage.cards.p.PanglacialWurm.class)); cards.add(new SetCardInfo("Perilous Research", 41, Rarity.UNCOMMON, mage.cards.p.PerilousResearch.class)); cards.add(new SetCardInfo("Phobian Phantasm", 66, Rarity.UNCOMMON, mage.cards.p.PhobianPhantasm.class)); cards.add(new SetCardInfo("Phyrexian Etchings", 67, Rarity.RARE, mage.cards.p.PhyrexianEtchings.class)); From 5a1a6f703116210da9e3ba77a64a72e1f7b3e9d6 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 01:23:52 +0100 Subject: [PATCH 04/11] Implemented Panglacial Wurm (buggy!) --- .../main/java/mage/players/PlayerImpl.java | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 6233a4ed6f..4db1dc051a 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -36,6 +36,7 @@ import mage.MageObject; import mage.Mana; import mage.abilities.*; import mage.abilities.common.PassAbility; +import mage.abilities.common.WhileSearchingPlayFromLibraryAbility; import mage.abilities.common.delayed.AtTheEndOfTurnStepPostDelayedTriggeredAbility; import mage.abilities.costs.*; import mage.abilities.costs.mana.ManaCost; @@ -53,6 +54,7 @@ import mage.cards.Cards; import mage.cards.CardsImpl; import mage.cards.SplitCard; import mage.cards.decks.Deck; +import mage.choices.ChoiceImpl; import mage.constants.*; import static mage.constants.Zone.BATTLEFIELD; import static mage.constants.Zone.EXILED; @@ -2317,18 +2319,81 @@ public abstract class PlayerImpl implements Player, Serializable { if (count < target.getNumberOfTargets()) { newTarget.setMinNumberOfTargets(count); } - if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - target.getTargets().clear(); - for (UUID targetId : newTarget.getTargets()) { - target.add(targetId, game); + boolean finishedSearch = false; + while (true) { + if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { + target.getTargets().clear(); + for (UUID targetId : newTarget.getTargets()) { + target.add(targetId, game); + } + finishedSearch = true; } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); + Card pickedCard = game.getCard(newTarget.getTargets().get(0)); + if (pickedCard != null) { + } + if (!targetPlayerId.equals(playerId) || handleLibraryCastableCreatures(library, game, targetPlayerId, newTarget)) { // for handling Panglacial Wurm + if (finishedSearch) { + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); + } + break; + } + newTarget.clearChosen(); + finishedSearch = false; } return true; } return false; } + private boolean handleLibraryCastableCreatures(Library library, Game game, UUID targetPlayerId, TargetCardInLibrary newTarget) { + // for handling Panglacial Wurm + Map libraryCastableCardTracker = new HashMap<>(); + for (Card card : library.getCards(game)) { + for (Ability ability : card.getAbilities()) { + if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { + libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); + } + } + } + if (!libraryCastableCardTracker.isEmpty()) { + Player player = game.getPlayer(targetPlayerId); + if (player != null) { + if (player.isHuman() && player.chooseUse(Outcome.AIDontUseIt, "Cast a creature card from your library? (choose \"No\" to finish search)", null, game)) { + ChoiceImpl chooseCard = new ChoiceImpl(); + chooseCard.setMessage("Which creature do you wish to cast from your library?"); + Set choice = new LinkedHashSet<>(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + choice.add(new java.util.AbstractMap.SimpleEntry(entry).getValue()); + } + chooseCard.setChoices(choice); + while (!choice.isEmpty()) { + if (player.choose(Outcome.AIDontUseIt, chooseCard, game)) { + String chosenCard = chooseCard.getChoice(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + if (chosenCard.equals(entry.getValue())) { + Card card = game.getCard(entry.getKey()); + if (card != null) { + // TODO: fix first target being impossible to rechoose + // TODO: fix costs (why is Panglacial Wurm automatically accepting payment?) + if (player.cast(card.getSpellAbility(), game, false)) { + choice.remove(chosenCard); + chooseCard.setChoices(choice); + newTarget.remove(card.getId()); + } + } + } + } + continue; + } + break; + } + return false; + } + } + } + return true; + } + @Override public boolean flipCoin(Game game) { return this.flipCoin(game, null); From d671c2a06ca5ffaef37a9f710f7068a7dbb96993 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 02:03:36 +0100 Subject: [PATCH 05/11] Plenty of Panglacial Wurm fixes --- .../main/java/mage/players/PlayerImpl.java | 60 ++++++++++++++++--- 1 file changed, 52 insertions(+), 8 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 4db1dc051a..44658da97a 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2322,17 +2322,14 @@ public abstract class PlayerImpl implements Player, Serializable { boolean finishedSearch = false; while (true) { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - target.getTargets().clear(); - for (UUID targetId : newTarget.getTargets()) { - target.add(targetId, game); - } finishedSearch = true; } - Card pickedCard = game.getCard(newTarget.getTargets().get(0)); - if (pickedCard != null) { - } - if (!targetPlayerId.equals(playerId) || handleLibraryCastableCreatures(library, game, targetPlayerId, newTarget)) { // for handling Panglacial Wurm + if (!targetPlayerId.equals(playerId) || handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm if (finishedSearch) { + target.getTargets().clear(); + for (UUID targetId : newTarget.getTargets()) { + target.add(targetId, game); + } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); } break; @@ -2345,6 +2342,53 @@ public abstract class PlayerImpl implements Player, Serializable { return false; } + private boolean handleLibraryCastableCreatures(Library library, Game game, UUID targetPlayerId) { + // for handling Panglacial Wurm + Map libraryCastableCardTracker = new HashMap<>(); + for (Card card : library.getCards(game)) { + for (Ability ability : card.getAbilities()) { + if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { + libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); + } + } + } + if (!libraryCastableCardTracker.isEmpty()) { + Player player = game.getPlayer(targetPlayerId); + if (player != null) { + if (player.isHuman() && player.chooseUse(Outcome.AIDontUseIt, "Cast a creature card from your library? (choose \"No\" to finish search)", null, game)) { + ChoiceImpl chooseCard = new ChoiceImpl(); + chooseCard.setMessage("Which creature do you wish to cast from your library?"); + Set choice = new LinkedHashSet<>(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + choice.add(new AbstractMap.SimpleEntry(entry).getValue()); + } + chooseCard.setChoices(choice); + while (!choice.isEmpty()) { + if (player.choose(Outcome.AIDontUseIt, chooseCard, game)) { + String chosenCard = chooseCard.getChoice(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + if (chosenCard.equals(entry.getValue())) { + Card card = game.getCard(entry.getKey()); + if (card != null) { + // TODO: fix costs (why is Panglacial Wurm automatically accepting payment?) + if (player.cast(card.getSpellAbility(), game, false)) { + choice.remove(chosenCard); + chooseCard.setChoices(choice); + } + } + } + } + continue; + } + break; + } + return false; + } + } + } + return true; + } + private boolean handleLibraryCastableCreatures(Library library, Game game, UUID targetPlayerId, TargetCardInLibrary newTarget) { // for handling Panglacial Wurm Map libraryCastableCardTracker = new HashMap<>(); From 818a005b59bee532ee69267c44c684e6462e2e46 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 02:06:39 +0100 Subject: [PATCH 06/11] Fixed double copypaste --- .../main/java/mage/players/PlayerImpl.java | 53 +------------------ 1 file changed, 2 insertions(+), 51 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 44658da97a..79a5161427 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2324,7 +2324,7 @@ public abstract class PlayerImpl implements Player, Serializable { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { finishedSearch = true; } - if (!targetPlayerId.equals(playerId) || handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm + if (!targetPlayerId.equals(playerId) || handleLibraryCastableCards(library, game, targetPlayerId)) { // for handling Panglacial Wurm if (finishedSearch) { target.getTargets().clear(); for (UUID targetId : newTarget.getTargets()) { @@ -2342,7 +2342,7 @@ public abstract class PlayerImpl implements Player, Serializable { return false; } - private boolean handleLibraryCastableCreatures(Library library, Game game, UUID targetPlayerId) { + private boolean handleLibraryCastableCards(Library library, Game game, UUID targetPlayerId) { // for handling Panglacial Wurm Map libraryCastableCardTracker = new HashMap<>(); for (Card card : library.getCards(game)) { @@ -2389,55 +2389,6 @@ public abstract class PlayerImpl implements Player, Serializable { return true; } - private boolean handleLibraryCastableCreatures(Library library, Game game, UUID targetPlayerId, TargetCardInLibrary newTarget) { - // for handling Panglacial Wurm - Map libraryCastableCardTracker = new HashMap<>(); - for (Card card : library.getCards(game)) { - for (Ability ability : card.getAbilities()) { - if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { - libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); - } - } - } - if (!libraryCastableCardTracker.isEmpty()) { - Player player = game.getPlayer(targetPlayerId); - if (player != null) { - if (player.isHuman() && player.chooseUse(Outcome.AIDontUseIt, "Cast a creature card from your library? (choose \"No\" to finish search)", null, game)) { - ChoiceImpl chooseCard = new ChoiceImpl(); - chooseCard.setMessage("Which creature do you wish to cast from your library?"); - Set choice = new LinkedHashSet<>(); - for (Entry entry : libraryCastableCardTracker.entrySet()) { - choice.add(new java.util.AbstractMap.SimpleEntry(entry).getValue()); - } - chooseCard.setChoices(choice); - while (!choice.isEmpty()) { - if (player.choose(Outcome.AIDontUseIt, chooseCard, game)) { - String chosenCard = chooseCard.getChoice(); - for (Entry entry : libraryCastableCardTracker.entrySet()) { - if (chosenCard.equals(entry.getValue())) { - Card card = game.getCard(entry.getKey()); - if (card != null) { - // TODO: fix first target being impossible to rechoose - // TODO: fix costs (why is Panglacial Wurm automatically accepting payment?) - if (player.cast(card.getSpellAbility(), game, false)) { - choice.remove(chosenCard); - chooseCard.setChoices(choice); - newTarget.remove(card.getId()); - } - } - } - } - continue; - } - break; - } - return false; - } - } - } - return true; - } - @Override public boolean flipCoin(Game game) { return this.flipCoin(game, null); From c675f3b4d10b3f7af13888d577cead6678fc3a94 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 02:26:14 +0100 Subject: [PATCH 07/11] Cleanup, improvements etc. --- .../main/java/mage/players/PlayerImpl.java | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 79a5161427..ebe58d9b41 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2319,24 +2319,21 @@ public abstract class PlayerImpl implements Player, Serializable { if (count < target.getNumberOfTargets()) { newTarget.setMinNumberOfTargets(count); } - boolean finishedSearch = false; - while (true) { + do { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - finishedSearch = true; - } - if (!targetPlayerId.equals(playerId) || handleLibraryCastableCards(library, game, targetPlayerId)) { // for handling Panglacial Wurm - if (finishedSearch) { + if (!targetPlayerId.equals(playerId) || !handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm target.getTargets().clear(); for (UUID targetId : newTarget.getTargets()) { target.add(targetId, game); } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); } - break; + } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCreatures(library, game, targetPlayerId)) { + newTarget.clearChosen(); + continue; } - newTarget.clearChosen(); - finishedSearch = false; - } + break; + } while (true); return true; } return false; @@ -2382,11 +2379,11 @@ public abstract class PlayerImpl implements Player, Serializable { } break; } - return false; + return true; } } } - return true; + return false; } @Override From 310764814fe95e703553c70292057ae88c426843 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 02:42:32 +0100 Subject: [PATCH 08/11] Minor fix --- Mage/src/main/java/mage/players/PlayerImpl.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index ebe58d9b41..8b8206eca1 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2321,13 +2321,15 @@ public abstract class PlayerImpl implements Player, Serializable { } do { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - if (!targetPlayerId.equals(playerId) || !handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm - target.getTargets().clear(); - for (UUID targetId : newTarget.getTargets()) { - target.add(targetId, game); - } - game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); + if (targetPlayerId.equals(playerId) && handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm + newTarget.clearChosen(); + continue; } + target.getTargets().clear(); + for (UUID targetId : newTarget.getTargets()) { + target.add(targetId, game); + } + game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCreatures(library, game, targetPlayerId)) { newTarget.clearChosen(); continue; From 4c5dc3f8392e87a8b5d18ca9938ad62aae1dd245 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 03:09:56 +0100 Subject: [PATCH 09/11] Fix attempt --- Mage/src/main/java/mage/players/PlayerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 8b8206eca1..5d800a4176 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2321,7 +2321,7 @@ public abstract class PlayerImpl implements Player, Serializable { } do { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - if (targetPlayerId.equals(playerId) && handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm + if (targetPlayerId.equals(playerId) && this.handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm newTarget.clearChosen(); continue; } @@ -2330,7 +2330,7 @@ public abstract class PlayerImpl implements Player, Serializable { target.add(targetId, game); } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); - } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCreatures(library, game, targetPlayerId)) { + } else if (targetPlayerId.equals(playerId) && this.handleLibraryCastableCreatures(library, game, targetPlayerId)) { newTarget.clearChosen(); continue; } From 1f5ab92e9da180fc339fe33938c16fbfc4b811a6 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 03:15:17 +0100 Subject: [PATCH 10/11] Fix attempt --- Mage/src/main/java/mage/players/PlayerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 5d800a4176..2316ec3001 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2321,7 +2321,7 @@ public abstract class PlayerImpl implements Player, Serializable { } do { if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { - if (targetPlayerId.equals(playerId) && this.handleLibraryCastableCreatures(library, game, targetPlayerId)) { // for handling Panglacial Wurm + if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library, game, targetPlayerId)) { // for handling Panglacial Wurm newTarget.clearChosen(); continue; } @@ -2330,7 +2330,7 @@ public abstract class PlayerImpl implements Player, Serializable { target.add(targetId, game); } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); - } else if (targetPlayerId.equals(playerId) && this.handleLibraryCastableCreatures(library, game, targetPlayerId)) { + } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library, game, targetPlayerId)) { newTarget.clearChosen(); continue; } From 0f61bdeabd14dc5d4d2411ee4e02554088c8f913 Mon Sep 17 00:00:00 2001 From: Zzooouhh Date: Sat, 30 Dec 2017 06:14:45 +0100 Subject: [PATCH 11/11] Lot of progress on Panglacial Wurm quirks --- .../main/java/mage/players/PlayerImpl.java | 102 ++++++++++-------- 1 file changed, 59 insertions(+), 43 deletions(-) diff --git a/Mage/src/main/java/mage/players/PlayerImpl.java b/Mage/src/main/java/mage/players/PlayerImpl.java index 2316ec3001..1301f19697 100644 --- a/Mage/src/main/java/mage/players/PlayerImpl.java +++ b/Mage/src/main/java/mage/players/PlayerImpl.java @@ -2309,17 +2309,27 @@ public abstract class PlayerImpl implements Player, Serializable { TargetCardInLibrary newTarget = target.copy(); int count; int librarySearchLimit = event.getAmount(); - if (librarySearchLimit == Integer.MAX_VALUE) { - count = searchedLibrary.count(target.getFilter(), game); - } else { - newTarget.setCardLimit(librarySearchLimit); - count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit); - } - - if (count < target.getNumberOfTargets()) { - newTarget.setMinNumberOfTargets(count); - } + List cardsFromTop = null; do { + // TODO: prevent shuffling from moving the visualized cards + if (librarySearchLimit == Integer.MAX_VALUE) { + count = searchedLibrary.count(target.getFilter(), game); + } else { + Player targetPlayer = game.getPlayer(targetPlayerId); + if (targetPlayer != null) { + if (cardsFromTop == null) { + cardsFromTop = new ArrayList<>(targetPlayer.getLibrary().getTopCards(game, librarySearchLimit)); + } else { + cardsFromTop.retainAll(targetPlayer.getLibrary().getCards(game)); + } + } + newTarget.setCardLimit(Math.min(librarySearchLimit, cardsFromTop.size())); + count = Math.min(searchedLibrary.count(target.getFilter(), game), librarySearchLimit); + } + + if (count < target.getNumberOfTargets()) { + newTarget.setMinNumberOfTargets(count); + } if (newTarget.choose(Outcome.Neutral, playerId, targetPlayerId, game)) { if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library, game, targetPlayerId)) { // for handling Panglacial Wurm newTarget.clearChosen(); @@ -2330,7 +2340,7 @@ public abstract class PlayerImpl implements Player, Serializable { target.add(targetId, game); } game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LIBRARY_SEARCHED, targetPlayerId, playerId)); - } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library, game, targetPlayerId)) { + } else if (targetPlayerId.equals(playerId) && handleLibraryCastableCards(library, game, targetPlayerId)) { // for handling Panglacial Wurm newTarget.clearChosen(); continue; } @@ -2343,49 +2353,55 @@ public abstract class PlayerImpl implements Player, Serializable { private boolean handleLibraryCastableCards(Library library, Game game, UUID targetPlayerId) { // for handling Panglacial Wurm + boolean alreadyChosenUse = false; Map libraryCastableCardTracker = new HashMap<>(); - for (Card card : library.getCards(game)) { - for (Ability ability : card.getAbilities()) { - if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { - libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); + searchForCards: + do { + for (Card card : library.getCards(game)) { + for (Ability ability : card.getAbilities()) { + if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) { + libraryCastableCardTracker.put(card.getId(), card.getName() + " [" + card.getId().toString().substring(0, 3) + "]"); + } } } - } - if (!libraryCastableCardTracker.isEmpty()) { - Player player = game.getPlayer(targetPlayerId); - if (player != null) { - if (player.isHuman() && player.chooseUse(Outcome.AIDontUseIt, "Cast a creature card from your library? (choose \"No\" to finish search)", null, game)) { - ChoiceImpl chooseCard = new ChoiceImpl(); - chooseCard.setMessage("Which creature do you wish to cast from your library?"); - Set choice = new LinkedHashSet<>(); - for (Entry entry : libraryCastableCardTracker.entrySet()) { - choice.add(new AbstractMap.SimpleEntry(entry).getValue()); - } - chooseCard.setChoices(choice); - while (!choice.isEmpty()) { - if (player.choose(Outcome.AIDontUseIt, chooseCard, game)) { - String chosenCard = chooseCard.getChoice(); - for (Entry entry : libraryCastableCardTracker.entrySet()) { - if (chosenCard.equals(entry.getValue())) { - Card card = game.getCard(entry.getKey()); - if (card != null) { - // TODO: fix costs (why is Panglacial Wurm automatically accepting payment?) - if (player.cast(card.getSpellAbility(), game, false)) { - choice.remove(chosenCard); - chooseCard.setChoices(choice); + if (!libraryCastableCardTracker.isEmpty()) { + Player player = game.getPlayer(targetPlayerId); + if (player != null) { + if (player.isHuman() && (alreadyChosenUse || player.chooseUse(Outcome.AIDontUseIt, "Cast a creature card from your library? (choose \"No\" to finish search)", null, game))) { + ChoiceImpl chooseCard = new ChoiceImpl(); + chooseCard.setMessage("Which creature do you wish to cast from your library?"); + Set choice = new LinkedHashSet<>(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + choice.add(new AbstractMap.SimpleEntry(entry).getValue()); + } + chooseCard.setChoices(choice); + while (!choice.isEmpty()) { + if (player.choose(Outcome.AIDontUseIt, chooseCard, game)) { + String chosenCard = chooseCard.getChoice(); + for (Entry entry : libraryCastableCardTracker.entrySet()) { + if (chosenCard.equals(entry.getValue())) { + Card card = game.getCard(entry.getKey()); + if (card != null) { + // TODO: fix costs (why is Panglacial Wurm automatically accepting payment?) + player.cast(card.getSpellAbility(), game, false); } + chooseCard.clearChoice(); + libraryCastableCardTracker.clear(); + alreadyChosenUse = true; + continue searchForCards; } } + continue; } - continue; + break; } - break; + return true; } - return true; } } - } - return false; + break; + } while (alreadyChosenUse); + return alreadyChosenUse; } @Override