Fixed so downtime actiosn can be used again

This commit is contained in:
WBHarry 2025-11-16 13:08:44 +01:00
parent 481ce46edf
commit 6ee02bb37b
7 changed files with 66 additions and 21 deletions

View file

@ -178,10 +178,17 @@ export default class DhpDowntime extends HandlebarsApplicationMixin(ApplicationV
}
static async takeDowntime() {
const moves = Object.values(this.moveData).flatMap(category => {
return Object.values(category.moves)
.filter(x => x.selected)
.flatMap(move => [...Array(move.selected).keys()].map(_ => move));
const moves = Object.keys(this.moveData).flatMap(categoryKey => {
const category = this.moveData[categoryKey];
return Object.keys(category.moves)
.filter(x => category.moves[x].selected)
.flatMap(key => {
const move = category.moves[key];
return [...Array(move.selected).keys()].map(_ => ({
...move,
movePath: `${categoryKey}.moves.${key}`
}));
});
});
const cls = getDocumentClass('ChatMessage');

View file

@ -132,12 +132,21 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
}
async actionUseButton(event, message) {
const { moveIndex, actionIndex } = event.currentTarget.dataset;
const { moveIndex, actionIndex, movePath } = event.currentTarget.dataset;
const parent = await foundry.utils.fromUuid(message.system.actor);
const actionType = message.system.moves[moveIndex].actions[actionIndex];
const cls = game.system.api.models.actions.actionsTypes[actionType.type];
const action = new cls(
{ ...actionType, _id: foundry.utils.randomID(), name: game.i18n.localize(actionType.name) },
{
...actionType,
_id: foundry.utils.randomID(),
name: game.i18n.localize(actionType.name),
itemSource: {
type: CONFIG.DH.ITEM.itemSourceType.restMove,
itemPath: movePath,
actionIndex: actionIndex
}
},
{ parent: parent.system }
);

View file

@ -1547,3 +1547,8 @@ export const beastformTypes = {
label: 'DAGGERHEART.CONFIG.BeastformType.hybrid'
}
};
export const itemSourceType = {
itemCollection: 'itemCollection',
restMove: 'restMove'
};

View file

@ -1,6 +1,7 @@
import DhpActor from '../../documents/actor.mjs';
import D20RollDialog from '../../applications/dialogs/d20RollDialog.mjs';
import { ActionMixin } from '../fields/actionField.mjs';
import { itemSourceField } 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' }),
itemSource: itemSourceField(),
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,
itemSource: this.itemSource,
action: this._id,
actor: this.actor.uuid
},

View file

@ -17,6 +17,16 @@ const targetsField = () =>
})
);
export const itemSourceField = () =>
new fields.SchemaField({
type: new fields.StringField({
choices: CONFIG.DH.ITEM.itemSourceType,
initial: CONFIG.DH.ITEM.itemSourceType.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(),
itemSource: itemSourceField(),
action: new fields.StringField()
}),
damage: new fields.ObjectField(),
@ -48,17 +59,27 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
return fromUuidSync(this.source.actor);
}
get actionItem() {
get itemAction() {
const actionActor = this.actionActor;
if (!actionActor || !this.source.item) return null;
return actionActor.items.get(this.source.item);
switch (this.source.itemSource.type) {
case CONFIG.DH.ITEM.itemSourceType.restMove:
const restMoves = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).restMoves;
return Array.from(foundry.utils.getProperty(restMoves, `${this.source.itemSource.itemPath}`).actions)[
this.source.itemSource.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;
itemAction = this.itemAction;
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;
}

View file

@ -24,9 +24,9 @@ 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];
targets = [this.actor.token ?? this.actor.getDependentTokens()[0]];
else {
targets = Array.from(game.user.targets);
if (this.target.type !== CONFIG.DH.GENERAL.targetTypes.any.id) {
@ -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 Actor 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

View file

@ -15,7 +15,7 @@
</div>
</details>
{{#each move.actions as | action index |}}
<button class="action-use-button" data-move-index="{{@../key}}" data-action-index="{{index}}">
<button class="action-use-button" data-move-index="{{@../key}}" data-action-index="{{index}}" data-move-path="{{../movePath}}" >
<span>{{localize action.name}}</span>
</button>
{{/each}}