From 49cdd4d36de9f3d217d4dd6ba397e6e80c07a2bb Mon Sep 17 00:00:00 2001 From: Hythonia Date: Mon, 12 Apr 2021 09:13:35 +0200 Subject: [PATCH] DefinedCost and DefinedManaCost --- .../java/forge/game/ability/AbilityUtils.java | 38 ++++++++++++++++--- forge-gui/res/cardsfolder/f/flash.txt | 3 +- forge-gui/res/cardsfolder/i/ice_cave.txt | 3 +- 3 files changed, 35 insertions(+), 9 deletions(-) diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index dfe462d9206..f9e56d059a3 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -1496,17 +1496,45 @@ public class AbilityUtils { else if (unlessCost.equals("ChosenNumber")) { cost = new Cost(new ManaCost(new ManaCostParser(String.valueOf(source.getChosenNumber()))), true); } - else if (unlessCost.equals("RememberedCostMinus2")) { - Card rememberedCard = (Card) source.getFirstRemembered(); - if (rememberedCard == null) { + else if (unlessCost.startsWith("DefinedCost")) { + CardCollection definedCards = AbilityUtils.getDefinedCards(sa.getHostCard(), unlessCost.split("_")[1], sa); + if (definedCards.isEmpty()) { sa.resolve(); resolveSubAbilities(sa, game); return; } - ManaCostBeingPaid newCost = new ManaCostBeingPaid(rememberedCard.getManaCost()); - newCost.decreaseGenericMana(2); + Card card = definedCards.getFirst(); + ManaCostBeingPaid newCost = new ManaCostBeingPaid(card.getManaCost()); + // Check if there's a third underscore for cost modifying + if (unlessCost.split("_").length == 3) { + String modifier = unlessCost.split("_")[2]; + if (modifier.startsWith("Minus")) { + newCost.decreaseGenericMana(Integer.parseInt(modifier.substring(5))); + } else { + newCost.increaseGenericMana(Integer.parseInt(modifier.substring(4))); + } + } cost = new Cost(newCost.toManaCost(), true); } + else if (unlessCost.startsWith("DefinedSACost")) { + FCollection definedSAs = AbilityUtils.getDefinedSpellAbilities(sa.getHostCard(), unlessCost.split("_")[1], sa); + if (definedSAs.isEmpty()) { + sa.resolve(); + resolveSubAbilities(sa, game); + return; + } + Card host = definedSAs.getFirst().getHostCard(); + if (host.getManaCost() == null) { + cost = new Cost(ManaCost.ZERO, true); + } else { + int xCount = host.getManaCost().countX(); + int xPaid = host.getXManaCostPaid() * xCount; + ManaCostBeingPaid toPay = new ManaCostBeingPaid(host.getManaCost()); + toPay.decreaseShard(ManaCostShard.X, xCount); + toPay.increaseGenericMana(xPaid); + cost = new Cost(toPay.toManaCost(), true); + } + } else if (!StringUtils.isBlank(sa.getSVar(unlessCost)) || !StringUtils.isBlank(source.getSVar(unlessCost))) { // check for X costs (stored in SVars int xCost = calculateAmount(source, TextUtil.fastReplace(sa.getParam("UnlessCost"), diff --git a/forge-gui/res/cardsfolder/f/flash.txt b/forge-gui/res/cardsfolder/f/flash.txt index 70df31d4ff3..4b2ddd374da 100644 --- a/forge-gui/res/cardsfolder/f/flash.txt +++ b/forge-gui/res/cardsfolder/f/flash.txt @@ -2,8 +2,7 @@ Name:Flash ManaCost:1 U Types:Instant A:SP$ ChangeZone | Cost$ 1 U | Origin$ Hand | Destination$ Battlefield | ChangeType$ Creature | ChangeNum$ 1 | SubAbility$ DBSac | RememberChanged$ True | SpellDescription$ You may put a creature card from your hand onto the battlefield. If you do, sacrifice it unless you pay its mana cost reduced by up to {2}. -SVar:DBSac:DB$ SacrificeAll | Defined$ Remembered | UnlessCost$ RememberedCostMinus2 | UnlessPayer$ You | SubAbility$ DBCleanup +SVar:DBSac:DB$ SacrificeAll | Defined$ Remembered | UnlessCost$ DefinedCost_Remembered_Minus2 | UnlessPayer$ You | SubAbility$ DBCleanup SVar:DBCleanup:DB$ Cleanup | ClearRemembered$ True AI:RemoveDeck:All -SVar:Picture:http://www.wizards.com/global/images/magic/general/flash.jpg Oracle:You may put a creature card from your hand onto the battlefield. If you do, sacrifice it unless you pay its mana cost reduced by up to {2}. diff --git a/forge-gui/res/cardsfolder/i/ice_cave.txt b/forge-gui/res/cardsfolder/i/ice_cave.txt index 1057a2c36d6..db3a2b44a3e 100644 --- a/forge-gui/res/cardsfolder/i/ice_cave.txt +++ b/forge-gui/res/cardsfolder/i/ice_cave.txt @@ -2,6 +2,5 @@ Name:Ice Cave ManaCost:3 U U Types:Enchantment T:Mode$ SpellCast | ValidCard$ Card | TriggerZones$ Battlefield | Execute$ TrigCounter | TriggerDescription$ Whenever a player casts a spell, any other player may pay that spell's mana cost. If a player does, counter the spell. (Mana cost includes color.) -SVar:TrigCounter:DB$ Counter | Defined$ TriggeredSpellAbility | UnlessCost$ TriggeredSpellManaCost | UnlessPayer$ NonTriggeredCardController | UnlessSwitched$ True -SVar:Picture:http://www.wizards.com/global/images/magic/general/ice_cave.jpg +SVar:TrigCounter:DB$ Counter | Defined$ TriggeredSpellAbility | UnlessCost$ DefinedSACost_TriggeredSpellAbility | UnlessPayer$ NonTriggeredCardController | UnlessSwitched$ True Oracle:Whenever a player casts a spell, any other player may pay that spell's mana cost. If a player does, counter the spell. (Mana cost includes color.)