Skip to content

Commit

Permalink
fix: Issue #80 Choose whether to show Effect or dice roll total.
Browse files Browse the repository at this point in the history
  • Loading branch information
xdy committed Sep 3, 2020
1 parent f0a983c commit 1e3c283
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 42 deletions.
9 changes: 9 additions & 0 deletions src/module/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
79 changes: 45 additions & 34 deletions src/module/sheets/TwodsixActorSheet.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import TwodsixItem from "../entities/TwodsixItem";
import {skillRollResultDisplay} from "../utils/sheetUtils";
import {TwodsixRolls} from "../utils/TwodsixRolls";

export class TwodsixActorSheet extends ActorSheet {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<any> {
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<any> {

const skillData = {};
const skills = this.getData().actor.skills;
Expand Down
5 changes: 2 additions & 3 deletions src/module/utils/TwodsixRolls.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {advantageDisadvantageTerm} from "../settings";
import { skillRollResultDisplay } from "./sheetUtils";

export class TwodsixRolls {
static async Roll({
Expand Down Expand Up @@ -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(' ');

Expand Down
9 changes: 9 additions & 0 deletions src/module/utils/sheetUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 + ")");
}



Expand Down
6 changes: 4 additions & 2 deletions static/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -163,7 +162,10 @@
"Rolls": {
"Cancel": "Cancel",
"Rolling": "Rolling",
"With": "with"
"With": "with",
"resultShows": "result shows",
"Effect": "Effect",
"sum": "sum"
}
},
"Simple": "Simple",
Expand Down
7 changes: 5 additions & 2 deletions static/lang/sv.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -168,8 +167,12 @@
"ItemDescription": "Sakbeskrivning"
},
"Rolls": {
"Cancel": "Avbryt",
"Rolling": "Rullar",
"With": "med"
"With": "med",
"resultShows": "resultatet är",
"Effect": "Effekten",
"sum": "summan"
}
},
"Simple": "Enkelt",
Expand Down
1 change: 0 additions & 1 deletion static/templates/chat/roll-dialog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<form>
<div>{{localize "TWODSIX.Chat.Roll.DialogNote"}}</div>
<div class="form-group">
<label>{{localize "TWODSIX.Chat.Roll.Difficulty"}}
<select name="difficulty">
Expand Down

0 comments on commit 1e3c283

Please sign in to comment.