Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#3763] Select spellcasting ability based on spell's associated class #3764

Merged
merged 4 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion module/data/item/spell.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ export default class SpellData extends ItemDataModel.mixin(

/** @inheritdoc */
get _typeAbilityMod() {
return this.parent?.actor?.system.attributes.spellcasting || "int";
return this.parent?.actor?.spellcastingClasses[this.sourceClass]?.spellcasting.ability
arbron marked this conversation as resolved.
Show resolved Hide resolved
?? this.parent?.actor?.system.attributes?.spellcasting
?? "int";
}

/* -------------------------------------------- */
Expand Down
27 changes: 23 additions & 4 deletions module/documents/actor/actor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,18 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {

/**
* The data source for Actor5e.classes allowing it to be lazily computed.
* @type {Object<Item5e>}
* @type {Record<string, Item5e>}
* @private
*/
_classes;

/**
* Cached spellcasting classes.
* @type {Record<string, Item5e>}
* @private
*/
_spellcastingClasses;

/**
* Mapping of item source IDs to the items.
* @type {Map<string, Item5e>}
Expand All @@ -35,7 +42,7 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {

/**
* A mapping of classes belonging to this Actor.
* @type {Object<Item5e>}
* @type {Record<string, Item5e>}
*/
get classes() {
if ( this._classes !== undefined ) return this._classes;
Expand All @@ -53,7 +60,8 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {
* @type {Record<string, Item5e>}
*/
get spellcastingClasses() {
return Object.entries(this.classes).reduce((obj, [identifier, cls]) => {
if ( this._spellcastingClasses !== undefined ) return this._spellcastingClasses;
return this._spellcastingClasses = Object.entries(this.classes).reduce((obj, [identifier, cls]) => {
if ( cls.spellcasting && (cls.spellcasting.progression !== "none") ) obj[identifier] = cls;
return obj;
}, {});
Expand Down Expand Up @@ -156,14 +164,25 @@ export default class Actor5e extends SystemDocumentMixin(Actor) {
/** @inheritDoc */
prepareData() {
if ( this.system.modelProvider !== dnd5e ) return super.prepareData();
this._classes = undefined;
this._clearCachedValues();
this._preparationWarnings = [];
super.prepareData();
this.items.forEach(item => item.prepareFinalAttributes());
}

/* --------------------------------------------- */

/**
* Clear cached class collections.
* @internal
*/
_clearCachedValues() {
this._classes = undefined;
this._spellcastingClasses = undefined;
}

/* --------------------------------------------- */

/** @inheritDoc */
prepareEmbeddedDocuments() {
this.sourcedItems = new Map();
Expand Down
3 changes: 2 additions & 1 deletion module/documents/item.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,8 @@ export default class Item5e extends SystemDocumentMixin(Item) {

// Actor spell-DC based scaling
if ( save.scaling === "spell" ) {
save.dc = this.isOwned ? this.actor.system.attributes.spelldc : null;
save.dc = this.isOwned ? this.actor.system.abilities?.[this.system.abilityMod]?.dc
?? this.actor.system.attributes.spelldc : null;
}

// Ability-score based scaling
Expand Down