- Adding a way to suppress testing canRegenerate from combat code temporarily to avoid re-entry from ComputerUtil#canRegenerate when testing cards such as Varolz, the Scar-Striped.

This commit is contained in:
Agetian
2017-05-21 06:35:17 +00:00
parent 010f3adcea
commit 376d127d8b
2 changed files with 15 additions and 4 deletions

View File

@@ -810,6 +810,9 @@ public class ComputerUtil {
return false;
}
boolean canRegen = false;
ComputerUtilCombat.setCombatRegenTestSuppression(true); // do not check canRegenerate recursively from combat code
final Player controller = card.getController();
final Game game = controller.getGame();
final CardCollectionView l = controller.getCardsIn(ZoneType.Battlefield);
@@ -846,10 +849,10 @@ public class ComputerUtil {
final TargetRestrictions tgt = sa.getTargetRestrictions();
if (tgt != null) {
if (CardLists.getValidCards(game.getCardsIn(ZoneType.Battlefield), tgt.getValidTgts(), controller, sa.getHostCard(), sa).contains(card)) {
return true;
canRegen = true;
}
} else if (AbilityUtils.getDefinedCards(sa.getHostCard(), sa.getParam("Defined"), sa).contains(card)) {
return true;
canRegen = true;
}
} catch (final Exception ex) {
@@ -857,7 +860,9 @@ public class ComputerUtil {
}
}
}
return false;
ComputerUtilCombat.setCombatRegenTestSuppression(false);
return canRegen;
}
public static int possibleDamagePrevention(final Card card) {

View File

@@ -66,6 +66,12 @@ import forge.util.collect.FCollection;
*/
public class ComputerUtilCombat {
// A special flag used in ComputerUtil#canRegenerate to avoid recursive reentry and stack overflow
private static boolean dontTestRegen = false;
public static void setCombatRegenTestSuppression(boolean shouldSuppress) {
dontTestRegen = shouldSuppress;
}
/**
* <p>
* canAttackNextTurn.
@@ -1840,7 +1846,7 @@ public class ComputerUtilCombat {
}
} // flanking
if (blocker.hasKeyword("Indestructible") || ComputerUtil.canRegenerate(blocker.getController(), blocker)) {
if (blocker.hasKeyword("Indestructible") || dontTestRegen || ComputerUtil.canRegenerate(blocker.getController(), blocker)) {
return false;
}