From 035a56a053dbdebeb8882f1d687887c5f2316c28 Mon Sep 17 00:00:00 2001 From: Jeff Hitchcock Date: Mon, 23 Sep 2024 10:20:37 -0700 Subject: [PATCH] [#4395] Populate roll data for scrolls with spell level Created spell scrolls are missing `@item.level` in their roll data. This adds that value to roll data so long as the `spellLevel` flag is present. This also sets the `flags.dnd5e.scaling` flag when creating the scroll to ensure other scaling occurs properly. Closes #4395 --- module/data/item/consumable.mjs | 12 ++++++++++++ module/documents/item.mjs | 1 + 2 files changed, 13 insertions(+) diff --git a/module/data/item/consumable.mjs b/module/data/item/consumable.mjs index 5999405c5b..7956065917 100644 --- a/module/data/item/consumable.mjs +++ b/module/data/item/consumable.mjs @@ -246,4 +246,16 @@ export default class ConsumableData extends ItemDataModel.mixin( .filter(p => p !== "material").forEach(p => valid.add(p)); return valid; } + + /* -------------------------------------------- */ + /* Helpers */ + /* -------------------------------------------- */ + + /** @inheritDoc */ + getRollData(...options) { + const data = super.getRollData(...options); + const spellLevel = this.parent.getFlag("dnd5e", "spellLevel"); + if ( spellLevel ) data.item.level = spellLevel.value ?? spellLevel.base; + return data; + } } diff --git a/module/documents/item.mjs b/module/documents/item.mjs index 1962c6da72..2b26669c05 100644 --- a/module/documents/item.mjs +++ b/module/documents/item.mjs @@ -1640,6 +1640,7 @@ export default class Item5e extends SystemDocumentMixin(Item) { const flags = itemData.flags ?? {}; if ( Number.isNumeric(config.level) ) { flags.dnd5e ??= {}; + flags.dnd5e.scaling = Math.max(0, config.level - spell.system.level); flags.dnd5e.spellLevel = { value: config.level, base: spell.system.level