From 2371d52c9d9fbf787b2005c8c2a95c14cb1bad4e Mon Sep 17 00:00:00 2001 From: excessum Date: Thu, 27 Mar 2014 13:52:03 +0000 Subject: [PATCH] - AI support for Polukranos, World Eater --- .../java/forge/ai/ability/CountersPutAi.java | 15 +++++++++ .../java/forge/ai/ability/DamageDealAi.java | 32 +++++++++++++++++++ .../cardsfolder/p/polukranos_world_eater.txt | 5 ++- 3 files changed, 49 insertions(+), 3 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java index 9e765855ffd..b0f727a5311 100644 --- a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java @@ -127,6 +127,21 @@ public class CountersPutAi extends SpellAbilityAi { amount = ComputerUtilMana.determineLeftoverMana(sa, ai); source.setSVar("PayX", Integer.toString(amount)); } + if ("Polukranos".equals(sa.getParam("AILogic"))) { + List humCreatures = ai.getOpponent().getCreaturesInPlay(); + //TODO how to grab target restrictions from subsequent triggered ability? + if (!humCreatures.isEmpty()){ + boolean canSurvive = false; + for (Card humanCreature : humCreatures) { + if (!FightAi.canKill(humanCreature, source, 0)){ + canSurvive = true; + } + } + if (!canSurvive){ + return false; + } + } + } // don't use it if no counters to add if (amount <= 0) { diff --git a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java index 6e7af128ac2..50cba71797c 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java @@ -2,6 +2,7 @@ package forge.ai.ability; import com.google.common.base.Predicate; import com.google.common.collect.Lists; + import forge.ai.*; import forge.game.Game; import forge.game.GameObject; @@ -254,6 +255,37 @@ public class DamageDealAi extends DamageAiBase { return false; } + if ("Polukranos".equals(sa.getParam("AILogic"))) { + int dmgTaken = 0; + List humCreatures = ai.getOpponent().getCreaturesInPlay(); + Card lastTgt = null; + humCreatures = CardLists.getTargetableCards(humCreatures, sa); + ComputerUtilCard.sortByEvaluateCreature(humCreatures); + for (Card humanCreature : humCreatures) { + if (FightAi.canKill(humanCreature, source, dmgTaken)) { + continue; + } + final int assignedDamage = ComputerUtilCombat.getEnoughDamageToKill(humanCreature, dmg, source, false, noPrevention); + if (assignedDamage <= dmg) { + tcs.add(humanCreature); + tgt.addDividedAllocation(humanCreature, assignedDamage); + lastTgt = humanCreature; + } + dmg -= assignedDamage; + if (!source.hasProtectionFrom(humanCreature)) { + dmgTaken += humanCreature.getNetAttack(); + } + if (dmg <= 0) { + break; + } + } + if (dmg > 0 && lastTgt != null) { + tgt.addDividedAllocation(lastTgt, tgt.getDividedValue(lastTgt) + dmg); + dmg = 0; + return true; + } + //fall back into generic targeting due to failure to restrict targets in CountersPutAi or change in board state + } while (tcs.getNumTargeted() < tgt.getMaxTargets(source, sa)) { if (oppTargetsChoice && sa.getActivatingPlayer().equals(ai) && !sa.isTrigger()) { // canPlayAI (sa activated by ai) diff --git a/forge-gui/res/cardsfolder/p/polukranos_world_eater.txt b/forge-gui/res/cardsfolder/p/polukranos_world_eater.txt index f7d07017494..55a9e3cbc8f 100644 --- a/forge-gui/res/cardsfolder/p/polukranos_world_eater.txt +++ b/forge-gui/res/cardsfolder/p/polukranos_world_eater.txt @@ -2,15 +2,14 @@ Name:Polukranos, World Eater ManaCost:2 G G Types:Legendary Creature Hydra PT:5/5 -K:Monstrosity X:X X G +K:Monstrosity X:X X G | AILogic$ Polukranos T:Mode$ BecomeMonstrous | ValidCard$ Card.Self | TriggerZones$ Battlefield | Execute$ TrigDmg | TriggerDescription$ When CARDNAME becomes monstrous, it deals X damage divided as you choose among any number of target creatures your opponents control. Each of those creatures deals damage equal to its power to CARDNAME. -SVar:TrigDmg:AB$ DealDamage | Cost$ 0 | ValidTgts$ Creature.OppCtrl | TgtPrompt$ Select target creature your opponents control distribute damage to | NumDmg$ MonstrosityX | TargetMin$ 1 | TargetMax$ MaxTgts | DividedAsYouChoose$ MonstrosityX | References$ MonstrosityX,MaxTgts | SubAbility$ DBDmg +SVar:TrigDmg:AB$ DealDamage | Cost$ 0 | ValidTgts$ Creature.OppCtrl | AILogic$ Polukranos | TgtPrompt$ Select target creature your opponents control distribute damage to | NumDmg$ MonstrosityX | TargetMin$ 1 | TargetMax$ MaxTgts | DividedAsYouChoose$ MonstrosityX | References$ MonstrosityX,MaxTgts | SubAbility$ DBDmg SVar:DBDmg:DB$ RepeatEach | RepeatSubAbility$ PolukranosFight | UseImprinted$ True | DefinedCards$ Targeted | StackDescription$ None SVar:PolukranosFight:DB$ DealDamage | DamageSource$ Imprinted | NumDmg$ Y | References$ Y | Defined$ Self | StackDescription$ None SVar:X:Count$xPaid SVar:Y:Imprinted$CardPower SVar:MonstrosityX:Count$MonstrosityMagnitude SVar:MaxTgts:Count$Valid Creature.OppCtrl -SVar:RemAIDeck:True SVar:Picture:http://www.wizards.com/global/images/magic/general/polukranos_world_eater.jpg Oracle:{X}{X}{G}: Monstrosity X. (If this creature isn't monstrous, put X +1/+1 counters on it and it becomes monstrous.) When Polukranos, World Eater becomes monstrous, it deals X damage divided as you choose among any number of target creatures your opponents control. Each of those creatures deals damage equal to its power to Polukranos. \ No newline at end of file