From b7b4722f7c8c8dc9702a35e9a646587252f4593c Mon Sep 17 00:00:00 2001 From: Dapoolp Date: Wed, 25 Jun 2025 02:45:20 +0200 Subject: [PATCH] Fix Adversary attack multiplier --- module/applications/config/Action.mjs | 18 +++++- module/applications/roll.mjs | 1 - module/applications/sheets/adversary.mjs | 1 - module/applications/sheets/character.mjs | 6 +- module/data/actor/adversary.mjs | 58 ++----------------- module/documents/actor.mjs | 3 +- module/ui/chatLog.mjs | 7 ++- templates/sheets/actors/adversary/main.hbs | 13 +---- .../sheets/global/partials/inventory-item.hbs | 4 +- templates/views/actionTypes/damage.hbs | 5 +- 10 files changed, 36 insertions(+), 80 deletions(-) diff --git a/module/applications/config/Action.mjs b/module/applications/config/Action.mjs index afd03e55..6551527d 100644 --- a/module/applications/config/Action.mjs +++ b/module/applications/config/Action.mjs @@ -38,6 +38,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { } }; + static CLEAN_ARRAYS = ["damage.parts", "cost", "effects"]; + _getTabs() { const tabs = { base: { active: true, cssClass: '', group: 'primary', id: 'base', icon: null, label: 'Base' }, @@ -64,7 +66,6 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { context.getRealIndex = this.getRealIndex.bind(this); context.disableOption = this.disableOption.bind(this); context.isNPC = this.action.actor.type !== 'character'; - return context; } @@ -88,6 +89,19 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { _prepareSubmitData(event, formData) { const submitData = foundry.utils.expandObject(formData.object); + for ( const keyPath of this.constructor.CLEAN_ARRAYS ) { + const data = foundry.utils.getProperty(submitData, keyPath); + if ( data ) foundry.utils.setProperty(submitData, keyPath, Object.values(data)); + /* const data = foundry.utils.getProperty(submitData, keyPath), + originalData = foundry.utils.getProperty(this.action.toObject(), keyPath); + if ( data ) { + const aData = Object.values(data); + originalData.forEach((v,i) => { + aData[i] = {...originalData[i], ...aData[i]}; + }) + foundry.utils.setProperty(submitData, keyPath, aData); + } */ + } // this.element.querySelectorAll("fieldset[disabled] :is(input, select)").forEach(input => { // foundry.utils.setProperty(submitData, input.name, input.value); // }); @@ -96,7 +110,7 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { static async updateForm(event, _, formData) { const submitData = this._prepareSubmitData(event, formData), - data = foundry.utils.expandObject(foundry.utils.mergeObject(this.action.toObject(), submitData)), + data = foundry.utils.mergeObject(this.action.toObject(), submitData), container = foundry.utils.getProperty(this.action.parent, this.action.systemPath); let newActions; if(Array.isArray(container)) { diff --git a/module/applications/roll.mjs b/module/applications/roll.mjs index dbe52961..30385205 100644 --- a/module/applications/roll.mjs +++ b/module/applications/roll.mjs @@ -71,7 +71,6 @@ export class DHRoll extends Roll { user: game.user.id, sound: config.mute ? null : CONFIG.sounds.dice, system: config, - // content: this.messageTemplate, content: await this.messageTemplate(config), rolls: [roll] }; diff --git a/module/applications/sheets/adversary.mjs b/module/applications/sheets/adversary.mjs index ee1f40a5..7243c5e0 100644 --- a/module/applications/sheets/adversary.mjs +++ b/module/applications/sheets/adversary.mjs @@ -55,7 +55,6 @@ export default class AdversarySheet extends DaggerheartSheet(ActorSheetV2) { context.tabs = super._getTabs(this.constructor.TABS); context.systemFields.attack.fields = this.document.system.attack.schema.fields; context.isNPC = true; - console.log(context) return context; } diff --git a/module/applications/sheets/character.mjs b/module/applications/sheets/character.mjs index 734c41ee..152004b7 100644 --- a/module/applications/sheets/character.mjs +++ b/module/applications/sheets/character.mjs @@ -32,7 +32,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { selectSubclass: this.selectSubclass, selectAncestry: this.selectAncestry, selectCommunity: this.selectCommunity, - viewObject: this.viewObject, + // viewObject: this.viewObject, useItem: this.useItem, useFeature: this.useFeature, takeShortRest: this.takeShortRest, @@ -537,7 +537,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { item.use(event); } - static async viewObject(_, button) { + /* static async viewObject(_, button) { const object = await fromUuid(button.dataset.value); if (!object) return; @@ -547,7 +547,7 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) { if (object.sheet.editMode) object.sheet.editMode = false; object.sheet.render(true); - } + } */ editItem(event) { const uuid = event.target.closest('[data-item-id]').dataset.itemId, diff --git a/module/data/actor/adversary.mjs b/module/data/actor/adversary.mjs index f1bd2684..ea00a0ca 100644 --- a/module/data/actor/adversary.mjs +++ b/module/data/actor/adversary.mjs @@ -1,6 +1,4 @@ -import DhpItem from '../../documents/item.mjs'; import ActionField from '../fields/actionField.mjs'; -import DHWeapon from '../item/weapon.mjs'; import BaseDataActor from './base.mjs'; const resourceField = () => @@ -42,39 +40,6 @@ export default class DhpAdversary extends BaseDataActor { hitPoints: resourceField(), stress: resourceField() }), - /* attack: new fields.SchemaField({ - name: new fields.StringField({}), - modifier: new fields.NumberField({ required: true, integer: true, initial: 0 }), - range: new fields.StringField({ - required: true, - choices: SYSTEM.GENERAL.range, - initial: SYSTEM.GENERAL.range.melee.id - }), - damage: new fields.SchemaField({ - value: new fields.StringField(), - type: new fields.StringField({ - required: true, - choices: SYSTEM.GENERAL.damageTypes, - initial: SYSTEM.GENERAL.damageTypes.physical.id - }) - }) - }), */ - /* attack: new fields.EmbeddedDocumentField(DhpItem, - { - // type: 'weapon' - // initial: new DhpItem( - // { - // name: 'Attack', - // type: 'weapon' - // }, - // { - // parent: this.parent, - // parentCollection: 'items' - // } - // ) - // initial: {type: 'weapon'} - } - ), */ attack: new ActionField({ initial: { name: 'Attack', @@ -91,7 +56,10 @@ export default class DhpAdversary extends BaseDataActor { }, damage: { parts: [{ - multiplier: 'flat' + multiplier: 'flat', + dice: 'd20', + bonus: 2, + flatMultiplier: 3 }] } } @@ -102,24 +70,6 @@ export default class DhpAdversary extends BaseDataActor { value: new fields.NumberField({ required: true, integer: true, initial: 1 }) }) ) - /* Features waiting on pseudo-document data model addition */ }; } - - prepareBaseData() { - // console.log(this.attack) - /* if(!this.attack) { - this.attack = new DhpItem( - { - name: 'Attack', - type: 'weapon', - _id: foundry.utils.randomID() - }, - { - parent: this.parent, - parentCollection: 'items' - } - ) - } */ - } } diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index 5ff0e456..0a7e467c 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -265,7 +265,8 @@ export default class DhpActor extends Actor { * @param {object} [config.costs] */ async diceRoll(config, action) { - config.source = {...(config.source ?? {}), actor: this._id}; + // config.source = {...(config.source ?? {}), actor: this._id}; + config.source = {...(config.source ?? {}), actor: this.uuid}; config.data = this.getRollData() const roll = await CONFIG.Dice.daggerheart[this.type === 'character' ? 'DualityRoll' : 'D20Roll'].build(config) return config; diff --git a/module/ui/chatLog.mjs b/module/ui/chatLog.mjs index 6c9a766f..822fb6ca 100644 --- a/module/ui/chatLog.mjs +++ b/module/ui/chatLog.mjs @@ -60,8 +60,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo super.close(options); } - getActor(id) { - return game.actors.get(id); + async getActor(id) { + // return game.actors.get(id); + return await fromUuid(id); } getAction(actor, itemId, actionId) { @@ -72,7 +73,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo onRollDamage = async (event, message) => { event.stopPropagation(); - const actor = this.getActor(message.system.source.actor); + const actor = await this.getActor(message.system.source.actor); if (!actor || !game.user.isGM) return true; if(message.system.source.item && message.system.source.action) { const action = this.getAction(actor, message.system.source.item, message.system.source.action); diff --git a/templates/sheets/actors/adversary/main.hbs b/templates/sheets/actors/adversary/main.hbs index 9f90228c..995befc8 100644 --- a/templates/sheets/actors/adversary/main.hbs +++ b/templates/sheets/actors/adversary/main.hbs @@ -63,7 +63,7 @@
-
Bonus
+
Bonus to Hit
{{formField systemFields.attack.fields.roll.fields.bonus value=source.system.attack.roll.bonus name="system.attack.roll.bonus"}} @@ -75,17 +75,6 @@
{{> 'systems/daggerheart/templates/views/actionTypes/effect.hbs'}}
- - - - {{!-- {{localize "DAGGERHEART.Sheets.Adversary.Attack"}} - - {{formGroup systemFields.attack.fields.name value=source.system.attack.name}} - - {{formGroup systemFields.attack.fields.modifier value=source.system.attack.modifier}} - {{formGroup systemFields.attack.fields.range value=source.system.attack.range localize=true}} - {{formGroup systemFields.attack.fields.damage.fields.value value=source.system.attack.damage.value}} - {{formGroup systemFields.attack.fields.damage.fields.type value=source.system.attack.damage.type localize=true}} --}}
diff --git a/templates/sheets/global/partials/inventory-item.hbs b/templates/sheets/global/partials/inventory-item.hbs index 093c804f..3fdff1e4 100644 --- a/templates/sheets/global/partials/inventory-item.hbs +++ b/templates/sheets/global/partials/inventory-item.hbs @@ -1,5 +1,5 @@ -
  • - +
  • +
    {{item.name}}
    {{#if (eq type 'weapon')}} diff --git a/templates/views/actionTypes/damage.hbs b/templates/views/actionTypes/damage.hbs index 633c7725..eee906a2 100644 --- a/templates/views/actionTypes/damage.hbs +++ b/templates/views/actionTypes/damage.hbs @@ -16,15 +16,18 @@ {{#each source.parts as |dmg index|}} {{#if @root.isNPC}} {{formField ../fields.custom.fields.enabled value=dmg.custom.enabled name=(concat ../path "damage.parts." index ".custom.enabled")}} + {{!-- {{formField ../fields.multiplier value=dmg.multiplier name=(concat ../path "damage.parts." index ".multiplier") localize=true}} --}} + {{#if dmg.custom.enabled}} {{formField ../fields.custom.fields.formula value=dmg.custom.formula name=(concat ../path "damage.parts." index ".custom.formula") localize=true}} {{else}}
    - {{formField ../fields.flatMultiplier value=dmg.flatMultiplier name=(concat "damage.parts." realIndex ".flatMultiplier") label="Multiplier" }} + {{formField ../fields.flatMultiplier value=dmg.flatMultiplier name=(concat ../path "damage.parts." index ".flatMultiplier") label="Multiplier" }} {{formField ../fields.dice value=dmg.dice name=(concat ../path "damage.parts." index ".dice")}} {{formField ../fields.bonus value=dmg.bonus name=(concat ../path "damage.parts." index ".bonus") localize=true}}
    {{/if}} + {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." index ".type") localize=true}} {{else}} {{#with (@root.getRealIndex index) as | realIndex |}}