[ZNR] fixed Kaza, Roil Chaser not correctly counting spells

This commit is contained in:
Evan Kranzler 2021-03-24 18:05:38 -04:00
parent 7484b520e5
commit b74ff4a2f8

View file

@ -19,9 +19,13 @@ import mage.constants.*;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.util.CardUtil; import mage.util.CardUtil;
import mage.watchers.common.CastSpellLastTurnWatcher; import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
/** /**
@ -49,7 +53,9 @@ public final class KazaRoilChaser extends CardImpl {
this.addAbility(HasteAbility.getInstance()); this.addAbility(HasteAbility.getInstance());
// {T}: The next instant or sorcery spell you cast this turn costs {X} less to cast, where X is the number of Wizards you control as this ability resolves. // {T}: The next instant or sorcery spell you cast this turn costs {X} less to cast, where X is the number of Wizards you control as this ability resolves.
this.addAbility(new SimpleActivatedAbility(new KazaRoilChaserEffect(), new TapSourceCost()).addHint(hint)); this.addAbility(new SimpleActivatedAbility(
new KazaRoilChaserEffect(), new TapSourceCost()
).addHint(hint), new KazaRoilChaserWatcher());
} }
private KazaRoilChaser(final KazaRoilChaser card) { private KazaRoilChaser(final KazaRoilChaser card) {
@ -64,9 +70,9 @@ public final class KazaRoilChaser extends CardImpl {
class KazaRoilChaserEffect extends CostModificationEffectImpl { class KazaRoilChaserEffect extends CostModificationEffectImpl {
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.WIZARD);
private int spellsCast; private int spellsCast;
private int wizardCount = 0; private int wizardCount = 0;
private static final FilterPermanent filter = new FilterControlledPermanent(SubType.WIZARD);
KazaRoilChaserEffect() { KazaRoilChaserEffect() {
super(Duration.EndOfTurn, Outcome.Benefit, CostModificationType.REDUCE_COST); super(Duration.EndOfTurn, Outcome.Benefit, CostModificationType.REDUCE_COST);
@ -83,9 +89,9 @@ class KazaRoilChaserEffect extends CostModificationEffectImpl {
@Override @Override
public void init(Ability source, Game game) { public void init(Ability source, Game game) {
super.init(source, game); super.init(source, game);
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); KazaRoilChaserWatcher watcher = game.getState().getWatcher(KazaRoilChaserWatcher.class);
if (watcher != null) { if (watcher != null) {
spellsCast = watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()); spellsCast = watcher.getCount(source.getControllerId());
} }
wizardCount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game); wizardCount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
} }
@ -98,11 +104,11 @@ class KazaRoilChaserEffect extends CostModificationEffectImpl {
@Override @Override
public boolean applies(Ability abilityToModify, Ability source, Game game) { public boolean applies(Ability abilityToModify, Ability source, Game game) {
CastSpellLastTurnWatcher watcher = game.getState().getWatcher(CastSpellLastTurnWatcher.class); KazaRoilChaserWatcher watcher = game.getState().getWatcher(KazaRoilChaserWatcher.class);
if (watcher == null) { if (watcher == null) {
return false; return false;
} }
if (watcher.getAmountOfSpellsPlayerCastOnCurrentTurn(source.getControllerId()) > spellsCast) { if (watcher.getCount(source.getControllerId()) > spellsCast) {
discard(); // only one use discard(); // only one use
return false; return false;
} }
@ -119,3 +125,33 @@ class KazaRoilChaserEffect extends CostModificationEffectImpl {
return new KazaRoilChaserEffect(this); return new KazaRoilChaserEffect(this);
} }
} }
class KazaRoilChaserWatcher extends Watcher {
private final Map<UUID, Integer> playerMap = new HashMap<>();
KazaRoilChaserWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.SPELL_CAST) {
return;
}
Spell spell = game.getSpell(event.getSourceId());
if (spell != null && spell.isInstantOrSorcery()) {
playerMap.compute(event.getPlayerId(), (u, i) -> i == null ? 1 : Integer.sum(i, 1));
}
}
@Override
public void reset() {
super.reset();
playerMap.clear();
}
int getCount(UUID playerId) {
return playerMap.getOrDefault(playerId, 0);
}
}