mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- 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:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user