Choose triggers order dialog - fixed game error on remember of multiple instances of the trigger (fixes #11194)

This commit is contained in:
Oleg Agafonov 2023-09-23 20:16:55 +04:00
parent 6cade21c4f
commit 8ebbeef8f4
4 changed files with 15 additions and 15 deletions

View file

@ -1317,7 +1317,7 @@ public class HumanPlayer extends PlayerImpl {
while (canRespond()) { while (canRespond()) {
// try to set trigger auto order // try to set trigger auto order
java.util.List<TriggeredAbility> abilitiesWithNoOrderSet = new ArrayList<>(); java.util.List<TriggeredAbility> abilitiesWithNoOrderSet = new ArrayList<>();
TriggeredAbility abilityOrderLast = null; java.util.List<TriggeredAbility> abilitiesOrderLast = new ArrayList<>();
for (TriggeredAbility ability : abilities) { for (TriggeredAbility ability : abilities) {
if (triggerAutoOrderAbilityFirst.contains(ability.getOriginalId())) { if (triggerAutoOrderAbilityFirst.contains(ability.getOriginalId())) {
return ability; return ability;
@ -1328,20 +1328,20 @@ public class HumanPlayer extends PlayerImpl {
return ability; return ability;
} }
if (triggerAutoOrderAbilityLast.contains(ability.getOriginalId())) { if (triggerAutoOrderAbilityLast.contains(ability.getOriginalId())) {
abilityOrderLast = ability; // multiple instances of same trigger has same originalId, no need to select order for it
abilitiesOrderLast.add(ability);
continue; continue;
} }
if (triggerAutoOrderNameLast.contains(rule)) { if (triggerAutoOrderNameLast.contains(rule)) {
if (abilityOrderLast != null) { abilitiesOrderLast.add(ability);
throw new IllegalArgumentException("Wrong code usage. Only one last ability allows by name");
}
abilityOrderLast = ability;
continue; continue;
} }
if (autoOrderUse) { if (autoOrderUse) {
// multiple triggers with same rule text will be auto-ordered
if (autoOrderRuleText == null) { if (autoOrderRuleText == null) {
autoOrderRuleText = rule; autoOrderRuleText = rule;
} else if (!rule.equals(autoOrderRuleText)) { } else if (!rule.equals(autoOrderRuleText)) {
// diff triggers, so must use choose dialog
autoOrderUse = false; autoOrderUse = false;
} }
} }
@ -1349,7 +1349,8 @@ public class HumanPlayer extends PlayerImpl {
} }
if (abilitiesWithNoOrderSet.isEmpty()) { if (abilitiesWithNoOrderSet.isEmpty()) {
return abilityOrderLast; // user can send diff abilities to the last, will be selected by "first" like first ordered ability above
return abilitiesOrderLast.stream().findFirst().orElse(null);
} }
if (abilitiesWithNoOrderSet.size() == 1 if (abilitiesWithNoOrderSet.size() == 1
@ -1359,9 +1360,8 @@ public class HumanPlayer extends PlayerImpl {
// runtime check: lost triggers for GUI // runtime check: lost triggers for GUI
List<Ability> processingAbilities = new ArrayList<>(abilitiesWithNoOrderSet); List<Ability> processingAbilities = new ArrayList<>(abilitiesWithNoOrderSet);
if (abilityOrderLast != null) { processingAbilities.addAll(abilitiesOrderLast);
processingAbilities.add(abilityOrderLast);
}
if (abilities.size() != processingAbilities.size()) { if (abilities.size() != processingAbilities.size()) {
throw new IllegalStateException(String.format("Choose dialog lost some of the triggered abilities:\n" throw new IllegalStateException(String.format("Choose dialog lost some of the triggered abilities:\n"
+ "Must %d:\n%s\n" + "Must %d:\n%s\n"

View file

@ -26,7 +26,7 @@ public final class BasilicaScreecher extends CardImpl {
// Flying // Flying
this.addAbility(FlyingAbility.getInstance()); this.addAbility(FlyingAbility.getInstance());
// Extort (Whenever you cast a spell, you pay {WB}. If you do, each opponent loses 1 life and you gain that much life.) // Extort (Whenever you cast a spell, you may pay {WB}. If you do, each opponent loses 1 life and you gain that much life.)
this.addAbility(new ExtortAbility()); this.addAbility(new ExtortAbility());
} }

View file

@ -23,7 +23,7 @@ public final class SyndicateEnforcer extends CardImpl {
this.power = new MageInt(3); this.power = new MageInt(3);
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
// Extort (Whenever you cast a spell, you pay {WB}. If you do, each opponent loses 1 life and you gain that much life.) // Extort (Whenever you cast a spell, you may pay {WB}. If you do, each opponent loses 1 life and you gain that much life.)
this.addAbility(new ExtortAbility()); this.addAbility(new ExtortAbility());
} }

View file

@ -22,7 +22,7 @@ public class UserData implements Serializable {
protected boolean manaPoolAutomaticRestricted; protected boolean manaPoolAutomaticRestricted;
protected boolean passPriorityCast; protected boolean passPriorityCast;
protected boolean passPriorityActivation; protected boolean passPriorityActivation;
protected boolean autoOrderTrigger; protected boolean autoOrderTrigger; // auto-order triggers with same rule text
protected int autoTargetLevel; protected int autoTargetLevel;
protected boolean useSameSettingsForReplacementEffects; protected boolean useSameSettingsForReplacementEffects;
protected boolean useFirstManaAbility = false; protected boolean useFirstManaAbility = false;