From f7b38a80f1fc6d2383ff6e30ea35cf0a5198932e Mon Sep 17 00:00:00 2001 From: grimreap124 <19590931+grimreap124@users.noreply.github.com> Date: Fri, 7 Jun 2024 10:45:34 +1000 Subject: [PATCH] VariableCosts added to costs VariableCosts will now be added to the costs list right after its select so it is in the same order as intended by the card --- .../single/m3c/HourglassOfTheLostTest.java | 12 ++++--- .../main/java/mage/abilities/AbilityImpl.java | 33 ++++++++++++++++++- 2 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/m3c/HourglassOfTheLostTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/m3c/HourglassOfTheLostTest.java index 75364f145ed..b9f3e149385 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/m3c/HourglassOfTheLostTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/m3c/HourglassOfTheLostTest.java @@ -22,21 +22,23 @@ public class HourglassOfTheLostTest extends CardTestPlayerBase { skipInitShuffling(); addCard(Zone.BATTLEFIELD, playerA, hourglass); - addCard(Zone.GRAVEYARD, playerA, "Birds of Paradise"); // Tribal Enchantment + addCard(Zone.GRAVEYARD, playerA, "Birds of Paradise"); // Mana value 1 + addCard(Zone.GRAVEYARD, playerA, "+2 Mace"); // Mana value 2 activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {W}"); setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); execute(); assertCounterCount(playerA, hourglass, CounterType.TIME,1); + assertExileCount(playerA, 0); + assertGraveyardCount(playerA, 2); - showAvailableAbilities("Abilities: ", 3, PhaseStep.PRECOMBAT_MAIN, playerA); - setChoiceAmount(playerA, 1); - activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Remove X"); + setChoiceAmount(playerA, 1); // Remove 1 counter + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Remove X"); // Return all with mana value 1 setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); execute(); assertExileCount(playerA, 1); - assertGraveyardCount(playerA, 0); + assertGraveyardCount(playerA, 1); // +2 Mace still in graveyard assertPermanentCount(playerA, "Birds of Paradise", 1); } diff --git a/Mage/src/main/java/mage/abilities/AbilityImpl.java b/Mage/src/main/java/mage/abilities/AbilityImpl.java index dd4a4d9e2fb..a1ea0e2e62f 100644 --- a/Mage/src/main/java/mage/abilities/AbilityImpl.java +++ b/Mage/src/main/java/mage/abilities/AbilityImpl.java @@ -550,7 +550,12 @@ public abstract class AbilityImpl implements Ability { if (!(variableCost instanceof VariableManaCost) && !((Cost) variableCost).isPaid()) { int xValue = variableCost.announceXValue(this, game); Cost fixedCost = variableCost.getFixedCostsFromAnnouncedValue(xValue); - addCost(fixedCost); + int index = getCosts().indexOf(variableCost); + if (index == -1) { + addCost(fixedCost); + } else { + addCost(fixedCost, index + 1); + } // set the xcosts to paid // no x events - rules from Unbound Flourishing: // - Spells with additional costs that include X won't be affected by Unbound Flourishing. X must be in the spell's mana cost. @@ -928,6 +933,32 @@ public abstract class AbilityImpl implements Ability { } } + public void addCost(Cost cost, int index) { + if (cost == null) { + return; + } + if (cost instanceof Costs) { + // as list of costs + Costs list = (Costs) cost; + for (Cost single : list) { + addCost(single); + } + } else { + // as single cost + if (cost instanceof ManaCost) { + manaCosts.add((ManaCost) cost); + manaCostsToPay.add((ManaCost) cost); + } else { + if (index > costs.size()) { + costs.add(cost); + } else { + costs.add(index, cost); + } + costs.add(index, cost); + } + } + } + @Override public void addManaCostsToPay(ManaCost manaCost) { if (manaCost == null) {