diff --git a/module/applications/dialogs/d20RollDialog.mjs b/module/applications/dialogs/d20RollDialog.mjs index 7eaeacb3..db15a7a3 100644 --- a/module/applications/dialogs/d20RollDialog.mjs +++ b/module/applications/dialogs/d20RollDialog.mjs @@ -63,18 +63,6 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio const context = await super._prepareContext(_options); context.rollConfig = this.config; context.hasRoll = !!this.config.roll; - context.roll = this.roll; - context.rollType = this.roll?.constructor.name; - context.experiences = Object.keys(this.config.data.experiences).map(id => ({ - id, - ...this.config.data.experiences[id] - })); - context.selectedExperiences = this.config.experiences; - context.advantage = this.config.roll?.advantage; - context.disadvantage = this.config.roll?.disadvantage; - context.diceOptions = CONFIG.DH.GENERAL.diceTypes; - context.canRoll = true; - context.isLite = this.config.roll?.lite; if (this.config.costs?.length) { const updatedCosts = this.action.calcCosts(this.config.costs); context.costs = updatedCosts; @@ -85,8 +73,22 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio context.uses = this.action.calcUses(this.config.uses); context.canRoll = context.canRoll && this.action.hasUses(context.uses); } - context.extraFormula = this.config.extraFormula; - context.formula = this.roll.constructFormula(this.config); + if(this.roll) { + context.roll = this.roll; + context.rollType = this.roll?.constructor.name; + context.experiences = Object.keys(this.config.data.experiences).map(id => ({ + id, + ...this.config.data.experiences[id] + })); + context.selectedExperiences = this.config.experiences; + context.advantage = this.config.roll?.advantage; + context.disadvantage = this.config.roll?.disadvantage; + context.diceOptions = CONFIG.DH.GENERAL.diceTypes; + context.canRoll = true; + context.isLite = this.config.roll?.lite; + context.extraFormula = this.config.extraFormula; + context.formula = this.roll.constructFormula(this.config); + } return context; } diff --git a/module/applications/ui/chatLog.mjs b/module/applications/ui/chatLog.mjs index 8b09a643..c6d5b57d 100644 --- a/module/applications/ui/chatLog.mjs +++ b/module/applications/ui/chatLog.mjs @@ -158,7 +158,7 @@ export default class DhpChatLog extends foundry.applications.sidebar.tabs.ChatLo const targetSelection = event.target .closest('.message-content') .querySelector('.button-target-selection.target-selected'), - isHit = Boolean(targetSelection.dataset.targetHit); + isHit = Boolean(targetSelection?.dataset?.targetHit) ?? false; return { isHit, targets: isHit diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index ef0921fa..2f674cec 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -123,6 +123,8 @@ export default class DHBaseAction extends foundry.abstract.DataModel { return extraSchemas; } + prepareData() {} + get index() { return foundry.utils.getProperty(this.parent, this.systemPath).indexOf(this); } @@ -229,7 +231,7 @@ export default class DHBaseAction extends foundry.abstract.DataModel { // Display configuration window if necessary // if (config.dialog?.configure && this.requireConfigurationDialog(config)) { if (this.requireConfigurationDialog(config)) { - config = await D20RollDialog.configure(config); + config = await D20RollDialog.configure(null, config); if (!config) return; } @@ -288,11 +290,12 @@ export default class DHBaseAction extends foundry.abstract.DataModel { } prepareTarget() { + if(!this.target?.type) return []; let targets; if (this.target?.type === CONFIG.DH.ACTIONS.targetTypes.self.id) targets = this.constructor.formatTarget(this.actor.token ?? this.actor.prototypeToken); targets = Array.from(game.user.targets); - if (this.target?.type && this.target.type !== CONFIG.DH.ACTIONS.targetTypes.any.id) { + if (this.target.type !== CONFIG.DH.ACTIONS.targetTypes.any.id) { targets = targets.filter(t => this.isTargetFriendly(t)); if (this.target.amount && targets.length > this.target.amount) targets = []; } diff --git a/module/data/action/effectAction.mjs b/module/data/action/effectAction.mjs index e2586c6d..65425a6f 100644 --- a/module/data/action/effectAction.mjs +++ b/module/data/action/effectAction.mjs @@ -3,38 +3,16 @@ import DHBaseAction from './baseAction.mjs'; export default class DHEffectAction extends DHBaseAction { static extraSchemas = ['effects', 'target']; - /* async use(event, ...args) { - const config = await super.use(event, args); - if (['error', 'warning'].includes(config.type)) return; - return await this.chatApplyEffects(event, config); - } */ - async trigger(event, data) { - const cls = getDocumentClass('ChatMessage'), - systemData = { - title: game.i18n.format('DAGGERHEART.Chat.ApplyEffect.Title', { name: this.name }), - origin: this.actor._id, - description: '', - targets: data.targets.map(x => ({ id: x.id, name: x.name, img: x.img, hit: true })), - action: { - itemId: this.item._id, - actionId: this._id - } - }, - msg = new cls({ - type: 'applyEffect', - user: game.user.id, - system: systemData, - content: await foundry.applications.handlebars.renderTemplate( - 'systems/daggerheart/templates/ui/chat/apply-effects.hbs', - systemData - ) - }); + if(this.effects.length) { + const cls = getDocumentClass('ChatMessage'), + msg = { + type: 'applyEffect', + user: game.user.id, + system: data + }; - cls.create(msg.toObject()); - } - - get chatTemplate() { - return 'systems/daggerheart/templates/ui/chat/apply-effects.hbs'; + return await cls.create(msg); + } else this.toChat(this.id); } } diff --git a/module/data/chat-message/applyEffects.mjs b/module/data/chat-message/applyEffects.mjs index 838dabfb..a7fdda69 100644 --- a/module/data/chat-message/applyEffects.mjs +++ b/module/data/chat-message/applyEffects.mjs @@ -1,11 +1,11 @@ +import DHBaseAction from "../action/baseAction.mjs"; + export default class DHApplyEffect extends foundry.abstract.TypeDataModel { static defineSchema() { const fields = foundry.data.fields; return { title: new fields.StringField(), - origin: new fields.StringField({}), - description: new fields.StringField({}), targets: new fields.ArrayField( new fields.SchemaField({ id: new fields.StringField({ required: true }), @@ -14,10 +14,24 @@ export default class DHApplyEffect extends foundry.abstract.TypeDataModel { hit: new fields.BooleanField({ initial: false }) }) ), - action: new fields.SchemaField({ - itemId: new fields.StringField(), - actionId: new fields.StringField() + targetSelection: new fields.BooleanField({ initial: true }), + source: new fields.SchemaField({ + actor: new fields.StringField(), + item: new fields.StringField(), + action: new fields.StringField() }) }; } + + prepareDerivedData() { + this.hasHitTarget = this.targets.filter(t => t.hit === true).length > 0; + this.currentTargets = + this.targetSelection !== true + ? Array.from(game.user.targets).map(t => DHBaseAction.formatTarget(t)) + : this.targets; + } + + get messageTemplate() { + return 'systems/daggerheart/templates/ui/chat/apply-effects.hbs'; + } } diff --git a/module/data/settings/Automation.mjs b/module/data/settings/Automation.mjs index bf2aed4b..89f8f134 100644 --- a/module/data/settings/Automation.mjs +++ b/module/data/settings/Automation.mjs @@ -4,9 +4,9 @@ export default class DhAutomation extends foundry.abstract.DataModel { static defineSchema() { const fields = foundry.data.fields; return { - hope: new fields.BooleanField({ required: true, initial: false }), - actionPoints: new fields.BooleanField({ required: true, initial: false }), - countdowns: new fields.BooleanField({ requireD: true, initial: false }) + hope: new fields.BooleanField({ required: true, initial: false, label: "DAGGERHEART.Settings.Automation.FIELDS.hope.label" }), // Label need to be updated into something like "Duality Roll Auto Gain" + a hint + actionPoints: new fields.BooleanField({ required: true, initial: false, label: "DAGGERHEART.Settings.Automation.FIELDS.actionPoints.label" }), + countdowns: new fields.BooleanField({ requireD: true, initial: false, label: "DAGGERHEART.Settings.Automation.FIELDS.countdowns.label" }) }; } } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 4c035252..83b2b3eb 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -138,10 +138,10 @@ export default class DHRoll extends Roll { export const registerRollDiceHooks = () => { Hooks.on(`${CONFIG.DH.id}.postRollDuality`, async(config, message) => { - if(config.roll.type !== 'action') return; + if(!game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).hope || config.roll.type !== 'action' || (!config.roll.hasOwnProperty('success') && !config.targets.length)) return; const actor = await fromUuid(config.source.actor), - rollResult = config.roll.result || config.targets.some(t => t.hit), + rollResult = config.roll.success || config.targets.some(t => t.hit), updates = []; let looseSpotlight = false; if(!actor) return; diff --git a/templates/dialogs/dice-roll/rollSelection.hbs b/templates/dialogs/dice-roll/rollSelection.hbs index fb0b2074..38b1a1d3 100644 --- a/templates/dialogs/dice-roll/rollSelection.hbs +++ b/templates/dialogs/dice-roll/rollSelection.hbs @@ -1,6 +1,6 @@
- {{#if @root.hasRoll}}
+ {{#if @root.hasRoll}} {{#unless @root.isLite}}
{{#if (eq @root.rollType 'D20Roll')}} @@ -121,6 +121,10 @@ Roll -
+ {{else}} + {{/if}} +
\ No newline at end of file diff --git a/templates/settings/automation-settings.hbs b/templates/settings/automation-settings.hbs index 8db980c7..7a637d08 100644 --- a/templates/settings/automation-settings.hbs +++ b/templates/settings/automation-settings.hbs @@ -1,22 +1,7 @@
-
- -
- {{formInput settingFields.schema.fields.hope value=settingFields._source.hope }} -
-
-
- -
- {{formInput settingFields.schema.fields.actionPoints value=settingFields._source.actionPoints }} -
-
-
- -
- {{formInput settingFields.schema.fields.countdowns value=settingFields._source.countdowns }} -
-
+ {{formGroup settingFields.schema.fields.hope value=settingFields._source.hope localize=true}} + {{formGroup settingFields.schema.fields.actionPoints value=settingFields._source.actionPoints localize=true}} + {{formGroup settingFields.schema.fields.countdowns value=settingFields._source.countdowns localize=true}}