mrkwnzl / cyphersystem-foundryvtt

The Cypher System for Foundry VTT
Other
21 stars 14 forks source link

Trigger a "useItem" hook when an item is used by an Actor. #329

Closed farling42 closed 1 year ago

farling42 commented 1 year ago

In order to make the activation of Active Effects more accurate, it would be nice if a hook was available (e.g. "cyphersystem.useItem") which is triggered at the same point that the costs of an ability/skill/attack would be deducted from the actor's pools (if no cost is associated, then the hook should trigger at the relevant point in the code anyway).

This is the only real way for my module to know, for certain, that an abillity has been used rather than cancelled.

This is primarily for effects which would apply to the triggering actor, rather than effects which would get applied to the target of the ability (which I handle separately via a button in the chat card)

mrkwnzl commented 1 year ago

There will be a rollEngine hook that is called at the end of any stat roll, which passes the actor and roll data as arguments. I called it that, even though it also fires when you don’t actually roll and just pay points, but that’s all part of the dice rolling engine as well. Since this isn’t user-facing, I think that small inaccuracy can be overlooked.

Whether an item has been used can be checked in data.itemID, which will be undefined if the roll comes directly from a stat.

farling42 commented 1 year ago

Thanks for the pointer. I will see how that goes.

farling42 commented 1 year ago

Are you referring to something triggered by a call to "Hooks.call" for the rollEngine hook, or is there just a function that I'd wrap with libWrapper to grab the usage of an item?

libWrapper on game.cyphersystem.rollEngineMain doesn't work, because you call the function directly rather than through the reference stored in game.cyphersystem

mrkwnzl commented 1 year ago

I was referring to a Hooks.call that will be in the next release.

mrkwnzl commented 1 year ago

Done in v2.9.0