@Override
public boolean apply(Game game, Ability source) {
UUID objectId = source.getFirstTarget();
UUID sourceId = source.getSourceId();
StackObject stackObject = game.getStack().getStackObject(objectId);
if (stackObject != null && !game.replaceEvent(GameEvent.getEvent(GameEvent.EventType.COUNTER, objectId, sourceId, stackObject.getControllerId()))) {
if (stackObject instanceof Spell) {
game.rememberLKI(objectId, Zone.STACK, (Spell) stackObject);
game.getStack().remove(stackObject);
if (!((Spell) stackObject).isCopiedSpell() && filter.match(stackObject, source.getControllerId(), game)) {
MageObject card = game.getObject(stackObject.getSourceId());
if (card instanceof Card) {
((Card) card).putOntoBattlefield(game, Zone.STACK, source.getSourceId(), source.getControllerId());
}
} else {
stackObject.counter(sourceId, game);
}
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.COUNTERED, objectId, sourceId, stackObject.getControllerId()));
return true;
}
}
return false;
}