Import RMFRP tables + properly rename all files
This commit is contained in:
50
module/rmfrp-process-table.js
Normal file
50
module/rmfrp-process-table.js
Normal file
@ -0,0 +1,50 @@
|
||||
export class RMFRPProcessTable {
|
||||
|
||||
constructor() {
|
||||
// Load a reference to the rmfrp-tables.json file
|
||||
this.rmfrpTables = require('./rmfrp-tables.json');
|
||||
// Loop thru the tables and create a definition object, with key, name and min/ax value of each table
|
||||
this.rmfrpTablesDef = {}
|
||||
for (let table in this.rmfrpTables) {
|
||||
let tableData = this.rmfrpTables[table]
|
||||
// Search min and max values in the tableData
|
||||
let min = Number.MAX_SAFE_INTEGER;
|
||||
let max = Number.MIN_SAFE_INTEGER;
|
||||
tableData.forEach((element) => {
|
||||
if (element.result) {
|
||||
if (Number(element.result)) {
|
||||
min = Math.min(min, Number(element.result));
|
||||
max = Math.max(max, Number(element.result));
|
||||
} else {
|
||||
let range = element.result.split("-");
|
||||
min = Math.min(min, Number(range[0]));
|
||||
max = Math.max(max, Number(range[1]));
|
||||
}
|
||||
}
|
||||
});
|
||||
this.rmfrpTablesDef[table] = {
|
||||
key: table,
|
||||
name: RMFRPUtility.capitalizeFirstLetters(table.replace(/_/g, " ")),
|
||||
min: min,
|
||||
max: max
|
||||
};
|
||||
}
|
||||
super();
|
||||
}
|
||||
|
||||
// Get roll result from table
|
||||
getAttackRollResult(table, roll, armorValue) {
|
||||
let result = this.rmfrpTables[table].find((element) => {
|
||||
if (Number(element.result) && Number(element.result) == Number(roll)) {
|
||||
return element[String(armorValue)];
|
||||
} else {
|
||||
// SPlit the result into a range
|
||||
let range = element.result.split("-");
|
||||
if (Number(roll) >= Number(range[0]) && Number(roll) <= Number(range[1])) {
|
||||
return element[String(armorValue)];
|
||||
}
|
||||
}
|
||||
});
|
||||
return undefined;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user