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

@ -91,6 +91,8 @@ Hooks.once('init', () => {
Actors.registerSheet(SYSTEM.id, applications.DhpEnvironment, { types: ['environment'], makeDefault: true }); Actors.registerSheet(SYSTEM.id, applications.DhpEnvironment, { types: ['environment'], makeDefault: true });
CONFIG.ActiveEffect.documentClass = documents.DhActiveEffect; CONFIG.ActiveEffect.documentClass = documents.DhActiveEffect;
CONFIG.ActiveEffect.dataModels = models.activeEffects.config;
foundry.applications.apps.DocumentSheetConfig.unregisterSheet( foundry.applications.apps.DocumentSheetConfig.unregisterSheet(
CONFIG.ActiveEffect.documentClass, CONFIG.ActiveEffect.documentClass,
'core', 'core',

View file

@ -23,7 +23,9 @@
"DAGGERHEART": { "DAGGERHEART": {
"UI": { "UI": {
"notifications": { "notifications": {
"adversaryMissing": "The linked adversary doesn't exist in the world." "adversaryMissing": "The linked adversary doesn't exist in the world.",
"beastformInapplicable": "A beastform can only be applied to a Character.",
"beastformAlreadyApplied": "The character already has a beastform applied!"
} }
}, },
"Settings": { "Settings": {
@ -1473,13 +1475,21 @@
} }
}, },
"Beastform": { "Beastform": {
"DialogTitle": "Beastform Selection",
"FIELDS": { "FIELDS": {
"tier": { "label": "Tier" }, "tier": { "label": "Tier" },
"examples": { "label": "Examples" }, "examples": { "label": "Examples" },
"advantageOn": { "label": "Gain Advantage On" } "advantageOn": { "label": "Gain Advantage On" },
"tokenImg": { "label": "Token Image" },
"tokenSize": {
"placeholder": "Using character dimensions",
"height": { "label": "Height" },
"width": { "label": "Width" }
}
}, },
"Transform": "Transform" "dialogTitle": "Beastform Selection",
"tokenTitle": "Beastform Token",
"transform": "Transform",
"beastformEffect": "Beastform Transformation"
}, },
"Global": { "Global": {
"Actions": "Actions", "Actions": "Actions",

View file

@ -304,11 +304,14 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
getItem(element) { getItem(element) {
const listElement = (element.target ?? element).closest('[data-item-id]'); const listElement = (element.target ?? element).closest('[data-item-id]');
const document = listElement.dataset.companion ? this.document.system.companion : this.document; const itemId = listElement.dataset.itemId;
if (listElement.dataset.type === 'effect') {
const itemId = listElement.dataset.itemId, return this.document.effects.get(itemId);
item = document.items.get(itemId); } else if (listElement.dataset.type === 'features') {
return item; return this.document.items.get(itemId);
} else {
return this.document.system[listElement.dataset.type].system.actions.find(x => x.id === itemId);
}
} }
static triggerContextMenu(event, button) { static triggerContextMenu(event, button) {
@ -615,8 +618,8 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
if (!item) return; if (!item) return;
// Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board // Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board
if (item.type === 'feature') { if (item.type === 'feature' || item instanceof ActiveEffect) {
item.toChat(); item.toChat(this);
} else { } else {
const wasUsed = await item.use(event); const wasUsed = await item.use(event);
if (wasUsed && item.type === 'weapon') { if (wasUsed && item.type === 'weapon') {

View file

@ -6,3 +6,4 @@ export * as items from './item/_module.mjs';
export { actionsTypes } from './action/_module.mjs'; export { actionsTypes } from './action/_module.mjs';
export * as messages from './chat-message/_modules.mjs'; export * as messages from './chat-message/_modules.mjs';
export * as fields from './fields/_module.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) { if (this instanceof DhBeastformAction) {
config = await BeastformDialog.configure(config); const abort = await this.handleActiveTransformations();
if (!config) return; if (abort) return;
const beastformUuid = await BeastformDialog.configure(config);
if (!beastformUuid) return;
await this.transform(beastformUuid);
} }
if (this.doFollowUp()) { 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 ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
import BaseDataItem from './base.mjs'; import BaseDataItem from './base.mjs';
@ -24,9 +24,90 @@ export default class DHBeastform extends BaseDataItem {
choices: SYSTEM.GENERAL.tiers, choices: SYSTEM.GENERAL.tiers,
initial: SYSTEM.GENERAL.tiers.tier1.id 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(), examples: new fields.StringField(),
advantageOn: new fields.ArrayField(new fields.StringField()), advantageOn: new fields.ArrayField(new fields.StringField()),
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }) 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);
}
} }

View file

@ -19,6 +19,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
height: 'auto' height: 'auto'
}, },
actions: { actions: {
selectBeastform: this.selectBeastform,
submitBeastform: this.submitBeastform submitBeastform: this.submitBeastform
}, },
form: { form: {
@ -29,7 +30,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
}; };
get title() { get title() {
return game.i18n.localize('DAGGERHEART.Sheets.Beastform.DialogTitle'); return game.i18n.localize('DAGGERHEART.Sheets.Beastform.dialogTitle');
} }
/** @override */ /** @override */
@ -64,6 +65,11 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
this.render(); this.render();
} }
static selectBeastform(_, target) {
this.selected = this.selected === target.dataset.uuid ? null : target.dataset.uuid;
this.render();
}
static async submitBeastform() { static async submitBeastform() {
await this.close({ submitted: true }); await this.close({ submitted: true });
} }
@ -76,7 +82,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
static async configure(configData) { static async configure(configData) {
return new Promise(resolve => { return new Promise(resolve => {
const app = new this(configData); const app = new this(configData);
app.addEventListener('close', () => resolve(app.config), { once: true }); app.addEventListener('close', () => resolve(app.selected), { once: true });
app.render({ force: true }); app.render({ force: true });
}); });
} }

View file

@ -28,4 +28,27 @@ export default class DhActiveEffect extends ActiveEffect {
change.value = Roll.safeEval(Roll.replaceFormulaData(change.value, change.effect.parent)); change.value = Roll.safeEval(Roll.replaceFormulaData(change.value, change.effect.parent));
super.applyField(model, change, field); super.applyField(model, change, field);
} }
async toChat(origin) {
const cls = getDocumentClass('ChatMessage');
const systemData = {
title: game.i18n.localize('DAGGERHEART.ActionType.action'),
origin: origin,
img: this.img,
name: this.name,
description: this.description,
actions: []
};
const msg = new cls({
type: 'abilityUse',
user: game.user.id,
system: systemData,
content: await foundry.applications.handlebars.renderTemplate(
'systems/daggerheart/templates/chat/ability-use.hbs',
systemData
)
});
cls.create(msg.toObject());
}
} }

View file

@ -294,3 +294,17 @@ export const adjustRange = (rangeVal, decrease) => {
const newIndex = decrease ? Math.max(index - 1, 0) : Math.min(index + 1, rangeKeys.length - 1); const newIndex = decrease ? Math.max(index - 1, 0) : Math.min(index + 1, rangeKeys.length - 1);
return range[rangeKeys[newIndex]]; return range[rangeKeys[newIndex]];
}; };
export const updateActorTokens = async (actor, update) => {
await actor.prototypeToken.update(update);
/* Update the tokens in all scenes belonging to Actor */
for (let scene of game.scenes) {
for (let token of scene.tokens) {
const actor = token.baseActor ?? token.actor;
if (actor?.id === actor.id) {
await token.update(update);
}
}
}
};

View file

@ -5006,7 +5006,7 @@ div.daggerheart.views.multiclass {
border-radius: 6px; border-radius: 6px;
cursor: pointer; cursor: pointer;
} }
.application.daggerheart.dh-style.views.beastform-selection .beastforms-container .beastforms-tier .beastform-container.disabled { .application.daggerheart.dh-style.views.beastform-selection .beastforms-container .beastforms-tier .beastform-container.inactive {
opacity: 0.4; opacity: 0.4;
} }
.application.daggerheart.dh-style.views.beastform-selection .beastforms-container .beastforms-tier .beastform-container img { .application.daggerheart.dh-style.views.beastform-selection .beastforms-container .beastforms-tier .beastform-container img {

View file

@ -23,7 +23,7 @@
border-radius: 6px; border-radius: 6px;
cursor: pointer; cursor: pointer;
&.disabled { &.inactive {
opacity: 0.4; opacity: 0.4;
} }

View file

@ -250,6 +250,9 @@
}, },
"beastform": {} "beastform": {}
}, },
"ActiveEffect": {
"beastform": {}
},
"Combat": { "Combat": {
"combat": {} "combat": {}
}, },

View file

@ -1,4 +1,4 @@
<li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-companion="{{companion}}" data-tooltip="{{concat "#item#" item.uuid}}"> <li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-companion="{{companion}}" data-type="{{type}}" data-tooltip="{{concat "#item#" item.uuid}}">
<img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem"/> <img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem"/>
<div class="item-label"> <div class="item-label">
<div class="item-name">{{item.name}}</div> <div class="item-name">{{item.name}}</div>

View file

@ -13,4 +13,15 @@
{{!-- {{formGroup systemFields.examples value=source.system.examples localize=true}} --}} {{!-- {{formGroup systemFields.examples value=source.system.examples localize=true}} --}}
</fieldset> </fieldset>
<fieldset class="two-columns even">
<legend>{{localize "DAGGERHEART.Sheets.Beastform.tokenTitle"}}</legend>
<div class="full-width">
{{formGroup systemFields.tokenImg value=source.system.tokenImg localize=true}}
</div>
{{formGroup systemFields.tokenSize.fields.height value=source.system.tokenSize.height localize=true placeholder=(localize "DAGGERHEART.Sheets.Beastform.FIELDS.tokenSize.placeholder") }}
{{formGroup systemFields.tokenSize.fields.width value=source.system.tokenSize.width localize=true placeholder=(localize "DAGGERHEART.Sheets.Beastform.FIELDS.tokenSize.placeholder")}}
</fieldset>
</section> </section>

View file

@ -0,0 +1,6 @@
<div>
<div>{{name}}</div>
<img src="{{system.tokenImg}}" />
<div>{{{system.examples}}}</div>
<div>{{system.advantageOn}}</div>
</div>

View file

@ -4,7 +4,7 @@
<fieldset class="beastforms-tier"> <fieldset class="beastforms-tier">
<legend>{{tier.label}}</legend> <legend>{{tier.label}}</legend>
{{#each tier.values as |form uuid|}} {{#each tier.values as |form uuid|}}
<div class="beastform-container {{#if (and @root.canSubmit (not form.selected))}}disabled{{/if}}"> {{!-- data-tooltip="{{concat "#item#" uuid}}" --}} <div data-action="selectBeastform" data-uuid="{{uuid}}" data-tooltip="{{concat "#item#" uuid}}" class="beastform-container {{#if (and @root.canSubmit (not form.selected))}}inactive{{/if}}">
<img src="{{form.value.img}}" /> <img src="{{form.value.img}}" />
<div class="beastform-title">{{form.value.name}}</div> <div class="beastform-title">{{form.value.name}}</div>
</div> </div>
@ -13,6 +13,6 @@
{{/each}} {{/each}}
</div> </div>
<footer> <footer>
<button data-action="submitBeastForm" {{#if (not canSubmit)}}disabled{{/if}}>{{localize "DAGGERHEART.Sheets.Beastform.Transform"}}</button> <button type="button" data-action="submitBeastform" {{#if (not canSubmit)}}disabled{{/if}}>{{localize "DAGGERHEART.Sheets.Beastform.transform"}}</button>
</footer> </footer>
</div> </div>