From 8a39ff469fb7d0e745cbb07f21c3918b04b883c2 Mon Sep 17 00:00:00 2001 From: Agetian Date: Tue, 1 Aug 2017 16:52:26 +0000 Subject: [PATCH] - Added Power Leak (for now, needs a special exclusion in the AI code to properly determine who the paying player is, otherwise the AI believes that it's the opponent who owns Power Leak in case it's cast by the opponent). --- .gitattributes | 1 + .../main/java/forge/ai/PlayerControllerAi.java | 17 ++++++++++++++++- forge-gui/res/cardsfolder/p/power_leak.txt | 15 +++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 forge-gui/res/cardsfolder/p/power_leak.txt diff --git a/.gitattributes b/.gitattributes index f34f0acf250..4ad43759d54 100644 --- a/.gitattributes +++ b/.gitattributes @@ -12285,6 +12285,7 @@ forge-gui/res/cardsfolder/p/powder_keg.txt svneol=native#text/plain forge-gui/res/cardsfolder/p/power_armor.txt svneol=native#text/plain forge-gui/res/cardsfolder/p/power_artifact.txt svneol=native#text/plain forge-gui/res/cardsfolder/p/power_conduit.txt -text +forge-gui/res/cardsfolder/p/power_leak.txt -text forge-gui/res/cardsfolder/p/power_matrix.txt svneol=native#text/plain forge-gui/res/cardsfolder/p/power_of_fire.txt svneol=native#text/plain forge-gui/res/cardsfolder/p/power_play.txt -text diff --git a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java index fc154226cc2..4d16b3c8818 100644 --- a/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java +++ b/forge-ai/src/main/java/forge/ai/PlayerControllerAi.java @@ -115,7 +115,22 @@ public class PlayerControllerAi extends PlayerController { if (ability.getApi() != null) { switch (ability.getApi()) { case ChooseNumber: - return ability.getActivatingPlayer().isOpponentOf(player) ? 0 : ComputerUtilMana.determineLeftoverMana(ability, player); + Player payingPlayer = ability.getActivatingPlayer(); + String logic = ability.getParamOrDefault("AILogic", ""); + + if (logic.startsWith("PowerLeakMaxMana.") && ability.getHostCard().isEnchantingCard()) { + // For cards like Power Leak, the payer will be the owner of the enchanted card + // TODO: is there any way to generalize this and avoid a special exclusion? + payingPlayer = ability.getHostCard().getEnchantingCard().getController(); + } + + int number = ComputerUtilMana.determineLeftoverMana(ability, player); + + if (logic.startsWith("MaxMana.") || logic.startsWith("PowerLeakMaxMana.")) { + number = Math.min(number, Integer.parseInt(logic.substring(logic.indexOf(".") + 1))); + } + + return payingPlayer.isOpponentOf(player) ? 0 : number; case BidLife: return 0; default: diff --git a/forge-gui/res/cardsfolder/p/power_leak.txt b/forge-gui/res/cardsfolder/p/power_leak.txt new file mode 100644 index 00000000000..18b782eaf87 --- /dev/null +++ b/forge-gui/res/cardsfolder/p/power_leak.txt @@ -0,0 +1,15 @@ +Name:Power Leak +ManaCost:1 U +Types:Enchantment Aura +K:Enchant enchantment +A:SP$ Attach | Cost$ 1 U | ValidTgts$ Enchantment | AILogic$ Curse +T:Mode$ Phase | Phase$ Upkeep | ValidPlayer$ EnchantedController | Execute$ DBPay | TriggerZones$ Battlefield | TriggerDescription$ At the beginning of the upkeep of enchanted enchantment's controller, that player may pay any amount of mana. CARDNAME deals 2 damage to that player. Prevent X of that damage, where X is the amount of mana that player paid this way. +S:Mode$ PreventDamage | Target$ EnchantedController | Source$ Card.Self | Amount$ PaidAmount | References$ PaidAmount | Secondary$ True +SVar:DBPay:DB$ ChooseNumber | Defined$ EnchantedController | ChooseAnyNumber$ True | ListTitle$ Pay Any Mana | AILogic$ PowerLeakMaxMana.2 | SubAbility$ DBStore +SVar:DBStore:DB$ StoreSVar | SVar$ PaidAmount | Type$ CountSVar | Expression$ X | UnlessCost$ X | UnlessPayer$ EnchantedController | UnlessSwitched$ True | References$ X,PaidAmount | SubAbility$ DBDmg +SVar:DBDmg:DB$ DealDamage | Defined$ EnchantedController | NumDmg$ 2 | SubAbility$ DBReset | References$ PaidAmount | StackDescription$ None +SVar:DBReset:DB$ StoreSVar | SVar$ PaidAmount | Type$ Number | Expression$ 0 | References$ PaidAmount +SVar:X:Count$ChosenNumber +SVar:PaidAmount:Number$0 +SVar:Picture:http://www.wizards.com/global/images/magic/general/power_leak.jpg +Oracle:Enchant enchantment\nAt the beginning of the upkeep of enchanted enchantment's controller, that player may pay any amount of mana. Power Leak deals 2 damage to that player. Prevent X of that damage, where X is the amount of mana that player paid this way.