diff --git a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java index cdd19a65318..47c2c2a9257 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java @@ -905,6 +905,28 @@ public class AttachAi extends SpellAbilityAi { }); } + // Look for triggers that will damage the creature and remove AI-owned creatures that will die + CardCollection toRemove = new CardCollection(); + for (Trigger t : attachSource.getTriggers()) { + if (t.getMode() == TriggerType.ChangesZone) { + final Map params = t.getMapParams(); + if ("Card.Self".equals(params.get("ValidCard")) && "Battlefield".equals(params.get("Destination"))) { + SpellAbility trigSa = AbilityFactory.getAbility(attachSource.getSVar(params.get("Execute")), attachSource); + if (trigSa.getApi() == ApiType.DealDamage && "Enchanted".equals(trigSa.getParam("Defined"))) { + for (Card target : list) { + if (!target.getController().isOpponentOf(ai)) { + int numDmg = AbilityUtils.calculateAmount(target, trigSa.getParam("NumDmg"), trigSa); + if (target.getNetToughness() <= numDmg) { + toRemove.add(target); + } + } + } + } + } + } + } + list.removeAll(toRemove); + if (magnetList != null) { // Look for Heroic triggers @@ -921,7 +943,7 @@ public class AttachAi extends SpellAbilityAi { } } } - + if (!magnetList.isEmpty()) { // Always choose something from the Magnet List. // Probably want to "weight" the list by amount of Enchantments and