From feee077c7383ea4263989addb0fd9f178389f397 Mon Sep 17 00:00:00 2001 From: Jonas Karlsson Date: Mon, 4 Jan 2021 13:52:39 +0100 Subject: [PATCH] fix: Adds the ability to set default rolltype for a skill. (Needed for traits, so might as well make it available in the gui). --- package-lock.json | 2 +- src/module/config.ts | 46 +++++++++--------- src/module/utils/TwodsixRolls.ts | 14 +++--- static/styles/twodsix.css | 5 ++ static/template.json | 59 ++++++------------------ static/templates/items/skills-sheet.html | 13 +++++- 6 files changed, 61 insertions(+), 78 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1c238f058..ffcc84b30 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3254,7 +3254,7 @@ "dev": true }, "foundry-vtt-types": { - "version": "git+https://github.com/kmoschcau/foundry-vtt-types.git#3dfc6979f28974909c345678745ce5e58256e6ec", + "version": "git+https://github.com/kmoschcau/foundry-vtt-types.git#df6784fd367b4757bd88353ff501ba9d36d3ed2d", "from": "git+https://github.com/kmoschcau/foundry-vtt-types.git", "dev": true, "requires": { diff --git a/src/module/config.ts b/src/module/config.ts index 64574079d..a97bbf9d4 100644 --- a/src/module/config.ts +++ b/src/module/config.ts @@ -1,15 +1,6 @@ // Namespace TWODSIX Configuration Values -export const TWODSIX = { - CHARACTERISTICS: undefined, - VARIANTS: undefined, - ROLLTYPES: undefined, - DIFFICULTIES: undefined, - RULESETS: undefined, - CRIT: undefined -}; - -TWODSIX.CHARACTERISTICS = { +const CHARACTERISTICS = Object.freeze({ "strength": "STR", "dexterity": "DEX", "endurance": "END", @@ -17,23 +8,23 @@ TWODSIX.CHARACTERISTICS = { "education": "EDU", "socialStanding": "SOC", "psionicStrength": "PSI" -}; +}); /** * Rules variants one can use. * Note that only variants that actually have different rules implementations are listed here. * @type {Object} */ -TWODSIX.VARIANTS = { +const VARIANTS = Object.freeze({ "CE": "CE", "CEL": "CEL", -}; +}); //TODO VARIANTS and RULESETS should really be combined/refactored. /** * Sets of Twodsix settings that best match each supported ruleset. */ -TWODSIX.RULESETS = { +const RULESETS = Object.freeze({ CE: { key: "CE", name: "Cepheus Engine", @@ -93,15 +84,15 @@ TWODSIX.RULESETS = { name: "Other", settings: {} } -}; +}); -TWODSIX.ROLLTYPES = { - Advantage: "3d6kh2", - Normal: "2d6", - Disadvantage: "3d6kl2" -}; +const ROLLTYPES = Object.freeze({ + Advantage: {key: 'Advantage', formula: "3d6kh2"}, + Normal: {key: 'Normal', formula: "2d6"}, + Disadvantage: {key: 'Disadvantage', formula: "3d6kl2"} +}); -TWODSIX.DIFFICULTIES = { +const DIFFICULTIES = Object.freeze({ CE: { Simple: {mod: 6, target: 2}, Easy: {mod: 4, target: 4}, @@ -119,6 +110,15 @@ TWODSIX.DIFFICULTIES = { VeryDifficult: {mod: -4, target: 10}, Formidable: {mod: -6, target: 12}, } -}; +}); + +const CRIT = Object.freeze({"SUCCESS": 1, "FAIL": 2}); -TWODSIX.CRIT = Object.freeze({"SUCCESS": 1, "FAIL": 2}); +export const TWODSIX = { + CHARACTERISTICS: CHARACTERISTICS, + VARIANTS: VARIANTS, + ROLLTYPES: ROLLTYPES, + DIFFICULTIES: DIFFICULTIES, + RULESETS: RULESETS, + CRIT: CRIT +}; diff --git a/src/module/utils/TwodsixRolls.ts b/src/module/utils/TwodsixRolls.ts index 39219bd5f..128e4352c 100644 --- a/src/module/utils/TwodsixRolls.ts +++ b/src/module/utils/TwodsixRolls.ts @@ -15,7 +15,7 @@ export class TwodsixRolls { let updatedSettings = settings; const template = 'systems/twodsix/templates/chat/throw-dialog.html'; const dialogData = { - rollType: "Normal", + rollType: settings.rollType, rollTypes: TWODSIX.ROLLTYPES, difficulty: getKeyByValue(difficulties, settings.difficulty), difficulties: difficulties, @@ -167,6 +167,7 @@ export class TwodsixRolls { } } + //TODO Refactor. This method is *way* too brittle. And long... private static async _handleThrows(dataset:DOMStringMap, actor:TwodsixActor, item:TwodsixItem | null, showEffect:boolean, characteristic, skill:TwodsixItem | null, showRollDialog:boolean, numAttacks:number) { let rollParts:string[] = []; const speaker = ChatMessage.getSpeaker({actor: actor}); @@ -174,10 +175,11 @@ export class TwodsixRolls { const rollMode = game.settings.get('core', 'rollMode'); const difficulty = skill ? difficulties[skill.data.data.difficulty] : difficulties.Average; const skillModifier = item?.data?.data?.skillModifier ?? 0; + const rollType = skill ? (skill.data.data.rolltype || TWODSIX.ROLLTYPES.Normal.key) : TWODSIX.ROLLTYPES.Normal.key; let settings:throwSettings = { shouldRoll: false, - rollType: "Normal", + rollType: rollType, rollMode: rollMode, difficulty: difficulty, skillModifier: skillModifier, @@ -240,13 +242,13 @@ export class TwodsixRolls { } if (settings.rollType && settings.rollType.length > 0) { - if (rollParts[0] == '2d6') { - rollParts[0] = TWODSIX.ROLLTYPES[settings.rollType]; + if (rollParts[0] == TWODSIX.ROLLTYPES.Normal.formula) { + rollParts[0] = TWODSIX.ROLLTYPES[settings.rollType].formula; } else { - rollParts.unshift(TWODSIX.ROLLTYPES[settings.rollType]); + rollParts.unshift(TWODSIX.ROLLTYPES[settings.rollType].formula); } - if (settings.rollType != 'Normal') { + if (settings.rollType != TWODSIX.ROLLTYPES.Normal.key) { flavorParts.push(game.i18n.localize("TWODSIX.Rolls.With")); flavorParts.push(`${(advantageDisadvantageTerm(settings.rollType))}`); } diff --git a/static/styles/twodsix.css b/static/styles/twodsix.css index 8c81edeac..d004ef7aa 100644 --- a/static/styles/twodsix.css +++ b/static/styles/twodsix.css @@ -764,6 +764,11 @@ select.select-difficulty { margin-left: 1em; } +select.select-rolltype { + width: 10em; + margin-left: 1em; +} + span.total-output { text-align: center; } diff --git a/static/template.json b/static/template.json index ab3e14849..1e4f46a6a 100644 --- a/static/template.json +++ b/static/template.json @@ -1,9 +1,6 @@ { "Actor": { - "types": [ - "traveller", - "ship" - ], + "types": ["traveller", "ship"], "traveller": { "name": "", "homeWorld": "", @@ -277,16 +274,7 @@ } }, "Item": { - "types": [ - "equipment", - "weapon", - "armor", - "augment", - "storage", - "tool", - "junk", - "skills" - ], + "types": ["equipment", "weapon", "armor", "augment", "storage", "tool", "junk", "skills"], "templates": { "gearTemplate": { "name": "", @@ -305,19 +293,12 @@ } }, "equipment": { - "templates": [ - "gearTemplate" - ], + "templates": ["gearTemplate"], "type": "equipment", - "location": [ - "inventory", - "storage" - ] + "location": ["inventory", "storage"] }, "weapon": { - "templates": [ - "gearTemplate" - ], + "templates": ["gearTemplate"], "range": 0, "damage": "3d6", "damageBonus": 0, @@ -325,10 +306,7 @@ "ammo": 0, "magazineCost": 0, "type": "weapon", - "location": [ - "inventory", - "storage" - ], + "location": ["inventory", "storage"], "lawLevel": 0, "rangeBand": "", "weaponType": "", @@ -337,9 +315,7 @@ "recoil": false }, "armor": { - "templates": [ - "gearTemplate" - ], + "templates": ["gearTemplate"], "armor": 0, "secondaryArmor": { "value": 0 @@ -348,27 +324,17 @@ "value": 0 }, "type": "armor", - "location": [ - "inventory", - "storage" - ] + "location": ["inventory", "storage"] }, "augment": { - "templates": [ - "gearTemplate" - ], + "templates": ["gearTemplate"], "auglocation": "None", "type": "augment", "bonus": "stat increase", - "location": [ - "inventory", - "storage" - ] + "location": ["inventory", "storage"] }, "skills": { - "templates": [ - "skillsTemplate" - ], + "templates": ["skillsTemplate"], "name": "Skill Name", "value": -3, "characteristic": "STR", @@ -378,7 +344,8 @@ "subtype": "", "reference": "", "key": "key", - "difficulty": "Average" + "difficulty": "Average", + "rolltype": "Normal" } } } diff --git a/static/templates/items/skills-sheet.html b/static/templates/items/skills-sheet.html index b15bd4e4f..ac5dc43d8 100644 --- a/static/templates/items/skills-sheet.html +++ b/static/templates/items/skills-sheet.html @@ -47,6 +47,17 @@ +
+ +
- -