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

Method checkApiLogic

forge-ai/src/main/java/forge/ai/ability/PumpAi.java:108–346  ·  view source on GitHub ↗
(Player ai, SpellAbility sa)

Source from the content-addressed store, hash-verified

106 }
107
108 @Override
109 protected AiAbilityDecision checkApiLogic(Player ai, SpellAbility sa) {
110 final Game game = ai.getGame();
111 final Card source = sa.getHostCard();
112 final SpellAbility root = sa.getRootAbility();
113 final List<String> keywords = sa.hasParam("KW") ? Arrays.asList(sa.getParam("KW").split(" & "))
114 : Lists.newArrayList();
115 final String numDefense = sa.getParamOrDefault("NumDef", "");
116 final String numAttack = sa.getParamOrDefault("NumAtt", "");
117
118 final String aiLogic = sa.getParamOrDefault("AILogic", "");
119
120 final boolean isFight = "Fight".equals(aiLogic) || "PowerDmg".equals(aiLogic);
121 final boolean isBerserk = "Berserk".equals(aiLogic);
122
123 if ("Pummeler".equals(aiLogic)) {
124 return SpecialCardAi.ElectrostaticPummeler.consider(ai, sa);
125 } else if (aiLogic.startsWith("AristocratCounters")) {
126 // the preconditions to this are already tested in checkAiLogic
127 return new AiAbilityDecision(100, AiPlayDecision.WillPlay);
128 } else if ("GideonBlackblade".equals(aiLogic)) {
129 return SpecialCardAi.GideonBlackblade.consider(ai, sa);
130 } else if ("MoveCounter".equals(aiLogic)) {
131 final SpellAbility moveSA = sa.findSubAbilityByType(ApiType.MoveCounter);
132
133 if (moveSA == null) {
134 return new AiAbilityDecision(0, AiPlayDecision.CantPlayAi);
135 }
136
137 final String counterType = moveSA.getParam("CounterType");
138 final String amountStr = moveSA.getParamOrDefault("CounterNum", "1");
139 final CounterType cType = "Any".equals(counterType) ? null : CounterType.getType(counterType);
140
141 final PhaseHandler ph = game.getPhaseHandler();
142 if (ph.inCombat() && ph.getPlayerTurn().isOpponentOf(ai)) {
143 CardCollection attr = ph.getCombat().getAttackers();
144 attr = CardLists.getTargetableCards(attr, sa);
145
146 if (cType != null) {
147 attr = CardLists.filter(attr, CardPredicates.hasCounter(cType));
148 if (attr.isEmpty()) {
149 return new AiAbilityDecision(0, AiPlayDecision.TargetingFailed);
150 }
151 CardCollection best = CardLists.filter(attr, card -> {
152 int amount = 0;
153 if (StringUtils.isNumeric(amountStr)) {
154 amount = AbilityUtils.calculateAmount(source, amountStr, moveSA);
155 } else if (source.hasSVar(amountStr)) {
156 if ("Count$ChosenNumber".equals(source.getSVar(amountStr))) {
157 amount = card.getCounters(cType);
158 }
159 }
160
161 int i = card.getCounters(cType);
162 if (i < amount) {
163 return false;
164 }
165

Callers

nothing calls this directly

Calls 15

getTypeMethod · 0.95
getPhaseHandlerMethod · 0.95
inCombatMethod · 0.95
getPlayerTurnMethod · 0.95
getCombatMethod · 0.95
getTargetableCardsMethod · 0.95
filterMethod · 0.95
hasCounterMethod · 0.95
calculateAmountMethod · 0.95
hasSVarMethod · 0.95
getSVarMethod · 0.95
getLKICopyMethod · 0.95

Tested by

no test coverage detected