Skip to content

Commit

Permalink
Give API logic access to castSA
Browse files Browse the repository at this point in the history
  • Loading branch information
tool4EvEr authored and tool4EvEr committed Jan 1, 2025
1 parent bc97d79 commit 4a7e319
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 28 deletions.
6 changes: 6 additions & 0 deletions forge-ai/src/main/java/forge/ai/AiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,15 @@ private AiPlayDecision canPlayAndPayFor(final SpellAbility sa) {
if (currentState != null) {
host.setState(sa.getCardStateName(), false);
}
if (sa.isSpell()) {
host.setCastSA(sa);
}

AiPlayDecision decision = canPlayAndPayForFace(sa);

if (sa.isSpell()) {
host.setCastSA(null);
}
if (currentState != null) {
host.setState(currentState, false);
}
Expand Down
28 changes: 0 additions & 28 deletions forge-ai/src/main/java/forge/ai/SpellAbilityAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ public List<OptionalCostValue> chooseOptionalCosts(SpellAbility chosen, Player p
List<OptionalCostValue> chosenOptCosts = Lists.newArrayList();
Cost costSoFar = chosen.getPayCosts().copy();

outer:
for (OptionalCostValue opt : optionalCostValues) {
// Choose the optional cost if it can be paid (to be improved later, check for playability and other conditions perhaps)
Cost fullCost = opt.getCost().copy().add(costSoFar);
Expand All @@ -436,33 +435,6 @@ public List<OptionalCostValue> chooseOptionalCosts(SpellAbility chosen, Player p
}

if (ComputerUtilCost.canPayCost(fullCostSa, player, false)) {
// check for additional Cost breaking targets AI had already chosen
boolean targeting = false;
SpellAbility sub = fullCostSa;

This comment has been minimized.

Copy link
@Hanmac

Hanmac Jan 1, 2025

Contributor

@tool4ever removing this wouldn't fix all the problems AI has with optional cost

It still needs logic when NOT to add more Costs

Like when it would change in the targets from 1 to 2

while (sub != null) {
if (sub.usesTargeting()) {
targeting = true;
break;
}
sub = sub.getSubAbility();
}
if (targeting) {
fullCostSa.addOptionalCost(opt.getType());
Card copy = CardCopyService.getLKICopy(chosen.getHostCard());
copy.setCastSA(fullCostSa);
fullCostSa.setHostCard(copy);

sub = fullCostSa;
while (sub != null) {
if (sub.usesTargeting() && !sub.isTargetNumberValid()) {
// adding cost would break target
continue outer;
}
sub = sub.getSubAbility();
}

}

chosenOptCosts.add(opt);
costSoFar.add(opt.getCost());
}
Expand Down

0 comments on commit 4a7e319

Please sign in to comment.