forked from xdy/twodsix-foundryvtt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Issue xdy#59 Add support for advantage/disadvantage
If you shift-click a skill a dialog where you can choose advantage/disadvantage, difficulty and modifiers show up. 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. A roll above 8 is considered a success. The Effect of the roll is the result - 8. I'd like to make the result row show 'Effect: 0' (or whatever the result was), but haven't figured out how yet, so that will have to wait for another time.
- Loading branch information
Showing
7 changed files
with
243 additions
and
48 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
export class TwodsixRolls { | ||
static async Roll({ | ||
parts = [], | ||
data = {}, | ||
flavorParts = [], | ||
title = null, | ||
speaker = null, | ||
} = {}):Promise<unknown> { | ||
let rolled = false; | ||
const usefulParts = parts.filter(function (el) { | ||
return el != '' && el; | ||
}); | ||
|
||
const template = 'systems/twodsix/templates/chat/roll-dialog.html'; | ||
const dialogData = { | ||
formula: usefulParts.join(' '), | ||
data: data, | ||
rollType: CONFIG.TWODSIX.ROLLTYPES.Normal, | ||
rollTypes: CONFIG.TWODSIX.ROLLTYPES, | ||
rollMode: game.settings.get('core', 'rollMode'), | ||
rollModes: CONFIG.Dice.rollModes, | ||
difficulty: CONFIG.TWODSIX.DIFFICULTIES.Normal, | ||
difficulties: CONFIG.TWODSIX.DIFFICULTIES | ||
}; | ||
|
||
const buttons = { | ||
ok: { | ||
label: "Roll", | ||
icon: '<i class="fas fa-dice"></i>', | ||
callback: (html) => { | ||
roll = TwodsixRolls._handleRoll({ | ||
form: html[0].children[0], | ||
rollParts: usefulParts, | ||
flavorParts, | ||
speaker, | ||
}); | ||
rolled = true; | ||
}, | ||
}, | ||
cancel: { | ||
icon: '<i class="fas fa-times"></i>', | ||
label: "Cancel", | ||
}, | ||
}; | ||
|
||
const html = await renderTemplate(template, dialogData); | ||
let roll:Roll; | ||
return new Promise((resolve) => { | ||
new Dialog({ | ||
title: title, | ||
content: html, | ||
buttons: buttons, | ||
default: 'ok', | ||
close: () => { | ||
resolve(rolled ? roll : false); | ||
}, | ||
}).render(true); | ||
}); | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
static _handleRoll({form = null, rollParts = [], data = {}, flavorParts = [], speaker = null,}):Roll { | ||
let rollMode = game.settings.get('core', 'rollMode'); | ||
|
||
if (form !== null) { | ||
data['bonus'] = form.bonus.value; | ||
data['difficulty'] = form.difficulty.value; | ||
data['rollType'] = form.rollType.value; | ||
data['rollMode'] = form.rollMode.value; | ||
} | ||
|
||
if (data['bonus'] && data['bonus'].length > 0) { | ||
rollParts.push("" + data['bonus']); | ||
} | ||
|
||
if (data['difficulty'] && data['difficulty'].length > 0) { | ||
rollParts.push("" + CONFIG.TWODSIX.DIFFICULTIES[data['difficulty']]); | ||
flavorParts.unshift(`${data['difficulty']}`); | ||
} | ||
|
||
flavorParts.unshift("Rolling:"); | ||
|
||
if (data['rollType'] && data['rollType'].length > 0) { | ||
rollParts[0] = CONFIG.TWODSIX.ROLLTYPES[data['rollType']]; | ||
flavorParts.push("with"); | ||
flavorParts.push(`${data['rollType']}`); | ||
} | ||
|
||
//So that the result is the Effect of the skill roll. | ||
rollParts.push("-8"); | ||
|
||
const roll = new Roll(rollParts.join('+'), data).roll(); | ||
const flavor = flavorParts.join(' '); | ||
|
||
rollMode = form ? form.rollMode.value : rollMode; | ||
roll.toMessage( | ||
{ | ||
speaker: speaker, | ||
flavor: flavor | ||
}, | ||
{rollMode: rollMode} | ||
); | ||
return roll; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<form> | ||
<div>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.</div> | ||
<div class="form-group"> | ||
<label>Difficulty | ||
<select name="difficulty"> | ||
{{#select difficulty}} | ||
{{#each difficulties as |label difficulty|}} | ||
<option value="{{difficulty}}">{{difficulty}}</option> | ||
{{/each}} | ||
{{/select}} | ||
</select> | ||
</label> | ||
</div> | ||
<div class="form-group"> | ||
<label>Roll type | ||
<select name="rollType"> | ||
{{#select rollType}} | ||
{{#each rollTypes as |label type|}} | ||
<option value="{{type}}">{{type}}</option> | ||
{{/each}} | ||
{{/select}} | ||
</select> | ||
</label> | ||
</div> | ||
<div class="form-group"> | ||
<label>Other modifiers | ||
<input type="number" name="bonus" value="0" placeholder="0" onClick="this.select();"/> | ||
</label> | ||
</div> | ||
<div class="form-group"> | ||
<label>Roll mode | ||
<select name="rollMode"> | ||
{{#select rollMode}} | ||
{{#each rollModes as |label mode|}} | ||
<option value="{{mode}}">{{label}}</option> | ||
{{/each}} | ||
{{/select}} | ||
</select> | ||
</label> | ||
</div> | ||
</form> |