mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 02:38:02 +00:00
- Prevent crash when AI is forced to play Angel of Salvation.
This commit is contained in:
@@ -122,10 +122,10 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
} // Protect combatants
|
} // Protect combatants
|
||||||
else if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
else if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
if (sa.canTarget(ai) && ComputerUtilCombat.wouldLoseLife(ai, combat)
|
if (sa.canTarget(ai) && ComputerUtilCombat.wouldLoseLife(ai, combat)
|
||||||
&& (ComputerUtilCombat.lifeInDanger(ai, combat) || sa.isAbility())
|
&& (ComputerUtilCombat.lifeInDanger(ai, combat) || sa.isAbility() || sa.isTrigger())
|
||||||
&& game.getPhaseHandler().isPlayerTurn(ai.getOpponent())) {
|
&& game.getPhaseHandler().getPlayerTurn().isOpponentOf(ai)) {
|
||||||
sa.getTargets().add(ai);
|
sa.getTargets().add(ai);
|
||||||
chance = true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
// filter AIs battlefield by what I can target
|
// filter AIs battlefield by what I can target
|
||||||
List<Card> targetables = ai.getCardsIn(ZoneType.Battlefield);
|
List<Card> targetables = ai.getCardsIn(ZoneType.Battlefield);
|
||||||
@@ -141,8 +141,7 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
for (final Card c : combatants) {
|
for (final Card c : combatants) {
|
||||||
if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) {
|
if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) {
|
||||||
sa.getTargets().add(c);
|
sa.getTargets().add(c);
|
||||||
chance = true;
|
return true;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,36 +185,38 @@ public class DamagePreventAi extends SpellAbilityAi {
|
|||||||
List<Card> targetables = game.getCardsIn(ZoneType.Battlefield);
|
List<Card> targetables = game.getCardsIn(ZoneType.Battlefield);
|
||||||
targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, sa.getSourceCard());
|
targetables = CardLists.getValidCards(targetables, tgt.getValidTgts(), ai, sa.getSourceCard());
|
||||||
final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai);
|
final List<Card> compTargetables = CardLists.filterControlledBy(targetables, ai);
|
||||||
|
Card target = null;
|
||||||
|
|
||||||
if (targetables.size() == 0) {
|
if (targetables.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mandatory && (compTargetables.size() == 0)) {
|
if (!mandatory && compTargetables.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (compTargetables.size() > 0) {
|
if (!compTargetables.isEmpty()) {
|
||||||
final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES);
|
final List<Card> combatants = CardLists.filter(compTargetables, CardPredicates.Presets.CREATURES);
|
||||||
CardLists.sortByEvaluateCreature(combatants);
|
CardLists.sortByEvaluateCreature(combatants);
|
||||||
if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
if (game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS)) {
|
||||||
Combat combat = game.getCombat();
|
Combat combat = game.getCombat();
|
||||||
for (final Card c : combatants) {
|
for (final Card c : combatants) {
|
||||||
if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) {
|
if (ComputerUtilCombat.combatantWouldBeDestroyed(ai, c, combat)) {
|
||||||
sa.getTargets().add(c);
|
target = c;
|
||||||
return true;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (target == null) {
|
||||||
// TODO see if something on the stack is about to kill something I
|
target = combatants.get(0);
|
||||||
// can target
|
}
|
||||||
|
} else {
|
||||||
sa.getTargets().add(combatants.get(0));
|
target = ComputerUtilCard.getCheapestPermanentAI(targetables, sa, true);
|
||||||
return true;
|
}
|
||||||
|
sa.getTargets().add(target);
|
||||||
|
if (sa.hasParam("DividedAsYouChoose")) {
|
||||||
|
tgt.addDividedAllocation(target, AbilityUtils.calculateAmount(sa.getSourceCard(), sa.getParam("Amount"), sa));
|
||||||
}
|
}
|
||||||
|
|
||||||
sa.getTargets().add(ComputerUtilCard.getCheapestPermanentAI(targetables, sa, true));
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user