mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-10 19:17:09 +01:00
[Feature] Phase Transform (#1710)
* Added transform action to handle phased adversaries * Added support for keeping currently marked hitPoints/stress when transforming * Minor fixes * Compendium update * Added consideration for an active combatant
This commit is contained in:
parent
f1f5102af1
commit
a42d708f15
16 changed files with 406 additions and 43 deletions
|
|
@ -28,6 +28,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
removeEffect: this.removeEffect,
|
||||
addElement: this.addElement,
|
||||
removeElement: this.removeElement,
|
||||
removeTransformActor: this.removeTransformActor,
|
||||
editEffect: this.editEffect,
|
||||
addDamage: this.addDamage,
|
||||
removeDamage: this.removeDamage,
|
||||
|
|
@ -41,7 +42,7 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
submitOnChange: true,
|
||||
closeOnSubmit: false
|
||||
},
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '#summon-drop-zone', handlers: ['_onDrop'] }]
|
||||
dragDrop: [{ dragSelector: null, dropSelector: '[data-is-drop-zone]', handlers: ['_onDrop'] }]
|
||||
};
|
||||
|
||||
static PARTS = {
|
||||
|
|
@ -120,6 +121,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
htmlElement.querySelectorAll('.summon-count-wrapper input').forEach(element => {
|
||||
element.addEventListener('change', this.updateSummonCount.bind(this));
|
||||
});
|
||||
|
||||
htmlElement.querySelectorAll('.transform-resource input').forEach(element => {
|
||||
element.addEventListener('change', this.updateTransformResource.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
async _prepareContext(_options) {
|
||||
|
|
@ -133,6 +138,18 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
context.summons.push({ actor, count: summon.count });
|
||||
}
|
||||
|
||||
if (context.source.transform) {
|
||||
const actor = await foundry.utils.fromUuid(context.source.transform.actorUUID);
|
||||
context.transform = {
|
||||
...context.source.transform,
|
||||
actor:
|
||||
actor ??
|
||||
(context.source.transform.actorUUID && !actor
|
||||
? { error: game.i18n.localize('DAGGERHEART.ACTIONS.Settings.transform.actorIsMissing') }
|
||||
: null)
|
||||
};
|
||||
}
|
||||
|
||||
context.openSection = this.openSection;
|
||||
context.tabs = this._getTabs(this.constructor.TABS);
|
||||
context.config = CONFIG.DH;
|
||||
|
|
@ -266,6 +283,12 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
if (doc) return doc.sheet.render({ force: true });
|
||||
}
|
||||
|
||||
static async removeTransformActor() {
|
||||
const data = this.action.toObject();
|
||||
data.transform.actorUUID = null;
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
static addDamage(_event) {
|
||||
if (!this.action.damage.parts) return;
|
||||
const data = this.action.toObject(),
|
||||
|
|
@ -346,6 +369,14 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
updateTransformResource(event) {
|
||||
event.stopPropagation();
|
||||
|
||||
const data = this.action.toObject();
|
||||
data.transform.resourceRefresh[event.target.dataset.resource] = event.target.checked;
|
||||
this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(data) });
|
||||
}
|
||||
|
||||
/** Specific implementation in extending classes **/
|
||||
static async addEffect(_event) {}
|
||||
static removeEffect(_event, _button) {}
|
||||
|
|
@ -364,6 +395,18 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
return;
|
||||
}
|
||||
|
||||
const dropZone = event.target.closest('[data-is-drop-zone]');
|
||||
if (!dropZone) return;
|
||||
|
||||
switch (dropZone.id) {
|
||||
case 'summon-drop-zone':
|
||||
return this.onSummonDrop(data);
|
||||
case 'transform-drop-zone':
|
||||
return this.onTransformDrop(data);
|
||||
}
|
||||
}
|
||||
|
||||
async onSummonDrop(data) {
|
||||
const actionData = this.action.toObject();
|
||||
let countvalue = 1;
|
||||
for (const entry of actionData.summon) {
|
||||
|
|
@ -380,4 +423,10 @@ export default class DHActionBaseConfig extends DaggerheartSheet(ApplicationV2)
|
|||
actionData.summon.push({ actorUUID: data.uuid, count: countvalue });
|
||||
await this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(actionData) });
|
||||
}
|
||||
|
||||
async onTransformDrop(data) {
|
||||
const actionData = this.action.toObject();
|
||||
actionData.transform.actorUUID = data.uuid;
|
||||
await this.constructor.updateForm.bind(this)(null, null, { object: foundry.utils.flattenObject(actionData) });
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@ export const actionTypes = {
|
|||
icon: 'fa-ghost',
|
||||
tooltip: 'DAGGERHEART.ACTIONS.TYPES.summon.tooltip'
|
||||
},
|
||||
transform: {
|
||||
id: 'transform',
|
||||
name: 'DAGGERHEART.ACTIONS.TYPES.transform.name',
|
||||
icon: 'fa-dragon',
|
||||
tooltip: 'DAGGERHEART.ACTIONS.TYPES.transform.tooltip'
|
||||
},
|
||||
effect: {
|
||||
id: 'effect',
|
||||
name: 'DAGGERHEART.ACTIONS.TYPES.effect.name',
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import EffectAction from './effectAction.mjs';
|
|||
import HealingAction from './healingAction.mjs';
|
||||
import MacroAction from './macroAction.mjs';
|
||||
import SummonAction from './summonAction.mjs';
|
||||
import TransformAction from './transformAction.mjs';
|
||||
|
||||
export const actionsTypes = {
|
||||
base: BaseAction,
|
||||
|
|
@ -17,5 +18,6 @@ export const actionsTypes = {
|
|||
summon: SummonAction,
|
||||
effect: EffectAction,
|
||||
macro: MacroAction,
|
||||
beastform: BeastformAction
|
||||
beastform: BeastformAction,
|
||||
transform: TransformAction
|
||||
};
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
async executeWorkflow(config) {
|
||||
for (const [key, part] of this.workflow) {
|
||||
if (Hooks.call(`${CONFIG.DH.id}.pre${key.capitalize()}Action`, this, config) === false) return;
|
||||
if ((await part.execute(config)) === false) return;
|
||||
if ((await part.execute(config)) === false) return false;
|
||||
if (Hooks.call(`${CONFIG.DH.id}.post${key.capitalize()}Action`, this, config) === false) return;
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +224,9 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
}
|
||||
|
||||
// Execute the Action Worflow in order based of schema fields
|
||||
await this.executeWorkflow(config);
|
||||
const result = await this.executeWorkflow(config);
|
||||
if (result === false) return;
|
||||
|
||||
await config.resourceUpdates.updateResources();
|
||||
|
||||
if (Hooks.call(`${CONFIG.DH.id}.postUseAction`, this, config) === false) return;
|
||||
|
|
|
|||
5
module/data/action/transformAction.mjs
Normal file
5
module/data/action/transformAction.mjs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import DHBaseAction from './baseAction.mjs';
|
||||
|
||||
export default class DHTransformAction extends DHBaseAction {
|
||||
static extraSchemas = [...super.extraSchemas, 'transform'];
|
||||
}
|
||||
|
|
@ -10,3 +10,4 @@ export { default as DamageField } from './damageField.mjs';
|
|||
export { default as RollField } from './rollField.mjs';
|
||||
export { default as MacroField } from './macroField.mjs';
|
||||
export { default as SummonField } from './summonField.mjs';
|
||||
export { default as TransformField } from './transformField.mjs';
|
||||
|
|
|
|||
101
module/data/fields/action/transformField.mjs
Normal file
101
module/data/fields/action/transformField.mjs
Normal file
|
|
@ -0,0 +1,101 @@
|
|||
const fields = foundry.data.fields;
|
||||
|
||||
export default class DHSummonField extends fields.SchemaField {
|
||||
/**
|
||||
* Action Workflow order
|
||||
*/
|
||||
static order = 130;
|
||||
|
||||
constructor(options = {}, context = {}) {
|
||||
const transformFields = {
|
||||
actorUUID: new fields.DocumentUUIDField({
|
||||
type: 'Actor',
|
||||
required: true
|
||||
}),
|
||||
resourceRefresh: new fields.SchemaField({
|
||||
hitPoints: new fields.BooleanField({ initial: true }),
|
||||
stress: new fields.BooleanField({ initial: true })
|
||||
})
|
||||
};
|
||||
super(transformFields, options, context);
|
||||
}
|
||||
|
||||
static async execute() {
|
||||
if (!this.transform.actorUUID) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.noTransformActor'));
|
||||
return false;
|
||||
}
|
||||
|
||||
const baseActor = await foundry.utils.fromUuid(this.transform.actorUUID);
|
||||
if (!baseActor) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.transformActorMissing'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!canvas.scene) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.canvasError'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this.actor.prototypeToken.actorLink) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.actorLinkError'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!this.actor.token) {
|
||||
ui.notifications.warn(game.i18n.localize('DAGGERHEART.ACTIONS.TYPES.transform.prototypeError'));
|
||||
return false;
|
||||
}
|
||||
|
||||
const actor = await DHSummonField.getWorldActor(baseActor);
|
||||
const tokenSizes = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).tokenSizes;
|
||||
const tokenSize = actor?.system.metadata.usesSize ? tokenSizes[actor.system.size] : actor.prototypeToken.width;
|
||||
|
||||
await this.actor.token.update(
|
||||
{ ...actor.prototypeToken.toJSON(), actorId: actor.id, width: tokenSize, height: tokenSize },
|
||||
{ diff: false, recursive: false, noHook: true }
|
||||
);
|
||||
|
||||
if (this.actor.token.combatant) {
|
||||
this.actor.token.combatant.update({ actorId: actor.id, img: actor.prototypeToken.texture.src });
|
||||
}
|
||||
|
||||
const marks = { hitPoints: 0, stress: 0 };
|
||||
if (!this.transform.resourceRefresh.hitPoints) {
|
||||
marks.hitPoints = Math.min(
|
||||
this.actor.system.resources.hitPoints.value,
|
||||
this.actor.token.actor.system.resources.hitPoints.max - 1
|
||||
);
|
||||
}
|
||||
if (!this.transform.resourceRefresh.stress) {
|
||||
marks.stress = Math.min(
|
||||
this.actor.system.resources.stress.value,
|
||||
this.actor.token.actor.system.resources.stress.max - 1
|
||||
);
|
||||
}
|
||||
if (marks.hitPoints || marks.stress) {
|
||||
this.actor.token.actor.update({
|
||||
'system.resources': {
|
||||
hitPoints: { value: marks.hitPoints },
|
||||
stress: { value: marks.stress }
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
const prevPosition = { ...this.actor.sheet.position };
|
||||
this.actor.sheet.close();
|
||||
this.actor.token.actor.sheet.render({ force: true, position: prevPosition });
|
||||
}
|
||||
|
||||
/* Check for any available instances of the actor present in the world, or create a world actor based on compendium */
|
||||
static async getWorldActor(baseActor) {
|
||||
const dataType = game.system.api.data.actors[`Dh${baseActor.type.capitalize()}`];
|
||||
if (baseActor.inCompendium && dataType && baseActor.img === dataType.DEFAULT_ICON) {
|
||||
const worldActorCopy = game.actors.find(x => x.name === baseActor.name);
|
||||
if (worldActorCopy) return worldActorCopy;
|
||||
}
|
||||
|
||||
const worldActor = await game.system.api.documents.DhpActor.create(baseActor.toObject());
|
||||
return worldActor;
|
||||
}
|
||||
}
|
||||
|
|
@ -33,6 +33,7 @@ export const preloadHandlebarsTemplates = async function () {
|
|||
'systems/daggerheart/templates/actionTypes/beastform.hbs',
|
||||
'systems/daggerheart/templates/actionTypes/countdown.hbs',
|
||||
'systems/daggerheart/templates/actionTypes/summon.hbs',
|
||||
'systems/daggerheart/templates/actionTypes/transform.hbs',
|
||||
'systems/daggerheart/templates/settings/components/settings-item-line.hbs',
|
||||
'systems/daggerheart/templates/ui/tooltip/parts/tooltipChips.hbs',
|
||||
'systems/daggerheart/templates/ui/tooltip/parts/tooltipTags.hbs',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue