diff --git a/module/applications/advancement/item-choice-flow.mjs b/module/applications/advancement/item-choice-flow.mjs index 8f623cc255..0bb0113c0a 100644 --- a/module/applications/advancement/item-choice-flow.mjs +++ b/module/applications/advancement/item-choice-flow.mjs @@ -1,3 +1,4 @@ +import Actor5e from "../../documents/actor/actor.mjs"; import ItemGrantFlow from "./item-grant-flow.mjs"; /** @@ -169,12 +170,27 @@ export default class ItemChoiceFlow extends ItemGrantFlow { * @returns {number} */ _maxSpellSlotLevel() { - const largestSlot = Object.entries(this.advancement.actor.system.spells).reduce((slot, [key, data]) => { + const spellcasting = this.advancement.item.spellcasting; + let spells; + + // For advancements on classes or subclasses, use the largest slot available for that class + if ( spellcasting ) { + const progression = { slot: 0, pact: {} }; + const maxSpellLevel = CONFIG.DND5E.SPELL_SLOT_TABLE[CONFIG.DND5E.SPELL_SLOT_TABLE.length - 1].length; + spells = Object.fromEntries(Array.fromRange(maxSpellLevel, 1).map(l => [`spell${l}`, {}])); + Actor5e.computeClassProgression(progression, this.advancement.item, { spellcasting }); + Actor5e.prepareSpellcastingSlots(spells, spellcasting.type, progression); + } + + // For all other items, use the largest slot possible + else spells = this.advancement.actor.system.spells; + + const largestSlot = Object.entries(spells).reduce((slot, [key, data]) => { if ( data.max === 0 ) return slot; const level = parseInt(key.replace("spell", "")); if ( !Number.isNaN(level) && level > slot ) return level; return slot; }, -1); - return Math.max(this.advancement.actor.system.spells.pact.level, largestSlot); + return Math.max(spells.pact?.level ?? 0, largestSlot); } } diff --git a/module/documents/actor/actor.mjs b/module/documents/actor/actor.mjs index fb7af39b6f..d179cb389a 100644 --- a/module/documents/actor/actor.mjs +++ b/module/documents/actor/actor.mjs @@ -659,7 +659,7 @@ export default class Actor5e extends Actor { * @protected */ _prepareSpellcasting() { - if ( this.type === "vehicle" ) return; + if ( !this.system.spells ) return; // Spellcasting DC const spellcastingAbility = this.system.abilities[this.system.attributes.spellcasting]; @@ -691,7 +691,7 @@ export default class Actor5e extends Actor { ); } - for ( const type of Object.keys(types) ) { + for ( const type of Object.keys(CONFIG.DND5E.spellcastingTypes) ) { this.constructor.prepareSpellcastingSlots(this.system.spells, type, progression, { actor: this }); } }