From c06cbbfe0f8c517e543c0407ad0742603c532750 Mon Sep 17 00:00:00 2001 From: Agetian Date: Sat, 21 Jan 2017 17:27:12 +0000 Subject: [PATCH] - Made Mizzium Meddler use AI SpellMagnet and thus made it AI-playable. --- .../forge/ai/ability/ChangeTargetsAi.java | 80 ++++++++++++------- .../res/cardsfolder/m/mizzium_meddler.txt | 3 +- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ability/ChangeTargetsAi.java b/forge-ai/src/main/java/forge/ai/ability/ChangeTargetsAi.java index 0049061daec..cdedc23132e 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChangeTargetsAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChangeTargetsAi.java @@ -28,37 +28,7 @@ public class ChangeTargetsAi extends SpellAbilityAi { if (sa.hasParam("AILogic")) { if ("SpellMagnet".equals(sa.getParam("AILogic"))) { - // Cards like Spellskite that retarget spells to itself - - if (topSa == null) { - // nothing on stack, so nothing to target - return false; - } - if (!topSa.usesTargeting() || topSa.getTargets().getTargetCards().contains(sa.getHostCard())) { - // if this does not target at all or already targets host, no need to redirect it again - return false; - } - if (topSa.getHostCard() != null && !topSa.getHostCard().getController().isOpponentOf(aiPlayer)) { - // make sure not to redirect our own abilities - return false; - } - if (!topSa.canTarget(sa.getHostCard())) { - // don't try targeting it if we can't legally target Spellskite with it in the first place - return false; - } - - if ("Spellskite".equals(sa.getHostCard().getName())) { - int potentialDmg = ComputerUtil.predictDamageFromSpell(topSa, aiPlayer); - boolean canPayBlue = ComputerUtilMana.canPayManaCost(new ManaCostBeingPaid(new ManaCost(new ManaCostParser("U"))), sa, aiPlayer); - if (potentialDmg != -1 && potentialDmg <= 2 && !canPayBlue && topSa.getTargets().getTargets().contains(aiPlayer)) { - // do not pay Phyrexian mana if the spell is a damaging one but it deals less damage or the same damage as we'll pay life - return false; - } - } - - sa.resetTargets(); - sa.getTargets().add(topSa); - return true; + return doSpellMagnet(sa, topSa, aiPlayer); } } @@ -68,6 +38,54 @@ public class ChangeTargetsAi extends SpellAbilityAi { @Override protected boolean doTriggerAINoCost(Player aiPlayer, SpellAbility sa, boolean mandatory) { + final Game game = sa.getHostCard().getGame(); + final SpellAbility topSa = game.getStack().isEmpty() ? null : ComputerUtilAbility.getTopSpellAbilityOnStack(game, sa); + + if (sa.hasParam("AILogic")) { + if ("SpellMagnet".equals(sa.getParam("AILogic"))) { + return doSpellMagnet(sa, topSa, aiPlayer); + } + } + + return true; + } + + private boolean doSpellMagnet(SpellAbility sa, SpellAbility topSa, Player aiPlayer) { + // For cards like Spellskite that retarget spells to itself + if (topSa == null) { + // nothing on stack, so nothing to target + return false; + } + + if (sa.getTargets().getNumTargeted() != 0) { + // something was already chosen before (e.g. in response to a trigger - Mizzium Meddler), so just proceed + return true; + } + + if (!topSa.usesTargeting() || topSa.getTargets().getTargetCards().contains(sa.getHostCard())) { + // if this does not target at all or already targets host, no need to redirect it again + return false; + } + if (topSa.getHostCard() != null && !topSa.getHostCard().getController().isOpponentOf(aiPlayer)) { + // make sure not to redirect our own abilities + return false; + } + if (!topSa.canTarget(sa.getHostCard())) { + // don't try targeting it if we can't legally target the host card with it in the first place + return false; + } + + if ("Spellskite".equals(sa.getHostCard().getName())) { + int potentialDmg = ComputerUtil.predictDamageFromSpell(topSa, aiPlayer); + boolean canPayBlue = ComputerUtilMana.canPayManaCost(new ManaCostBeingPaid(new ManaCost(new ManaCostParser("U"))), sa, aiPlayer); + if (potentialDmg != -1 && potentialDmg <= 2 && !canPayBlue && topSa.getTargets().getTargets().contains(aiPlayer)) { + // do not pay Phyrexian mana if the spell is a damaging one but it deals less damage or the same damage as we'll pay life + return false; + } + } + + sa.resetTargets(); + sa.getTargets().add(topSa); return true; } } diff --git a/forge-gui/res/cardsfolder/m/mizzium_meddler.txt b/forge-gui/res/cardsfolder/m/mizzium_meddler.txt index 7aa6143a7d9..cbd3383e9bc 100644 --- a/forge-gui/res/cardsfolder/m/mizzium_meddler.txt +++ b/forge-gui/res/cardsfolder/m/mizzium_meddler.txt @@ -4,7 +4,6 @@ Types:Creature Vedalken Wizard PT:1/4 K:Flash T:Mode$ ChangesZone | Origin$ Any | Destination$ Battlefield | ValidCard$ Card.Self | Execute$ TrigChange | OptionalDecider$ You | TriggerDescription$ When CARDNAME enters the battlefield, you may change a target of target spell or ability to CARDNAME. -SVar:TrigChange:AB$ ChangeTargets | Cost$ 0 | TargetType$ Spell,Activated,Triggered | ValidTgts$ Card | DefinedMagnet$ Self | ChangeSingleTarget$ True -SVar:RemAIDeck:True +SVar:TrigChange:AB$ ChangeTargets | Cost$ 0 | TargetType$ Spell,Activated,Triggered | ValidTgts$ Card | DefinedMagnet$ Self | ChangeSingleTarget$ True | AILogic$ SpellMagnet SVar:Picture:http://www.wizards.com/global/images/magic/general/mizzium_meddler.jpg Oracle:Flash (You may cast this spell any time you could cast an instant.)\nWhen Mizzium Meddler enters the battlefield, you may change a target of target spell or ability to Mizzium Meddler. \ No newline at end of file