From d34272a301a0f80153d2d14a7136db2ca3436d91 Mon Sep 17 00:00:00 2001 From: IrkTheImp <41175833+IrkTheImp@users.noreply.github.com> Date: Sat, 31 May 2025 03:53:47 -0500 Subject: [PATCH] finding and fixing bugs. (#88) --- module/applications/sheets/pc.mjs | 45 ++++++++++++++++++++------- module/data/abilityUse.mjs | 9 +++--- module/documents/actor.mjs | 19 +++++++++-- module/ui/chatLog.mjs | 5 +-- styles/chat.less | 5 +++ styles/daggerheart.css | 4 +++ templates/chat/ability-use.hbs | 1 + templates/sheets/parts/domainCard.hbs | 1 + 8 files changed, 69 insertions(+), 20 deletions(-) diff --git a/module/applications/sheets/pc.mjs b/module/applications/sheets/pc.mjs index 4a91b0e5..d6167085 100644 --- a/module/applications/sheets/pc.mjs +++ b/module/applications/sheets/pc.mjs @@ -37,9 +37,10 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { attackRoll: this.attackRoll, tabToLoadout: () => this.domainCardsTab(false), tabToVault: () => this.domainCardsTab(true), - sendToVault: (_, button) => this.moveDomainCard(button, true), - sentToLoadout: (_, button) => this.moveDomainCard(button, false), + sendToVault: this.moveDomainCard, + sendToLoadout: this.moveDomainCard, useDomainCard: this.useDomainCard, + removeCard: this.removeDomainCard, selectClass: this.selectClass, selectSubclass: this.selectSubclass, selectAncestry: this.selectAncestry, @@ -640,7 +641,8 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { this.render(); } - static async moveDomainCard(button, toVault) { + static async moveDomainCard(_, button) { + const toVault = button.dataset.action === 'sendToVault'; if (!toVault && this.document.system.domainCards.loadout.length >= this.document.system.domainData.maxLoadout) { return; } @@ -655,6 +657,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { const cls = getDocumentClass('ChatMessage'); const systemData = { title: `${game.i18n.localize('DAGGERHEART.Chat.DomainCard.Title')} - ${capitalize(button.dataset.domain)}`, + origin: this.document.id, img: card.img, name: card.name, description: card.system.effect, @@ -673,6 +676,13 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { cls.create(msg.toObject()); } + static async removeDomainCard(_, button) { + if (button.dataset.type === 'domainCard') { + const card = this.document.items.find(x => x.uuid === button.dataset.key); + await card.delete(); + } + } + static async selectClass() { (await game.packs.get('daggerheart.classes'))?.render(true); } @@ -872,6 +882,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { const cls = getDocumentClass('ChatMessage'); const systemData = { title: game.i18n.localize('DAGGERHEART.Chat.FeatureTitle'), + origin: this.document.id, img: item.img, name: item.name, description: item.system.description, @@ -902,6 +913,7 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { : type === 'community' ? game.i18n.localize('DAGGERHEART.Chat.FoundationCard.CommunityTitle') : game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'), + origin: this.document.id, img: item.img, name: item.name, description: item.system.description, @@ -929,14 +941,20 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { const title = `${item.name} - ${game.i18n.localize(`DAGGERHEART.Sheets.PC.DomainCard.${capitalize(button.dataset.key)}Title`)}`; const cls = getDocumentClass('ChatMessage'); + const systemData = { + title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'), + origin: this.document.id, + name: title, + img: item.img, + description: ability.description + }; 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', - { - title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'), - card: { name: title, img: item.img, description: ability.description } - } + systemData ) }); @@ -948,14 +966,19 @@ export default class PCSheet extends DaggerheartSheet(ActorSheetV2) { const item = this.document.items.find(x => x.uuid === button.dataset.id); const cls = getDocumentClass('ChatMessage'); + const systemData = { + title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'), + origin: this.document.id, + name: item.name, + img: item.img, + description: item.system.description + }; const msg = new cls({ user: game.user.id, + system: systemData, content: await foundry.applications.handlebars.renderTemplate( 'systems/daggerheart/templates/chat/ability-use.hbs', - { - title: game.i18n.localize('DAGGERHEART.Chat.FoundationCard.SubclassFeatureTitle'), - card: { name: item.name, img: item.img, description: item.system.description } - } + systemData ) }); diff --git a/module/data/abilityUse.mjs b/module/data/abilityUse.mjs index 5d95cd11..c95a9ff3 100644 --- a/module/data/abilityUse.mjs +++ b/module/data/abilityUse.mjs @@ -4,11 +4,12 @@ export default class DhpAbilityUse extends foundry.abstract.TypeDataModel { return { title: new fields.StringField({}), + origin: new fields.StringField({}), img: new fields.StringField({}), name: new fields.StringField({}), description: new fields.StringField({}), actions: new fields.ArrayField( - new fields.SchemaField({ + new fields.ObjectField({ name: new fields.StringField({}), damage: new fields.SchemaField({ type: new fields.StringField({}), @@ -19,11 +20,11 @@ export default class DhpAbilityUse extends foundry.abstract.TypeDataModel { value: new fields.StringField({}) }), cost: new fields.SchemaField({ - type: new fields.StringField({ nullable: true }), - value: new fields.NumberField({ nullable: true }) + type: new fields.StringField({}), + value: new fields.NumberField({}) }), target: new fields.SchemaField({ - type: new fields.StringField({}) + type: new fields.StringField({ nullable: true }) }) }) ) diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 60f83c60..60e051bb 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -307,10 +307,20 @@ export default class DhpActor extends Actor { let update = {}; switch (type) { case SYSTEM.GENERAL.healingTypes.health.id: - update = { 'system.resources.health.value': Math.max(this.system.resources.health.value - healing, 0) }; + update = { + 'system.resources.health.value': Math.min( + this.system.resources.health.value + healing, + this.system.resources.health.max + ) + }; break; case SYSTEM.GENERAL.healingTypes.stress.id: - update = { 'system.resources.stress.value': Math.max(this.system.resources.stress.value - healing, 0) }; + update = { + 'system.resources.stress.value': Math.min( + this.system.resources.stress.value + healing, + this.system.resources.stress.max + ) + }; break; } @@ -343,7 +353,10 @@ export default class DhpActor extends Actor { } if (action.cost.type != null && action.cost.value != null) { - if (this.system.resources[action.cost.type].value < action.cost.value - 1) { + if ( + this.system.resources[action.cost.type].value - action.cost.value <= + this.system.resources[action.cost.type].min + ) { ui.notifications.error(game.i18n.localize(`Insufficient ${action.cost.type} to use this ability`)); return; } diff --git a/module/ui/chatLog.mjs b/module/ui/chatLog.mjs index 183060b0..1b575aa8 100644 --- a/module/ui/chatLog.mjs +++ b/module/ui/chatLog.mjs @@ -36,7 +36,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo element.addEventListener('click', event => this.selectAdvantage.bind(this)(event, data.message)) ); html.querySelectorAll('.ability-use-button').forEach(element => - element.addEventListener('click', this.abilityUseButton.bind(this)(event, data.message)) + element.addEventListener('click', event => this.abilityUseButton.bind(this)(event, data.message)) ); }; @@ -134,6 +134,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo event.stopPropagation(); const action = message.system.actions[Number.parseInt(event.currentTarget.dataset.index)]; - await game.user.character.useAction(action); + const actor = game.actors.get(message.system.origin); + await actor.useAction(action); }; } diff --git a/styles/chat.less b/styles/chat.less index e6bb20c2..ea9c95ef 100644 --- a/styles/chat.less +++ b/styles/chat.less @@ -547,6 +547,11 @@ margin-top: @tinyMargin; } } + + .ability-card-action-cost { + margin: auto; + font-size: 1.5em; + } } img { diff --git a/styles/daggerheart.css b/styles/daggerheart.css index 529c979e..e890794f 100755 --- a/styles/daggerheart.css +++ b/styles/daggerheart.css @@ -1770,6 +1770,10 @@ .daggerheart.chat.domain-card .ability-card-footer button:nth-of-type(n + 3) { margin-top: 2px; } +.daggerheart.chat.domain-card .ability-card-footer .ability-card-action-cost { + margin: auto; + font-size: 1.5em; +} .daggerheart.chat.domain-card img { width: 80px; } diff --git a/templates/chat/ability-use.hbs b/templates/chat/ability-use.hbs index c719d02f..51d56ace 100644 --- a/templates/chat/ability-use.hbs +++ b/templates/chat/ability-use.hbs @@ -10,6 +10,7 @@ + {{#if action.cost.value}}
{{action.cost.value}} {{action.cost.type}}
{{/if}} {{/each}} \ No newline at end of file diff --git a/templates/sheets/parts/domainCard.hbs b/templates/sheets/parts/domainCard.hbs index 8acf7008..7d092855 100644 --- a/templates/sheets/parts/domainCard.hbs +++ b/templates/sheets/parts/domainCard.hbs @@ -16,6 +16,7 @@
+
{{card.name}}
{{#if inVault}}
{{{card.system.effect}}}