Skip to content
This repository has been archived by the owner on Jan 21, 2023. It is now read-only.

Commit

Permalink
fixed race conditions on new turn logic
Browse files Browse the repository at this point in the history
  • Loading branch information
trioderegion committed Dec 29, 2020
1 parent edbb9aa commit a75dfaa
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .github/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@
- First pass at abstracting and working towards splitting this off as a standalone API that 5e helpers will hook into.
- Token#computeTargetCover now returns a promise of raw cover data which can be interpretted according to your needs

###1.8.4
- Fixed several race conditions relating to token updates on new combat turns.

2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "dnd5e-helpers",
"title": "DnD5e Helpers",
"description": "Little helpers for little tasks.",
"version": "1.8.3",
"version": "1.8.4",
"authors": [
{
"name": "honeybadger",
Expand Down
Binary file modified module.zip
Binary file not shown.
26 changes: 14 additions & 12 deletions scripts/dnd5e-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,17 +325,17 @@ function GetStatusEffect(statusName) {

//toggle core status effects
async function ToggleStatus(token, status) {
await token.toggleEffect(status);
return await token.toggleEffect(status);
}

//apply a CUB status effect
async function ApplyCUB(token, cubStatus) {
await game.cub.addCondition(cubStatus, token)
return await game.cub.addCondition(cubStatus, token)
}

//remove a CUB status effect
async function RemoveCUB(token, cubStatus) {
await game.cub.removeCondition(cubStatus, token)
return await game.cub.removeCondition(cubStatus, token)
}

/** Prof array check */
Expand Down Expand Up @@ -422,19 +422,21 @@ function WildMagicSuge_preUpdateActor(actor, update, options, userId) {
}

/** sets current legendary actions to max (or current if higher) */
async function ResetLegAct(token) {
if (token.actor == null) {
return;
async function ResetLegAct(actor, tokenName) {
if (actor == null) {
return null;
}
let legact = token.actor.data.data.resources.legact;
let legact = actor.data.data.resources.legact;
if (legact && legact.value !== null) {
/** only reset if needed */
if (legact.value < legact.max) {
ui.notifications.info(`Legendary actions restored to ${legact.max} for ${token.name}`)
legact.value = legact.max;
await token.actor.update({ 'data.resources.legact': legact });
token.actor.sheet.render(false);
ui.notifications.info(`Legendary actions restored to ${legact.max} for ${tokenName}`)
let newActor = await actor.update({ 'data.resources.legact.value': legact.max });
newActor.sheet.render(false);
return newActor;
}

return actor;
}
}

Expand Down Expand Up @@ -951,7 +953,7 @@ Hooks.on("updateCombat", async (combat, changed, options, userId) => {
/** @todo data vs _data -- multiple updates reset changes made by previous updates */
if (currentToken) {
if (game.settings.get('dnd5e-helpers', 'cbtLegactEnable') == true) {
await ResetLegAct(currentToken)
await ResetLegAct(currentToken.actor, currentToken.name)
}

if (game.settings.get('dnd5e-helpers', 'cbtAbilityRecharge') == true) {
Expand Down

0 comments on commit a75dfaa

Please sign in to comment.