[Bugfix] Targeting when attack.def = '' #229
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue
When creating a power, It is possible to select the defense for the attack as no defense.
![no_def_example](https://user-images.githubusercontent.com/20159776/185827839-a8eee652-80d6-4c63-be3e-1f94c2e00e6a.png)
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
Fix
The solution offered in this PR
DND4EBETA.VS
text if the attack isn't against any defense.targDefVal
toundefined
when the targeted creature does not have that defense, using optional chaining.hitState
iftargDefVal
===undefined
.Example: Attacking four targeted tokens when
![no_def_example_2](https://user-images.githubusercontent.com/20159776/185828930-e3eafbd2-9893-4a67-8991-55eacc8a0e0d.png)
Item4e.data.data.attack.def = ''
.I have tested that the
hitState
is still calculated when the value of a target's defense is equal to0
for a valid defense. It would only not display thehitState
if a creature somehow hadundefined
for a valid defense.