Skip to content

Commit

Permalink
CharmAi: fix duplicated choice (#6776)
Browse files Browse the repository at this point in the history
  • Loading branch information
tool4ever authored Jan 15, 2025
1 parent bf2c184 commit 42416bf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions forge-ai/src/main/java/forge/ai/ability/CharmAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@ protected boolean checkApiLogic(Player ai, SpellAbility sa) {
}

boolean timingRight = sa.isTrigger(); //is there a reason to play the charm now?
boolean choiceForOpp = !ai.equals(sa.getActivatingPlayer());

// Reset the chosen list otherwise it will be locked in forever by earlier calls
sa.setChosenList(null);
sa.setSubAbility(null);
List<AbilitySub> chosenList;
if (!ai.equals(sa.getActivatingPlayer())) {

if (choiceForOpp) {
// This branch is for "An Opponent chooses" Charm spells from Alliances
// Current just choose the first available spell, which seem generally less disastrous for the AI.
chosenList = choices.subList(1, choices.size());
Expand Down Expand Up @@ -78,6 +79,11 @@ protected boolean checkApiLogic(Player ai, SpellAbility sa) {

// store the choices so they'll get reused
sa.setChosenList(chosenList);

if (choiceForOpp) {
return true;
}

if (sa.isSpell()) {
// prebuild chain to improve cost calculation accuracy
CharmEffect.chainAbilities(sa, chosenList);
Expand Down Expand Up @@ -107,9 +113,8 @@ private List<AbilitySub> chooseOptionsAi(SpellAbility sa, List<AbilitySub> choic
int curPawprintAmount = AbilityUtils.calculateAmount(sub.getHostCard(), sub.getParamOrDefault("Pawprint", "0"), sub);
if (pawprintAmount + curPawprintAmount > pawprintLimit) {
continue;
} else {
pawprintAmount += curPawprintAmount;
}
pawprintAmount += curPawprintAmount;
}
chosenList.add(sub);
if (chosenList.size() == num) {
Expand Down

0 comments on commit 42416bf

Please sign in to comment.