Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions module/data/activity/base-activity.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,16 @@ export default class BaseActivityData extends foundry.abstract.DataModel {

const lastType = this.item.getFlag("dnd5e", `last.${this.id}.damageType.${index}`);

const options = foundry.utils.mergeObject(foundry.utils.deepClone(damage.options ?? {}), {
type: (damage.types.has(lastType) ? lastType : null) ?? damage.types.first(),
types: Array.from(damage.types),
properties: Array.from(this.item.system.properties ?? [])
.filter(p => CONFIG.DND5E.itemProperties[p]?.isPhysical)
}, { inplace: false });

return {
data, parts,
options: {
type: (damage.types.has(lastType) ? lastType : null) ?? damage.types.first(),
types: Array.from(damage.types),
properties: Array.from(this.item.system.properties ?? [])
.filter(p => CONFIG.DND5E.itemProperties[p]?.isPhysical)
}
options
};
}

Expand Down
1 change: 1 addition & 0 deletions module/data/shared/_types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @property {string} bonus Bonus added to the damage.
* @property {Set<string>} types One or more damage types. If multiple are selected, then the user will be able to
* select from those types.
* @property {object} options Options to pass through to the damage roll.
* @property {object} custom
* @property {boolean} custom.enabled Should the custom formula be used?
* @property {string} custom.formula Custom damage formula.
Expand Down
4 changes: 3 additions & 1 deletion module/data/shared/damage-field.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Scaling from "../../documents/scaling.mjs";
import FormulaField from "../fields/formula-field.mjs";

const { BooleanField, EmbeddedDataField, NumberField, SchemaField, SetField, StringField } = foundry.data.fields;
const { BooleanField, EmbeddedDataField, NumberField, ObjectField, SchemaField, SetField, StringField } =
foundry.data.fields;

/**
* Field for storing damage data.
Expand Down Expand Up @@ -30,6 +31,7 @@ export class DamageData extends foundry.abstract.DataModel {
denomination: new NumberField({ min: 0, integer: true }),
bonus: new FormulaField(),
types: new SetField(new StringField()),
options: new ObjectField(),
custom: new SchemaField({
enabled: new BooleanField(),
formula: new FormulaField()
Expand Down
2 changes: 2 additions & 0 deletions module/dice/_types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@
*
* @typedef {BasicRollOptions} DamageRollOptions
* @property {boolean} [isCritical] Should critical damage be calculated for this roll?
* @property {boolean} [maximize] Maximize dice results when evaluating this roll?
* @property {boolean} [minimize] Minimize dice results when evaluating this roll?
* @property {CriticalDamageConfiguration} [critical] Critical configuration for this roll.
* @property {string[]} [properties] Physical properties of the source (e.g. magical, silvered).
* @property {string} [type] Type of damage represented.
Expand Down
37 changes: 34 additions & 3 deletions module/dice/damage-roll.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ export default class DamageRoll extends BasicRoll {
return this.options.isCritical === true;
}

/* -------------------------------------------- */
/* Evaluate Methods */
/* -------------------------------------------- */

/** @inheritDoc */
async evaluate(options={}) {
options = this._prepareEvaluationOptions(options);
return super.evaluate(options);
}

/* -------------------------------------------- */

/** @inheritDoc */
evaluateSync(options={}) {
options = this._prepareEvaluationOptions(options);
return super.evaluateSync(options);
}

/* -------------------------------------------- */

/**
* Merge roll-level evaluation options into the explicit evaluation options.
* @param {object} [options={}] Evaluation options.
* @returns {object}
* @protected
*/
_prepareEvaluationOptions(options={}) {
return foundry.utils.mergeObject(this.options, options, { inplace: false });
}

/* -------------------------------------------- */
/* Roll Configuration */
/* -------------------------------------------- */
Expand Down Expand Up @@ -159,6 +189,7 @@ export default class DamageRoll extends BasicRoll {
*/
configureDamage({ critical={} }={}) {
critical = foundry.utils.mergeObject(critical, this.options.critical ?? {}, { inplace: false });
const allowCritical = critical.allow !== false;

// Remove previous critical bonus damage
this.terms = this.terms.filter(t => !t.options.criticalBonusDamage && !t.options.criticalFlatBonus);
Expand All @@ -174,7 +205,7 @@ export default class DamageRoll extends BasicRoll {
}
term.options.baseNumber = term.options.baseNumber ?? term.number; // Reset back
term.number = term.options.baseNumber;
if ( this.isCritical ) {
if ( this.isCritical && allowCritical ) {
let cm = critical.multiplier ?? 2;

// Powerful critical - maximize damage and reduce the multiplier by 1
Expand All @@ -199,7 +230,7 @@ export default class DamageRoll extends BasicRoll {
if ( critical.multiplyNumeric ) {
term.options.baseNumber = term.options.baseNumber ?? term.number; // Reset back
term.number = term.options.baseNumber;
if ( this.isCritical ) {
if ( this.isCritical && allowCritical ) {
term.number *= (critical.multiplier ?? 2);
term.options.critical = true;
}
Expand All @@ -216,7 +247,7 @@ export default class DamageRoll extends BasicRoll {
}

// Add extra critical damage term
if ( this.isCritical && critical.bonusDamage ) {
if ( this.isCritical && allowCritical && critical.bonusDamage ) {
let extraTerms = new Roll(critical.bonusDamage, this.data).terms;
if ( !(extraTerms[0] instanceof OperatorTerm) ) extraTerms.unshift(new OperatorTerm({ operator: "+" }));
extraTerms.forEach(t => t.options.criticalBonusDamage = true);
Expand Down