@Override public void watch(GameEvent event, Game game) { /** * This does still not handle if a spell is cast from hand and comes to * play from other zones during the same step. But at least the state is * reset if the game comes to a new step */ if (event.getType() == GameEvent.EventType.SPELL_CAST && event.getZone() == Zone.GRAVEYARD) { Spell spell = (Spell) game.getObject(event.getTargetId()); if (spell != null) { Set<Integer> zcc = spellsCastFromGraveyard.computeIfAbsent(spell.getSourceId(), k -> new HashSet<>()); zcc.add(spell.getZoneChangeCounter(game)); } } }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanentEntering(source.getSourceId()); int zccDiff = 0; if (permanent == null) { permanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); // can be alredy again removed from battlefield so also check LKI zccDiff = -1; } if (permanent != null) { // check that the spell is still in the LKI Spell spell = game.getStack().getSpell(source.getSourceId()); if (spell == null || spell.getZoneChangeCounter(game) != permanent.getZoneChangeCounter(game) + zccDiff) { if (game.getLastKnownInformation(source.getSourceId(), Zone.STACK, permanent.getZoneChangeCounter(game) + zccDiff) == null) { return false; } } return true; } return false; }
@Override public boolean apply(Game game, Ability source) { UUID targetId = source.getEffects().get(0).getTargetPointer().getFirst(game, source); Permanent permanent = game.getPermanentEntering(targetId); int zccDiff = 0; if (permanent == null) { permanent = game.getPermanentOrLKIBattlefield(targetId); // can be alredy again removed from battlefield so also check LKI zccDiff = -1; } if (permanent != null) { // check that the spell is still in the LKI Spell spell = game.getStack().getSpell(targetId); if (spell == null || spell.getZoneChangeCounter(game) != permanent.getZoneChangeCounter(game) + zccDiff) { if (game.getLastKnownInformation(targetId, Zone.STACK, permanent.getZoneChangeCounter(game) + zccDiff) == null) { return false; } } CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class); if (watcher != null && watcher.spellWasCastFromHand(targetId)) { return true; } } return false; }
@Override public boolean apply(Game game, Ability source) { Permanent permanent = game.getPermanentEntering(source.getSourceId()); int zccDiff = 0; if (permanent == null) { permanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); // can be alredy again removed from battlefield so also check LKI zccDiff = -1; } if (permanent != null) { // check that the spell is still in the LKI Spell spell = game.getStack().getSpell(source.getSourceId()); if (spell == null || spell.getZoneChangeCounter(game) != permanent.getZoneChangeCounter(game) + zccDiff) { if (game.getLastKnownInformation(source.getSourceId(), Zone.STACK, permanent.getZoneChangeCounter(game) + zccDiff) == null) { return false; } } CastFromHandWatcher watcher = game.getState().getWatcher(CastFromHandWatcher.class); if (watcher != null && watcher.spellWasCastFromHand(source.getSourceId())) { return true; } } return false; }