more-hooks-itemroll-hooks

For those of you interested in such things, I have hacked together a way to inject hooks into the middle of larger 5e class methods and thus I'm starting to look in earnest at pre hooks for the Item workflow. The biggest baddest of these is obviously Item5e#roll. I can think of a a few places a hook might be a useful checkpoint in this frankly massive method but would like some input. First some assumptions and constraints: - Hooks are only for Synchronous workflows, but may be used to interrupt a workflow in order to do something asynchronous. - Hooks cannot return values (other than false to interrupt a workflow as mentioned above), but they are encouraged to mutate their arguments. - Hooks are meant to be interacted with by potentially many modules at once. Now the method itself, as it currently stands: https://gitlab.com/foundrynet/dnd5e/-/blob/master/module/item/entity.js#L492 This bad boi does the following: - Sets up for the AbilityUseDialog (and determines if it is necessary) - Normalizes the output of the AbilityUseDialog and feeds those inputs into the next steps. - If a spell is being upcast, clone that spell as its higher level version Good Candidate for Hook: Item5e.preItemUsage - Test if the item consumption requested by the AbilityUseDialog is possible and create the update objects. Hook Candidate: Item5e.preItemConsumption - Handle that consumption on both Actor and Items Hook Candidate: Item5e.itemConsumption - Begin creation of a measured template if necessary - Begin the displayCard process to actually output the Item to chat. Current Hook: Item5e.roll
4 Replies
Calego
Calego•3y ago
I wanna hear 2 things from anyone with an idea that fits: 1. Where in this monstrosity would a hook help? 2. What is the specific use case you can imagine for such a hook? Use case: Allowing items to consume several different things. (Eg spell slots or multiple different charges from different items) The preItemConsumption (or the post one?) hook above would allow for a module to check if the item being used has a flag denoting some additional consumption, and if so fire off a server request for executing that consumption. I think ideally the consumption step would be fully contained in a different method but that's a different matter. Use case: checking some usage condition and cancelling the item workflow early. PreItemUsage firing after the ability use Dialog resolves to check for some additional cases which would cause the item to fail to be used. Use case: display animation automatically when an item is used based on what item is used. Existing Roll hook would allow this with some caveats regarding measured templates. I think ideally the roll flow would await the template placement but that's a different topic. I'm gonna go ahead and ping @more-hooks-5e in here, since there's only like a dozen of you. My apologies but I deeply desire your input
ccjmk
ccjmk•3y ago
I a little a lot sleepy right now so I might be getting the idea wrong, but I would love some hooks wrapping the spell upcasting shenanigans I... can't think of a use case right now, but there's definitely mischief possible there
Calego
Calego•3y ago
Do tell me more, you mean before the spell level is locked in, like after the ability use dialog but before the item is cloned? That would allow the hook to change the level of spell selected (though I'm not sure to what end, as the user just had the chance to select such a thing)
ccjmk
ccjmk•3y ago
my main idea is allowing for implementing spell point variants, but I just noticed there's a module for that already. It does mention it leverages the "Roll" class, so I think this might be a better place for implementing such a feature 🤔