diff --git a/lang/en.json b/lang/en.json index 94599465..3dbe1db1 100755 --- a/lang/en.json +++ b/lang/en.json @@ -1519,6 +1519,11 @@ "Macro": { "Name": "Macro" } + }, + "Settings": { + "ResultBased": { + "label": "Formula based on Hope/Fear result." + } } }, "RollTypes": { diff --git a/module/applications/config/Action.mjs b/module/applications/config/Action.mjs index d178996a..a27dc67d 100644 --- a/module/applications/config/Action.mjs +++ b/module/applications/config/Action.mjs @@ -67,6 +67,8 @@ export default class DHActionConfig extends DaggerheartSheet(ApplicationV2) { context.getRealIndex = this.getRealIndex.bind(this); context.disableOption = this.disableOption.bind(this); context.isNPC = this.action.actor && this.action.actor.type !== 'character'; + context.hasRoll = this.action.hasRoll(); + console.log(context) return context; } diff --git a/module/applications/costSelectionDialog.mjs b/module/applications/costSelectionDialog.mjs index 8abc9a7a..08bfb1d9 100644 --- a/module/applications/costSelectionDialog.mjs +++ b/module/applications/costSelectionDialog.mjs @@ -42,13 +42,12 @@ export default class CostSelectionDialog extends HandlebarsApplicationMixin(Appl } async _prepareContext(_options) { - console.log(this.costs); const updatedCosts = this.action.calcCosts(this.costs), updatedUses = this.action.calcUses(this.uses); return { costs: updatedCosts, uses: updatedUses, - canUse: this.action.getRealCosts(updatedCosts)?.hasCost && this.action.hasUses(updatedUses) + canUse: this.action.hasCost(updatedCosts) && this.action.hasUses(updatedUses) }; } diff --git a/module/applications/roll.mjs b/module/applications/roll.mjs index de997321..781ffb81 100644 --- a/module/applications/roll.mjs +++ b/module/applications/roll.mjs @@ -28,10 +28,6 @@ export class DHRoll extends Roll { this.applyKeybindings(config); - // let roll; - // if(config.dialog?.configure === false) { - // roll = new this('', config.actor, config); - // } else { if (config.dialog.configure !== false) { // Open Roll Dialog const DialogClass = config.dialog?.class ?? this.DefaultDialog; diff --git a/module/data/action/action.mjs b/module/data/action/action.mjs index f7e06fc1..fc81641f 100644 --- a/module/data/action/action.mjs +++ b/module/data/action/action.mjs @@ -129,7 +129,9 @@ export class DHBaseAction extends foundry.abstract.DataModel { initial: SYSTEM.GENERAL.healingTypes.hitPoints.id, label: 'Healing' }), - value: new fields.EmbeddedDataField(DHActionDiceData) + resultBased: new fields.BooleanField({ initial: false, label: "DAGGERHEART.Actions.Settings.ResultBased.label" }), + value: new fields.EmbeddedDataField(DHActionDiceData), + valueAlt: new fields.EmbeddedDataField(DHActionDiceData), }) }, extraSchemas = {}; @@ -228,7 +230,8 @@ export class DHBaseAction extends foundry.abstract.DataModel { ...config, ...(await this.getCost(config)) }; - if (!this.hasRoll() && (!config.costs.hasCost || !this.hasUses(config.uses))) + + if ((!this.hasRoll() || config.event.shiftKey) && (!this.hasCost(config.costs) || !this.hasUses(config.uses))) return ui.notifications.warn("You don't have the resources to use that action."); // Proceed with Roll @@ -245,7 +248,7 @@ export class DHBaseAction extends foundry.abstract.DataModel { /* ROLL */ hasRoll() { // return this.roll?.type && this.roll?.trait; - return this.roll?.type; + return !!this.roll?.type; } async proceedRoll(config) { @@ -269,9 +272,9 @@ export class DHBaseAction extends foundry.abstract.DataModel { /* COST */ async getCost(config) { - let costs = this.cost?.length ? foundry.utils.deepClone(this.cost) : { values: [], hasCost: true }; + let costs = this.cost?.length ? foundry.utils.deepClone(this.cost) : []; let uses = this.getUses(); - if (!config.event.shiftKey && !this.hasRoll()) { + if (!config.event.shiftKey && !this.hasRoll() && !(!costs.length && !uses)) { const dialogClosed = new Promise((resolve, _) => { new CostSelectionDialog(costs, uses, this, resolve).render(true); }); @@ -282,7 +285,7 @@ export class DHBaseAction extends foundry.abstract.DataModel { getRealCosts(costs) { const realCosts = costs?.length ? costs.filter(c => c.enabled) : []; - return { values: realCosts, hasCost: this.hasCost(realCosts) }; + return realCosts; } calcCosts(costs) { @@ -296,7 +299,8 @@ export class DHBaseAction extends foundry.abstract.DataModel { } hasCost(costs) { - return costs.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true); + const realCosts = this.getRealCosts(costs); + return realCosts.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true); } async spendCost(config) { @@ -314,13 +318,14 @@ export class DHBaseAction extends foundry.abstract.DataModel { } getUses() { - if (!this.uses) return { hasUse: true }; + if (!this.uses?.max) return null; const uses = foundry.utils.deepClone(this.uses); if (!uses.value) uses.value = 0; return uses; } calcUses(uses) { + if(!uses) return null; return { ...uses, enabled: uses.hasOwnProperty('enabled') ? uses.enabled : true @@ -328,7 +333,8 @@ export class DHBaseAction extends foundry.abstract.DataModel { } hasUses(uses) { - return !uses.enabled || uses.value + 1 <= uses.max; + if(!uses) return true; + return (uses.hasOwnProperty('enabled') && !uses.enabled) || uses.value + 1 <= uses.max; } /* USES */ @@ -430,8 +436,14 @@ export class DHDamageAction extends DHBaseAction { return await this.rollDamage(event, config); } + getFormulaValue(part, data) { + let formulaValue = part.value; + if(this.hasRoll() && part.resultBased && data.system.roll.result.duality === -1) return part.valueAlt; + return formulaValue; + } + async rollDamage(event, data) { - let formula = this.damage.parts.map(p => p.getFormula(this.actor)).join(' + '); + let formula = this.damage.parts.map(p => this.getFormulaValue(p, data).getFormula(this.actor)).join(' + '); if (!formula || formula == '') return; let roll = { formula: formula, total: formula }, @@ -475,9 +487,11 @@ export class DHAttackAction extends DHDamageAction { getParentDamage() { return { - multiplier: 'proficiency', - dice: this.item?.system?.damage.value, - bonus: this.item?.system?.damage.bonus ?? 0, + value: { + multiplier: 'proficiency', + dice: this.item?.system?.damage.value, + bonus: this.item?.system?.damage.bonus ?? 0 + }, type: this.item?.system?.damage.type, base: true }; @@ -498,13 +512,20 @@ export class DHHealingAction extends DHBaseAction { return await this.rollHealing(event, config); } + getFormulaValue(data) { + let formulaValue = this.healing.value; + if(this.hasRoll() && this.healing.resultBased && data.system.roll.result.duality === -1) return this.healing.valueAlt; + return formulaValue; + } + async rollHealing(event, data) { - let formula = this.healing.value.getFormula(this.actor); + let formulaValue = this.getFormulaValue(data), + formula = formulaValue.getFormula(this.actor); if (!formula || formula == '') return; let roll = { formula: formula, total: formula }, bonusDamage = []; - + const config = { title: game.i18n.format('DAGGERHEART.Chat.HealingRoll.Title', { healing: game.i18n.localize(SYSTEM.GENERAL.healingTypes[this.healing.type].label) diff --git a/module/data/action/actionDice.mjs b/module/data/action/actionDice.mjs index fe934f1e..3bb51b50 100644 --- a/module/data/action/actionDice.mjs +++ b/module/data/action/actionDice.mjs @@ -40,11 +40,11 @@ export class DHDamageField extends fields.SchemaField { } } -export class DHDamageData extends DHActionDiceData { +export class DHDamageData extends foundry.abstract.DataModel { /** @override */ static defineSchema() { return { - ...super.defineSchema(), + // ...super.defineSchema(), base: new fields.BooleanField({ initial: false, readonly: true, label: 'Base' }), type: new fields.StringField({ choices: SYSTEM.GENERAL.damageTypes, @@ -52,7 +52,10 @@ export class DHDamageData extends DHActionDiceData { label: 'Type', nullable: false, required: true - }) + }), + resultBased: new fields.BooleanField({ initial: false, label: "DAGGERHEART.Actions.Settings.ResultBased.label" }), + value: new fields.EmbeddedDataField(DHActionDiceData), + valueAlt: new fields.EmbeddedDataField(DHActionDiceData), }; } } diff --git a/module/dialogs/d20RollDialog.mjs b/module/dialogs/d20RollDialog.mjs index b682f734..52b940e7 100644 --- a/module/dialogs/d20RollDialog.mjs +++ b/module/dialogs/d20RollDialog.mjs @@ -61,7 +61,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio if (this.config.costs?.length) { const updatedCosts = this.action.calcCosts(this.config.costs); context.costs = updatedCosts; - context.canRoll = this.action.getRealCosts(updatedCosts)?.hasCost; + context.canRoll = this.action.hasCost(updatedCosts); } if (this.config.uses?.max) { context.uses = this.action.calcUses(this.config.uses); diff --git a/templates/views/actionTypes/damage.hbs b/templates/views/actionTypes/damage.hbs index eee906a2..1f8f81d1 100644 --- a/templates/views/actionTypes/damage.hbs +++ b/templates/views/actionTypes/damage.hbs @@ -8,7 +8,6 @@
{{#if @root.hasBaseDamage}}