Skip to content

Commit

Permalink
Merge pull request #142 from PwQt/134-bug-recharge-on-long-rest-is-no…
Browse files Browse the repository at this point in the history
…t-working

#134 fix to recharging on formula
  • Loading branch information
PwQt authored May 23, 2024
2 parents 0ff57cb + c334ba6 commit 122ec58
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/scripts/magic-item/OwnedMagicItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@ export class OwnedMagicItem extends MagicItem {
return destroyed;
}

onShortRest() {
async onShortRest() {
if (this.rechargeable && this.rechargeUnit === MAGICITEMS.SHORT_REST) {
return this.doRecharge();
return await this.doRecharge();
}
}

onLongRest() {
async onLongRest() {
if (this.rechargeable && [MAGICITEMS.LONG_REST, MAGICITEMS.SHORT_REST].includes(this.rechargeUnit)) {
return this.doRecharge();
return await this.doRecharge();
}
}

onNewDay() {
async onNewDay() {
if (this.rechargeable && [MAGICITEMS.DAILY, MAGICITEMS.DAWN, MAGICITEMS.SUNSET].includes(this.rechargeUnit)) {
return this.doRecharge();
return await this.doRecharge();
}
}

doRecharge() {
async doRecharge() {
let amount = 0,
updated = 0,
msg = `<b>Magic Item:</b> ${this.rechargeableLabel}<br>`;
Expand All @@ -167,7 +167,7 @@ export class OwnedMagicItem extends MagicItem {
}
if (this.rechargeType === MAGICITEMS.FORMULA_RECHARGE) {
let r = new Roll(this.recharge);
r.evaluate({ async: false });
await r.evaluate();
amount = r.total;
msg += `<b>${prefix}</b>: ${r.result} = ${r.total} ${postfix}`;
}
Expand Down
16 changes: 8 additions & 8 deletions src/scripts/magicitemactor.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export class MagicItemActor {
shortRest(original, me) {
return async function () {
let result = await original.apply(me.actor, arguments);
me.onShortRest(result);
await me.onShortRest(result);
return result;
};
}
Expand All @@ -109,7 +109,7 @@ export class MagicItemActor {
longRest(original, me) {
return async function () {
let result = await original.apply(me.actor, arguments);
me.onLongRest(result);
await me.onLongRest(result);
return result;
};
}
Expand Down Expand Up @@ -151,10 +151,10 @@ export class MagicItemActor {
*
* @param result
*/
onShortRest(result) {
async onShortRest(result) {
if (result) {
this.items.forEach((item) => {
item.onShortRest();
this.items.forEach(async (item) => {
await item.onShortRest();
if (result.newDay) item.onNewDay();
});
this.fireChange();
Expand All @@ -167,10 +167,10 @@ export class MagicItemActor {
*
* @param result
*/
onLongRest(result) {
async onLongRest(result) {
if (result) {
this.items.forEach((item) => {
item.onLongRest();
this.items.forEach(async (item) => {
await item.onLongRest();
if (result.newDay) item.onNewDay();
});
this.fireChange();
Expand Down

0 comments on commit 122ec58

Please sign in to comment.