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

@ -147,3 +147,11 @@ rmfrp.armor_values = {
"19": "19",
"20": "20"
}
rmfrp.keyToCriticalTable ={
K: "krush",
P: "puncture",
S: "slash",
U: "unbalance",
G: "grapple"
}

View File

@ -183,19 +183,24 @@ export class RMFRPProcessTable {
}
let roll = new Roll("1d100")
await roll.evaluate()
await RMFRPUtility.showDiceSoNice(roll, game.settings.get("core", "rollMode"))
let score = roll.total
console.log("Critical Roll: ", score)
// Search the result
for (let criticalDef of table.criticals) {
if (Number(criticalDef.score) ) {
if (Number(criticalDef.score) == score) {
return criticalDef.levels[criticalKey.toUpperCase()]
let critDef = foundry.utils.duplicate(criticalDef.levels[criticalKey.toUpperCase()])
critDef.diceResult = score
return critDef
}
} else {
// Score is XX-YY so split it to get the range values
let range = criticalDef.score.split("-")
if (Number(range[0]) <= score && score <= Number(range[1])) {
return criticalDef.levels[criticalKey.toUpperCase()]
let critDef = foundry.utils.duplicate(criticalDef.levels[criticalKey.toUpperCase()])
critDef.diceResult = score
return critDef
}
}
}

View File

@ -6,9 +6,9 @@ export class RMFRPUtility {
static async init() {
}
static capitalizeFirstLetters(str){
static capitalizeFirstLetters(str) {
return str.toLowerCase().replace(/^\w|\s\w/g, function (letter) {
return letter.toUpperCase();
return letter.toUpperCase();
})
}
@ -19,7 +19,7 @@ export class RMFRPUtility {
this.gameSystem = game.settings.get("fvtt-rolemaster-frp", "game_system");
const skillCategories = await RMFRPUtility.loadCompendium("fvtt-rolemaster-frp.skill_categories")
this.skillCategories = skillCategories.map(i => i.toObject()).filter( i => i.system.game_system == "common" || i.system.game_system == this.gameSystem);
this.skillCategories = skillCategories.map(i => i.toObject()).filter(i => i.system.game_system == "common" || i.system.game_system == this.gameSystem);
// Sort skill categories by name
this.skillCategories.sort((a, b) => a.name.localeCompare(b.name));
}
@ -27,7 +27,7 @@ export class RMFRPUtility {
static getGameSystem() {
return this.gameSystem;
}
/* -------------------------------------------- */
static getSkillCategories() {
return this.skillCategories
@ -47,9 +47,35 @@ export class RMFRPUtility {
rmfrp: "Rolemaster Fantasy Role Playing (RMFRP)",
merp: "Middle Earth Role Playing (MERP)"
}
});
});
}
/* -------------------------------------------- */
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 = 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);
}
}
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium);

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);
}
}