mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 13:32:06 -08:00
updated ManaSpentToCastWatcher to default watcher list, reworked it to be game scope
This commit is contained in:
parent
943c67fbca
commit
91eb324847
190 changed files with 272 additions and 280 deletions
|
|
@ -38,11 +38,11 @@ public enum AdamantCondition implements Condition {
|
|||
}
|
||||
return source.getManaCostsToPay().getUsedManaToPay().getColor(coloredManaSymbol) > 2;
|
||||
}
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, source.getSourceId());
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||
if (watcher == null) {
|
||||
return false;
|
||||
}
|
||||
Mana payment = watcher.getAndResetLastPayment();
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
if (payment == null) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@ public class ManaWasSpentCondition implements Condition {
|
|||
@Override
|
||||
public boolean apply(Game game, Ability source) {
|
||||
if (source.getAbilityType() == AbilityType.SPELL) {
|
||||
return (source.getManaCostsToPay().getUsedManaToPay().getColor(coloredManaSymbol) > 0);
|
||||
return source.getManaCostsToPay().getUsedManaToPay().getColor(coloredManaSymbol) > 0;
|
||||
}
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, source.getSourceId());
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||
if (watcher != null) {
|
||||
Mana payment = watcher.getAndResetLastPayment();
|
||||
Mana payment = watcher.getAndResetLastPayment(source.getSourceId());
|
||||
if (payment != null) {
|
||||
return payment.getColor(coloredManaSymbol) > 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,25 +3,24 @@ package mage.abilities.dynamicvalue.common;
|
|||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.AbilityType;
|
||||
import mage.game.Game;
|
||||
import mage.watchers.common.ManaSpentToCastWatcher;
|
||||
|
||||
public enum ManacostVariableValue implements DynamicValue {
|
||||
instance;
|
||||
REGULAR, ETB;
|
||||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
if (sourceAbility.getAbilityType() == AbilityType.SPELL) {
|
||||
if (this == REGULAR) {
|
||||
return sourceAbility.getManaCostsToPay().getX();
|
||||
}
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class, sourceAbility.getSourceId());
|
||||
return watcher != null ? watcher.getAndResetLastXValue() : sourceAbility.getManaCostsToPay().getX();
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||
return watcher != null ? watcher.getAndResetLastXValue(sourceAbility.getSourceId()) : sourceAbility.getManaCostsToPay().getX();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ManacostVariableValue copy() {
|
||||
return ManacostVariableValue.instance;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -19,13 +19,11 @@ public enum SnowManaSpentValue implements DynamicValue {
|
|||
if (sourceAbility.getAbilityType() == AbilityType.SPELL) {
|
||||
return sourceAbility.getManaCostsToPay().getUsedManaToPay().getSnow();
|
||||
}
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(
|
||||
ManaSpentToCastWatcher.class, sourceAbility.getSourceId()
|
||||
);
|
||||
ManaSpentToCastWatcher watcher = game.getState().getWatcher(ManaSpentToCastWatcher.class);
|
||||
if (watcher == null) {
|
||||
return 0;
|
||||
}
|
||||
Mana payment = watcher.getAndResetLastPayment();
|
||||
Mana payment = watcher.getAndResetLastPayment(sourceAbility.getSourceId());
|
||||
if (payment == null) {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,10 @@ 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
|
||||
* automatically added in each game
|
||||
|
|
@ -17,48 +21,44 @@ import mage.watchers.Watcher;
|
|||
*/
|
||||
public class ManaSpentToCastWatcher extends Watcher {
|
||||
|
||||
private Mana payment = null;
|
||||
private Integer xValue = 0;
|
||||
private final Map<UUID, Mana> manaMap = new HashMap<>();
|
||||
private final Map<UUID, Integer> xValueMap = new HashMap<>();
|
||||
|
||||
public ManaSpentToCastWatcher() {
|
||||
super(WatcherScope.CARD);
|
||||
super(WatcherScope.GAME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void watch(GameEvent event, Game game) {
|
||||
// There was a check for the from zone being the hand, but that should not matter
|
||||
if (event.getType() == GameEvent.EventType.SPELL_CAST) {
|
||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||
if (spell != null && this.getSourceId().equals(spell.getSourceId())) {
|
||||
payment = spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay();
|
||||
xValue = spell.getSpellAbility().getManaCostsToPay().getX();
|
||||
}
|
||||
}
|
||||
if (event.getType() == GameEvent.EventType.ZONE_CHANGE
|
||||
&& this.getSourceId().equals(event.getSourceId())) {
|
||||
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
||||
payment = null;
|
||||
xValue = 0;
|
||||
}
|
||||
switch (event.getType()) {
|
||||
case SPELL_CAST:
|
||||
Spell spell = (Spell) game.getObject(event.getTargetId());
|
||||
if (spell != null) {
|
||||
manaMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getUsedManaToPay());
|
||||
xValueMap.put(spell.getSourceId(), spell.getSpellAbility().getManaCostsToPay().getX());
|
||||
}
|
||||
return;
|
||||
case ZONE_CHANGE:
|
||||
if (((ZoneChangeEvent) event).getFromZone() == Zone.BATTLEFIELD) {
|
||||
manaMap.remove(event.getSourceId());
|
||||
xValueMap.remove(event.getSourceId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Mana getAndResetLastPayment() {
|
||||
Mana returnPayment = null;
|
||||
if (payment != null) {
|
||||
returnPayment = payment.copy();
|
||||
}
|
||||
return returnPayment;
|
||||
public Mana getAndResetLastPayment(UUID sourceId) {
|
||||
return manaMap.getOrDefault(sourceId, null);
|
||||
}
|
||||
|
||||
public int getAndResetLastXValue() {
|
||||
return xValue;
|
||||
public int getAndResetLastXValue(UUID sourceId) {
|
||||
return xValueMap.getOrDefault(sourceId, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reset() {
|
||||
super.reset();
|
||||
payment = null;
|
||||
xValue = 0;
|
||||
manaMap.clear();
|
||||
xValueMap.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue