Skip to content

Commit

Permalink
PumpAi: check if creature would die through damage and check for rege…
Browse files Browse the repository at this point in the history
…neration
  • Loading branch information
Hanmac committed Aug 15, 2023
1 parent bf3e7b2 commit 840d078
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions forge-ai/src/main/java/forge/ai/ability/PumpAi.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.google.common.collect.Maps;

import forge.ai.*;
import forge.game.CardTraitPredicates;
import forge.game.Game;
import forge.game.ability.AbilityKey;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.*;
Expand All @@ -19,6 +21,9 @@
import forge.game.phase.PhaseType;
import forge.game.player.Player;
import forge.game.player.PlayerActionConfirmMode;
import forge.game.replacement.ReplacementEffect;
import forge.game.replacement.ReplacementLayer;
import forge.game.replacement.ReplacementType;
import forge.game.spellability.SpellAbility;
import forge.game.spellability.TargetRestrictions;
import forge.game.staticability.StaticAbility;
Expand Down Expand Up @@ -526,10 +531,27 @@ public boolean apply(Card input) {
// 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;

// check if creature could regenerate
Map<AbilityKey, Object> runParams = AbilityKey.mapFromAffected(input);
runParams.put(AbilityKey.Regeneration, true);
List<ReplacementEffect> repDestoryList = game.getReplacementHandler().getReplacementList(ReplacementType.Destroy, runParams, ReplacementLayer.Other);
// non-Regeneration one like Totem-Armor
// should do it anyway to destroy the aura?
if (Iterables.any(repDestoryList, Predicates.not(CardTraitPredicates.hasParam("Regeneration")))) {
return false;
}
return false;
// TODO make it force to use regen?
// should check phase and make it before combat damage or better before blocker?
if (Iterables.any(repDestoryList, CardTraitPredicates.hasParam("Regeneration")) && input.canBeShielded()) {
return false;
}

// maybe do it anyway to reduce its power?
if (input.getLethal() - input.getDamage() > 0) {
return false;
}
return true;
}

});
Expand Down

0 comments on commit 840d078

Please sign in to comment.