- Added a castSpellInMain1 AI function that currently checks for Cipher subAbilities and BuffedBy SVars.

This commit is contained in:
Sloth
2013-05-15 14:50:41 +00:00
parent 5e4fb591be
commit 848fd460dc
5 changed files with 41 additions and 6 deletions

View File

@@ -89,9 +89,7 @@ public class DrawAi extends SpellAbilityAi {
}
final boolean bFlag = targetAI(ai, sa, false);
if (!bFlag) {
if (!targetAI(ai, sa, false)) {
return false;
}
@@ -104,7 +102,7 @@ public class DrawAi extends SpellAbilityAi {
// Don't use draw abilities before main 2 if possible
if (game.getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)
&& !sa.hasParam("ActivationPhases")) {
&& !sa.hasParam("ActivationPhases") && !ComputerUtil.castSpellInMain1(ai, sa)) {
return false;
}
if ((!game.getPhaseHandler().getNextTurn().equals(ai)

View File

@@ -181,7 +181,7 @@ public abstract class TapAiBase extends SpellAbilityAi {
List<Card> creatureList = CardLists.filter(tapList, findBlockers);
if (!attackers.isEmpty() && !creatureList.isEmpty()) {
choice = ComputerUtilCard.getBestCreatureAI(creatureList);
} else if (sa.isTrigger()) {
} else if (sa.isTrigger() || ComputerUtil.castSpellInMain1(ai, sa)) {
choice = ComputerUtilCard.getMostExpensivePermanentAI(tapList, sa, false);
}

View File

@@ -105,7 +105,8 @@ public class TokenAi extends SpellAbilityAi {
// Don't generate tokens without haste before main 2 if possible
if (ph.getPhase().isBefore(PhaseType.MAIN2)
&& ph.isPlayerTurn(ai) && !haste
&& !sa.hasParam("ActivationPhases")) {
&& !sa.hasParam("ActivationPhases")
&& !ComputerUtil.castSpellInMain1(ai, sa)) {
return false;
}
if ((ph.isPlayerTurn(ai)

View File

@@ -1000,6 +1000,41 @@ public class ComputerUtil {
&& (ph.getPhase().isBefore(PhaseType.COMBAT_DECLARE_BLOCKERS_INSTANT_ABILITY)
|| !ph.getNextTurn().equals(sa.getActivatingPlayer())));
}
/**
* <p>
* castSpellMain1.
* </p>
*
* @param sa
* a {@link forge.card.spellability.SpellAbility} object.
* @return a boolean (returns true if it's better to wait until blockers are declared).
*/
public static boolean castSpellInMain1(final Player ai, final SpellAbility sa) {
final Card source = sa.getSourceCard();
final SpellAbility sub = sa.getSubAbility();
// Cipher spells
if (sub != null && ApiType.Encode == sa.getSubAbility().getApi() && !ai.getCreaturesInPlay().isEmpty()) {
return true;
}
final List<Card> buffed = ai.getCardsIn(ZoneType.Battlefield);
for (Card buffedcard : buffed) {
if (buffedcard.hasSVar("BuffedBy")) {
final String buffedby = buffedcard.getSVar("BuffedBy");
final String[] bffdby = buffedby.split(",");
if (source.isValid(bffdby, buffedcard.getController(), buffedcard)) {
return true;
}
}
}
if (sub != null) {
return castSpellInMain1(ai, sub);
}
return false;
}
// returns true if the AI should stop using the ability
/**