mirror of
https://github.com/magefree/mage.git
synced 2025-12-22 03:22:00 -08:00
* Fixed a bug that mana source restrictins got lost with mana cost madification (e.g. cast Myr Superion while Etherium Sculptor in play).
This commit is contained in:
parent
fcc28ac0f3
commit
f84d624f1f
4 changed files with 58 additions and 6 deletions
|
|
@ -45,4 +45,51 @@ public class CostModificationTest extends CardTestPlayerBase {
|
||||||
assertGraveyardCount(playerA, 1);
|
assertGraveyardCount(playerA, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that cost reduction also works with mana source restriction
|
||||||
|
* Myr Superion
|
||||||
|
* Spend only mana produced by creatures to cast Myr Superion
|
||||||
|
*
|
||||||
|
* Etherium Sculptor {1}{U}
|
||||||
|
* Artifact Creature - Vedalken Artificer
|
||||||
|
* 1/2
|
||||||
|
* Artifact spells you cast cost {1} less to cast.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCostReductionWithManaSourceRestrictionWorking() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Etherium Sculptor");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Llanowar Elves");
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Myr Superion");
|
||||||
|
|
||||||
|
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Add {G} to your mana pool.");
|
||||||
|
castSpell(3, PhaseStep.PRECOMBAT_MAIN, playerA, "Myr Superion");
|
||||||
|
setStopAt(3, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Myr Superion", 1); // Can be cast because mana was produced by a creature
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCostReductionWithManaSourceRestrictionNotWorking() {
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Etherium Sculptor");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain");
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerA, "Myr Superion");
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Myr Superion");
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertLife(playerA, 20);
|
||||||
|
assertLife(playerB, 20);
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Myr Superion", 0); // Can't be cast because mana was not produced by a creature
|
||||||
|
assertHandCount(playerA, "Myr Superion", 1); // Can't be cast because mana was not produced by a creature
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -422,7 +422,12 @@ public class ManaCostsImpl<T extends ManaCost> extends ArrayList<T> implements M
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Filter getSourceFilter() {
|
public Filter getSourceFilter() {
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
for (T cost : this) {
|
||||||
|
if (cost.getSourceFilter() != null) {
|
||||||
|
return cost.getSourceFilter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -102,7 +102,7 @@ public class SpellsCostReductionControllerEffect extends CostModificationEffectI
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
return this.filter.match(spell, game);
|
return this.filter.match(spell, game);
|
||||||
} else {
|
} else {
|
||||||
// used at least for flashback ability because Flashback ability doesn't use stack
|
// used at least for flashback ability because Flashback ability doesn't use stack or for getPlayables where spell is not cast yet
|
||||||
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
Card sourceCard = game.getCard(abilityToModify.getSourceId());
|
||||||
return sourceCard != null && this.filter.match(sourceCard, game);
|
return sourceCard != null && this.filter.match(sourceCard, game);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,7 +195,7 @@ public class CardUtil {
|
||||||
|
|
||||||
private static ManaCosts<ManaCost> adjustCost(ManaCosts<ManaCost> manaCosts, int reduceCount) {
|
private static ManaCosts<ManaCost> adjustCost(ManaCosts<ManaCost> manaCosts, int reduceCount) {
|
||||||
int restToReduce = reduceCount;
|
int restToReduce = reduceCount;
|
||||||
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
|
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
|
||||||
boolean updated = false;
|
boolean updated = false;
|
||||||
for (ManaCost manaCost : manaCosts) {
|
for (ManaCost manaCost : manaCosts) {
|
||||||
Mana mana = manaCost.getOptions().get(0);
|
Mana mana = manaCost.getOptions().get(0);
|
||||||
|
|
@ -217,7 +217,7 @@ public class CardUtil {
|
||||||
if (!updated && reduceCount < 0) {
|
if (!updated && reduceCount < 0) {
|
||||||
adjustedCost.add(new GenericManaCost(-reduceCount));
|
adjustedCost.add(new GenericManaCost(-reduceCount));
|
||||||
}
|
}
|
||||||
|
adjustedCost.setSourceFilter(manaCosts.getSourceFilter());
|
||||||
return adjustedCost;
|
return adjustedCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,7 +255,7 @@ public class CardUtil {
|
||||||
*/
|
*/
|
||||||
public static void adjustCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce, boolean convertToGeneric) {
|
public static void adjustCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce, boolean convertToGeneric) {
|
||||||
ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
|
ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
|
||||||
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
|
ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
|
||||||
// save X value (e.g. convoke ability)
|
// save X value (e.g. convoke ability)
|
||||||
for (VariableCost vCost: previousCost.getVariableCosts()) {
|
for (VariableCost vCost: previousCost.getVariableCosts()) {
|
||||||
if (vCost instanceof VariableManaCost) {
|
if (vCost instanceof VariableManaCost) {
|
||||||
|
|
@ -352,7 +352,7 @@ public class CardUtil {
|
||||||
adjustedCost.add(0, new GenericManaCost(mana.count()));
|
adjustedCost.add(0, new GenericManaCost(mana.count()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
adjustedCost.setSourceFilter(previousCost.getSourceFilter()); // keep mana source restrictions
|
||||||
spellAbility.getManaCostsToPay().clear();
|
spellAbility.getManaCostsToPay().clear();
|
||||||
spellAbility.getManaCostsToPay().addAll(adjustedCost);
|
spellAbility.getManaCostsToPay().addAll(adjustedCost);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue