mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 11:18:01 +00:00
- Trying to restore the new SpellAbilityAi format for ManaEffectAi.
- Limited mana ritual AI a bit more, it's bad at prioritizing instants for it.
This commit is contained in:
@@ -332,12 +332,7 @@ public class SpecialCardAi {
|
|||||||
public static class ManaRitual {
|
public static class ManaRitual {
|
||||||
public static boolean consider(final Player ai, SpellAbility sa) {
|
public static boolean consider(final Player ai, SpellAbility sa) {
|
||||||
final Card host = sa.getHostCard();
|
final Card host = sa.getHostCard();
|
||||||
final PhaseHandler ph = ai.getGame().getPhaseHandler();
|
|
||||||
|
|
||||||
if (!(ph.getPlayerTurn().equals(ai) && (ph.is(PhaseType.MAIN2) || ph.is(PhaseType.MAIN1)))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
CardCollection manaSources = ComputerUtilMana.getAvailableMana(ai, true);
|
CardCollection manaSources = ComputerUtilMana.getAvailableMana(ai, true);
|
||||||
int numManaSrcs = manaSources.size();
|
int numManaSrcs = manaSources.size();
|
||||||
int manaReceived = AbilityUtils.calculateAmount(host, sa.getParam("Amount"), sa);
|
int manaReceived = AbilityUtils.calculateAmount(host, sa.getParam("Amount"), sa);
|
||||||
@@ -377,16 +372,11 @@ public class SpecialCardAi {
|
|||||||
SpellAbility testSaNoCost = testSa.copyWithNoManaCost();
|
SpellAbility testSaNoCost = testSa.copyWithNoManaCost();
|
||||||
testSaNoCost.setActivatingPlayer(ai);
|
testSaNoCost.setActivatingPlayer(ai);
|
||||||
if (((PlayerControllerAi)ai.getController()).getAi().canPlaySa(testSaNoCost) == AiPlayDecision.WillPlay) {
|
if (((PlayerControllerAi)ai.getController()).getAi().canPlaySa(testSaNoCost) == AiPlayDecision.WillPlay) {
|
||||||
if (!testSa.getHostCard().isInstant() && !ph.is(PhaseType.MAIN2)) {
|
if (testSa.getHostCard().isInstant()) {
|
||||||
// AI sometimes thinks that it's willing to cast a sorcery in Main1 and then it doesn't,
|
// AI is bad at choosing which instants are worth a Ritual
|
||||||
// so avoid evaluating them unless already in Main2
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (testSa.getApi() == ApiType.Counter || testSa.getApi() == ApiType.Mana) {
|
|
||||||
// do not specifically look to activate this for a counterspell or for another mana-
|
|
||||||
// producing ability.
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the AI is willing to play the spell
|
// the AI is willing to play the spell
|
||||||
if (!cardList.contains(testSa.getHostCard())) {
|
if (!cardList.contains(testSa.getHostCard())) {
|
||||||
cardList.add(testSa.getHostCard());
|
cardList.add(testSa.getHostCard());
|
||||||
|
|||||||
@@ -4,36 +4,85 @@ package forge.ai.ability;
|
|||||||
import forge.ai.ComputerUtil;
|
import forge.ai.ComputerUtil;
|
||||||
import forge.ai.SpecialCardAi;
|
import forge.ai.SpecialCardAi;
|
||||||
import forge.ai.SpellAbilityAi;
|
import forge.ai.SpellAbilityAi;
|
||||||
|
import forge.game.phase.PhaseHandler;
|
||||||
import forge.game.phase.PhaseType;
|
import forge.game.phase.PhaseType;
|
||||||
import forge.game.player.Player;
|
import forge.game.player.Player;
|
||||||
import forge.game.spellability.SpellAbility;
|
import forge.game.spellability.SpellAbility;
|
||||||
|
|
||||||
public class ManaEffectAi extends SpellAbilityAi {
|
public class ManaEffectAi extends SpellAbilityAi {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see forge.ai.SpellAbilityAi#checkAiLogic(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility, java.lang.String)
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected boolean canPlayAI(Player ai, SpellAbility sa) {
|
protected boolean checkAiLogic(Player ai, SpellAbility sa, String aiLogic) {
|
||||||
if ("ManaRitual".equals(sa.getParam("AILogic"))) {
|
if ("ManaRitual".equals(aiLogic)) {
|
||||||
return SpecialCardAi.ManaRitual.consider(ai, sa);
|
return SpecialCardAi.ManaRitual.consider(ai, sa);
|
||||||
}
|
}
|
||||||
if (ai.getGame().getPhaseHandler().is(PhaseType.MAIN2) && ComputerUtil.activateForCost(sa, ai)) {
|
return super.checkAiLogic(ai, sa, aiLogic);
|
||||||
return true;
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* forge.ai.SpellAbilityAi#checkPhaseRestrictions(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility, forge.game.phase.PhaseHandler)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph) {
|
||||||
|
if (!ph.is(PhaseType.MAIN2) || !ComputerUtil.activateForCost(sa, ai)) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if (sa.getPayCosts() != null && sa.getPayCosts().hasNoManaCost()
|
return super.checkPhaseRestrictions(ai, sa, ph);
|
||||||
&& sa.getPayCosts().isReusuableResource()
|
}
|
||||||
&& sa.getSubAbility() == null
|
|
||||||
&& ComputerUtil.playImmediately(ai, sa)) {
|
/*
|
||||||
return true;
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see
|
||||||
|
* forge.ai.SpellAbilityAi#checkPhaseRestrictions(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility, forge.game.phase.PhaseHandler,
|
||||||
|
* java.lang.String)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean checkPhaseRestrictions(Player ai, SpellAbility sa, PhaseHandler ph, String logic) {
|
||||||
|
if ("ManaRitual".equals(logic)) {
|
||||||
|
return ph.is(PhaseType.MAIN2, ai) || ph.is(PhaseType.MAIN1, ai);
|
||||||
}
|
}
|
||||||
return false;
|
return super.checkPhaseRestrictions(ai, sa, ph, logic);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see forge.ai.SpellAbilityAi#checkApiLogic(forge.game.player.Player,
|
||||||
|
* forge.game.spellability.SpellAbility)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected boolean checkApiLogic(Player ai, SpellAbility sa) {
|
||||||
|
if (sa.hasParam("AILogic")) {
|
||||||
|
return true; // handled elsewhere, does not meet the standard requirements
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(sa.getPayCosts() != null && sa.getPayCosts().hasNoManaCost() && sa.getPayCosts().isReusuableResource()
|
||||||
|
&& sa.getSubAbility() == null && ComputerUtil.playImmediately(ai, sa))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
// return super.checkApiLogic(ai, sa);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @param ai
|
||||||
|
* the AI player.
|
||||||
* @param sa
|
* @param sa
|
||||||
* a {@link forge.game.spellability.SpellAbility} object.
|
* a {@link forge.game.spellability.SpellAbility} object.
|
||||||
* @param mandatory
|
* @param mandatory
|
||||||
* a boolean.
|
* a boolean.
|
||||||
* @param af
|
|
||||||
* a {@link forge.game.ability.AbilityFactory} object.
|
|
||||||
*
|
*
|
||||||
* @return a boolean.
|
* @return a boolean.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user