Skip to content

Commit

Permalink
[#1401] Adjust how available spell level is calculated for classes
Browse files Browse the repository at this point in the history
  • Loading branch information
arbron committed Jan 15, 2023
1 parent 5601781 commit eb0de39
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 18 additions & 2 deletions module/applications/advancement/item-choice-flow.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Actor5e from "../../documents/actor/actor.mjs";
import ItemGrantFlow from "./item-grant-flow.mjs";

/**
Expand Down Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions module/documents/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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 });
}
}
Expand Down

0 comments on commit eb0de39

Please sign in to comment.