p4535992 / foundryvtt-arms-reach

FoundryVTT Door little Utilities, Arms Reach for door
MIT License
3 stars 4 forks source link

Add support for distance overrides #6

Closed mkahvi closed 3 years ago

mkahvi commented 3 years ago

I would like to have some way to override the built-in accepted door interaction distance with a module for example.

The primary purpose would be to support game system specific concepts relating to it, such as limits of natural reach in Pathfinder 1e.

I wanted this so bad that I converted the original arms reach to do exactly that (https://gitlab.com/mkah-fvtt/pf1/arms-reach) before I learned of your module, but honestly I'd like for your module to have more generic support for such.

p4535992 commented 3 years ago

Hi, ty for the feedback. Forgive me I don't know anything about Pathfinder, could you try to better describe which feature you would like to be integrated?

Would you like to have the possibility to set the distance instead of in grid of squares in units of measure such as "ft" or "mt"?

I always try to make this module as independent as possible from the system used, and eventually I add additional settings to manage the use cases of the various game systems.

mkahvi commented 3 years ago

More of an ability to override the distance calculation, with a hook or something.

But if you want to implement it directly: It's essentially using actor.data.data.range.melee for checking the appropriate distance at which to allow opening things, preferably with minimum distance of 1 grid cell (Math.max(5, actor.data.data.range.melee) pretty much). That variable stores its distance in feet as is normal for the system.

It doesn't need to be exact distance, but simply using that variable for determining it.

Tho I still think it's better to just provide a hook for it that a module or even the game system could fill independently (so any system could have their custom thing fairly trivially), since this would probably not work for people who use the alternative metric system.

But speaking of it, option of ignoring cell distance would be nice for people who play gridless regardless of system (which is also a by rules option for PF1).

Sorry if this doesn't clear it up sufficiently.

p4535992 commented 3 years ago

Hei mkahvl, i'm trying to integrate a hook for "replace" my standard calculation distance, but i encounter some issue on the developing..... here the code i have in mind:

const resultExplicitComputeDistance = Hooks.call('ReplaceArmsReachInteraction', doorData);
          // undefined|null|Nan go with the standard compute distance
          if(resultExplicitComputeDistance && typeof(resultExplicitComputeDistance) == 'number'){
            // 0 : Custom compute distance fail
            if (<number>resultExplicitComputeDistance === 0) {
              isNotNearEnough = false;
            }
            // 1 : Custom compute success
            else if (<number>resultExplicitComputeDistance === 1) {
              isNotNearEnough = true;
            }
            // 2 : If Custom compute distance fail fallback to the standard compute distance
            else if (<number>resultExplicitComputeDistance === 2) {
              // Conntinue
            }
            // x < 0 || x > 2 just fail
            else{
              isNotNearEnough = false;
            }
          }

but with the Hooks.call i retireve only a boolean did you know if there is a way to return a number like in this case ?

mkahvi commented 3 years ago

Add third parameter to the call that holds a return value object:

const result = { distance: 0 };
Hooks.call('ReplaceArmsReachInteraction', doorData, result);
// and then do something with `result.distance`

And then you'd hook into it something like:

Hooks.on('ReplaceArmsReachInteraction', (doorData, result) => result.distance = 5);
p4535992 commented 3 years ago

Add some hook for try to solve this issue

p4535992 commented 3 years ago

This issue is solved with version 2.0.0 . Now you can customize the module drag-ruler , here the details on the api and the calculation distance is the same i used for door and stairways. P.S. you can finally add the range arm based on the value on the single actor/token