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}}
- {{!-- --}} {{formField @root.fields.damage.fields.includeBase value=@root.source.damage.includeBase label="Include Item Damage" name="damage.includeBase" }}
{{/if}} @@ -16,7 +15,6 @@ {{#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}} @@ -30,26 +28,48 @@ {{formField ../fields.type value=dmg.type name=(concat ../path "damage.parts." index ".type") localize=true}} {{else}} {{#with (@root.getRealIndex index) as | realIndex |}} - - {{#unless dmg.base}} - {{formField ../../fields.custom.fields.enabled value=dmg.custom.enabled name=(concat "damage.parts." realIndex ".custom.enabled")}} - {{/unless}} - {{#if dmg.custom.enabled}} - {{formField ../../fields.custom.fields.formula value=dmg.custom.formula name=(concat "damage.parts." realIndex ".custom.formula") localize=true}} - {{else}} -
- {{formField ../../fields.multiplier value=dmg.multiplier name=(concat "damage.parts." realIndex ".multiplier") localize=true}} - {{#if (eq dmg.multiplier 'flat')}}{{formField ../../fields.flatMultiplier value=dmg.flatMultiplier name=(concat "damage.parts." realIndex ".flatMultiplier") }}{{/if}} - {{formField ../../fields.dice value=dmg.dice name=(concat "damage.parts." realIndex ".dice")}} - {{formField ../../fields.bonus value=dmg.bonus name=(concat "damage.parts." realIndex ".bonus") localize=true}} -
- {{/if}} - {{formField ../../fields.type value=dmg.type name=(concat "damage.parts." realIndex ".type") localize=true}} - - {{#unless dmg.base}}
{{/unless}} - + + {{#if (and (not @root.isNPC) @root.hasRoll (not dmg.base))}} + {{formField ../../fields.resultBased value=dmg.resultBased name=(concat "damage.parts." realIndex ".resultBased") localize=true}} + {{/if}} + {{#if (and (not @root.isNPC) @root.hasRoll (not dmg.base) dmg.resultBased)}} +
+ +
With Hope
+
+ {{> formula fields=../../fields.value.fields type=../../fields.type dmg=dmg source=dmg.value target="value" realIndex=realIndex}} +
+
+ +
With Fear
+
+ {{> formula fields=../../fields.valueAlt.fields type=../../fields.type dmg=dmg source=dmg.valueAlt target="valueAlt" realIndex=realIndex}} +
+ {{else}} + {{> formula fields=../../fields.value.fields type=../fields.type dmg=dmg source=dmg.value target="value" realIndex=realIndex}} + {{/if}} + {{formField ../../fields.type value=dmg.type name=(concat "damage.parts." realIndex ".type") localize=true}} + + {{#unless dmg.base}}
{{/unless}} + {{/with}} {{/if}} {{/each}} - \ No newline at end of file + + +{{#*inline "formula"}} + {{#unless dmg.base}} + {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "damage.parts." realIndex "." target ".custom.enabled")}} + {{/unless}} + {{#if source.custom.enabled}} + {{formField fields.custom.fields.formula value=source.custom.formula name=(concat "damage.parts." realIndex "." target ".custom.formula") localize=true}} + {{else}} +
+ {{formField fields.multiplier value=source.multiplier name=(concat "damage.parts." realIndex "." target ".multiplier") localize=true}} + {{#if (eq source.multiplier 'flat')}}{{formField fields.flatMultiplier value=source.flatMultiplier name=(concat "damage.parts." realIndex ".flatMultiplier") }}{{/if}} + {{formField fields.dice value=source.dice name=(concat "damage.parts." realIndex "." target ".dice")}} + {{formField fields.bonus value=source.bonus name=(concat "damage.parts." realIndex "." target ".bonus") localize=true}} +
+ {{/if}} +{{/inline}} \ No newline at end of file diff --git a/templates/views/actionTypes/healing.hbs b/templates/views/actionTypes/healing.hbs index 52fe23dc..5bf46f7a 100644 --- a/templates/views/actionTypes/healing.hbs +++ b/templates/views/actionTypes/healing.hbs @@ -6,16 +6,38 @@
{{formField fields.type value=source.type name="healing.type" localize=true}} -
- {{formField fields.value.fields.custom.fields.enabled value=source.value.custom.enabled name="healing.value.custom.enabled"}} - {{#if source.value.custom.enabled}} - {{formField fields.value.fields.custom.fields.formula value=source.value.custom.formula name="healing.value.custom.formula" localize=true}} - {{else}} - {{formField fields.value.fields.multiplier value=source.value.multiplier name="healing.value.multiplier" localize=true}} - {{formField fields.value.fields.dice value=source.value.dice name="healing.value.dice"}} - {{formField fields.value.fields.bonus value=source.value.bonus name="healing.value.bonus" localize=true}} - {{/if}} -
+ {{#if (and (not @root.isNPC) @root.hasRoll)}} + {{formField fields.resultBased value=source.resultBased name="healing.resultBased" localize=true}} + {{/if}} + {{#if (and (not @root.isNPC) @root.hasRoll source.resultBased)}} +
+ +
With Hope
+
+ {{> formula fields=fields.value.fields source=source.value target="value"}} +
+
+ +
With Fear
+
+ {{> formula fields=fields.valueAlt.fields source=source.valueAlt target="valueAlt"}} +
+ {{else}} + {{> formula fields=fields.value.fields source=source.value target="value"}} + {{/if}}
- \ No newline at end of file + + +{{#*inline "formula"}} +
+ {{formField fields.custom.fields.enabled value=source.custom.enabled name=(concat "healing." target ".custom.enabled")}} + {{#if source.custom.enabled}} + {{formField fields.custom.fields.formula value=source.custom.formula name=(concat "healing." target ".custom.formula") localize=true}} + {{else}} + {{formField fields.multiplier value=source.multiplier name=(concat "healing." target ".multiplier") localize=true}} + {{formField fields.dice value=source.dice name=(concat "healing." target ".dice")}} + {{formField fields.bonus value=source.bonus name=(concat "healing." target ".bonus") localize=true}} + {{/if}} +
+{{/inline}} \ No newline at end of file