Skip to content

Commit

Permalink
Choose triggers order dialog - fixed game error on remember of multip…
Browse files Browse the repository at this point in the history
…le instances of the trigger (fixes #11194)
  • Loading branch information
JayDi85 committed Sep 23, 2023
1 parent 6cade21 commit 8ebbeef
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public TriggeredAbility chooseTriggeredAbility(java.util.List<TriggeredAbility>
while (canRespond()) {
// try to set trigger auto order
java.util.List<TriggeredAbility> abilitiesWithNoOrderSet = new ArrayList<>();
TriggeredAbility abilityOrderLast = null;
java.util.List<TriggeredAbility> abilitiesOrderLast = new ArrayList<>();
for (TriggeredAbility ability : abilities) {
if (triggerAutoOrderAbilityFirst.contains(ability.getOriginalId())) {
return ability;
Expand All @@ -1328,28 +1328,29 @@ public TriggeredAbility chooseTriggeredAbility(java.util.List<TriggeredAbility>
return ability;
}
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;
}
if (triggerAutoOrderNameLast.contains(rule)) {
if (abilityOrderLast != null) {
throw new IllegalArgumentException("Wrong code usage. Only one last ability allows by name");
}
abilityOrderLast = ability;
abilitiesOrderLast.add(ability);
continue;
}
if (autoOrderUse) {
// multiple triggers with same rule text will be auto-ordered
if (autoOrderRuleText == null) {
autoOrderRuleText = rule;
} else if (!rule.equals(autoOrderRuleText)) {
// diff triggers, so must use choose dialog
autoOrderUse = false;
}
}
abilitiesWithNoOrderSet.add(ability);
}

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
Expand All @@ -1359,13 +1360,12 @@ public TriggeredAbility chooseTriggeredAbility(java.util.List<TriggeredAbility>

// runtime check: lost triggers for GUI
List<Ability> processingAbilities = new ArrayList<>(abilitiesWithNoOrderSet);
if (abilityOrderLast != null) {
processingAbilities.add(abilityOrderLast);
}
processingAbilities.addAll(abilitiesOrderLast);

if (abilities.size() != processingAbilities.size()) {
throw new IllegalStateException(String.format("Choose dialog lost some of the triggered abilities:\n"
+ "Must %d:\n%s\n"
+ "Has %d:\n%s",
+ "Must %d:\n%s\n"
+ "Has %d:\n%s",
abilities.size(),
abilities.stream().map(Ability::getRule).collect(Collectors.joining("\n")),
processingAbilities.size(),
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/b/BasilicaScreecher.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public BasilicaScreecher(UUID ownerId, CardSetInfo setInfo) {
// Flying
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());
}

Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/s/SyndicateEnforcer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public SyndicateEnforcer(UUID ownerId, CardSetInfo setInfo) {
this.power = new MageInt(3);
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());
}

Expand Down
2 changes: 1 addition & 1 deletion Mage/src/main/java/mage/players/net/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UserData implements Serializable {
protected boolean manaPoolAutomaticRestricted;
protected boolean passPriorityCast;
protected boolean passPriorityActivation;
protected boolean autoOrderTrigger;
protected boolean autoOrderTrigger; // auto-order triggers with same rule text
protected int autoTargetLevel;
protected boolean useSameSettingsForReplacementEffects;
protected boolean useFirstManaAbility = false;
Expand Down

0 comments on commit 8ebbeef

Please sign in to comment.