mirror of
https://github.com/magefree/mage.git
synced 2025-12-26 05:22:02 -08:00
updated ManaSpentToCastCount, added tests
This commit is contained in:
parent
cdfe8be5fc
commit
70b040473b
3 changed files with 45 additions and 17 deletions
|
|
@ -1,13 +1,10 @@
|
|||
|
||||
package mage.abilities.dynamicvalue.common;
|
||||
|
||||
import mage.MageObject;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.dynamicvalue.DynamicValue;
|
||||
import mage.abilities.effects.Effect;
|
||||
import mage.constants.Zone;
|
||||
import mage.game.Game;
|
||||
import mage.game.stack.Spell;
|
||||
import mage.watchers.common.ManaPaidSourceWatcher;
|
||||
|
||||
/**
|
||||
* @author LevelX2
|
||||
|
|
@ -17,18 +14,7 @@ public enum ManaSpentToCastCount implements DynamicValue {
|
|||
|
||||
@Override
|
||||
public int calculate(Game game, Ability sourceAbility, Effect effect) {
|
||||
Spell spell = game.getStack().getSpell(sourceAbility.getSourceId());
|
||||
if (spell == null) {
|
||||
MageObject mageObject = game.getLastKnownInformation(sourceAbility.getSourceId(), Zone.STACK);
|
||||
if (mageObject instanceof Spell) {
|
||||
spell = (Spell) mageObject;
|
||||
}
|
||||
}
|
||||
if (spell != null) {
|
||||
// NOT the cmc of the spell on the stack
|
||||
return spell.getSpellAbility().getManaCostsToPay().manaValue();
|
||||
}
|
||||
return 0;
|
||||
return ManaPaidSourceWatcher.getTotalPaid(sourceAbility.getSourceId(), game);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -45,5 +31,4 @@ public enum ManaSpentToCastCount implements DynamicValue {
|
|||
public String getMessage() {
|
||||
return "the amount of mana spent to cast it";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import java.util.UUID;
|
|||
public class ManaPaidSourceWatcher extends Watcher {
|
||||
|
||||
private static final class ManaPaidTracker implements Serializable {
|
||||
private int total = 0;
|
||||
private int whiteSnow = 0;
|
||||
private int blueSnow = 0;
|
||||
private int blackSnow = 0;
|
||||
|
|
@ -35,6 +36,7 @@ public class ManaPaidSourceWatcher extends Watcher {
|
|||
private int treasure = 0;
|
||||
|
||||
private void increment(MageObject sourceObject, ManaType manaType, Game game) {
|
||||
total++;
|
||||
if (sourceObject.hasSubtype(SubType.TREASURE, game)) {
|
||||
treasure++;
|
||||
}
|
||||
|
|
@ -108,6 +110,11 @@ public class ManaPaidSourceWatcher extends Watcher {
|
|||
manaMap.clear();
|
||||
}
|
||||
|
||||
public static int getTotalPaid(UUID sourceId, Game game) {
|
||||
ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class);
|
||||
return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).total;
|
||||
}
|
||||
|
||||
public static int getTreasurePaid(UUID sourceId, Game game) {
|
||||
ManaPaidSourceWatcher watcher = game.getState().getWatcher(ManaPaidSourceWatcher.class);
|
||||
return watcher == null ? 0 : watcher.manaMap.getOrDefault(sourceId, emptyTracker).treasure;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue