forked from External/mage
game: fixed "if mana was spent to cast" abilities after leaves (#11419)
* ManaWasSpentCondition should use MageObjectReferences
This commit is contained in:
parent
44b8a0faf4
commit
ca80849249
6 changed files with 63 additions and 22 deletions
|
|
@ -11,6 +11,7 @@ import mage.cards.CardSetInfo;
|
||||||
import mage.constants.*;
|
import mage.constants.*;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import mage.watchers.common.ManaSpentToCastWatcher;
|
import mage.watchers.common.ManaSpentToCastWatcher;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
@ -69,7 +70,7 @@ class RadiantEpicureEffect extends OneShotEffect {
|
||||||
if (player == null || watcher == null) {
|
if (player == null || watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
Mana payment = watcher.getManaPayment(CardUtil.getSourceStackMomentReference(game, source));
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,9 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
addCard(Zone.BATTLEFIELD, playerB, "Abzan Banner");
|
addCard(Zone.BATTLEFIELD, playerB, "Abzan Banner");
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tin Street Hooligan");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tin Street Hooligan");
|
||||||
// Abzan Banner is auto-chosen since only possible target
|
addTarget(playerA, "Abzan Banner");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -42,16 +44,43 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
addCard(Zone.BATTLEFIELD, playerB, "Abzan Banner");
|
addCard(Zone.BATTLEFIELD, playerB, "Abzan Banner");
|
||||||
|
|
||||||
setStrictChooseMode(true);
|
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tin Street Hooligan");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tin Street Hooligan");
|
||||||
// {G} was not spent, so no target is chosen
|
// {G} was not spent, so no target is chosen
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
assertPermanentCount(playerA, "Tin Street Hooligan", 1);
|
assertPermanentCount(playerA, "Tin Street Hooligan", 1);
|
||||||
}
|
}
|
||||||
|
//ManaWasSpentCondition gives false negative after permanent leaves battlefield
|
||||||
|
//Fixed by using MageObjectReference instead of UUID
|
||||||
|
@Test
|
||||||
|
public void testArtifactWillBeDestroyedAfterDeath() {
|
||||||
|
// Tin Street Hooligan - Creature 2/1 {1}{R}
|
||||||
|
// When Tin Street Hooligan enters the battlefield, if {G} was spent to cast Tin Street Hooligan, destroy target artifact.
|
||||||
|
addCard(Zone.HAND, playerA, "Tin Street Hooligan");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Forest", 1);
|
||||||
|
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 1);
|
||||||
|
|
||||||
|
addCard(Zone.HAND, playerB, "Lightning Bolt");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Abzan Banner");
|
||||||
|
addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1);
|
||||||
|
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Tin Street Hooligan");
|
||||||
|
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN,true);
|
||||||
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB,"Lightning Bolt","Tin Street Hooligan");
|
||||||
|
addTarget(playerA, "Abzan Banner");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
|
setStopAt(1, PhaseStep.BEGIN_COMBAT);
|
||||||
|
execute();
|
||||||
|
|
||||||
|
assertPermanentCount(playerA, "Tin Street Hooligan", 0);
|
||||||
|
assertPermanentCount(playerB, "Abzan Banner", 0);
|
||||||
|
assertGraveyardCount(playerA, 1);
|
||||||
|
assertGraveyardCount(playerB, 2);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSnowMana() {
|
public void testSnowMana() {
|
||||||
|
|
@ -59,9 +88,12 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Boreal Druid");
|
addCard(Zone.BATTLEFIELD, playerA, "Boreal Druid");
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Plains");
|
addCard(Zone.BATTLEFIELD, playerA, "Plains");
|
||||||
addCard(Zone.HAND, playerA, "Search for Glory");
|
addCard(Zone.HAND, playerA, "Search for Glory");
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Snow-Covered Plains");
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Search for Glory");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Search for Glory");
|
||||||
|
addTarget(playerA, "Snow-Covered Plains");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -78,12 +110,15 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Vodalian Arcanist");
|
addCard(Zone.BATTLEFIELD, playerA, "Vodalian Arcanist");
|
||||||
addCard(Zone.BATTLEFIELD, playerA, "Rimefeather Owl");
|
addCard(Zone.BATTLEFIELD, playerA, "Rimefeather Owl");
|
||||||
addCard(Zone.HAND, playerA, "Search for Glory");
|
addCard(Zone.HAND, playerA, "Search for Glory");
|
||||||
|
addCard(Zone.LIBRARY, playerA, "Snow-Covered Plains");
|
||||||
|
|
||||||
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {U}");
|
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {U}");
|
||||||
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {R}");
|
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}: Add {R}");
|
||||||
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{1}{S}", "Vodalian Arcanist");
|
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{1}{S}", "Vodalian Arcanist");
|
||||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Search for Glory");
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Search for Glory");
|
||||||
|
addTarget(playerA, "Snow-Covered Plains");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -99,7 +134,9 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
addCard(Zone.HAND, playerA, "Berg Strider");
|
addCard(Zone.HAND, playerA, "Berg Strider");
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Berg Strider");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Berg Strider");
|
||||||
|
addTarget(playerA, "Silvercoat Lion");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
|
setStopAt(2, PhaseStep.PRECOMBAT_MAIN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -113,8 +150,11 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
addCard(Zone.HAND, playerA, "Strike It Rich", 1);
|
addCard(Zone.HAND, playerA, "Strike It Rich", 1);
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Strike It Rich", true);
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Strike It Rich", true);
|
||||||
|
activateManaAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "{T}, Sacrifice");
|
||||||
|
setChoice(playerA, "Red");
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -129,6 +169,7 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Jaded Sell-Sword");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -145,6 +186,7 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
setChoice(playerA, "X=2");
|
setChoice(playerA, "X=2");
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Verazol, the Split Current");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Verazol, the Split Current");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -163,6 +205,7 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
|
|
||||||
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Prossh, Skyraider of Kher");
|
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Prossh, Skyraider of Kher");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
@ -226,6 +269,7 @@ public class ManaWasSpentToCastTest extends CardTestPlayerBase {
|
||||||
waitStackResolved(1, PhaseStep.POSTCOMBAT_MAIN); // Let the Mana Drain delayed triggered ability resolve
|
waitStackResolved(1, PhaseStep.POSTCOMBAT_MAIN); // Let the Mana Drain delayed triggered ability resolve
|
||||||
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Sliver Construct");
|
castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerA, "Sliver Construct");
|
||||||
|
|
||||||
|
setStrictChooseMode(true);
|
||||||
setStopAt(1, PhaseStep.END_TURN);
|
setStopAt(1, PhaseStep.END_TURN);
|
||||||
execute();
|
execute();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import mage.abilities.condition.Condition;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
import mage.constants.ColoredManaSymbol;
|
import mage.constants.ColoredManaSymbol;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import mage.watchers.common.ManaSpentToCastWatcher;
|
import mage.watchers.common.ManaSpentToCastWatcher;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -53,7 +54,7 @@ public enum AdamantCondition implements Condition {
|
||||||
if (watcher == null) {
|
if (watcher == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
Mana payment = watcher.getManaPayment(CardUtil.getSourceStackMomentReference(game, source));
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import mage.abilities.condition.Condition;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
import mage.constants.ColoredManaSymbol;
|
import mage.constants.ColoredManaSymbol;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import mage.watchers.common.ManaSpentToCastWatcher;
|
import mage.watchers.common.ManaSpentToCastWatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,7 +34,7 @@ public enum ManaWasSpentCondition implements Condition {
|
||||||
}
|
}
|
||||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||||
if (watcher != null) {
|
if (watcher != null) {
|
||||||
Mana payment = watcher.getLastManaPayment(source.getSourceId());
|
Mana payment = watcher.getManaPayment(CardUtil.getSourceStackMomentReference(game, source));
|
||||||
if (payment != null) {
|
if (payment != null) {
|
||||||
return payment.getColor(coloredManaSymbol) > 0;
|
return payment.getColor(coloredManaSymbol) > 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import mage.abilities.effects.Effect;
|
||||||
import mage.constants.AbilityType;
|
import mage.constants.AbilityType;
|
||||||
import mage.constants.ColoredManaSymbol;
|
import mage.constants.ColoredManaSymbol;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
|
import mage.util.CardUtil;
|
||||||
import mage.watchers.common.ManaSpentToCastWatcher;
|
import mage.watchers.common.ManaSpentToCastWatcher;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,7 +33,7 @@ public enum EachTwoManaSpentToCastValue implements DynamicValue {
|
||||||
Mana payment = game
|
Mana payment = game
|
||||||
.getState()
|
.getState()
|
||||||
.getWatcher(ManaSpentToCastWatcher.class)
|
.getWatcher(ManaSpentToCastWatcher.class)
|
||||||
.getLastManaPayment(sourceAbility.getSourceId());
|
.getManaPayment(CardUtil.getSourceStackMomentReference(game, sourceAbility));
|
||||||
if (payment == null) {
|
if (payment == null) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,16 @@
|
||||||
package mage.watchers.common;
|
package mage.watchers.common;
|
||||||
|
|
||||||
|
import mage.MageObjectReference;
|
||||||
import mage.Mana;
|
import mage.Mana;
|
||||||
import mage.abilities.Ability;
|
|
||||||
import mage.constants.WatcherScope;
|
import mage.constants.WatcherScope;
|
||||||
import mage.constants.Zone;
|
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.events.GameEvent;
|
import mage.game.events.GameEvent;
|
||||||
import mage.game.events.ZoneChangeEvent;
|
|
||||||
import mage.game.stack.Spell;
|
import mage.game.stack.Spell;
|
||||||
import mage.watchers.Watcher;
|
import mage.watchers.Watcher;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Watcher saves the mana that was spent to cast a spell
|
* Watcher saves the mana that was spent to cast a spell
|
||||||
|
|
@ -24,7 +22,7 @@ import java.util.UUID;
|
||||||
*/
|
*/
|
||||||
public class ManaSpentToCastWatcher extends Watcher {
|
public class ManaSpentToCastWatcher extends Watcher {
|
||||||
|
|
||||||
private final Map<UUID, Mana> manaMap = new HashMap<>();
|
private final Map<MageObjectReference, Mana> manaMap = new HashMap<>();
|
||||||
|
|
||||||
public ManaSpentToCastWatcher() {
|
public ManaSpentToCastWatcher() {
|
||||||
super(WatcherScope.GAME);
|
super(WatcherScope.GAME);
|
||||||
|
|
@ -33,22 +31,17 @@ public class ManaSpentToCastWatcher extends Watcher {
|
||||||
@Override
|
@Override
|
||||||
public void watch(GameEvent event, Game game) {
|
public void watch(GameEvent event, Game game) {
|
||||||
// There was a check for the from zone being the hand, but that should not matter
|
// There was a check for the from zone being the hand, but that should not matter
|
||||||
switch (event.getType()) {
|
if (event.getType() == GameEvent.EventType.SPELL_CAST){
|
||||||
case SPELL_CAST:
|
|
||||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||||
if (spell != null) {
|
if (spell != null) {
|
||||||
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
manaMap.put(new MageObjectReference(spell.getSpellAbility()),
|
||||||
}
|
spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
||||||
return;
|
|
||||||
case ZONE_CHANGE:
|
|
||||||
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
|
||||||
manaMap.remove(event.getTargetId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Mana getLastManaPayment(UUID sourceId) {
|
public Mana getManaPayment(MageObjectReference source) {
|
||||||
return manaMap.getOrDefault(sourceId, null);
|
return manaMap.getOrDefault(source, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue