MCPcopy Create free account
hub / github.com/Card-Forge/forge / checkApiLogic

Method checkApiLogic

forge-ai/src/main/java/forge/ai/ability/DrawAi.java:43–80  ·  view source on GitHub ↗
(Player ai, SpellAbility sa)

Source from the content-addressed store, hash-verified

41 * @see forge.ai.SpellAbilityAi#checkApiLogic(forge.game.player.Player, forge.game.spellability.SpellAbility)
42 */
43 @Override
44 protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
45 if (!targetAI(ai, sa, false)) {
46 return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
47 }
48
49 if (sa.usesTargeting()) {
50 final Player player = sa.getTargets().getFirstTargetedPlayer();
51 if (player != null && player.isOpponentOf(ai)) {
52 return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
53 }
54 }
55
56 if (ComputerUtil.playImmediately(ai, sa)) {
57 return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
58 }
59
60 // Don't tap creatures that may be able to block
61 if (ComputerUtil.waitForBlocking(sa)) {
62 return new AiAbilityDecision(0, AiPlayDecision.WaitForCombat);
63 }
64
65 if (!canLoot(ai, sa)) {
66 return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
67 }
68
69 if (ComputerUtilCost.isSacrificeSelfCost(sa.getPayCosts())) {
70 // Canopy lands and other cards that sacrifice themselves to draw cards
71 if (ai.getCardsIn(ZoneType.Hand).isEmpty()
72 || (sa.getHostCard().isLand() && ai.getLandsInPlay().size() >= 5)) {
73 // TODO: make this configurable in the AI profile
74 return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
75 }
76 return new AiAbilityDecision(0, AiPlayDecision.CostNotAcceptable);
77 }
78
79 return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
80 }
81
82 /*
83 * (non-Javadoc)

Callers

nothing calls this directly

Calls 15

targetAIMethod · 0.95
isOpponentOfMethod · 0.95
playImmediatelyMethod · 0.95
waitForBlockingMethod · 0.95
canLootMethod · 0.95
isSacrificeSelfCostMethod · 0.95
getPayCostsMethod · 0.80
getLandsInPlayMethod · 0.80
isEmptyMethod · 0.65
isLandMethod · 0.65
getHostCardMethod · 0.65

Tested by

no test coverage detected