Fix optional shuffle into Library cases (#6147)

This commit is contained in:
tool4ever
2024-09-15 16:21:39 +02:00
committed by GitHub
parent 653bf46404
commit 91e952da63
7 changed files with 44 additions and 34 deletions

View File

@@ -463,8 +463,7 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
origin.addAll(ZoneType.listValueOf(sa.getParam("Origin")));
}
int libraryPosition = sa.hasParam("LibraryPosition") ?
AbilityUtils.calculateAmount(hostCard, sa.getParam("LibraryPosition"), sa) : 0;
int libraryPosition = sa.hasParam("LibraryPosition") ? AbilityUtils.calculateAmount(hostCard, sa.getParam("LibraryPosition"), sa) : 0;
if (sa.hasParam("DestinationAlternative")) {
Pair<ZoneType, Integer> pair = handleAltDest(sa, hostCard, destination, libraryPosition, activator);
destination = pair.getKey();
@@ -505,6 +504,11 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
final boolean shuffle = sa.hasParam("Shuffle") && "True".equals(sa.getParam("Shuffle"));
boolean combatChanged = false;
if (sa.hasParam("ShuffleNonMandatory") &&
!activator.getController().confirmAction(sa, null, Localizer.getInstance().getMessage("lblDoyouWantShuffleTheLibrary"), null)) {
return;
}
Player chooser = activator;
if (sa.hasParam("Chooser")) {
chooser = AbilityUtils.getDefinedPlayers(hostCard, sa.getParam("Chooser"), sa).get(0);
@@ -537,8 +541,9 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
}
final String prompt = TextUtil.concatWithSpace(Localizer.getInstance().getMessage("lblDoYouWantMoveTargetFromOriToDest", CardTranslation.getTranslatedName(gameCard.getName()), Lang.joinHomogenous(origin, ZoneType::getTranslatedName), destination.getTranslatedName()));
if (optional && !chooser.getController().confirmAction(sa, null, prompt, null))
if (optional && !chooser.getController().confirmAction(sa, null, prompt, null)) {
continue;
}
final Zone originZone = game.getZoneOf(gameCard);
@@ -1047,28 +1052,10 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
player.addController(controlTimestamp, searchControlPlayer.getValue());
}
decider.incLibrarySearched();
// should only count the number of searching player's own library
// Panglacial Wurm
CardCollection canCastWhileSearching = CardLists.getKeyword(fetchList,
"While you're searching your library, you may cast CARDNAME from your library.");
decider.getController().tempShowCards(canCastWhileSearching);
for (final Card tgtCard : canCastWhileSearching) {
List<SpellAbility> sas = AbilityUtils.getSpellsFromPlayEffect(tgtCard, decider, CardStateName.Original, true);
if (sas.isEmpty()) {
continue;
}
SpellAbility tgtSA = decider.getController().getAbilityToPlay(tgtCard, sas);
if (!decider.getController().confirmAction(tgtSA, null, Localizer.getInstance().getMessage("lblDoYouWantPlayCard", CardTranslation.getTranslatedName(tgtCard.getName())), null)) {
continue;
}
// if played, that card cannot be found
if (decider.getController().playSaFromPlayEffect(tgtSA)) {
fetchList.remove(tgtCard);
}
//some kind of reset here?
}
decider.getController().endTempShowCards();
decider.incLibrarySearched();
handleCastWhileSearching(fetchList, decider);
}
final Map<AbilityKey, Object> runParams = AbilityKey.mapFromPlayer(decider);
runParams.put(AbilityKey.Target, Lists.newArrayList(player));
@@ -1507,6 +1494,29 @@ public class ChangeZoneEffect extends SpellAbilityEffect {
}
}
private void handleCastWhileSearching(final CardCollection fetchList, final Player decider) {
// Panglacial Wurm
CardCollection canCastWhileSearching = CardLists.getKeyword(fetchList,
"While you're searching your library, you may cast CARDNAME from your library.");
decider.getController().tempShowCards(canCastWhileSearching);
for (final Card tgtCard : canCastWhileSearching) {
List<SpellAbility> sas = AbilityUtils.getSpellsFromPlayEffect(tgtCard, decider, CardStateName.Original, true);
if (sas.isEmpty()) {
continue;
}
SpellAbility tgtSA = decider.getController().getAbilityToPlay(tgtCard, sas);
if (!decider.getController().confirmAction(tgtSA, null, Localizer.getInstance().getMessage("lblDoYouWantPlayCard", CardTranslation.getTranslatedName(tgtCard.getName())), null)) {
continue;
}
// if played, that card cannot be found
if (decider.getController().playSaFromPlayEffect(tgtSA)) {
fetchList.remove(tgtCard);
}
//some kind of reset here?
}
decider.getController().endTempShowCards();
}
private static class HiddenOriginChoices {
boolean shuffleMandatory;
boolean searchedLibrary;