From b878a93d403e236ef1e11f3d740f76eaf4120a9c Mon Sep 17 00:00:00 2001 From: Agetian Date: Sun, 25 Jun 2017 16:47:17 +0000 Subject: [PATCH] - Added a way to define card-based AI priority for paying the Remove Counter cost. - Set the AI priority for Power Conduit to ANY to avoid the AI lagging heavily while looping through the cost and spamming the console with errors. - Currently the AI will use this card rather randomly. Consider improving or marking it as RemRandomDeck at the very least. --- .../main/java/forge/ai/AiCostDecision.java | 31 +++++++++++++++++++ forge-gui/res/cardsfolder/p/power_conduit.txt | 1 + 2 files changed, 32 insertions(+) diff --git a/forge-ai/src/main/java/forge/ai/AiCostDecision.java b/forge-ai/src/main/java/forge/ai/AiCostDecision.java index b7451254003..7e2946c7c3b 100644 --- a/forge-ai/src/main/java/forge/ai/AiCostDecision.java +++ b/forge-ai/src/main/java/forge/ai/AiCostDecision.java @@ -22,6 +22,7 @@ import forge.game.player.Player; import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbilityStackInstance; import forge.game.zone.ZoneType; +import forge.util.TextUtil; import forge.util.collect.FCollectionView; public class AiCostDecision extends CostDecisionMakerBase { @@ -710,6 +711,36 @@ public class AiCostDecision extends CostDecisionMakerBase { return result; } + // check if the card defines its own priorities for counter removal as cost + if (source.hasSVar("AIRemoveCounterCostPriority")) { + String[] counters = TextUtil.split(source.getSVar("AIRemoveCounterCostPriority"), ','); + + for (final String ctr : counters) { + List withCtr = CardLists.filter(typeList, new Predicate() { + @Override + public boolean apply(final Card crd) { + for (Map.Entry e : crd.getCounters().entrySet()) { + if (e.getValue() >= c && (ctr.equals("ANY") || e.getKey() == CounterType.valueOf(ctr))) { + return true; + } + } + return false; + } + }); + if (!withCtr.isEmpty()) { + final Card card = withCtr.get(0); + PaymentDecision result = PaymentDecision.card(card); + + for (Map.Entry e : card.getCounters().entrySet()) { + if (e.getValue() >= c && (ctr.equals("ANY") || e.getKey() == CounterType.valueOf(ctr))) { + result.ct = e.getKey(); + break; + } + } + return result; + } + } + } return null; } diff --git a/forge-gui/res/cardsfolder/p/power_conduit.txt b/forge-gui/res/cardsfolder/p/power_conduit.txt index 2ff6867f929..0feda535bd2 100644 --- a/forge-gui/res/cardsfolder/p/power_conduit.txt +++ b/forge-gui/res/cardsfolder/p/power_conduit.txt @@ -4,5 +4,6 @@ Types:Artifact A:AB$ Charm | Cost$ T RemoveAnyCounter<1/Permanent.YouCtrl/a permanent you control> | Choices$ ConduitCharge,ConduitP1P1 | Defined$ You SVar:ConduitCharge:DB$ PutCounter | ValidTgts$ Artifact | TgtPrompt$ Select target artifact | CounterType$ CHARGE | CounterNum$ 1 | SpellDescription$ Put a charge counter on target artifact. SVar:ConduitP1P1:DB$ PutCounter | ValidTgts$ Creature | TgtPrompt$ Select target creature | CounterType$ P1P1 | CounterNum$ 1 | SpellDescription$ Put a +1/+1 counter on target creature. +SVar:AIRemoveCounterCostPriority:ANY SVar:Picture:http://www.wizards.com/global/images/magic/general/power_conduit.jpg Oracle:{T}, Remove a counter from a permanent you control: Choose one —\n• Put a charge counter on target artifact.\n• Put a +1/+1 counter on target creature.