use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.
the class NullstoneGargoyleTriggeredAbility method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Spell spell = game.getSpell(event.getTargetId());
if (spell.isCreature(game)) {
return false;
}
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher != null && watcher.getNumberOfNonCreatureSpells() == 1) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getTargetId()));
}
return true;
}
return false;
}
use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.
the class ArchfiendsVesselEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (super.checkTrigger(event, game)) {
if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
if (entersTheBattlefieldEvent.getTargetId().equals(getSourceId()) && entersTheBattlefieldEvent.getFromZone() == Zone.GRAVEYARD) {
return true;
} else {
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
List<Spell> spellsCastFromGraveyard = watcher.getSpellsCastFromGraveyardThisTurn(getControllerId());
if (spellsCastFromGraveyard != null) {
return spellsCastFromGraveyard.stream().anyMatch(spell -> spell.getMainCard().getId().equals((entersTheBattlefieldEvent.getTarget().getMainCard().getId())));
}
}
}
}
return false;
}
use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.
the class ShowOfConfidenceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = (Spell) getValue("spellCast");
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (spell == null || watcher == null) {
return false;
}
int copies = watcher.getSpellsCastThisTurn(source.getControllerId()).stream().filter(Objects::nonNull).filter(spell1 -> spell1.isInstantOrSorcery(game)).filter(s -> !s.getSourceId().equals(source.getSourceId()) || s.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()).mapToInt(x -> 1).sum();
if (copies > 0) {
spell.createCopyOnStack(game, source, source.getControllerId(), true, copies);
}
return true;
}
use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.
the class CurseOfShakenFaithEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Permanent enchantment = game.getPermanentOrLKIBattlefield(sourceId);
if (enchantment != null) {
UUID enchantedPlayerId = enchantment.getAttachedTo();
Spell spell = game.getSpell(event.getTargetId());
if (spell != null && spell.isControlledBy(enchantedPlayerId)) {
if (event.getType() == GameEvent.EventType.COPIED_STACKOBJECT) {
return true;
}
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (watcher != null) {
return watcher.getSpellsCastThisTurn(enchantedPlayerId).size() > 1;
}
}
}
return false;
}
use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.
the class EsperSentinelEffect method checkTrigger.
@Override
public boolean checkTrigger(GameEvent event, Game game) {
Player controller = game.getPlayer(getControllerId());
Spell spell = game.getSpell(event.getTargetId());
SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
if (controller != null && spell != null && watcher != null && !spell.isCreature(game) && controller.hasOpponent(spell.getControllerId(), game)) {
int nonCreatureSpells = 0;
for (Spell spellCastThisTurn : watcher.getSpellsCastThisTurn(spell.getControllerId())) {
if (!spellCastThisTurn.isCreature(game) && ++nonCreatureSpells > 1) {
break;
}
}
if (nonCreatureSpells == 1) {
for (Effect effect : getEffects()) {
effect.setTargetPointer(new FixedTarget(spell.getControllerId()));
}
return true;
}
}
return false;
}
Aggregations