Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Targeting when attack.def = '' #229

Merged
merged 2 commits into from
Aug 23, 2022

Conversation

kyleady
Copy link
Contributor

@kyleady kyleady commented Aug 22, 2022

Issue

When creating a power, It is possible to select the defense for the attack as no defense.
no_def_example

This functions without issue when nothing is targeted. However, when at least one token is targeted an exception is thrown, leaving the Attack button in the Power Chat Card in the disabled state. A new Power Chat Card needs to be generated and all tokens untargeted before trying again. The error is

dice.js:206 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'value')
[Detected 1 package: system:dnd4e]
    at performD20RollAndCreateMessage (dice.js:206)
    at Object.callback (dice.js:90)
    at Dialog.submit (foundry.js:44156)
    at Dialog._onClickButton (foundry.js:44119)
    at HTMLButtonElement.dispatch (jquery.min.js:2)
    at HTMLButtonElement.v.handle (jquery.min.js:2)

Fix

The solution offered in this PR

  • Conditionally skips adding the DND4EBETA.VS text if the attack isn't against any defense.
  • Sets targDefVal to undefined when the targeted creature does not have that defense, using optional chaining.
  • Skips calculating hitState if targDefVal === undefined.

Example: Attacking four targeted tokens when Item4e.data.data.attack.def = ''.
no_def_example_2

I have tested that the hitState is still calculated when the value of a target's defense is equal to 0 for a valid defense. It would only not display the hitState if a creature somehow had undefined for a valid defense.

…efense is selected. This left the Attack button in the item in the disabled state.
@EndlesNights EndlesNights changed the base branch from main to dev August 23, 2022 01:18
@EndlesNights EndlesNights merged commit b160648 into EndlesNights:dev Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants