game: fixed "if mana was spent to cast" abilities after leaves (#11419)

* ManaWasSpentCondition should use MageObjectReferences
This commit is contained in:
ssk97 2023-11-17 00:02:47 -08:00 committed by GitHub
parent 44b8a0faf4
commit ca80849249
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 63 additions and 22 deletions

View file

@ -6,6 +6,7 @@ import mage.abilities.condition.Condition;
import mage.constants.AbilityType;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
import mage.util.CardUtil;
import mage.watchers.common.ManaSpentToCastWatcher;
import java.util.Arrays;
@ -53,7 +54,7 @@ public enum AdamantCondition implements Condition {
if (watcher == null) {
return false;
}
Mana payment = watcher.getLastManaPayment(source.getSourceId());
Mana payment = watcher.getManaPayment(CardUtil.getSourceStackMomentReference(game, source));
if (payment == null) {
return false;
}

View file

@ -6,6 +6,7 @@ import mage.abilities.condition.Condition;
import mage.constants.AbilityType;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
import mage.util.CardUtil;
import mage.watchers.common.ManaSpentToCastWatcher;
/**
@ -33,7 +34,7 @@ public enum ManaWasSpentCondition implements Condition {
}
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
if (watcher != null) {
Mana payment = watcher.getLastManaPayment(source.getSourceId());
Mana payment = watcher.getManaPayment(CardUtil.getSourceStackMomentReference(game, source));
if (payment != null) {
return payment.getColor(coloredManaSymbol) > 0;
}

View file

@ -7,6 +7,7 @@ import mage.abilities.effects.Effect;
import mage.constants.AbilityType;
import mage.constants.ColoredManaSymbol;
import mage.game.Game;
import mage.util.CardUtil;
import mage.watchers.common.ManaSpentToCastWatcher;
/**
@ -32,7 +33,7 @@ public enum EachTwoManaSpentToCastValue implements DynamicValue {
Mana payment = game
.getState()
.getWatcher(ManaSpentToCastWatcher.class)
.getLastManaPayment(sourceAbility.getSourceId());
.getManaPayment(CardUtil.getSourceStackMomentReference(game, sourceAbility));
if (payment == null) {
return 0;
}

View file

@ -1,18 +1,16 @@
package mage.watchers.common;
import mage.MageObjectReference;
import mage.Mana;
import mage.abilities.Ability;
import mage.constants.WatcherScope;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
import mage.game.stack.Spell;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* Watcher saves the mana that was spent to cast a spell
@ -24,7 +22,7 @@ import java.util.UUID;
*/
public class ManaSpentToCastWatcher extends Watcher {
private final Map<UUID, Mana> manaMap = new HashMap<>();
private final Map<MageObjectReference, Mana> manaMap = new HashMap<>();
public ManaSpentToCastWatcher() {
super(WatcherScope.GAME);
@ -33,22 +31,17 @@ public class ManaSpentToCastWatcher extends Watcher {
@Override
public void watch(GameEvent event, Game game) {
// There was a check for the from zone being the hand, but that should not matter
switch (event.getType()) {
case SPELL_CAST:
if (event.getType() == GameEvent.EventType.SPELL_CAST){
Spell spell = (Spell) game.getObject(event.getTargetId());
if (spell != null) {
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
}
return;
case ZONE_CHANGE:
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
manaMap.remove(event.getTargetId());
manaMap.put(new MageObjectReference(spell.getSpellAbility()),
spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
}
}
}
public Mana getLastManaPayment(UUID sourceId) {
return manaMap.getOrDefault(sourceId, null);
public Mana getManaPayment(MageObjectReference source) {
return manaMap.getOrDefault(source, null);
}
@Override