diff --git a/module/applications/dialogs/damageDialog.mjs b/module/applications/dialogs/damageDialog.mjs index 0cc62649..fbc584e4 100644 --- a/module/applications/dialogs/damageDialog.mjs +++ b/module/applications/dialogs/damageDialog.mjs @@ -64,7 +64,6 @@ export default class DamageDialog extends HandlebarsApplicationMixin(Application const { ...rest } = foundry.utils.expandObject(formData.object); foundry.utils.mergeObject(this.config.roll, rest.roll); foundry.utils.mergeObject(this.config.modifiers, rest.modifiers); - console.log(rest) this.config.selectedRollMode = rest.selectedRollMode; this.render(); diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index 7f646460..f35ebb9f 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -333,7 +333,7 @@ export default function DHApplicationMixin(Base) { } ]; - if (usable) + if (usable) { options.unshift({ name: 'DAGGERHEART.GENERAL.damage', icon: 'fa-solid fa-explosion', @@ -353,24 +353,11 @@ export default function DHApplicationMixin(Base) { icon: 'fa-solid fa-burst', condition: target => { const doc = getDocFromElementSync(target); - return doc?.system?.attack?.damage.parts.length || doc?.damage?.parts.length; + return doc && !(doc.type === 'domainCard' && doc.system.inVault); }, - callback: async (target, event) => { - const doc = await getDocFromElement(target), - action = doc?.system?.attack ?? doc; - return action && action.use(event, { byPassRoll: true }); - } + callback: async (target, event) => (await getDocFromElement(target)).use(event) }); - - options.unshift({ - name: 'DAGGERHEART.APPLICATIONS.ContextMenu.useItem', - icon: 'fa-solid fa-burst', - condition: target => { - const doc = getDocFromElementSync(target); - return doc && !(doc.type === 'domainCard' && doc.system.inVault); - }, - callback: async (target, event) => (await getDocFromElement(target)).use(event) - }); + } if (toChat) options.push({ diff --git a/module/dice/damageRoll.mjs b/module/dice/damageRoll.mjs index 57707e38..34973108 100644 --- a/module/dice/damageRoll.mjs +++ b/module/dice/damageRoll.mjs @@ -121,14 +121,14 @@ export default class DamageRoll extends DHRoll { } /* To Remove When Reaction System */ - if(index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id && config.modifiers.rally?.value) { - const rallyFaces = config.modifiers.rally.values.find(r => r.value === config.modifiers.rally.value)?.label; - part.roll.terms.push( - new foundry.dice.terms.OperatorTerm({ operator: '+' }), - ...this.constructor.parse(`1${rallyFaces}`) - ); + if(index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { + for(const mod in config.modifiers) { + const modifier = config.modifiers[mod]; + if(modifier.beforeCrit === true && (modifier.enabled || modifier.value)) + modifier.callback(part); + } } - + if (part.extraFormula) { part.roll.terms.push( new foundry.dice.terms.OperatorTerm({ operator: '+' }), @@ -144,8 +144,11 @@ export default class DamageRoll extends DHRoll { /* To Remove When Reaction System */ if(index === 0 && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) { - if(config.modifiers.massive?.enabled) config.modifiers.massive.callback(part); - if(config.modifiers.powerful?.enabled) config.modifiers.powerful.callback(part); + for(const mod in config.modifiers) { + const modifier = config.modifiers[mod]; + if(!modifier.beforeCrit && (modifier.enabled || modifier.value)) + modifier.callback(part); + } } return (part.roll._formula = this.constructor.getFormula(part.roll.terms)); @@ -154,11 +157,8 @@ export default class DamageRoll extends DHRoll { /* To Remove When Reaction System */ static temporaryModifierBuilder(config) { const mods = {}; - if(config.data?.parent) { if(config.data.parent.appliedEffects) { - const effects = config.data.parent.appliedEffects; - // Bardic Rally mods.rally = { label: "DAGGERHEART.CLASS.Feature.rallyDice", @@ -168,8 +168,13 @@ export default class DamageRoll extends DHRoll { return a; }, []), value: null, - callback: (...args) => { - + beforeCrit: true, + callback: (part) => { + const rallyFaces = config.modifiers.rally.values.find(r => r.value === config.modifiers.rally.value)?.label; + part.roll.terms.push( + new foundry.dice.terms.OperatorTerm({ operator: '+' }), + ...this.parse(`1${rallyFaces}`) + ); } }; } @@ -177,9 +182,9 @@ export default class DamageRoll extends DHRoll { const item = config.data.parent.items?.get(config.source.item); if(item) { // Massive (Weapon Feature) - if(item.effects.has("cffkpiwGpEGhjiUC")) + if(item.system.itemFeatures.find(f => f.value === "massive")) mods.massive = { - label: item.effects.get("cffkpiwGpEGhjiUC").name, + label: CONFIG.DH.ITEM.weaponFeatures.massive.label, enabled: true, callback: (part) => { part.roll.terms[0].modifiers.push(`kh${part.roll.terms[0].number}`); @@ -188,20 +193,50 @@ export default class DamageRoll extends DHRoll { }; // Powerful (Weapon Feature) - if(item.effects.has("DCie5eR1dZH2Qvln")) + if(item.system.itemFeatures.find(f => f.value === "powerful")) mods.powerful = { - label: item.effects.get("DCie5eR1dZH2Qvln").name, + label: CONFIG.DH.ITEM.weaponFeatures.powerful.label, enabled: true, callback: (part) => { part.roll.terms[0].modifiers.push(`kh${part.roll.terms[0].number}`); part.roll.terms[0].number += 1; } }; + + // Brutal (Weapon Feature) + if(item.system.itemFeatures.find(f => f.value === "brutal")) + mods.brutal = { + label: CONFIG.DH.ITEM.weaponFeatures.brutal.label, + enabled: true, + beforeCrit: true, + callback: (part) => { + part.roll.terms[0].modifiers.push(`x${part.roll.terms[0].faces}`); + } + }; + + // Serrated (Weapon Feature) + if(item.system.itemFeatures.find(f => f.value === "serrated")) + mods.serrated = { + label: CONFIG.DH.ITEM.weaponFeatures.serrated.label, + enabled: true, + callback: (part) => { + part.roll.terms[0].modifiers.push(`sc8`); + } + }; + + // Self-Correcting (Weapon Feature) + if(item.system.itemFeatures.find(f => f.value === "selfCorrecting")) + mods.selfCorrecting = { + label: CONFIG.DH.ITEM.weaponFeatures.selfCorrecting.label, + enabled: true, + callback: (part) => { + part.roll.terms[0].modifiers.push(`sc6`); + } + }; } } config.modifiers = mods; - console.log(config) return mods; } } diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index 99f84115..a785e508 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -211,8 +211,7 @@ export default class DHRoll extends Roll { } static temporaryModifierBuilder(config) { - const mods = new Map(); - return mods; + return {}; } } diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index 7b588fc7..f1483e31 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -172,6 +172,26 @@ Roll.replaceFormulaData = function (formula, data = {}, { missing, warn = false return nativeReplaceFormulaData(formula, data, { missing, warn }); }; +foundry.dice.terms.Die.MODIFIERS.sc = "selfCorrecting"; + +/** + * Return the configured value as result if 1 is rolled + * Example: 6d6sc6 Roll 6d6, each result of 1 will be changed into 6 + * @param {string} modifier The matched modifier query + */ +foundry.dice.terms.Die.prototype.selfCorrecting = function(modifier) { + const rgx = /(?:sc)([0-9]+)/i; + const match = modifier.match(rgx); + if ( !match ) return false; + let [target] = match.slice(1); + target = parseInt(target); + for ( const r of this.results ) { + if ( r.result === 1 ) { + r.result = target; + } + } +} + export const getDamageKey = damage => { return ['none', 'minor', 'major', 'severe'][damage]; }; diff --git a/styles/less/global/dialog.less b/styles/less/global/dialog.less index aaa5c812..701d5025 100644 --- a/styles/less/global/dialog.less +++ b/styles/less/global/dialog.less @@ -53,7 +53,7 @@ font-weight: 500; font-size: 14px; line-height: 17px; - + white-space: nowrap; color: light-dark(@dark, @beige); }