Larkinabout / fvtt-token-action-hud-pf2e

Token Action HUD is a repositionable HUD of actions for a selected token.
10 stars 15 forks source link

[BUG] Shields Causing HUD to Stop Working #129

Closed Larkinabout closed 5 months ago

Larkinabout commented 6 months ago

Reported on Discord: https://discord.com/channels/170995199584108546/697845559435853865/1207226792725717002

Silvertower commented 6 months ago

I cannot view Discord.

Silvertower commented 6 months ago

All tests that I performed with shields work without issue. Will need more details.

Larkinabout commented 6 months ago

From what I can glean it's related to Shield Ally and Shield Block. I'll ask anyone that has issues to post more info and hopefully error messages here.

Silvertower commented 6 months ago

Thanks.

The only thing you can do from the HUD is raise the shield or change grip, sheathe, drop, etc. Blocking is done via the chat options. I created a Champion with Shield Ally and do not see any obvious issues.

Larkinabout commented 6 months ago

I've posted asking for input, so maybe we just leave this open for a while and see if anything comes in.

Geodragon9 commented 6 months ago

I run 2 servers.
On one server, the person has shield ally received at a higher level.. And I'm not able to replicate on there.. But, the one I run for PFS2e, that was the one where I had a person with a broken shield ally.. I dropped character to level 0, then back to level 7. And chose shield ally.. Drop a new shield on him. The moment I edit the shield HP, it drops to 0, and won't let me change it from 0. Turn off TAH-PF2e, and the shield behaves.. I haven't checked the differences between the 2 servers yet, since I'm at work to see what modules are selected in both.. But, I did test his character just now in the other world and it's working fine..
NotWorkingPackageList.json WorksFinePackageList.json fvtt-Actor-sapphire-acacia-root-lliQ3g8gZYSDt0Xd.json

Silvertower commented 6 months ago

Thanks for the additional information. I am unable to reproduce using the basic steps outlined. If you can double-check the following: Does this happen with the latest versions of PF2e System, Token Action HUD Core, and token Action HUD PF2e and no other modules enabled?

Geodragon9 commented 6 months ago

No.. But, I get an error about Socketlib.. The moment I enable socketlib -- the failure of shield ally kicks back in..

socketlib 1.0.13 -- Yet, verified on my other server that it's the same version..

Silvertower commented 6 months ago

When able, please provide the full error trace messages from the browser's console (F12 -> Console) and I can look further.

Silvertower commented 6 months ago

I don't have errors in the console, nor do I have a problem where the HUD stops working, but I can reproduce the issue where the shield HP drops to 0 after adjusting the shield HP value.

The problem is with this Rule Element:

{"itemType":"shield","key":"ItemAlteration","mode":"multiply","predicate":["item:equipped"],"property":"hp-max","value":1.5}

However, since no error is thrown, and because I have no immediate idea as to why this would cause a problem with Token Action HUD PF2e, I am not sure where to start looking.

I can confirm that disabling Token Action HUD PF2e resolves the issue of editing the HP, but I am not sure as to why this happens.

Even more confusingly, the issue does not happen with a test character that I created that is also a level 7 Champion with Shield Ally.

Geodragon9 commented 6 months ago

https://share.firefox.dev/3OLqgNL console-export-2024-2-14_9-52-24.txt

Geodragon9 commented 6 months ago

@Silvertower -- If you leave TAH PF2e on, but turn off Socketlib -- for me the shield works like one expects.. What about for you?

And, I still don't know why on one server it works and the other it doesn't.

Silvertower commented 6 months ago

image Something is very, very wrong with Saphire's character, as best as I can find. I created an identical character and everything works fine. I would recommend re-building the character from scratch. Attached is my export. Can you test importing this when able? fvtt-Actor-sapphire-acacia-root-(new)-lakkPpUhMQU5S7Dm.json

My guess is that this character was exported and imported from different versions of PF2e system or other modules and something in JSON is bad or didn't get migrated correctly.

Geodragon9 commented 6 months ago

Hmm, I suspect, my export might have fixed it.. Since I exported to a different server and it works there.. Your import also works fine.. So, I don't have an original of his file.. So, I'm going to have to agree with you, there is something very wrong with his import of the character..

Geodragon9 commented 6 months ago

@Silvertower I imported the one you linked above, and the shield is still broken.. But not on my other server.

May have to wait till I have some free time.. Take a look at my settings for socketlib and TAH. Maybe one has something selected the other does not.

Geodragon9 commented 6 months ago

Also, here's the original json: fvtt-Actor-sapphire-level-7.json

Silvertower commented 6 months ago

It looks like I spoke too soon. I tried importing my exported version again and the shield is messed up again on the new character as well. The multiplier rule element is being applied multiple times or is multiplying the wrong number, etc. This didn't happen after fresh character creation, however. Very odd.

Silvertower commented 6 months ago

Every time the character is dragged onto a scene, the shield modifiers are multiplied, cumulatively.

Silvertower commented 6 months ago

Strangely, I have isolated the issue to the buildSpells() function in TAH2e. Investigating further.

Silvertower commented 6 months ago

Going down the rabbit-hole, the problem is from getTooltipData().

Silvertower commented 6 months ago

The issue is the following statement in getTooltipData() in action-handler.js:

await entity.getChatData()

As soon as the above is called, even if the data is not used in any way (e.g. just assigning the result to a variable), then shields become corrupted.

This is beyond my skillset to resolve, as I have tried several potential solutions, and nothing works for me.

@Larkinabout perhaps you have an idea.

Silvertower commented 6 months ago

As an interesting aside to the above, the section of code that triggers this is buildSpells(), which has nothing to do with shields.

The section of buildSpells() that calls getTooltipData() is contained in a rather strange (to me) construct of multiple types of maps:

const items = new Map(activeSpells.map(spell => [spell.id, spell]))

const actions = await Promise.all(
    [...items].map(async ([itemId, itemData]) => {
    ...
    const tooltipData = await this.#getTooltipData(actionType, itemData)
})
Geodragon9 commented 6 months ago

Oh just wanted to give an update.. My shield ally user in the other game on the other server, was working fine, until he tried to repair it back to full, then it went to 0 and effed up.. So, turning off the module so I can continue running

Geodragon9 commented 6 months ago

Also, I wonder if the 'Shield Ally' feat uses the 'spell effect' to apply the changes to shields.

Geodragon9 commented 6 months ago

Looking at shield ally: {"itemType":"shield","key":"ItemAlteration","mode":"multiply","predicate":["item:equipped"],"property":"hp-max","value":1.5} {"itemType":"shield","key":"ItemAlteration","mode":"add","predicate":["item:equipped"],"property":"hardness","value":2}

Silvertower commented 6 months ago

I have developed an ugly workaround for this issue. I will publish the fix sometime tomorrow, but I am going to leave this issue open until the root cause can be found and a permanent fix can be issued.

WitchFreya commented 6 months ago

Having a similar issue; as a workaround for GMs, you can do the following with the rule elements for Shield Ally:

  1. Apply priorities 110 and 111 to the hardness and HP ItemAlteration rule elements.
  2. Add a RollOption rule element with priority 112 that adds an option to predicate off of, e.g. shield-ally-applied.
  3. Predicate the Hardness and HP item alterations on the roll option not being present.

Example:

{
  "key": "ItemAlteration",
  "itemType": "shield",
  "mode": "multiply",
  "predicate": ["item:equipped", {
    "not": "shield-ally-applied"
  }],
  "property": "hp-max",
  "value": 1.5,
  "priority": 110
}
{
  "key": "ItemAlteration",
  "itemType": "shield",
  "mode": "add",
  "predicate": ["item:equipped", {
    "not": "shield-ally-applied"
  }],
  "property": "hardness",
  "value": 2,
  "priority": 111
}
{ "key": "RollOption", "option": "shield-ally-applied",  "priority": 112 }

Might not help you fix the bug in the addon but it'll at least let GMs keep the addon loaded.

Silvertower commented 6 months ago

Thanks for sharing. At this point in time, I do not believe the bug is with TAH2e. But I don't have the time or knowledge to troubleshoot the root cause on the PF2e system side.

Silvertower commented 5 months ago

This issue is resolved in PF2e System 5.14.0 and later. The workaround mentioned above will be removed from Token Action HUD PF2e in the next release.

Silvertower commented 5 months ago

Fixed in Token Action HUD PF2e version 1.5.11.