mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-11 19:25:21 +01:00
[Fix] Downtime Actions (#1295)
* Fixed so downtime actiosn can be used again * Update module/data/fields/action/targetField.mjs Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com> * . --------- Co-authored-by: Carlos Fernandez <CarlosFdez@users.noreply.github.com>
This commit is contained in:
parent
fe8e98ef35
commit
b9d67e44da
13 changed files with 86 additions and 32 deletions
|
|
@ -1,6 +1,7 @@
|
|||
import DhpActor from '../../documents/actor.mjs';
|
||||
import D20RollDialog from '../../applications/dialogs/d20RollDialog.mjs';
|
||||
import { ActionMixin } from '../fields/actionField.mjs';
|
||||
import { originItemField } from '../chat-message/actorRoll.mjs';
|
||||
|
||||
const fields = foundry.data.fields;
|
||||
|
||||
|
|
@ -25,6 +26,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
description: new fields.HTMLField(),
|
||||
img: new fields.FilePathField({ initial: undefined, categories: ['IMAGE'], base64: false }),
|
||||
chatDisplay: new fields.BooleanField({ initial: true, label: 'DAGGERHEART.ACTIONS.Config.displayInChat' }),
|
||||
originItem: originItemField(),
|
||||
actionType: new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.actionTypes,
|
||||
initial: 'action',
|
||||
|
|
@ -215,6 +217,7 @@ export default class DHBaseAction extends ActionMixin(foundry.abstract.DataModel
|
|||
title: `${this.item instanceof CONFIG.Actor.documentClass ? '' : `${this.item.name}: `}${game.i18n.localize(this.name)}`,
|
||||
source: {
|
||||
item: this.item._id,
|
||||
originItem: this.originItem,
|
||||
action: this._id,
|
||||
actor: this.actor.uuid
|
||||
},
|
||||
|
|
|
|||
|
|
@ -17,6 +17,16 @@ const targetsField = () =>
|
|||
})
|
||||
);
|
||||
|
||||
export const originItemField = () =>
|
||||
new fields.SchemaField({
|
||||
type: new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.originItemType,
|
||||
initial: CONFIG.DH.ITEM.originItemType.itemCollection
|
||||
}),
|
||||
itemPath: new fields.StringField(),
|
||||
actionIndex: new fields.StringField()
|
||||
});
|
||||
|
||||
export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
||||
static defineSchema() {
|
||||
return {
|
||||
|
|
@ -35,6 +45,7 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
source: new fields.SchemaField({
|
||||
actor: new fields.StringField(),
|
||||
item: new fields.StringField(),
|
||||
originItem: originItemField(),
|
||||
action: new fields.StringField()
|
||||
}),
|
||||
damage: new fields.ObjectField(),
|
||||
|
|
@ -51,14 +62,23 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
get actionItem() {
|
||||
const actionActor = this.actionActor;
|
||||
if (!actionActor || !this.source.item) return null;
|
||||
return actionActor.items.get(this.source.item);
|
||||
|
||||
switch (this.source.originItem.type) {
|
||||
case CONFIG.DH.ITEM.originItemType.restMove:
|
||||
const restMoves = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).restMoves;
|
||||
return Array.from(foundry.utils.getProperty(restMoves, `${this.source.originItem.itemPath}`).actions)[
|
||||
this.source.originItem.actionIndex
|
||||
];
|
||||
default:
|
||||
const item = actionActor.items.get(this.source.item);
|
||||
return item ? item.system.actionsList?.find(a => a.id === this.source.action) : null;
|
||||
}
|
||||
}
|
||||
|
||||
get action() {
|
||||
const actionActor = this.actionActor,
|
||||
actionItem = this.actionItem;
|
||||
const { actionActor, actionItem: itemAction } = this;
|
||||
if (!this.source.action) return null;
|
||||
if (actionItem) return actionItem.system.actionsList?.find(a => a.id === this.source.action);
|
||||
if (itemAction) return itemAction;
|
||||
else if (actionActor?.system.attack?._id === this.source.action) return actionActor.system.attack;
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -98,7 +98,9 @@ export default class DamageField extends fields.SchemaField {
|
|||
});
|
||||
}
|
||||
|
||||
const token = game.scenes.find(x => x.active).tokens.find(x => x.id === target.id);
|
||||
const token = target.id
|
||||
? game.scenes.find(x => x.active).tokens.find(x => x.id === target.id)
|
||||
: actor.prototypeToken;
|
||||
if (config.hasHealing)
|
||||
damagePromises.push(
|
||||
actor.takeHealing(config.damage).then(updates => targetDamage.push({ token, updates }))
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export default class TargetField extends fields.SchemaField {
|
|||
if (!this.target?.type) return (config.targets = []);
|
||||
config.hasTarget = true;
|
||||
let targets;
|
||||
// If the Action is configured as self-targeted, set targets as the owner.
|
||||
// If the Action is configured as self-targeted, set targets as the owner. Probably better way than to fallback to getDependentTokens
|
||||
if (this.target?.type === CONFIG.DH.GENERAL.targetTypes.self.id)
|
||||
targets = [this.actor.token ?? this.actor.prototypeToken];
|
||||
else {
|
||||
|
|
@ -72,17 +72,17 @@ export default class TargetField extends fields.SchemaField {
|
|||
|
||||
/**
|
||||
* Format actor to useful datas for Action roll workflow.
|
||||
* @param {*} actor Actor object to format.
|
||||
* @param {*} token Token object to format.
|
||||
* @returns {*} Formatted Actor.
|
||||
*/
|
||||
static formatTarget(actor) {
|
||||
static formatTarget(token) {
|
||||
return {
|
||||
id: actor.id,
|
||||
actorId: actor.actor.uuid,
|
||||
name: actor.actor.name,
|
||||
img: actor.actor.img,
|
||||
difficulty: actor.actor.system.difficulty,
|
||||
evasion: actor.actor.system.evasion,
|
||||
id: token.id,
|
||||
actorId: token.actor.uuid,
|
||||
name: token.actor.name,
|
||||
img: token.actor.img,
|
||||
difficulty: token.actor.system.difficulty,
|
||||
evasion: token.actor.system.evasion,
|
||||
saved: {
|
||||
value: null,
|
||||
success: null
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue