Some ActiveEffect shenanigans with training levels

This commit is contained in:
Oliver-Akins 2024-04-20 23:12:38 -06:00
parent cfaed0d230
commit c466e0e539
3 changed files with 19 additions and 6 deletions

View file

@ -1,8 +1,17 @@
import { DotDungeonActor } from "./GenericActor.mjs"; import { DotDungeonActor } from "./GenericActor.mjs";
import { DotDungeonItem } from "../Item/GenericItem.mjs";
export class Player extends DotDungeonActor { 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() { async createCustomPet() {
const body = new URLSearchParams({ const body = new URLSearchParams({
number: 1, number: 1,

View file

@ -74,6 +74,7 @@ export class PlayerSheetv2 extends GenericActorSheet {
/** @type {ActorHandler} */ /** @type {ActorHandler} */
const actor = this.actor; const actor = this.actor;
ctx.original = actor.toObject().system;
ctx.system = actor.system; ctx.system = actor.system;
ctx.flags = actor.flags; ctx.flags = actor.flags;
ctx.items = this.actor.itemTypes; ctx.items = this.actor.itemTypes;
@ -92,11 +93,13 @@ export class PlayerSheetv2 extends GenericActorSheet {
get #statData() { get #statData() {
const stats = []; const stats = [];
const usedDice = new Set(Object.values(this.actor.system.stats)); const original = this.actor.toObject().system;
for (const statName in this.actor.system.stats) { const usedDice = new Set(Object.values(original.stats));
for (const statName in original.stats) {
const stat = { const stat = {
key: statName, key: statName,
name: localizer(`dotdungeon.stat.${statName}`), name: localizer(`dotdungeon.stat.${statName}`),
original: original.stats[statName],
value: this.actor.system.stats[statName], value: this.actor.system.stats[statName],
}; };
@ -111,7 +114,7 @@ export class PlayerSheetv2 extends GenericActorSheet {
return { return {
value: die, value: die,
label: localizer(`dotdungeon.die.${die}`, { stat: statName }), 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, key: skill,
name: game.i18n.format(`dotdungeon.skills.${skill}`), name: game.i18n.format(`dotdungeon.skills.${skill}`),
value, value,
original: original.skills[statName][skill],
formula: `1` + stat.value + modifierToString(value, { spaces: true }), formula: `1` + stat.value + modifierToString(value, { spaces: true }),
rollDisabled: value === -1, rollDisabled: value === -1,
}); });

View file

@ -7,7 +7,7 @@
name="system.stats.{{stat.key}}" name="system.stats.{{stat.key}}"
class="e-2dp dice-select" class="e-2dp dice-select"
> >
{{{dd-options stat.value stat.dieOptions}}} {{{dd-options stat.original stat.dieOptions}}}
</select> </select>
<button <button
type="button" type="button"
@ -35,7 +35,7 @@
class="e-2dp skill__training" class="e-2dp skill__training"
> >
{{{dd-options {{{dd-options
skill.value skill.original
@root.config.trainingLevels @root.config.trainingLevels
localize=true localize=true
}}} }}}