Performance reorder

This commit is contained in:
tool4EvEr
2022-04-23 21:57:40 +02:00
parent e95d348402
commit 1356d05f6b
4 changed files with 10 additions and 13 deletions

View File

@@ -642,21 +642,19 @@ public class AiController {
// Ideally this should cast canPlaySa to determine that the AI is truly able/willing to cast a spell, // Ideally this should cast canPlaySa to determine that the AI is truly able/willing to cast a spell,
// but that is currently difficult to implement due to various side effects leading to stack overflow. // but that is currently difficult to implement due to various side effects leading to stack overflow.
Card host = sa.getHostCard(); Card host = sa.getHostCard();
if (!ComputerUtil.castPermanentInMain1(player, sa) && host != null && !host.isLand() && ComputerUtilCost.canPayCost(sa, player, false)) { if (sa instanceof SpellPermanent && host != null && !host.isLand() && !ComputerUtil.castPermanentInMain1(player, sa) && ComputerUtilCost.canPayCost(sa, player, false)) {
if (sa instanceof SpellPermanent) { return sa;
return sa;
}
} }
} }
return null; return null;
} }
public boolean reserveManaSources(SpellAbility sa) {
return reserveManaSources(sa, PhaseType.MAIN2, false, false, null);
}
public boolean reserveManaSourcesForNextSpell(SpellAbility sa, SpellAbility exceptForSa) { public boolean reserveManaSourcesForNextSpell(SpellAbility sa, SpellAbility exceptForSa) {
return reserveManaSources(sa, null, false, true, exceptForSa); return reserveManaSources(sa, null, false, true, exceptForSa);
} }
public boolean reserveManaSources(SpellAbility sa) {
return reserveManaSources(sa, PhaseType.MAIN2, false, false, null);
}
public boolean reserveManaSources(SpellAbility sa, PhaseType phaseType, boolean enemy) { public boolean reserveManaSources(SpellAbility sa, PhaseType phaseType, boolean enemy) {
return reserveManaSources(sa, phaseType, enemy, true, null); return reserveManaSources(sa, phaseType, enemy, true, null);
} }

View File

@@ -1676,7 +1676,7 @@ public class ComputerUtil {
// Lethal Damage => prevent damage/regeneration/bounce/shroud // Lethal Damage => prevent damage/regeneration/bounce/shroud
if (threatApi == ApiType.DealDamage || threatApi == ApiType.DamageAll) { if (threatApi == ApiType.DealDamage || threatApi == ApiType.DamageAll) {
// If PredictDamage is >= Lethal Damage // If PredictDamage is >= Lethal Damage
final int dmg = AbilityUtils.calculateAmount(topStack.getHostCard(), final int dmg = AbilityUtils.calculateAmount(source,
topStack.getParam("NumDmg"), topStack); topStack.getParam("NumDmg"), topStack);
final SpellAbility sub = topStack.getSubAbility(); final SpellAbility sub = topStack.getSubAbility();
boolean noRegen = false; boolean noRegen = false;
@@ -1756,7 +1756,7 @@ public class ComputerUtil {
&& (saviourApi == ApiType.ChangeZone || saviourApi == ApiType.Pump || saviourApi == ApiType.PumpAll && (saviourApi == ApiType.ChangeZone || saviourApi == ApiType.Pump || saviourApi == ApiType.PumpAll
|| saviourApi == ApiType.Protection || saviourApi == ApiType.PutCounter || saviourApi == ApiType.PutCounterAll || saviourApi == ApiType.Protection || saviourApi == ApiType.PutCounter || saviourApi == ApiType.PutCounterAll
|| saviourApi == null)) { || saviourApi == null)) {
final int dmg = -AbilityUtils.calculateAmount(topStack.getHostCard(), final int dmg = -AbilityUtils.calculateAmount(source,
topStack.getParam("NumDef"), topStack); topStack.getParam("NumDef"), topStack);
for (final Object o : objects) { for (final Object o : objects) {
if (o instanceof Card) { if (o instanceof Card) {

View File

@@ -11,7 +11,6 @@ import forge.ai.AiController;
import forge.ai.ComputerUtil; import forge.ai.ComputerUtil;
import forge.ai.ComputerUtilCard; import forge.ai.ComputerUtilCard;
import forge.ai.ComputerUtilCombat; import forge.ai.ComputerUtilCombat;
import forge.ai.ComputerUtilMana;
import forge.ai.PlayerControllerAi; import forge.ai.PlayerControllerAi;
import forge.ai.SpecialCardAi; import forge.ai.SpecialCardAi;
import forge.ai.SpellAbilityAi; import forge.ai.SpellAbilityAi;
@@ -122,8 +121,8 @@ public class EffectAi extends SpellAbilityAi {
randomReturn = true; randomReturn = true;
} else if (logic.equals("WillCastCreature") && ai.isAI()) { } else if (logic.equals("WillCastCreature") && ai.isAI()) {
AiController aic = ((PlayerControllerAi)ai.getController()).getAi(); AiController aic = ((PlayerControllerAi)ai.getController()).getAi();
SpellAbility saCreature = aic.predictSpellToCastInMain2(ApiType.PermanentCreature); SpellAbility saCreature = aic.predictSpellToCastInMain2(ApiType.PermanentNoncreature);
randomReturn = saCreature != null && ComputerUtilMana.canPayManaCost(saCreature, ai, 0, false); randomReturn = saCreature != null;
} else if (logic.equals("Always")) { } else if (logic.equals("Always")) {
randomReturn = true; randomReturn = true;
} else if (logic.equals("Main1")) { } else if (logic.equals("Main1")) {

View File

@@ -42,7 +42,7 @@ public class PermanentAi extends SpellAbilityAi {
} }
// Wait for Main2 if possible // Wait for Main2 if possible
return !ph.is(PhaseType.MAIN1) || !ph.isPlayerTurn(ai) || ComputerUtil.castPermanentInMain1(ai, sa) || sa.hasParam("WithoutManaCost"); return !ph.is(PhaseType.MAIN1) || !ph.isPlayerTurn(ai) || sa.hasParam("WithoutManaCost") || ComputerUtil.castPermanentInMain1(ai, sa);
} }
/** /**