diff --git a/forge-ai/src/main/java/forge/ai/ability/DamageEachAi.java b/forge-ai/src/main/java/forge/ai/ability/DamageEachAi.java index 03057b3c86b..f3081ab7003 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamageEachAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamageEachAi.java @@ -2,7 +2,13 @@ package forge.ai.ability; import forge.game.ability.AbilityUtils; +import forge.game.card.Card; +import forge.game.card.CardCollection; +import forge.game.card.CardLists; +import forge.game.card.CardPredicates; import forge.game.player.Player; +import forge.game.player.PlayerCollection; +import forge.game.player.PlayerPredicates; import forge.game.spellability.SpellAbility; import forge.game.spellability.TargetRestrictions; @@ -14,12 +20,28 @@ public class DamageEachAi extends DamageAiBase { @Override protected boolean canPlayAI(Player ai, SpellAbility sa) { final TargetRestrictions tgt = sa.getTargetRestrictions(); + final String logic = sa.getParam("AILogic"); - if (tgt != null && sa.canTarget(ai.getOpponent())) { + PlayerCollection targetableOpps = ai.getOpponents().filter(PlayerPredicates.isTargetableBy(sa)); + Player weakestOpp = targetableOpps.min(PlayerPredicates.compareByLife()); + + if (tgt != null && weakestOpp != null) { sa.resetTargets(); - sa.getTargets().add(ai.getOpponent()); + sa.getTargets().add(weakestOpp); } + if ("MadSarkhanUltimate".equals(logic)) { + int minLife = weakestOpp.getLife(); + + int dragonPower = 0; + CardCollection dragons = CardLists.filter(ai.getCreaturesInPlay(), CardPredicates.isType("Dragon")); + for (Card c : dragons) { + dragonPower += c.getCurrentPower(); + } + + return dragonPower >= minLife; + } + final String damage = sa.getParam("NumDmg"); final int iDmg = AbilityUtils.calculateAmount(sa.getHostCard(), damage, sa); return this.shouldTgtP(ai, sa, iDmg, false); diff --git a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java index 3e44a27b3a9..3960a560235 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java @@ -77,7 +77,7 @@ public class DestroyAi extends SpellAbilityAi { } if ("MadSarkhanDragon".equals(logic)) { // TODO: expand this logic to make the AI force the opponent to sacrifice a big threat bigger than a 5/5 flier? - CardCollection creatures = CardLists.filter(ai.getCardsIn(ZoneType.Battlefield), CardPredicates.Presets.CREATURES); + CardCollection creatures = ai.getCreaturesInPlay(); boolean hasValidTgt = !CardLists.filter(creatures, new Predicate() { @Override public boolean apply(Card t) { diff --git a/forge-gui/res/cardsfolder/s/sarkhan_the_mad.txt b/forge-gui/res/cardsfolder/s/sarkhan_the_mad.txt index 9673d4a5b81..b3320157ba2 100644 --- a/forge-gui/res/cardsfolder/s/sarkhan_the_mad.txt +++ b/forge-gui/res/cardsfolder/s/sarkhan_the_mad.txt @@ -9,7 +9,7 @@ SVar:Y:Remembered$CardManaCost A:AB$ Destroy | Cost$ SubCounter<2/LOYALTY> | ValidTgts$ Creature | TgtPrompt$ Select target creature | Sacrifice$ True | SubAbility$ DBToken | Planeswalker$ True | AILogic$ MadSarkhanDragon | SpellDescription$ Target creature's controller sacrifices it, then that player creates a 5/5 red Dragon creature token with flying. SVar:DBToken:DB$ Token | TokenAmount$ 1 | TokenName$ Dragon | TokenTypes$ Creature,Dragon | TokenOwner$ TargetedController | TokenColors$ Red | TokenPower$ 5 | TokenToughness$ 5 | TokenImage$ r 5 5 dragon WWK | TokenKeywords$ Flying #for this AF, the DefinedCards$ Self is the target for Each damaging. They EachDamage themselves. -A:AB$ EachDamage | Cost$ SubCounter<4/LOYALTY> | ValidCards$ Dragon.Creature+YouCtrl | ValidDescription$ Dragon creature you control | NumDmg$ X | DamageDesc$ damage equal to its power | ValidTgts$ Player | TgtPrompt$ Select target player | Planeswalker$ True | Ultimate$ True | References$ X | SpellDescription$ Each Dragon creature you control deals damage equal to its power to target player. +A:AB$ EachDamage | Cost$ SubCounter<4/LOYALTY> | ValidCards$ Dragon.Creature+YouCtrl | ValidDescription$ Dragon creature you control | NumDmg$ X | DamageDesc$ damage equal to its power | ValidTgts$ Player | TgtPrompt$ Select target player | Planeswalker$ True | Ultimate$ True | References$ X | AILogic$ MadSarkhanUltimate | SpellDescription$ Each Dragon creature you control deals damage equal to its power to target player. #NumDmg isn't really used here. It is left for clarity. The AF pulls Damage straight from "X" hardcoded. SVar:X:Count$CardPower SVar:Picture:http://www.wizards.com/global/images/magic/general/sarkhan_the_mad.jpg