diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 862df56..b46566f 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -210,7 +210,7 @@ export class DeltaGreenActorSheet extends ActorSheet { }); // Rollable abilities - bind to everything with the 'Rollable' class - html.find('.rollable').mouseup(this._onRoll.bind(this)); + html.find('.rollable').click(this._onRoll.bind(this)); // Macro for toggling an item's equipped state html.find('.equipped-item').mousedown(this._onEquippedStatusChange.bind(this)); @@ -604,12 +604,21 @@ export class DeltaGreenActorSheet extends ActorSheet { return; } + const item = this.actor.items.get(dataset.iid); + const rollOptions = { + rollType: dataset.rolltype, + key: dataset.key, + actor: this.actor, + item + } + switch (dataset.rolltype) { case "stat": case "skill": case "typedskill": + case "weapon": case "sanity": { - const roll = new DGPercentileRoll(dataset.rolltype, dataset.key, this.actor); + const roll = new DGPercentileRoll("1D100", {}, rollOptions); if (event.shiftKey || event.which === 3) { const dialogData = await roll.showDialog(dataset.key); if (!dialogData) return; @@ -618,22 +627,6 @@ export class DeltaGreenActorSheet extends ActorSheet { roll.toChat(); break; } - - case "weapon": { - if (!dataset.iid) { - return ui.notifications.error("No item id provided.") - } - const item = this.actor.items.get(dataset.iid); - const roll = new DGPercentileRoll(dataset.rolltype, dataset.key, this.actor, item); - if (event.shiftKey || event.which === 3) { - const dialogData = await roll.showDialog(dataset.key); - if (!dialogData) return; - roll.modifier += dialogData.targetModifier; - } - roll.toChat(); - break; - } - case "damage": { let diceFormula = dataset.roll; let skillType = dataset.key; @@ -644,19 +637,16 @@ export class DeltaGreenActorSheet extends ActorSheet { sendDamageRollToChat(this.actor, diceFormula, game.settings.get("core", "rollMode")); break; } - case "lethality": { sendLethalityTestToChat(this.actor, game.settings.get("core", "rollMode")); break; } - case "sanitydamage":{ const lowRollFormula = dataset.roll; const highRollFormula = dataset.roll2; sendSanityDamageToChat(this.actor, lowRollFormula, highRollFormula, game.settings.get("core", "rollMode")) break; } - default: break; } diff --git a/module/roll/roll.js b/module/roll/roll.js index d27264f..e6a4696 100644 --- a/module/roll/roll.js +++ b/module/roll/roll.js @@ -3,8 +3,22 @@ import {localizeWithFallback} from "../other/utility-functions.js" export class DGPercentileRoll extends Roll { - constructor(rollType, key, actor, item, options) { + /** + * In order for all of our custom data to persist, our constructor must use the same parameters as its parent class. + * So, even though percentile rolls will always have a formula of "1d100" and we don't use the `data` object, + * we still have to keep them as parameters. + * + * @param {string} formula Unused - The string formula to parse (from Foundry) - Always "1d100" for percentile rolls. + * @param {Object} data Unused - The data object against which to parse attributes within the formula + * @param {Object} [options] Additional data which is preserved in the database + * @param {Number} [options.rollType] The type of roll (stat, skill, sanity, etc). + * @param {String} [options.key] The key of the skill, stat, etc. to use as a basis for this roll. + * @param {DeltaGreenActor} [options.actor] The actor that this roll originates from. + * @param {DeltaGreenItem} [options.item] Optional - The item from which the roll originates. + */ + constructor(formula = "1D100", data = {}, options) { super("1D100", {}, options); + const { rollType, key, actor, item } = options; this.type = rollType; this.key = key; this.actor = actor;