Skip to content

Commit

Permalink
fix: Adds the ability to set default rolltype for a skill. (Needed fo…
Browse files Browse the repository at this point in the history
…r traits, so might as well make it available in the gui).
  • Loading branch information
xdy committed Jan 4, 2021
1 parent e8319a2 commit feee077
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 23 additions & 23 deletions src/module/config.ts
Original file line number Diff line number Diff line change
@@ -1,39 +1,30 @@
// 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",
"intelligence": "INT",
"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",
Expand Down Expand Up @@ -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},
Expand All @@ -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
};
14 changes: 8 additions & 6 deletions src/module/utils/TwodsixRolls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -167,17 +167,19 @@ 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});
const difficulties = TWODSIX.DIFFICULTIES[game.settings.get('twodsix', 'difficultyListUsed')];
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,
Expand Down Expand Up @@ -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))}`);
}
Expand Down
5 changes: 5 additions & 0 deletions static/styles/twodsix.css
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,11 @@ select.select-difficulty {
margin-left: 1em;
}

select.select-rolltype {
width: 10em;
margin-left: 1em;
}

span.total-output {
text-align: center;
}
Expand Down
59 changes: 13 additions & 46 deletions static/template.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"Actor": {
"types": [
"traveller",
"ship"
],
"types": ["traveller", "ship"],
"traveller": {
"name": "",
"homeWorld": "",
Expand Down Expand Up @@ -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": "",
Expand All @@ -305,30 +293,20 @@
}
},
"equipment": {
"templates": [
"gearTemplate"
],
"templates": ["gearTemplate"],
"type": "equipment",
"location": [
"inventory",
"storage"
]
"location": ["inventory", "storage"]
},
"weapon": {
"templates": [
"gearTemplate"
],
"templates": ["gearTemplate"],
"range": 0,
"damage": "3d6",
"damageBonus": 0,
"magazineSize": 0,
"ammo": 0,
"magazineCost": 0,
"type": "weapon",
"location": [
"inventory",
"storage"
],
"location": ["inventory", "storage"],
"lawLevel": 0,
"rangeBand": "",
"weaponType": "",
Expand All @@ -337,9 +315,7 @@
"recoil": false
},
"armor": {
"templates": [
"gearTemplate"
],
"templates": ["gearTemplate"],
"armor": 0,
"secondaryArmor": {
"value": 0
Expand All @@ -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",
Expand All @@ -378,7 +344,8 @@
"subtype": "",
"reference": "",
"key": "key",
"difficulty": "Average"
"difficulty": "Average",
"rolltype": "Normal"
}
}
}
13 changes: 11 additions & 2 deletions static/templates/items/skills-sheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@
</select>
</label>
</div>
<div class="item-name left">
<label class="resource-label">{{localize "TWODSIX.Chat.Roll.Type"}}
<select class="select-rolltype" name="data.rolltype" value={{rolltype}}>
{{#select data.rolltype}}
{{#each data.config.ROLLTYPES as |label rolltype|}}
<option value="{{rolltype}}">{{localize rolltype}}</option>
{{/each}}
{{/select}}
</select>
</label>
</div>
<span class="total-output flex1 skill-mod"></span>
<div class="item-short">
<label for="data.shortdescr" class="resource-label">{{localize "TWODSIX.Items.Equipment.ShortDescription"}}
Expand All @@ -60,5 +71,3 @@
</div>
</div>
</form>


0 comments on commit feee077

Please sign in to comment.