Skip to content

Commit

Permalink
first logic fo SwitchPT to kill opponent creatures
Browse files Browse the repository at this point in the history
  • Loading branch information
Hanmac committed Aug 15, 2023
1 parent 8b09682 commit bf3e7b2
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions forge-ai/src/main/java/forge/ai/ability/PumpAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,53 @@ private boolean pumpTgtAI(final Player ai, final SpellAbility sa, final int defe
}
}

if (sa.hasParam("SwitchPT")) {
// Logic to kill opponent creatures
CardCollection oppCreatures = CardLists.getTargetableCards(ai.getOpponents().getCreaturesInPlay(), sa);
if (!oppCreatures.isEmpty()) {
CardCollection oppCreaturesFiltered = CardLists.filter(oppCreatures, new Predicate<Card>() {

@Override
public boolean apply(Card input) {
// don't care about useless creatures
if (ComputerUtilCard.isUselessCreature(ai, input)
|| input.hasSVar("EndOfTurnLeavePlay")) {
return false;
}
// dies by target
if (input.getSVar("Targeting").equals("Dies")) {
return true;
}
// dies by state based action
if (input.getNetPower() <= 0) {
return true;
}
if (input.hasKeyword(Keyword.INDESTRUCTIBLE)) {
return false;
}
// check if switching PT causes it to be lethal
Card lki = CardUtil.getLKICopy(input);
lki.addSwitchPT(-1, 0);
if (input.getLethal() - input.getDamage() <= 0) {
return true;
}
return false;
}

});
// the ones that die by switching PT
if (!oppCreaturesFiltered.isEmpty()) {
Card best = ComputerUtilCard.getBestCreatureAI(oppCreaturesFiltered);
if (best != null) {
sa.getTargets().add(best);
return true;
}
}
}

return false;
}

if (sa.isCurse()) {
for (final Player opp : ai.getOpponents()) {
if (sa.canTarget(opp)) {
Expand Down

0 comments on commit bf3e7b2

Please sign in to comment.