diff --git a/module/applications/roll.mjs b/module/applications/roll.mjs index 486780d5..de997321 100644 --- a/module/applications/roll.mjs +++ b/module/applications/roll.mjs @@ -412,8 +412,8 @@ export class DamageRoll extends DHRoll { static async postEvaluate(roll, config = {}) { config.roll = { result: roll.total, - dice: roll.dice + dice: roll.dice, + type: config.type }; - if (roll.healing) config.roll.type = roll.healing.type; } } diff --git a/module/config/generalConfig.mjs b/module/config/generalConfig.mjs index bfea6cc2..a3ba21db 100644 --- a/module/config/generalConfig.mjs +++ b/module/config/generalConfig.mjs @@ -68,8 +68,8 @@ export const damageTypes = { }; export const healingTypes = { - health: { - id: 'health', + hitPoints: { + id: 'hitPoints', label: 'DAGGERHEART.HealingType.HitPoints.Name', abbreviation: 'DAGGERHEART.HealingType.HitPoints.Abbreviation' }, diff --git a/module/data/action/action.mjs b/module/data/action/action.mjs index 1d0e9fb3..f7e06fc1 100644 --- a/module/data/action/action.mjs +++ b/module/data/action/action.mjs @@ -126,7 +126,7 @@ export class DHBaseAction extends foundry.abstract.DataModel { choices: SYSTEM.GENERAL.healingTypes, required: true, blank: false, - initial: SYSTEM.GENERAL.healingTypes.health.id, + initial: SYSTEM.GENERAL.healingTypes.hitPoints.id, label: 'Healing' }), value: new fields.EmbeddedDataField(DHActionDiceData) @@ -516,7 +516,8 @@ export class DHHealingAction extends DHBaseAction { img: x.img, hit: true })), - messageTemplate: 'systems/daggerheart/templates/chat/healing-roll.hbs' + messageTemplate: 'systems/daggerheart/templates/chat/healing-roll.hbs', + type: this.healing.type }; roll = CONFIG.Dice.daggerheart.DamageRoll.build(config); diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index 492fcfe1..219b43aa 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -1,3 +1,5 @@ +import { actionsTypes } from '../action/_module.mjs'; + /** * Describes metadata about the item data model type * @typedef {Object} ItemDataModelMetadata @@ -50,4 +52,24 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { const data = { ...actorRollData, item: { ...this } }; return data; } + + async _preCreate(data, options, user) { + if(!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return; + const actionType = { + weapon: 'attack' + }[this.constructor.metadata.type], + cls = actionsTypes.attack, + action = new cls( + { + _id: foundry.utils.randomID(), + type: actionType, + name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name), + ...cls.getSourceConfig(this.parent) + }, + { + parent: this.parent + } + ); + this.updateSource({actions: [action]}); + } } diff --git a/module/data/item/weapon.mjs b/module/data/item/weapon.mjs index fefe096a..e7551a21 100644 --- a/module/data/item/weapon.mjs +++ b/module/data/item/weapon.mjs @@ -14,7 +14,8 @@ export default class DHWeapon extends BaseDataItem { isQuantifiable: true, embedded: { feature: 'featureTest' - } + }, + hasInitialAction: true }); } @@ -51,24 +52,6 @@ export default class DHWeapon extends BaseDataItem { }; } - async _preCreate(data, options, user) { - const actionType = 'attack', - cls = actionsTypes.attack, - action = new cls( - { - _id: foundry.utils.randomID(), - type: actionType, - name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name), - ...cls.getSourceConfig(this.parent) - }, - { - parent: this.parent - } - ); - this.updateSource({actions: [action]}); - return super._preCreate(data, options, user); - } - async _preUpdate(changes, options, user) { const allowed = await super._preUpdate(changes, options, user); if (allowed === false) return false; diff --git a/module/documents/actor.mjs b/module/documents/actor.mjs index a2136403..90ff49d5 100644 --- a/module/documents/actor.mjs +++ b/module/documents/actor.mjs @@ -401,22 +401,27 @@ export default class DhpActor extends Actor { } } + async takeHealing(resources) { + resources.forEach(r => r.value *= -1); + await this.modifyResource(resources); + } + async modifyResource(resources) { if (!resources.length) return; let updates = { actor: { target: this, resources: {} }, armor: { target: this.system.armor, resources: {} } }; resources.forEach(r => { switch (r.type) { case 'armorStack': - updates.armor.resources['system.marks.value'] = Math.min( + updates.armor.resources['system.marks.value'] = Math.max(Math.min( this.system.armor.system.marks.value + r.value, this.system.armorScore - ); + ), 0); break; default: - updates.actor.resources[`system.resources.${r.type}.value`] = Math.min( + updates.actor.resources[`system.resources.${r.type}.value`] = Math.max(Math.min( this.system.resources[r.type].value + r.value, this.system.resources[r.type].max - ); + ), 0); break; } }); diff --git a/module/ui/chatLog.mjs b/module/ui/chatLog.mjs index 93366402..584a50ce 100644 --- a/module/ui/chatLog.mjs +++ b/module/ui/chatLog.mjs @@ -33,7 +33,9 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo html.querySelectorAll('.damage-button').forEach(element => element.addEventListener('click', event => this.onDamage(event, data.message)) ); - html.querySelectorAll('.healing-button').forEach(element => element.addEventListener('click', this.onHealing)); + html.querySelectorAll('.healing-button').forEach(element => + element.addEventListener('click', event => this.onHealing(event, data.message)) + ); html.querySelectorAll('.target-indicator').forEach(element => element.addEventListener('click', this.onToggleTargets) ); @@ -87,7 +89,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo onRollHealing = 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); @@ -98,7 +100,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo onApplyEffect = 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); @@ -137,22 +139,20 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo if (targets.length === 0) ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected')); - for (var target of targets) { - await target.actor.takeDamage(message.system.damage.total, message.system.damage.type); + await target.actor.takeDamage(message.system.roll.result, message.system.roll.type); } }; - onHealing = async event => { + onHealing = async (event, message) => { event.stopPropagation(); - const healing = Number.parseInt(event.currentTarget.dataset.value); const targets = Array.from(game.user.targets); if (targets.length === 0) ui.notifications.info(game.i18n.localize('DAGGERHEART.Notification.Info.NoTargetsSelected')); - + for (var target of targets) { - await target.actor.modifyResource([{ value: healing, type: event.currentTarget.dataset.type }]); + await target.actor.takeHealing([{ value: message.system.roll.result, type: message.system.roll.type }]); } }; diff --git a/templates/chat/healing-roll.hbs b/templates/chat/healing-roll.hbs index d2b6b1e4..7a089459 100644 --- a/templates/chat/healing-roll.hbs +++ b/templates/chat/healing-roll.hbs @@ -24,7 +24,7 @@
{{roll.result}}
- +
\ No newline at end of file