mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-07 22:46:12 +01:00
change behaviour to be entirely based on parent actor and item
This commit is contained in:
parent
fb4af90b07
commit
abda31bdfa
2 changed files with 25 additions and 38 deletions
|
|
@ -1332,6 +1332,8 @@
|
||||||
"noAssignedPlayerCharacter": "You have no assigned character.",
|
"noAssignedPlayerCharacter": "You have no assigned character.",
|
||||||
"noSelectedToken": "You have no selected token",
|
"noSelectedToken": "You have no selected token",
|
||||||
"noSourceItem": "No source item found in chat message",
|
"noSourceItem": "No source item found in chat message",
|
||||||
|
"noSourceActor": "No source actor found in chat message",
|
||||||
|
"sourceActorNotFound": "Source actor not found",
|
||||||
"sourceItemNotFound": "Source item not found",
|
"sourceItemNotFound": "Source item not found",
|
||||||
"actionNotFound": "Action '{id}' not found on source item",
|
"actionNotFound": "Action '{id}' not found on source item",
|
||||||
"actionUseFailed": "Failed to use action '{action}': {error}",
|
"actionUseFailed": "Failed to use action '{action}': {error}",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import { getCommandTarget } from '../../helpers/utils.mjs';
|
|
||||||
|
|
||||||
export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog {
|
export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLog {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
|
|
@ -286,19 +284,24 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
// Get the action data from the chat message
|
// Get the action data from the chat message
|
||||||
const actionData = message.system.actions[Number.parseInt(event.currentTarget.dataset.index)];
|
const actionData = message.system.actions[Number.parseInt(event.currentTarget.dataset.index)];
|
||||||
|
|
||||||
// Get the currently selected actor (from selected token)
|
|
||||||
const actor = getCommandTarget();
|
|
||||||
|
|
||||||
if (!actor) {
|
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSelectedToken'));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Get the source item from the chat message
|
// Get the source actor and item from the chat message
|
||||||
|
const sourceActorUuid = message.system.source?.actor;
|
||||||
const sourceItemUuid = message.system.source?.item;
|
const sourceItemUuid = message.system.source?.item;
|
||||||
|
|
||||||
|
if (!sourceActorUuid) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.sourceActorNotFound'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!sourceItemUuid) {
|
if (!sourceItemUuid) {
|
||||||
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.noSourceItem'));
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.sourceItemNotFound'));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sourceActor = await foundry.utils.fromUuid(sourceActorUuid);
|
||||||
|
if (!sourceActor) {
|
||||||
|
ui.notifications.error(game.i18n.localize('DAGGERHEART.UI.Notifications.sourceActorNotFound'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,34 +311,16 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a temporary copy of the item with a unique name
|
// Find the action on the source item
|
||||||
const tempItemData = sourceItem.toObject();
|
const action = sourceItem.system.actions?.find(a => a._id === actionData._id);
|
||||||
tempItemData._id = foundry.utils.randomID(); // Give it a new ID
|
if (!action) {
|
||||||
const originalName = tempItemData.name;
|
ui.notifications.error(game.i18n.format('DAGGERHEART.UI.Notifications.actionNotFound', { id: actionData._id }));
|
||||||
tempItemData.name = `${tempItemData.name} (${foundry.utils.randomID()})`;
|
return;
|
||||||
|
|
||||||
// Create the temporary item on the selected actor
|
|
||||||
const [tempItem] = await actor.createEmbeddedDocuments('Item', [tempItemData]);
|
|
||||||
|
|
||||||
// Immediately rename it back to the original name for display purposes
|
|
||||||
await tempItem.update({ name: originalName });
|
|
||||||
|
|
||||||
try {
|
|
||||||
// Find the action on the temporary item
|
|
||||||
const action = tempItem.system.actions?.find(a => a._id === actionData._id);
|
|
||||||
if (!action) {
|
|
||||||
ui.notifications.error(game.i18n.format('DAGGERHEART.UI.Notifications.actionNotFound', { id: actionData._id }));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the action
|
|
||||||
await action.use(event);
|
|
||||||
|
|
||||||
} finally {
|
|
||||||
// Clean up: delete the temporary item
|
|
||||||
await actor.deleteEmbeddedDocuments('Item', [tempItem.id]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Use the action directly from the original item
|
||||||
|
await action.use(event);
|
||||||
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error('Error using action from chat:', e);
|
console.error('Error using action from chat:', e);
|
||||||
ui.notifications.error(game.i18n.format('DAGGERHEART.UI.Notifications.actionUseFailed', {
|
ui.notifications.error(game.i18n.format('DAGGERHEART.UI.Notifications.actionUseFailed', {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue