put getCount method in SpellsCastWatcher and use it where applicable

This commit is contained in:
xenohedron 2023-08-12 20:40:49 -04:00
parent 7d170ef902
commit 817e1a813a
12 changed files with 32 additions and 119 deletions

View file

@ -4,11 +4,8 @@ import mage.abilities.effects.Effect;
import mage.filter.FilterSpell;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.stack.Spell;
import mage.watchers.common.SpellsCastWatcher;
import java.util.List;
/**
* @author TheElk801
*/
@ -19,7 +16,6 @@ public class FirstSpellOpponentsTurnTriggeredAbility extends SpellCastController
public FirstSpellOpponentsTurnTriggeredAbility(Effect effect, boolean optional) {
super(effect, defaultFilter, optional);
this.addWatcher(new SpellsCastWatcher());
}
private FirstSpellOpponentsTurnTriggeredAbility(final FirstSpellOpponentsTurnTriggeredAbility ability) {
@ -38,13 +34,7 @@ public class FirstSpellOpponentsTurnTriggeredAbility extends SpellCastController
|| !game.getOpponents(this.getControllerId()).contains(game.getActivePlayerId())) {
return false;
}
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher == null) {
return false;
}
List<Spell> spells = watcher.getSpellsCastThisTurn(event.getPlayerId());
return spells != null && spells.size() == 1;
return watcher != null && watcher.getCount(event.getPlayerId()) == 1;
}
}

View file

@ -29,7 +29,6 @@ public final class JaceUnravelerOfSecretsEmblem extends Emblem {
Effect effect = new CounterTargetEffect();
effect.setText("counter that spell");
Ability ability = new JaceUnravelerOfSecretsTriggeredAbility(effect, false);
ability.addWatcher(new SpellsCastWatcher());
this.getAbilities().add(ability);
}

View file

@ -89,4 +89,9 @@ public class SpellsCastWatcher extends Watcher {
}
return null;
}
public int getCount(UUID playerId) {
return spellsCast.getOrDefault(playerId, new ArrayList<>()).size();
}
}