jbhaywood / 5e-statblock-importer

A module for FoundryVTT that creates a new actor from any 5e monster or NPC statblock.
MIT License
18 stars 14 forks source link

FM - Villain Actions #64

Closed MaxPat931 closed 10 months ago

MaxPat931 commented 11 months ago

Related to #58
If Villain Actions are detected, sets the Legendary Action Uses fields to 3

And some big tweaks to actionTitleRegex - it took me quite a while to get to something that was working for several of the different roadblocks I came up against, hopefully these changes don't impact other sources (only tested with FM

#actionTitleRegex = /^((?!.*has three villain actions)(Action \d+: )?([A-Z][\w\d\-+,;']?[\s\-]?)((of|and|the|from|in|at|on|with|to|by|into)\s)?([\w\d\-+,;'’]+\s?){0,5}(\((?!spell save)[^)]+\))?)[.!?]/;

(?!.*has three villain actions) - rejects matches with the text "has three villain actions" this was necessary due to the increased word allotment below (it was creating a new feature with the title "X has three villain actions", which broke the Legendary Action Uses function)
(Action \d+: )? - Optional match for villain actions, using this instead of adding : to the allowed punctuation saves one word allotment
([A-Z][\w\d\-+,;']?[\s\-]?) - changed the + in between the [ ] groups to a ? because a couple VAs start with "I " and they werent being captured. Not sure if this has wider implications for other issues.
[\w\d\-+,;'’] - added (weird apostrophe) that is used in a few VAs
{0,5} - increase word allotment from 3 to 5 to account for all VAs (Queen Bargnot has the longest one) I think this could open the possibility of some unintended consequences for other statblocks?
[.!?] - added ? as a few VAs use it to end the title

jbhaywood commented 10 months ago

I'm looking at this now. I have an idea of how to restructure the parser to allow it to support more special cases. It's getting pretty cumbersome, which I'm sure you've noticed. If I can get that to a place I like I'll roll these changes into it.

jbhaywood commented 10 months ago

I submitted the overhaul update, v1.80.0. Now I'll look through the changes here and bring them in manually. That's going to be easier than trying to merge the pull request.

I'm a little concerned about the increase to the title word allotment. The reason it ignores a bunch of words right now is to keep the count down, since I found in the past that the larger size makes it easier to trigger on false positives. It might make sense to create a new regex just for the VA actions because they're very consistent. And the new code structure makes it easy to know that we're dealing specifically with VAs.

Anyway, thanks for the work and I'll get VAs supported one way or another.

jbhaywood commented 10 months ago

I pulled in these updates with v1.80.1. Thanks!