Fixed basic beastform

This commit is contained in:
WBHarry 2025-07-03 14:13:49 +02:00
parent 978d45b931
commit 3186468f28
18 changed files with 231 additions and 21 deletions

View file

@ -6,3 +6,4 @@ export * as items from './item/_module.mjs';
export { actionsTypes } from './action/_module.mjs';
export * as messages from './chat-message/_modules.mjs';
export * as fields from './fields/_module.mjs';
export * as activeEffects from './activeEffect/_module.mjs';

View file

@ -271,8 +271,13 @@ export class DHBaseAction extends foundry.abstract.DataModel {
}
if (this instanceof DhBeastformAction) {
config = await BeastformDialog.configure(config);
if (!config) return;
const abort = await this.handleActiveTransformations();
if (abort) return;
const beastformUuid = await BeastformDialog.configure(config);
if (!beastformUuid) return;
await this.transform(beastformUuid);
}
if (this.doFollowUp()) {
@ -774,4 +779,24 @@ export class DhBeastformAction extends DHBaseAction {
})
};
}
async transform(beastformUuid) {
const beastform = await foundry.utils.fromUuid(beastformUuid);
this.actor.createEmbeddedDocuments('Item', [beastform.toObject()]);
}
async handleActiveTransformations() {
const activeBeastforms = this.actor.items.filter(x => x.type === 'beastform');
if (activeBeastforms.length > 0) {
for (let form of activeBeastforms) {
await form.delete();
}
this.actor.effects.filter(x => x.type === 'beastform').forEach(x => x.delete());
return true;
}
return false;
}
}

View file

@ -0,0 +1,7 @@
import beastformEffect from './beastformEffect.mjs';
export { beastformEffect };
export const config = {
beastform: beastformEffect
};

View file

@ -0,0 +1,18 @@
export default class BeastformEffect extends foundry.abstract.TypeDataModel {
static defineSchema() {
const fields = foundry.data.fields;
return {
isBeastform: new fields.BooleanField({ initial: false })
};
}
async _preDelete() {
if (this.parent.parent.type === 'character') {
for (let item of this.parent.parent.items) {
if (item.type === 'beastform') {
await item.delete();
}
}
}
}
}

View file

@ -1,4 +1,4 @@
import ActionField from '../fields/actionField.mjs';
import { updateActorTokens } from '../../helpers/utils.mjs';
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import BaseDataItem from './base.mjs';
@ -24,9 +24,90 @@ export default class DHBeastform extends BaseDataItem {
choices: SYSTEM.GENERAL.tiers,
initial: SYSTEM.GENERAL.tiers.tier1.id
}),
tokenImg: new fields.FilePathField({
initial: 'icons/svg/mystery-man.svg',
categories: ['IMAGE'],
base64: false
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, min: 1, initial: null, nullable: true })
}),
characterTokenData: new fields.SchemaField({
tokenImg: new fields.FilePathField({
categories: ['IMAGE'],
base64: false,
nullable: true,
initial: null
}),
tokenSize: new fields.SchemaField({
height: new fields.NumberField({ integer: true, initial: null, nullable: true }),
width: new fields.NumberField({ integer: true, initial: null, nullable: true })
})
}),
examples: new fields.StringField(),
advantageOn: new fields.ArrayField(new fields.StringField()),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
};
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
if (this.actor?.type !== 'character') {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.beastformInapplicable'));
return;
}
if (this.actor.items.find(x => x.type === 'beastform')) {
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.beastformAlreadyApplied'));
return;
}
await this.updateSource({
characterTokenData: {
tokenImg: this.parent.parent.prototypeToken.texture.src,
tokenSize: {
height: this.parent.parent.prototypeToken.height,
width: this.parent.parent.prototypeToken.width
}
}
});
}
_onCreate(data, options, userId) {
super._onCreate(data, options, userId);
const update = {
height: this.tokenSize.height,
width: this.tokenSize.width,
texture: {
src: this.tokenImg
}
};
updateActorTokens(this.parent.parent, update);
this.parent.parent.createEmbeddedDocuments('ActiveEffect', [
{
type: 'beastform',
name: game.i18n.localize('DAGGERHEART.Sheets.Beastform.beastformEffect'),
img: 'icons/creatures/abilities/paw-print-pair-purple.webp',
system: {
isBeastform: true
}
}
]);
}
async _preDelete() {
const update = {
height: this.characterTokenData.tokenSize.height,
width: this.characterTokenData.tokenSize.width,
texture: {
src: this.characterTokenData.tokenImg
}
};
await updateActorTokens(this.parent.parent, update);
}
}