Simuler les lancers de dés
Lorsqu'on force le résultat des dés, on force l'affichage d'un lancer donnant ce résultat avec DiceSoNice
This commit is contained in:
parent
6dc7272ef6
commit
81ae15a6a2
@ -132,18 +132,15 @@ export class RdDDice {
|
||||
}
|
||||
}
|
||||
|
||||
static async roll(formula, options = { showDice: SHOW_DICE, rollMode: undefined }) {
|
||||
const roll = new Roll(formula);
|
||||
await roll.evaluate({ async: true });
|
||||
if (options.showDice != HIDE_DICE) {
|
||||
await this.showDiceSoNice(roll, options.rollMode ?? game.settings.get("core", "rollMode"));
|
||||
}
|
||||
return roll;
|
||||
static async rollTotal(formula, options = { showDice: HIDE_DICE }) {
|
||||
return (await RdDDice.roll(formula, options)).total;
|
||||
}
|
||||
|
||||
static async rollTotal(formula, options = { showDice: HIDE_DICE}) {
|
||||
const roll = await RdDDice.roll(formula, options);
|
||||
return roll.total;
|
||||
static async roll(formula, options = { showDice: SHOW_DICE, rollMode: undefined }) {
|
||||
const roll = new Roll(RdDDice._formulaOrFake(formula, options));
|
||||
await roll.evaluate({ async: true });
|
||||
await this.showDiceSoNice(roll, options);
|
||||
return roll;
|
||||
}
|
||||
|
||||
static async rollOneOf(array) {
|
||||
@ -160,27 +157,79 @@ export class RdDDice {
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async showDiceSoNice(roll, rollMode) {
|
||||
if (game.modules.get("dice-so-nice")?.active) {
|
||||
if (game.dice3d) {
|
||||
let whisper = null;
|
||||
let blind = false;
|
||||
rollMode = rollMode ?? game.settings.get("core", "rollMode");
|
||||
switch (rollMode) {
|
||||
case "blindroll": //GM only
|
||||
blind = true;
|
||||
case "gmroll": //GM + rolling player
|
||||
whisper = ChatUtility.getUsers(user => user.isGM);
|
||||
break;
|
||||
case "roll": //everybody
|
||||
whisper = ChatUtility.getUsers(user => user.active);
|
||||
break;
|
||||
case "selfroll":
|
||||
whisper = [game.user.id];
|
||||
break;
|
||||
}
|
||||
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
||||
static async showDiceSoNice(roll, options) {
|
||||
if (options.showDice == HIDE_DICE || !game.modules.get("dice-so-nice")?.active || !game.dice3d) {
|
||||
return;
|
||||
}
|
||||
|
||||
let { whisper, blind } = RdDDice._getWhisperBlind(options);
|
||||
if (options.forceDiceResult?.total) {
|
||||
let terms = await RdDDice._getForcedTerms(options);
|
||||
if (terms) {
|
||||
await game.dice3d.show({ throws: [{ dice: terms }] })
|
||||
return;
|
||||
}
|
||||
}
|
||||
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
||||
}
|
||||
|
||||
static _formulaOrFake(formula, options) {
|
||||
if (options?.forceDiceResult?.total) {
|
||||
options.forceDiceResult.formula = formula;
|
||||
return options.forceDiceResult.total.toString()
|
||||
}
|
||||
return formula;
|
||||
}
|
||||
|
||||
static async _getForcedTerms(options) {
|
||||
const total = options.forceDiceResult.total;
|
||||
switch (options.forceDiceResult.formula) {
|
||||
case '1d100':
|
||||
return terms1d100(total);
|
||||
case "2d10":
|
||||
// TODO
|
||||
}
|
||||
return undefined;
|
||||
|
||||
function terms1d100(total) {
|
||||
const unites = total % 10;
|
||||
const dizaines = Math.floor(total / 10);
|
||||
return [{
|
||||
resultLabel: dizaines * 10,
|
||||
d100Result: total,
|
||||
result: dizaines,
|
||||
type: "d100",
|
||||
vectors: [],
|
||||
options: {}
|
||||
},
|
||||
{
|
||||
resultLabel: unites,
|
||||
d100Result: total,
|
||||
result: unites,
|
||||
type: "d10",
|
||||
vectors: [],
|
||||
options: {}
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
static _getWhisperBlind(options) {
|
||||
let whisper = null;
|
||||
let blind = false;
|
||||
let rollMode = options.rollMode ?? game.settings.get("core", "rollMode");
|
||||
switch (rollMode) {
|
||||
case "blindroll": //GM only
|
||||
blind = true;
|
||||
case "gmroll": //GM + rolling player
|
||||
whisper = ChatUtility.getUsers(user => user.isGM);
|
||||
break;
|
||||
case "roll": //everybody
|
||||
whisper = ChatUtility.getUsers(user => user.active);
|
||||
break;
|
||||
case "selfroll":
|
||||
whisper = [game.user.id];
|
||||
break;
|
||||
}
|
||||
return { whisper, blind };
|
||||
}
|
||||
}
|
@ -142,10 +142,8 @@ export class RdDResolutionTable {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async rollChances(chances, diviseur, forceDiceResult = -1) {
|
||||
if (forceDiceResult <= 0 || forceDiceResult > 100) {
|
||||
forceDiceResult = -1;
|
||||
}
|
||||
chances.roll = await RdDDice.rollTotal((forceDiceResult == -1) ? "1d100" : `${forceDiceResult}`, chances);
|
||||
chances.forceDiceResult = forceDiceResult <= 0 || forceDiceResult > 100 ? undefined : {total: forceDiceResult};
|
||||
chances.roll = await RdDDice.rollTotal( "1d100", chances);
|
||||
mergeObject(chances, this.computeReussite(chances, chances.roll, diviseur), { overwrite: true });
|
||||
return chances;
|
||||
}
|
||||
|
@ -144,6 +144,7 @@ export class RdDRoll extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async onAction(action, html) {
|
||||
this.rollData.forceDiceResult = Number.parseInt($('#force-dice-result').val()) ?? -1;
|
||||
await RdDResolutionTable.rollData(this.rollData);
|
||||
console.log("RdDRoll -=>", this.rollData, this.rollData.rolled);
|
||||
this.actor.setRollWindowsOpened(false);
|
||||
|
Loading…
Reference in New Issue
Block a user