From c466e0e53975b553d5ac23f9a3a708a1ca7326ec Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Sat, 20 Apr 2024 23:12:38 -0600 Subject: [PATCH] Some ActiveEffect shenanigans with training levels --- module/documents/Actor/Player.mjs | 11 ++++++++++- module/sheets/Actors/PC/PlayerSheetV2.mjs | 10 +++++++--- .../actors/char-sheet/v2/partials/stats.v2.pc.hbs | 4 ++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/module/documents/Actor/Player.mjs b/module/documents/Actor/Player.mjs index ff54481..6140ecb 100644 --- a/module/documents/Actor/Player.mjs +++ b/module/documents/Actor/Player.mjs @@ -1,8 +1,17 @@ import { DotDungeonActor } from "./GenericActor.mjs"; -import { DotDungeonItem } from "../Item/GenericItem.mjs"; export class Player extends DotDungeonActor { + applyActiveEffects() { + super.applyActiveEffects(); + + // These are the (groups of) fields that ActiveEffects may modify safely + // and remain editable in the sheet. This needs to be done because of default + // Foundry behaviour that otherwise prevents these fields from being edited + delete this.overrides.system.stats; + delete this.overrides.system.skills; + }; + async createCustomPet() { const body = new URLSearchParams({ number: 1, diff --git a/module/sheets/Actors/PC/PlayerSheetV2.mjs b/module/sheets/Actors/PC/PlayerSheetV2.mjs index e39f7e3..142744b 100644 --- a/module/sheets/Actors/PC/PlayerSheetV2.mjs +++ b/module/sheets/Actors/PC/PlayerSheetV2.mjs @@ -74,6 +74,7 @@ export class PlayerSheetv2 extends GenericActorSheet { /** @type {ActorHandler} */ const actor = this.actor; + ctx.original = actor.toObject().system; ctx.system = actor.system; ctx.flags = actor.flags; ctx.items = this.actor.itemTypes; @@ -92,11 +93,13 @@ export class PlayerSheetv2 extends GenericActorSheet { get #statData() { const stats = []; - const usedDice = new Set(Object.values(this.actor.system.stats)); - for (const statName in this.actor.system.stats) { + const original = this.actor.toObject().system; + const usedDice = new Set(Object.values(original.stats)); + for (const statName in original.stats) { const stat = { key: statName, name: localizer(`dotdungeon.stat.${statName}`), + original: original.stats[statName], value: this.actor.system.stats[statName], }; @@ -111,7 +114,7 @@ export class PlayerSheetv2 extends GenericActorSheet { return { value: die, label: localizer(`dotdungeon.die.${die}`, { stat: statName }), - disabled: usedDice.has(die) && this.actor.system.stats[statName] !== die, + disabled: usedDice.has(die) && original.stats[statName] !== die, }; }) ]; @@ -127,6 +130,7 @@ export class PlayerSheetv2 extends GenericActorSheet { key: skill, name: game.i18n.format(`dotdungeon.skills.${skill}`), value, + original: original.skills[statName][skill], formula: `1` + stat.value + modifierToString(value, { spaces: true }), rollDisabled: value === -1, }); diff --git a/templates/actors/char-sheet/v2/partials/stats.v2.pc.hbs b/templates/actors/char-sheet/v2/partials/stats.v2.pc.hbs index 5a5a5f1..6353120 100644 --- a/templates/actors/char-sheet/v2/partials/stats.v2.pc.hbs +++ b/templates/actors/char-sheet/v2/partials/stats.v2.pc.hbs @@ -7,7 +7,7 @@ name="system.stats.{{stat.key}}" class="e-2dp dice-select" > - {{{dd-options stat.value stat.dieOptions}}} + {{{dd-options stat.original stat.dieOptions}}}