Fix criticals roll

This commit is contained in:
2025-02-09 18:11:17 +01:00
parent 8168cbfdd9
commit 7bc7570eb4
17 changed files with 99 additions and 74 deletions

View File

@ -1,3 +1,4 @@
import { RMFRPUtility } from "../../rmfrp-utility.js";
export default class RMFRPToolsDiceRoller extends FormApplication {
@ -72,34 +73,14 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
}
/* -------------------------------------------- */
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 = this.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = this.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user.id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
getWeaponCriticalTableName( key) {
return CONFIG.rmfrp.keyToCriticalTable[key.toUpperCase()]
}
/* -------------------------------------------- */
async roll(rollKey, formData) {
let baseRoll = await new Roll("1d100").roll();
await this.showDiceSoNice(baseRoll, game.settings.get("core", "rollMode"))
await RMFRPUtility.showDiceSoNice(baseRoll, game.settings.get("core", "rollMode"))
let rollType = this.rollType.find(r => r.value == rollKey)?.text;
let rollData = {
name: this.itemName,
@ -126,11 +107,11 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
if (baseRoll.result < 6) {
rollData.lowopen = true
let newRoll = await new Roll("-1d100").roll();
await this.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
await RMFRPUtility.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
rollData.rolls.push(newRoll);
while (newRoll.result > 95) {
newRoll = await new Roll("-1d100").roll();
await this.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
await RMFRPUtility.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
rollData.rolls.push(newRoll);
}
}
@ -140,11 +121,11 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
if (baseRoll.result > 95) {
rollData.highopen = true
let newRoll = await new Roll("1d100").roll();
await this.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
await RMFRPUtility.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
rollData.rolls.push(newRoll);
while (newRoll.result > 95) {
newRoll = await new Roll("1d100").roll();
await this.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
await RMFRPUtility.showDiceSoNice(newRoll, game.settings.get("core", "rollMode"))
rollData.rolls.push(newRoll);
}
}
@ -181,17 +162,19 @@ export default class RMFRPToolsDiceRoller extends FormApplication {
rollData.attackResult = attackResult;
// Is it a a critical ?
let critical = attackResult.match(/(\d+)(\w)?(\w)?/);
if (critical && critical[2]) {
if (critical && critical[2] && critical[3]) {
if ( critical[2] === "F") {
hasFumble = true
} else {
let criticalTable = this.weapon.system.critical_table
let criticalTable = this.getWeaponCriticalTableName(critical[3])
//let criticalTable = this.weapon.system.critical_table
if ( !criticalTable ) {
ui.notifications.error("Critical table not found for weapon: " + this.weapon.name);
return
}
let criticalResult = await game.rmfrp.attackTables.getCriticalResult(criticalTable, critical[2]);
rollData.criticalResult = criticalResult;
rollData.criticalTable = criticalTable;
console.log("Critical Result: ", criticalResult);
}
}