mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-04-21 15:03:37 +02:00
Fix rolling critical damage after rerolling into a crit (#1761)
This commit is contained in:
parent
25264c26e9
commit
29734c5fb5
4 changed files with 48 additions and 51 deletions
|
|
@ -40,7 +40,6 @@ export default class DHActorRoll extends foundry.abstract.TypeDataModel {
|
|||
hasSave: new fields.BooleanField({ initial: false }),
|
||||
hasTarget: new fields.BooleanField({ initial: false }),
|
||||
isDirect: new fields.BooleanField({ initial: false }),
|
||||
isCritical: new fields.BooleanField({ initial: false }),
|
||||
onSave: new fields.StringField(),
|
||||
source: new fields.SchemaField({
|
||||
actor: new fields.StringField(),
|
||||
|
|
|
|||
|
|
@ -49,11 +49,14 @@ export default class DamageField extends fields.SchemaField {
|
|||
|
||||
formulas = DamageField.formatFormulas.call(this, formulas, config);
|
||||
|
||||
messageId = config.message?._id ?? messageId;
|
||||
const message = game.messages.get(messageId);
|
||||
const damageConfig = {
|
||||
dialog: {},
|
||||
...config,
|
||||
roll: formulas,
|
||||
data: this.getRollData()
|
||||
data: this.getRollData(),
|
||||
isCritical: message?.system.roll.isCritical
|
||||
};
|
||||
delete damageConfig.evaluate;
|
||||
|
||||
|
|
@ -61,7 +64,7 @@ export default class DamageField extends fields.SchemaField {
|
|||
damageConfig.dialog.configure = false;
|
||||
if (config.hasSave) config.onSave = damageConfig.onSave = this.save.damageMod;
|
||||
|
||||
damageConfig.source.message = config.message?._id ?? messageId;
|
||||
damageConfig.source.message = messageId;
|
||||
damageConfig.directDamage = !!damageConfig.source?.message;
|
||||
|
||||
// if(damageConfig.source?.message && game.modules.get('dice-so-nice')?.active)
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ export default class D20Roll extends DHRoll {
|
|||
rerolls: dice.results.filter(x => x.rerolled)
|
||||
}
|
||||
}));
|
||||
data.isCritical = config.isCritical = roll.isCritical;
|
||||
data.isCritical = roll.isCritical;
|
||||
data.extra = roll.dice
|
||||
.filter(d => !roll.baseTerms.includes(d))
|
||||
.map(d => {
|
||||
|
|
|
|||
|
|
@ -138,57 +138,52 @@ export default class DamageRoll extends DHRoll {
|
|||
}
|
||||
|
||||
constructFormula(config) {
|
||||
this.options.roll.forEach((part, index) => {
|
||||
for (const [index, part] of this.options.roll.entries()) {
|
||||
part.roll = new Roll(Roll.replaceFormulaData(part.formula, config.data));
|
||||
this.constructFormulaPart(config, part, index);
|
||||
});
|
||||
part.roll.terms = Roll.parse(part.roll.formula, config.data);
|
||||
if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
||||
part.modifiers = this.applyBaseBonus(part);
|
||||
this.addModifiers(part);
|
||||
part.modifiers?.forEach(m => {
|
||||
part.roll.terms.push(...this.formatModifier(m.value));
|
||||
});
|
||||
}
|
||||
|
||||
/* To Remove When Reaction System */
|
||||
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: '+' }),
|
||||
...this.constructor.parse(part.extraFormula, this.options.data)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
||||
const total = part.roll.dice.reduce((acc, term) => acc + term._faces * term._number, 0);
|
||||
if (total > 0) {
|
||||
part.roll.terms.push(...this.formatModifier(total));
|
||||
}
|
||||
}
|
||||
|
||||
/* To Remove When Reaction System */
|
||||
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 && (modifier.enabled || modifier.value)) modifier.callback(part);
|
||||
}
|
||||
}
|
||||
|
||||
part.roll._formula = this.constructor.getFormula(part.roll.terms);
|
||||
}
|
||||
return this.options.roll;
|
||||
}
|
||||
|
||||
constructFormulaPart(config, part, index) {
|
||||
part.roll.terms = Roll.parse(part.roll.formula, config.data);
|
||||
|
||||
if (part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
||||
part.modifiers = this.applyBaseBonus(part);
|
||||
this.addModifiers(part);
|
||||
part.modifiers?.forEach(m => {
|
||||
part.roll.terms.push(...this.formatModifier(m.value));
|
||||
});
|
||||
}
|
||||
|
||||
/* To Remove When Reaction System */
|
||||
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: '+' }),
|
||||
...this.constructor.parse(part.extraFormula, this.options.data)
|
||||
);
|
||||
}
|
||||
|
||||
if (config.isCritical && part.applyTo === CONFIG.DH.GENERAL.healingTypes.hitPoints.id) {
|
||||
const total = part.roll.dice.reduce((acc, term) => acc + term._faces * term._number, 0);
|
||||
if (total > 0) {
|
||||
part.roll.terms.push(...this.formatModifier(total));
|
||||
}
|
||||
}
|
||||
|
||||
/* To Remove When Reaction System */
|
||||
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 && (modifier.enabled || modifier.value)) modifier.callback(part);
|
||||
}
|
||||
}
|
||||
|
||||
return (part.roll._formula = this.constructor.getFormula(part.roll.terms));
|
||||
}
|
||||
|
||||
/* To Remove When Reaction System */
|
||||
static temporaryModifierBuilder(config) {
|
||||
const mods = {};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue