mirror of
https://github.com/correl/mage.git
synced 2024-11-15 11:09:30 +00:00
Lot of progress on Panglacial Wurm quirks
This commit is contained in:
parent
1f5ab92e9d
commit
0f61bdeabd
1 changed files with 59 additions and 43 deletions
|
@ -2309,17 +2309,27 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
TargetCardInLibrary newTarget = target.copy();
|
||||
int count;
|
||||
int librarySearchLimit = event.getAmount();
|
||||
List<Card> cardsFromTop = null;
|
||||
do {
|
||||
// TODO: prevent shuffling from moving the visualized cards
|
||||
if (librarySearchLimit == Integer.MAX_VALUE) {
|
||||
count = searchedLibrary.count(target.getFilter(), game);
|
||||
} else {
|
||||
newTarget.setCardLimit(librarySearchLimit);
|
||||
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);
|
||||
}
|
||||
do {
|
||||
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,7 +2353,10 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
|
||||
private boolean handleLibraryCastableCards(Library library, Game game, UUID targetPlayerId) {
|
||||
// for handling Panglacial Wurm
|
||||
boolean alreadyChosenUse = false;
|
||||
Map<UUID, String> libraryCastableCardTracker = new HashMap<>();
|
||||
searchForCards:
|
||||
do {
|
||||
for (Card card : library.getCards(game)) {
|
||||
for (Ability ability : card.getAbilities()) {
|
||||
if (ability.getClass() == WhileSearchingPlayFromLibraryAbility.class) {
|
||||
|
@ -2354,7 +2367,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
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)) {
|
||||
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<String> choice = new LinkedHashSet<>();
|
||||
|
@ -2370,11 +2383,12 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
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);
|
||||
}
|
||||
player.cast(card.getSpellAbility(), game, false);
|
||||
}
|
||||
chooseCard.clearChoice();
|
||||
libraryCastableCardTracker.clear();
|
||||
alreadyChosenUse = true;
|
||||
continue searchForCards;
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
@ -2385,7 +2399,9 @@ public abstract class PlayerImpl implements Player, Serializable {
|
|||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
break;
|
||||
} while (alreadyChosenUse);
|
||||
return alreadyChosenUse;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue