- Basic logic for fake counter move on Spikes from Tempest.

This commit is contained in:
Agetian
2018-12-05 21:30:21 +03:00
parent 6c0465a1d0
commit 17a922ae5a
11 changed files with 44 additions and 11 deletions

View File

@@ -11,6 +11,7 @@ import forge.game.GameEntity;
import forge.game.ability.AbilityUtils;
import forge.game.ability.ApiType;
import forge.game.card.*;
import forge.game.combat.Combat;
import forge.game.combat.CombatUtil;
import forge.game.cost.*;
import forge.game.keyword.Keyword;
@@ -43,6 +44,8 @@ public class CountersPutAi extends SpellAbilityAi {
protected boolean willPayCosts(Player ai, SpellAbility sa, Cost cost, Card source) {
final String type = sa.getParam("CounterType");
final String aiLogic = sa.getParamOrDefault("AILogic", "");
// TODO Auto-generated method stub
if (!super.willPayCosts(ai, sa, cost, source)) {
return false;
@@ -53,7 +56,7 @@ public class CountersPutAi extends SpellAbilityAi {
if (part instanceof CostRemoveCounter) {
final CostRemoveCounter remCounter = (CostRemoveCounter) part;
final CounterType counterType = remCounter.counter;
if (counterType.name().equals(type)) {
if (counterType.name().equals(type) && !aiLogic.startsWith("MoveCounter")) {
return false;
}
if (!part.payCostFromSource()) {
@@ -279,6 +282,36 @@ public class CountersPutAi extends SpellAbilityAi {
if (!source.canTransform()) {
return false;
}
} else if (logic.equals("MoveCounterSpike")) {
// Spikes (Tempest)
// Try not to do it unless at the end of opponent's turn or the creature is threatened
Combat combat = ai.getGame().getCombat();
boolean threatened = ComputerUtil.predictThreatenedObjects(ai, null, true).contains(sa.getHostCard());
if (!(threatened || (ph.is(PhaseType.END_OF_TURN) && ph.getNextTurn() == ai))) {
return false;
}
CardCollection targets = CardLists.getTargetableCards(ai.getCreaturesInPlay(), sa);
targets.remove(sa.getHostCard());
targets = CardLists.filter(targets, new Predicate<Card>() {
@Override
public boolean apply(Card card) {
// when threatened, any target is good to preserve the counter
return threatened || ComputerUtilCard.evaluateCreature(card, false, false) > ComputerUtilCard.evaluateCreature(sa.getHostCard(), false, false);
}
});
Card bestTgt = ComputerUtilCard.getBestCreatureAI(targets);
if (bestTgt != null) {
sa.getTargets().add(bestTgt);
return true;
}
return false;
}
if (sa.getConditions() != null && !sa.getConditions().areMet(sa) && sa.getSubAbility() == null) {