33import forge .ai .*;
44import forge .game .ability .AbilityUtils ;
55import forge .game .card .Card ;
6+ import forge .game .cost .Cost ;
67import forge .game .player .Player ;
78import forge .game .player .PlayerActionConfirmMode ;
9+ import forge .game .spellability .AbilitySub ;
810import forge .game .spellability .Spell ;
911import forge .game .spellability .SpellAbility ;
1012
@@ -14,7 +16,32 @@ public class DiscoverAi extends SpellAbilityAi {
1416
1517 @ Override
1618 protected AiAbilityDecision checkApiLogic (final Player ai , final SpellAbility sa ) {
17- return new AiAbilityDecision (0 , AiPlayDecision .CantPlayAi );
19+ if (sa instanceof AbilitySub ) {
20+ // If its a subability, just let the AI do it. Casting spells is fun!
21+ return new AiAbilityDecision (100 , AiPlayDecision .WillPlay );
22+ }
23+
24+ Card c = sa .getHostCard ();
25+ Cost cost = sa .getPayCosts ();
26+ if (cost != null ) {
27+ // IF self sacrifice, make sure its "work it". For lands, make sure we still have a decent amount of lands. Or not losing a color source we might need
28+ if (ComputerUtilCost .isSacrificeSelfCost (cost )) {
29+ if (c .isLand ()) {
30+ // The discover lands cost 5 plus tapping this land to activate.
31+ // Let's make sure we don't have too few lands in play before we sacrifice this land.
32+ if (ai .getLandsInPlay ().size () <= 6 ) {
33+ return new AiAbilityDecision (0 , AiPlayDecision .CantPlayAi );
34+ }
35+ }
36+ }
37+
38+ // Other discover costs that we should probably consider:
39+ // Sub Loyalty
40+ // Exile creature card from graveyard
41+ // Tapping creatures/artifacts
42+ }
43+
44+ return new AiAbilityDecision (100 , AiPlayDecision .WillPlay );
1845 }
1946
2047 /**
@@ -34,6 +61,11 @@ protected AiAbilityDecision doTriggerNoCost(final Player ai, final SpellAbility
3461 return new AiAbilityDecision (100 , AiPlayDecision .WillPlay );
3562 }
3663
64+ // If cost is free, and we're just resolving a trigger, lets just do it.
65+ if (sa .getPayCosts () == null || sa .getPayCosts ().isFree ()) {
66+ return new AiAbilityDecision (100 , AiPlayDecision .WillPlay );
67+ }
68+
3769 return checkApiLogic (ai , sa );
3870 }
3971
0 commit comments