Skip to content
This repository has been archived by the owner on Nov 2, 2024. It is now read-only.

Commit

Permalink
Several fixes and implementations
Browse files Browse the repository at this point in the history
- Closes #151.
- Closes #150.
- Closes #149.
  • Loading branch information
krbz999 committed Mar 7, 2023
1 parent 7957e24 commit 704d47c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
2 changes: 1 addition & 1 deletion scripts/applications/dataModel.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class Babonus extends foundry.abstract.DataModel {
return Object.values(this.bonuses).some(val => !!val && (val !== "0"));
}

// The source item or actor of a babonus. If an aura, effect, template, always resolves to the ORIGIN item or actor, unless deleted.
// The source item or actor of a babonus. Attempts to always return the original source item or actor.
get origin() {
if (this.parent instanceof MeasuredTemplateDocument) {
const origin = this.parent.flags.dnd5e?.origin ?? "";
Expand Down
23 changes: 15 additions & 8 deletions scripts/applications/rollConfigApp.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export class OptionalSelector {

/** Custom helper method for retrieving all the data for the template. */
async getData() {
const bonuses = this.bonuses.reduce((acc, bonus) => {
const bonuses = [];
for (const bonus of this.bonuses) {
let data = null;
if (bonus.isConsuming) {
if (["uses", "quantity"].includes(bonus.consume.type)) {
Expand All @@ -49,13 +50,18 @@ export class OptionalSelector {
} else if (bonus.consume.type === "effect") {
data = this._getDataConsumeEffects(bonus);
}
if (!this._canSupplyMinimum(bonus)) return acc;
if (!this._canSupplyMinimum(bonus)) continue;
} else {
data = this._getDataNoConsume(bonus);
}
if (data) acc.push(data);
return acc;
}, []);
if (data) bonuses.push({
...data,
description: await TextEditor.enrichHTML(bonus.description, {
async: true,
rollData: bonus.origin?.getRollData() ?? {}
})
});
}

return {bonuses};
}
Expand Down Expand Up @@ -383,7 +389,8 @@ export class OptionalSelector {
if (!scale) return new CONFIG.Dice.DamageRoll(bonus.bonuses.bonus, data).formula;
const roll = new CONFIG.Dice.DamageRoll(bonus.consume.formula || bonus.bonuses.bonus, data);
const formula = roll.alter(scale, 0, {multiplyNumeric: true}).formula;
return dnd5e.dice.simplifyRollFormula(`${bonus.bonuses.bonus} + ${formula}`, {preserveFlavor: true});
const base = Roll.replaceFormulaData(bonus.bonuses.bonus, data);
return dnd5e.dice.simplifyRollFormula(`${base} + ${formula}`, {preserveFlavor: true});
}

/**
Expand Down Expand Up @@ -417,8 +424,8 @@ export class OptionalSelector {
}
}
if (level === Infinity) return false;
if ((pact > 0) && (pact <= level)) return "system.spells.pact.value";
return `system.spells.spell${level}.value`;
if ((pact > 0) && (pact <= level)) return "pact";
return `spell${level}`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion templates/subapplications/optionalBonuses.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{{bonus.babonus.name}}.
</span>
<span class="description">
{{{bonus.babonus.description}}}
{{{description}}}
</span>
</div>

Expand Down

0 comments on commit 704d47c

Please sign in to comment.