From 1e3c2837a8020c59fe4ba6ff3a370b558efaf3f6 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Thu, 3 Sep 2020 19:59:45 +0200 Subject: [PATCH] fix: Issue #80 Choose whether to show Effect or dice roll total. --- src/module/settings.ts | 9 +++ src/module/sheets/TwodsixActorSheet.ts | 79 +++++++++++++++----------- src/module/utils/TwodsixRolls.ts | 5 +- src/module/utils/sheetUtils.ts | 9 +++ static/lang/en.json | 6 +- static/lang/sv.json | 7 ++- static/templates/chat/roll-dialog.html | 1 - 7 files changed, 74 insertions(+), 42 deletions(-) diff --git a/src/module/settings.ts b/src/module/settings.ts index f3bb1a80f..f565b2db1 100644 --- a/src/module/settings.ts +++ b/src/module/settings.ts @@ -59,6 +59,15 @@ export const registerSettings = function ():void { default: 'disadvantage', }); + game.settings.register('twodsix', 'effectOrTotal', { + name: 'Show effect or total roll value for skill and characteristic rolls.', + hint: "true=Show effect (i.e. roll+modifiers-target number, usually 8), false=show total (i.e. roll+modifiers)", + scope: 'world', + config: true, + default: true, + type: Boolean, + }); + game.settings.register('twodsix', 'absoluteBonusValueForEachTimeIncrement', { name: 'What bonus/penalty to give per each time increment change in a task.', hint: "Leave empty to use default (+/-1). Not currently used.", diff --git a/src/module/sheets/TwodsixActorSheet.ts b/src/module/sheets/TwodsixActorSheet.ts index 38150adba..02d6d7cae 100644 --- a/src/module/sheets/TwodsixActorSheet.ts +++ b/src/module/sheets/TwodsixActorSheet.ts @@ -1,4 +1,5 @@ import TwodsixItem from "../entities/TwodsixItem"; +import {skillRollResultDisplay} from "../utils/sheetUtils"; import {TwodsixRolls} from "../utils/TwodsixRolls"; export class TwodsixActorSheet extends ActorSheet { @@ -41,28 +42,33 @@ export class TwodsixActorSheet extends ActorSheet { // Iterate through items, allocating to containers for (const i of sheetData.items) { i.img = i.img || CONST.DEFAULT_TOKEN; - // Append to gear. - if (i.type === 'storage') { - storage.push(i); - } - if (i.type === 'inventory') { - inventory.push(i); - } - if (i.type === 'equipment') { - equipment.push(i); - } - if (i.type === 'weapon') { - weapon.push(i); - } - if (i.type === 'armor') { - armor.push(i); - } - if (i.type === 'augment') { - augment.push(i); - } - if (i.type === 'skills') { - skills.push(i); + switch (i.type) { + case 'storage': + storage.push(i); + break; + case 'inventory': + inventory.push(i); + break; + case 'equipment': + equipment.push(i); + break; + case 'weapon': + weapon.push(i); + break; + case 'armor': + armor.push(i); + break; + case 'augment': + augment.push(i); + break; + case 'skills': + skills.push(i); + break; + default: + break; } + + actorData.showEffect = game.settings.get("twodsix", "effectOrTotal"); } // Assign and return actorData.storage = storage; @@ -176,24 +182,29 @@ export class TwodsixActorSheet extends ActorSheet { if (dataset.roll) { if (item != null && 'skills' === item.type && event.shiftKey) { - this.rollSkill(itemId, event, dataset); + this.advancedSkillRoll(itemId, event, dataset); } else { - const roll = new Roll(dataset.roll, this.actor.data.data); - const label = dataset.label ? game.i18n.localize("TWODSIX.Actor.Rolling") + ` ${dataset.label}` : ''; - - roll.roll().toMessage({ - speaker: ChatMessage.getSpeaker({actor: this.actor}), - flavor: label - }); + this.simpleSkillRoll(dataset); } } } - rollSkill( - skillId:string, - event:{ preventDefault:() => void; currentTarget:any; }, - dataset:{ roll:string; } - ):Promise { + private simpleSkillRoll(dataset:DOMStringMap) { + const rollParts = dataset.roll.split("+"); + const flavorParts:string[] = []; + const label = dataset.label ? game.i18n.localize("TWODSIX.Actor.Rolling") + ` ${dataset.label}` : ''; + flavorParts.push(label); + skillRollResultDisplay(rollParts, flavorParts); + const flavor = flavorParts.join(' '); + const roll = new Roll(rollParts.join('+'), this.actor.data.data); + + roll.roll().toMessage({ + speaker: ChatMessage.getSpeaker({actor: this.actor}), + flavor: flavor + }); + } + + advancedSkillRoll(skillId:string, event:{ preventDefault:() => void; currentTarget:any; }, dataset:{ roll:string; }):Promise { const skillData = {}; const skills = this.getData().actor.skills; diff --git a/src/module/utils/TwodsixRolls.ts b/src/module/utils/TwodsixRolls.ts index a42cbb775..320ab880b 100644 --- a/src/module/utils/TwodsixRolls.ts +++ b/src/module/utils/TwodsixRolls.ts @@ -1,4 +1,5 @@ import {advantageDisadvantageTerm} from "../settings"; +import { skillRollResultDisplay } from "./sheetUtils"; export class TwodsixRolls { static async Roll({ @@ -90,9 +91,7 @@ export class TwodsixRolls { } } - //So that the result is the Effect of the skill roll. - rollParts.push("-8"); - + skillRollResultDisplay(rollParts, flavorParts); const roll = new Roll(rollParts.join('+'), data).roll(); const flavor = flavorParts.join(' '); diff --git a/src/module/utils/sheetUtils.ts b/src/module/utils/sheetUtils.ts index 8c14f0c72..f5ebaa1dd 100644 --- a/src/module/utils/sheetUtils.ts +++ b/src/module/utils/sheetUtils.ts @@ -180,6 +180,15 @@ export function calcModFor(characteristic:number):number { // return calcModFor(characteristic); // } +export function skillRollResultDisplay(rollParts:string[], flavorParts:string[]):void { + const showEffect = game.settings.get("twodsix", "effectOrTotal"); + if (showEffect) { + //So that the result is the Effect of the skill roll. + rollParts.push("-8"); + } + const string = showEffect ? game.i18n.localize("TWODSIX.Rolls.Effect") : game.i18n.localize("TWODSIX.Rolls.sum"); + flavorParts.push("(" + game.i18n.localize("TWODSIX.Rolls.resultShows") + " " + string + ")"); +} diff --git a/static/lang/en.json b/static/lang/en.json index e9bbafca2..b85c6b680 100644 --- a/static/lang/en.json +++ b/static/lang/en.json @@ -95,7 +95,6 @@ }, "Chat": { "Roll": { - "DialogNote": "Note that this skill roll dialog uses the Cepheus Engine rules, i.e. it adds a modifier for difficulty rather than change the target number. It then subtracts 8 from the result, showing the Effect of the skill roll.", "Difficulty": "Roll difficulty", "Type": "Roll type", "Mode": "Roll mode", @@ -163,7 +162,10 @@ "Rolls": { "Cancel": "Cancel", "Rolling": "Rolling", - "With": "with" + "With": "with", + "resultShows": "result shows", + "Effect": "Effect", + "sum": "sum" } }, "Simple": "Simple", diff --git a/static/lang/sv.json b/static/lang/sv.json index fd07dd249..53e5240ef 100644 --- a/static/lang/sv.json +++ b/static/lang/sv.json @@ -93,7 +93,6 @@ }, "Chat": { "Roll": { - "DialogNote": "Notera att denna färdighetsslagsdialog använder Cepheus Engine-reglerna, dvs. den lägger till en modifierare för svårigheter snarare än att ändra målnumret. Därefter subtraheras 8 från resultatet vilket visas som Effekten av färdighetsslaget.", "Difficulty": "Svårighet", "Type": "Slagtyp", "Mode": "Slagläge", @@ -168,8 +167,12 @@ "ItemDescription": "Sakbeskrivning" }, "Rolls": { + "Cancel": "Avbryt", "Rolling": "Rullar", - "With": "med" + "With": "med", + "resultShows": "resultatet är", + "Effect": "Effekten", + "sum": "summan" } }, "Simple": "Enkelt", diff --git a/static/templates/chat/roll-dialog.html b/static/templates/chat/roll-dialog.html index e033c5896..3f0c19430 100644 --- a/static/templates/chat/roll-dialog.html +++ b/static/templates/chat/roll-dialog.html @@ -1,5 +1,4 @@
-
{{localize "TWODSIX.Chat.Roll.DialogNote"}}