Skip to content

Commit

Permalink
fix: item error report and property display when upcasted
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFdez committed Jun 2, 2021
1 parent 5d450b4 commit eea8403
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
18 changes: 11 additions & 7 deletions betterrolls5e/scripts/custom-roll.js
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,8 @@ export class CustomItemRoll {
* and returns the spell configuration, or "error" on forced close.
*/
async configureSpell() {
let { item, actor } = this;
const item = await this.getItem();
const actor = await this.getActor();
let spellLevel = null;
let consume = false;
let placeTemplate = false;
Expand Down Expand Up @@ -1144,10 +1145,9 @@ export class CustomItemRoll {
spellLevel = getProperty(actor, `data.data.spells.pact.level`) || spellLevel;
}

if (spellLevel !== data.level) {
this.item = item.clone({ "data.level": spellLevel }, { keepId: true });
}

// Update params and item data temporarily
// We use data.update() so that changes are maintained even through clone() uses
item.data.update({ 'data.castedLevel': spellLevel });
this.params.slotLevel = spellLevel;
this.params.consumeSpellLevel = consume;
return { lvl: spellLevel, consume, placeTemplate };
Expand Down Expand Up @@ -1188,8 +1188,12 @@ export class CustomItemRoll {
*/
async consume() {
const actor = await this.getActor();
const item = await this.getItem();
if (!item) return;
const baseItem = await this.getItem();
if (!baseItem) return;

// The error message for spells uses the item level, so we tweak so that it reports correctly
const itemLevel = this.params.slotLevel ?? baseItem.data.data.level;
const item = baseItem.clone({ "data.level": itemLevel }, { keepId: true });

let actorUpdates = {};
let itemUpdates = {};
Expand Down
2 changes: 1 addition & 1 deletion betterrolls5e/scripts/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,8 +757,8 @@ export class ItemUtils {
data.isAttack = data.actionType === "attack";

properties = [
dnd5e.spellLevels[data.castedLevel ?? data.level],
dnd5e.spellSchools[data.school],
dnd5e.spellLevels[data.level],
data.components.ritual ? i18n("Ritual") : null,
activation,
duration,
Expand Down

0 comments on commit eea8403

Please sign in to comment.