First version with weapons
This commit is contained in:
@ -308,6 +308,8 @@ export class RMFRPActor extends Actor {
|
||||
ownedItems[item._id] = item.name;
|
||||
}
|
||||
}
|
||||
// sort the ownedItems by name
|
||||
ownedItems = Object.fromEntries(Object.entries(ownedItems).sort((a,b) => a[1].localeCompare(b[1])));
|
||||
return (ownedItems);
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,50 +1,100 @@
|
||||
import { RMFRPUtility } from "./rmfrp-utility.js";
|
||||
import { RMFRP_ATTACK_TABLES } from "./rmfrp-attack-tables.js";
|
||||
|
||||
export class RMFRPProcessTable {
|
||||
|
||||
constructor() {
|
||||
// Load a reference to the rmfrp-tables.json file
|
||||
this.rmfrpTables = require('./rmfrp-tables.json');
|
||||
this.rmfrpTables = RMFRP_ATTACK_TABLES
|
||||
// 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 minKey = "";
|
||||
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));
|
||||
let maxKey = "";
|
||||
for (let resultData of tableData) {
|
||||
let element = resultData["result"];
|
||||
if (Number(element.result)) {
|
||||
let value = Number(element.result)
|
||||
if (value > max) {
|
||||
max = value
|
||||
maxKey = element.result
|
||||
}
|
||||
if (value < min) {
|
||||
min = value
|
||||
minKey = element.result
|
||||
} else {
|
||||
let range = element.result.split("-");
|
||||
min = Math.min(min, Number(range[0]));
|
||||
max = Math.max(max, Number(range[1]));
|
||||
if (Number(range[0]) > max) {
|
||||
max = Number(range[0])
|
||||
maxKey = element.result
|
||||
}
|
||||
if (Number(range[1]) < min) {
|
||||
min = Number(range[1])
|
||||
minKey = element.result
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
this.rmfrpTablesDef[table] = {
|
||||
key: table,
|
||||
name: RMFRPUtility.capitalizeFirstLetters(table.replace(/_/g, " ")),
|
||||
min: min,
|
||||
max: max
|
||||
minKey: minKey,
|
||||
max: max,
|
||||
maxKey: maxKey
|
||||
};
|
||||
}
|
||||
super();
|
||||
// Sort rmfrpTablesDef by name
|
||||
this.rmfrpTablesDef = Object.values(this.rmfrpTablesDef).sort((a, b) => a.name.localeCompare(b.name))
|
||||
}
|
||||
|
||||
getTableDef() {
|
||||
return this.rmfrpTablesDef;
|
||||
}
|
||||
|
||||
// Get roll result from table
|
||||
getAttackRollResult(table, roll, armorValue) {
|
||||
let result = this.rmfrpTables[table].find((element) => {
|
||||
getAttackRollResult(tableKey, roll, armorValue) {
|
||||
roll = Number(roll);
|
||||
if (isNaN(roll)) {
|
||||
return undefined;
|
||||
}
|
||||
let table = this.rmfrpTables[tableKey]
|
||||
let tableDef = this.rmfrpTablesDef[tableKey]
|
||||
if (!table || !tableDef) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Check min and max values
|
||||
if (roll < tableDef.min) {
|
||||
// return the min value
|
||||
return table.find((element) => {
|
||||
let elem = element.result == tableDef.minKey;
|
||||
return elem[String(armorValue)];
|
||||
});
|
||||
}
|
||||
if (roll > tableDef.max) {
|
||||
// return the min value
|
||||
return table.find((element) => {
|
||||
let elem = element.result == tableDef.maxKey;
|
||||
return elem[String(armorValue)];
|
||||
});
|
||||
}
|
||||
|
||||
return table.find((element) => {
|
||||
if (Number(element.result) && Number(element.result) == Number(roll)) {
|
||||
return element[String(armorValue)];
|
||||
} else {
|
||||
// SPlit the result into a range
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ export class RMFRPUtility {
|
||||
|
||||
this.gameSystem = game.settings.get("fvtt-rolemaster-frp", "game_system");
|
||||
|
||||
const skillCategories = await RFRPUtility.loadCompendium("fvtt-rolemaster-frp.skill_categories")
|
||||
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);
|
||||
// Sort skill categories by name
|
||||
this.skillCategories.sort((a, b) => a.name.localeCompare(b.name));
|
||||
@ -58,7 +58,7 @@ export class RMFRPUtility {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async loadCompendium(compendium, filter = item => true) {
|
||||
let compendiumData = await RFRPUtility.loadCompendiumData(compendium);
|
||||
let compendiumData = await RMFRPUtility.loadCompendiumData(compendium);
|
||||
return compendiumData.filter(filter);
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ export class RMFRPUtility {
|
||||
}
|
||||
|
||||
static findChatMessageId(current) {
|
||||
return RFRPUtility.getChatMessageId(HeritiersUtility.findChatMessage(current));
|
||||
return RMFRPUtility.getChatMessageId(HeritiersUtility.findChatMessage(current));
|
||||
}
|
||||
|
||||
static getChatMessageId(node) {
|
||||
@ -78,7 +78,7 @@ export class RMFRPUtility {
|
||||
}
|
||||
|
||||
static findChatMessage(current) {
|
||||
return RFRPUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'))
|
||||
return RMFRPUtility.findNodeMatching(current, it => it.classList.contains('chat-message') && it.attributes.getNamedItem('data-message-id'))
|
||||
}
|
||||
|
||||
static findNodeMatching(current, predicate) {
|
||||
@ -86,7 +86,7 @@ export class RMFRPUtility {
|
||||
if (predicate(current)) {
|
||||
return current;
|
||||
}
|
||||
return RFRPUtility.findNodeMatching(current.parentElement, predicate);
|
||||
return RMFRPUtility.findNodeMatching(current.parentElement, predicate);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
@ -28,9 +28,17 @@ export default class RMFRPWeaponSheet extends ItemSheet {
|
||||
item: baseData.item,
|
||||
system: baseData.item.system,
|
||||
config: CONFIG.rmfrp,
|
||||
skills: {},
|
||||
criticalTables: {},
|
||||
attackTables: game.rmfrp.attackTables.getTableDef(),
|
||||
enrichedDescription: enrichedDescription
|
||||
};
|
||||
|
||||
}
|
||||
console.log("Parent", this.object)
|
||||
// Add the skill data to the sheet if the item is owned
|
||||
if (this.object.actor) {
|
||||
sheetData.skills = this.object.actor.getOwnedItemsByType("skill");
|
||||
}
|
||||
console.log(sheetData);
|
||||
return sheetData;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user