mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
Fixed basic beastform
This commit is contained in:
parent
978d45b931
commit
3186468f28
18 changed files with 231 additions and 21 deletions
|
|
@ -304,11 +304,14 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
|
||||
getItem(element) {
|
||||
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,
|
||||
item = document.items.get(itemId);
|
||||
return item;
|
||||
const itemId = listElement.dataset.itemId;
|
||||
if (listElement.dataset.type === 'effect') {
|
||||
return this.document.effects.get(itemId);
|
||||
} else if (listElement.dataset.type === 'features') {
|
||||
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) {
|
||||
|
|
@ -615,8 +618,8 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
|
|||
if (!item) return;
|
||||
|
||||
// Should dandle its actions. Or maybe they'll be separate buttons as per an Issue on the board
|
||||
if (item.type === 'feature') {
|
||||
item.toChat();
|
||||
if (item.type === 'feature' || item instanceof ActiveEffect) {
|
||||
item.toChat(this);
|
||||
} else {
|
||||
const wasUsed = await item.use(event);
|
||||
if (wasUsed && item.type === 'weapon') {
|
||||
|
|
|
|||
|
|
@ -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';
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
7
module/data/activeEffect/_module.mjs
Normal file
7
module/data/activeEffect/_module.mjs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import beastformEffect from './beastformEffect.mjs';
|
||||
|
||||
export { beastformEffect };
|
||||
|
||||
export const config = {
|
||||
beastform: beastformEffect
|
||||
};
|
||||
18
module/data/activeEffect/beastformEffect.mjs
Normal file
18
module/data/activeEffect/beastformEffect.mjs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
|
|||
height: 'auto'
|
||||
},
|
||||
actions: {
|
||||
selectBeastform: this.selectBeastform,
|
||||
submitBeastform: this.submitBeastform
|
||||
},
|
||||
form: {
|
||||
|
|
@ -29,7 +30,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
|
|||
};
|
||||
|
||||
get title() {
|
||||
return game.i18n.localize('DAGGERHEART.Sheets.Beastform.DialogTitle');
|
||||
return game.i18n.localize('DAGGERHEART.Sheets.Beastform.dialogTitle');
|
||||
}
|
||||
|
||||
/** @override */
|
||||
|
|
@ -64,6 +65,11 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
|
|||
this.render();
|
||||
}
|
||||
|
||||
static selectBeastform(_, target) {
|
||||
this.selected = this.selected === target.dataset.uuid ? null : target.dataset.uuid;
|
||||
this.render();
|
||||
}
|
||||
|
||||
static async submitBeastform() {
|
||||
await this.close({ submitted: true });
|
||||
}
|
||||
|
|
@ -76,7 +82,7 @@ export default class BeastformDialog extends HandlebarsApplicationMixin(Applicat
|
|||
static async configure(configData) {
|
||||
return new Promise(resolve => {
|
||||
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 });
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,4 +28,27 @@ export default class DhActiveEffect extends ActiveEffect {
|
|||
change.value = Roll.safeEval(Roll.replaceFormulaData(change.value, change.effect.parent));
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -294,3 +294,17 @@ export const adjustRange = (rangeVal, decrease) => {
|
|||
const newIndex = decrease ? Math.max(index - 1, 0) : Math.min(index + 1, rangeKeys.length - 1);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue