Reworked Action storage

This commit is contained in:
WBHarry 2025-06-30 23:01:50 +02:00
parent 3333a9e00a
commit ce593d02f3
16 changed files with 196 additions and 23 deletions

View file

@ -1,6 +1,8 @@
import DamageSelectionDialog from '../applications/damageSelectionDialog.mjs';
import { GMUpdateEvent, socketEvent } from '../helpers/socket.mjs';
import DamageReductionDialog from '../applications/damageReductionDialog.mjs';
import { actionsTypes } from '../data/_module.mjs';
import { LevelOptionType } from '../data/levelTier.mjs';
export default class DhpActor extends Actor {
async _preCreate(data, options, user) {
@ -20,10 +22,6 @@ export default class DhpActor extends Actor {
async updateLevel(newLevel) {
if (!['character', 'companion'].includes(this.type) || newLevel === this.system.levelData.level.changed) return;
if (this.system.companion) {
this.system.companion.updateLevel(newLevel);
}
if (newLevel > this.system.levelData.level.current) {
const maxLevel = Object.values(
game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.LevelTiers).tiers
@ -122,10 +120,15 @@ export default class DhpActor extends Actor {
}
}
});
if (this.system.companion) {
this.system.companion.updateLevel(newLevel);
}
}
}
async levelUp(levelupData) {
const actions = [];
const levelups = {};
for (var levelKey of Object.keys(levelupData)) {
const level = levelupData[levelKey];
@ -150,6 +153,7 @@ export default class DhpActor extends Actor {
}
let multiclass = null;
const actionIds = [];
const domainCards = [];
const subclassFeatureState = { class: null, multiclass: null };
const selections = [];
@ -158,6 +162,27 @@ export default class DhpActor extends Actor {
for (var checkboxNr of Object.keys(selection)) {
const checkbox = selection[checkboxNr];
const tierOption = LevelOptionType[checkbox.type];
for (var actionData of tierOption.actions ?? []) {
const cls = actionsTypes[actionData.type];
const actionId = foundry.utils.randomID();
actionIds.push(actionId);
actions.push(
new cls(
{
// ...cls.getSourceConfig(target),
...actionData,
_id: actionId,
name: game.i18n.localize(actionData.name),
description: game.i18n.localize(actionData.description)
},
{
parent: this
}
)
);
}
if (checkbox.type === 'multiclass') {
multiclass = {
...checkbox,
@ -255,6 +280,7 @@ export default class DhpActor extends Actor {
await this.update({
system: {
actions: [...this.system.actions, ...actions],
levelData: {
level: {
current: this.system.levelData.level.changed
@ -263,6 +289,10 @@ export default class DhpActor extends Actor {
}
}
});
if (this.system.companion) {
this.system.companion.updateLevel(this.system.levelData.level.changed);
}
}
/**