- Updated some more AI functions.

This commit is contained in:
Sloth
2012-12-05 13:01:03 +00:00
parent 8f0963645a
commit 760c32caf4
3 changed files with 25 additions and 21 deletions

View File

@@ -43,12 +43,16 @@ import forge.util.MyRandom;
public class DrawAi extends SpellAiLogic { public class DrawAi extends SpellAiLogic {
@Override
public boolean chkAIDrawback(SpellAbility sa, Player ai) {
return targetAI(ai, sa, false);
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility) * @see forge.card.abilityfactory.SpellAiLogic#canPlayAI(forge.game.player.Player, java.util.Map, forge.card.spellability.SpellAbility)
*/ */
@Override @Override
protected boolean canPlayAI(Player ai, SpellAbility sa) { protected boolean canPlayAI(Player ai, SpellAbility sa) {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final Cost abCost = sa.getPayCosts(); final Cost abCost = sa.getPayCosts();
@@ -102,9 +106,10 @@ public class DrawAi extends SpellAiLogic {
&& !sa.hasParam("ActivationPhases")) { && !sa.hasParam("ActivationPhases")) {
return false; return false;
} }
if (!Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai) if ((!Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai)
|| Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN))
&& !sa.hasParam("PlayerTurn") && !AbilityFactory.isSorcerySpeed(sa) && !sa.hasParam("PlayerTurn") && !AbilityFactory.isSorcerySpeed(sa)
&& ai.getCardsIn(ZoneType.Hand).size() < 2) { && ai.getCardsIn(ZoneType.Hand).size() > 1) {
return false; return false;
} }
@@ -135,7 +140,7 @@ public class DrawAi extends SpellAiLogic {
private boolean targetAI(final Player ai, final SpellAbility sa, final boolean mandatory) { private boolean targetAI(final Player ai, final SpellAbility sa, final boolean mandatory) {
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
final Card source = sa.getSourceCard(); final Card source = sa.getSourceCard();
final boolean drawback = (sa instanceof AbilitySub);
Player opp = ai.getOpponent(); Player opp = ai.getOpponent();
int computerHandSize = ai.getCardsIn(ZoneType.Hand).size(); int computerHandSize = ai.getCardsIn(ZoneType.Hand).size();
@@ -216,7 +221,7 @@ public class DrawAi extends SpellAiLogic {
} }
} }
if (numCards == 0 && !mandatory) { if (numCards == 0 && !mandatory && !drawback) {
return false; return false;
} }
@@ -227,27 +232,25 @@ public class DrawAi extends SpellAiLogic {
} else { } else {
return false; return false;
} }
} else { } else if (!mandatory) {
// TODO: consider if human is the defined player // TODO: consider if human is the defined player
// ability is not targeted // ability is not targeted
if (numCards >= computerLibrarySize) { if (numCards >= computerLibrarySize) {
// Don't deck yourself // Don't deck yourself
if (!mandatory) {
return false;
}
}
if (numCards == 0 && !mandatory) {
return false; return false;
} }
if (((computerHandSize + numCards) > computerMaxHandSize) if (numCards == 0 && !drawback) {
return false;
}
if ((computerHandSize + numCards > computerMaxHandSize)
&& Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn().isComputer() && Singletons.getModel().getGame().getPhaseHandler().getPlayerTurn().isComputer()
&& !sa.isTrigger()) { && !sa.isTrigger()) {
// Don't draw too many cards and then risk discarding cards at // Don't draw too many cards and then risk discarding cards at
// EOT // EOT
if (!(sa.hasParam("NextUpkeep") || (sa instanceof AbilitySub)) && !mandatory) { if (!sa.hasParam("NextUpkeep") && !drawback) {
return false; return false;
} }
} }

View File

@@ -97,7 +97,8 @@ public class LifeGainAi extends SpellAiLogic {
return false; return false;
} }
// Don't use lifegain before main 2 if possible // Don't use lifegain before main 2 if possible
if (!lifeCritical && !Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai) if (!lifeCritical && (!Singletons.getModel().getGame().getPhaseHandler().getNextTurn().equals(ai)
|| Singletons.getModel().getGame().getPhaseHandler().getPhase().isBefore(PhaseType.END_OF_TURN))
&& !sa.hasParam("PlayerTurn") && !AbilityFactory.isSorcerySpeed(sa)) { && !sa.hasParam("PlayerTurn") && !AbilityFactory.isSorcerySpeed(sa)) {
return false; return false;
} }

View File

@@ -98,8 +98,8 @@ public class ChooseCardEffect extends SpellEffect {
} }
choice = CardFactoryUtil.getBestCreatureAI(choices); choice = CardFactoryUtil.getBestCreatureAI(choices);
} else if (logic.equals("Clone")) { } else if (logic.equals("Clone")) {
if (!CardLists.getValidCards(choices, "Permanent.YouDontCtrl,Permanent.NonLegendary", host.getController(), host).isEmpty()) { if (!CardLists.getValidCards(choices, "Permanent.YouDontCtrl,Permanent.nonLegendary", host.getController(), host).isEmpty()) {
choices = CardLists.getValidCards(choices, "Permanent.YouDontCtrl,Permanent.NonLegendary", host.getController(), host); choices = CardLists.getValidCards(choices, "Permanent.YouDontCtrl,Permanent.nonLegendary", host.getController(), host);
} }
choice = CardFactoryUtil.getBestAI(choices); choice = CardFactoryUtil.getBestAI(choices);
} }