- The AI will no longer deck itself with Dig spells.

This commit is contained in:
Sloth
2013-06-15 14:24:13 +00:00
parent 97c75209f3
commit 0d05da4e0a

View File

@@ -3,6 +3,7 @@ package forge.card.ability.ai;
import java.util.Random; import java.util.Random;
import forge.Card; import forge.Card;
import forge.card.ability.AbilityUtils;
import forge.card.ability.SpellAbilityAi; import forge.card.ability.SpellAbilityAi;
import forge.card.spellability.SpellAbility; import forge.card.spellability.SpellAbility;
import forge.card.spellability.Target; import forge.card.spellability.Target;
@@ -20,10 +21,8 @@ public class DigAi extends SpellAbilityAi {
@Override @Override
protected boolean canPlayAI(Player ai, SpellAbility sa) { protected boolean canPlayAI(Player ai, SpellAbility sa) {
final Random r = MyRandom.getRandom();
boolean randomReturn = r.nextFloat() <= Math.pow(0.9, sa.getActivationsThisTurn());
Player opp = ai.getOpponent(); Player opp = ai.getOpponent();
final Card host = sa.getSourceCard();
final Target tgt = sa.getTarget(); final Target tgt = sa.getTarget();
Player libraryOwner = ai; Player libraryOwner = ai;
@@ -42,14 +41,25 @@ public class DigAi extends SpellAbilityAi {
return false; return false;
} }
// don't deck yourself
if (sa.hasParam("DestinationZone2") && !"Library".equals(sa.getParam("DestinationZone2"))) {
int numToDig = AbilityUtils.calculateAmount(host, sa.getParam("DigNum"), sa);
if (libraryOwner == ai && ai.getCardsIn(ZoneType.Library).size() <= numToDig + 1) {
return false;
}
}
// Don't use draw abilities before main 2 if possible // Don't use draw abilities before main 2 if possible
if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases") if (ai.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2) && !sa.hasParam("ActivationPhases")
&& !sa.hasParam("DestinationZone")) { && !sa.hasParam("DestinationZone")) {
return false; return false;
} }
final Random r = MyRandom.getRandom();
boolean randomReturn = r.nextFloat() <= Math.pow(0.9, sa.getActivationsThisTurn());
if (SpellAbilityAi.playReusable(ai, sa)) { if (SpellAbilityAi.playReusable(ai, sa)) {
randomReturn = true; return true;
} }
return randomReturn; return randomReturn;