- Added a little more safety code to prevent AI freezing.

This commit is contained in:
Sloth
2012-05-07 11:47:40 +00:00
parent 95fa160115
commit 4a51cdca13

View File

@@ -88,14 +88,10 @@ public class ComputerUtil {
} }
sa.setActivatingPlayer(AllZone.getComputerPlayer()); sa.setActivatingPlayer(AllZone.getComputerPlayer());
if (ComputerUtil.canBePlayedAndPayedByAI(sa)) { if (ComputerUtil.canBePlayedAndPayedByAI(sa) && ComputerUtil.handlePlayingSpellAbility(sa)) {
ComputerUtil.handlePlayingSpellAbility(sa);
if (!(sa instanceof AbilityStatic)) {
return false; return false;
} }
} }
}
return true; return true;
} // playCards() } // playCards()
@@ -124,13 +120,13 @@ public class ComputerUtil {
* @param sa * @param sa
* a {@link forge.card.spellability.SpellAbility} object. * a {@link forge.card.spellability.SpellAbility} object.
*/ */
public static void handlePlayingSpellAbility(final SpellAbility sa) { public static boolean handlePlayingSpellAbility(final SpellAbility sa) {
if (sa instanceof AbilityStatic) { if (sa instanceof AbilityStatic) {
if (ComputerUtil.payManaCost(sa, AllZone.getComputerPlayer(), false, 0)) { if (ComputerUtil.payManaCost(sa, AllZone.getComputerPlayer(), false, 0)) {
sa.resolve(); sa.resolve();
} }
return; return false;
} }
AllZone.getStack().freezeStack(); AllZone.getStack().freezeStack();
@@ -148,6 +144,7 @@ public class ComputerUtil {
sa.chooseTargetAI(); sa.chooseTargetAI();
sa.getBeforePayManaAI().execute(); sa.getBeforePayManaAI().execute();
AllZone.getStack().addAndUnfreeze(sa); AllZone.getStack().addAndUnfreeze(sa);
return true;
} else { } else {
if ((tgt != null) && tgt.doesTarget()) { if ((tgt != null) && tgt.doesTarget()) {
sa.chooseTargetAI(); sa.chooseTargetAI();
@@ -156,10 +153,14 @@ public class ComputerUtil {
final CostPayment pay = new CostPayment(cost, sa); final CostPayment pay = new CostPayment(cost, sa);
if (pay.payComputerCosts()) { if (pay.payComputerCosts()) {
AllZone.getStack().addAndUnfreeze(sa); AllZone.getStack().addAndUnfreeze(sa);
return true;
// TODO: solve problems with TapsForMana triggers by adding // TODO: solve problems with TapsForMana triggers by adding
// sources tapped here if possible (ArsenalNut) // sources tapped here if possible (ArsenalNut)
} }
} }
//Should not arrive here
System.out.println("AI failed to play " + sa.getSourceCard());
return false;
} }
/** /**