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
This commit is contained in:
grimreap124 2024-06-07 10:45:34 +10:00
parent 015a19f6c6
commit f7b38a80f1
2 changed files with 39 additions and 6 deletions

View file

@ -22,21 +22,23 @@ public class HourglassOfTheLostTest extends CardTestPlayerBase {
skipInitShuffling(); skipInitShuffling();
addCard(Zone.BATTLEFIELD, playerA, hourglass); 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}"); activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {W}");
setStopAt(1, PhaseStep.POSTCOMBAT_MAIN); setStopAt(1, PhaseStep.POSTCOMBAT_MAIN);
execute(); execute();
assertCounterCount(playerA, hourglass, CounterType.TIME,1); assertCounterCount(playerA, hourglass, CounterType.TIME,1);
assertExileCount(playerA, 0);
assertGraveyardCount(playerA, 2);
showAvailableAbilities("Abilities: ", 3, PhaseStep.PRECOMBAT_MAIN, playerA); setChoiceAmount(playerA, 1); // Remove 1 counter
setChoiceAmount(playerA, 1); activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Remove X"); // Return all with mana value 1
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Remove X");
setStopAt(3, PhaseStep.POSTCOMBAT_MAIN); setStopAt(3, PhaseStep.POSTCOMBAT_MAIN);
execute(); execute();
assertExileCount(playerA, 1); assertExileCount(playerA, 1);
assertGraveyardCount(playerA, 0); assertGraveyardCount(playerA, 1); // +2 Mace still in graveyard
assertPermanentCount(playerA, "Birds of Paradise", 1); assertPermanentCount(playerA, "Birds of Paradise", 1);
} }

View file

@ -550,7 +550,12 @@ public abstract class AbilityImpl implements Ability {
if (!(variableCost instanceof VariableManaCost) && !((Cost) variableCost).isPaid()) { if (!(variableCost instanceof VariableManaCost) && !((Cost) variableCost).isPaid()) {
int xValue = variableCost.announceXValue(this, game); int xValue = variableCost.announceXValue(this, game);
Cost fixedCost = variableCost.getFixedCostsFromAnnouncedValue(xValue); Cost fixedCost = variableCost.getFixedCostsFromAnnouncedValue(xValue);
int index = getCosts().indexOf(variableCost);
if (index == -1) {
addCost(fixedCost); addCost(fixedCost);
} else {
addCost(fixedCost, index + 1);
}
// set the xcosts to paid // set the xcosts to paid
// no x events - rules from Unbound Flourishing: // 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. // - 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<Cost> list = (Costs<Cost>) 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 @Override
public void addManaCostsToPay(ManaCost manaCost) { public void addManaCostsToPay(ManaCost manaCost) {
if (manaCost == null) { if (manaCost == null) {