Add rollTables

This commit is contained in:
2022-08-05 10:04:42 +02:00
parent cb54f6eda3
commit 2517149ab4
840 changed files with 77 additions and 40 deletions

View File

@@ -6,6 +6,8 @@ import { CrucibleCommands } from "./crucible-commands.js";
const __level2Dice = ["d0", "d4", "d6", "d8", "d10", "d12"];
const __name2DiceValue = { "0": 0, "d0": 0, "d4": 4, "d6": 6, "d8": 8, "d10": 10, "d12": 12 }
const __skillLevel2Dice = ["0d8", "1d8", "2d8","3d8", "4d8", '6d8', "8d8", "10d8"]
const __color2RollTable = { blue: "Blue Armor Die", black: "Black Armor Die", green: "Green Armor Die", purple: "Purple Armor Die",
white: "White Armor Die", red: "Red Armor Die", blackgreen: "Black & Green Armor Dice"}
/* -------------------------------------------- */
export class CrucibleUtility {
@@ -66,18 +68,35 @@ export class CrucibleUtility {
this.skills = skills.map(i => i.toObject())
this.weaponSkills = duplicate( this.skills.filter( item => item.data.isweaponskill))
this.shieldSkills = duplicate( this.skills.filter( item => item.data.isshieldskill))
const rollTables = await CrucibleUtility.loadCompendium("fvtt-crucible-rpg.rolltables")
this.rollTables = rollTables.map(i => i.toObject())
}
/* -------------------------------------------- */
static async loadCompendiumData(compendium) {
const pack = game.packs.get(compendium);
return await pack?.getDocuments() ?? [];
const pack = game.packs.get(compendium)
return await pack?.getDocuments() ?? []
}
/* -------------------------------------------- */
static async loadCompendium(compendium, filter = item => true) {
let compendiumData = await CrucibleUtility.loadCompendiumData(compendium);
return compendiumData.filter(filter);
let compendiumData = await CrucibleUtility.loadCompendiumData(compendium)
return compendiumData.filter(filter)
}
/* -------------------------------------------- */
static async getRollTableFromDiceColor( diceColor) {
let rollTableName = __color2RollTable[diceColor]
if (rollTableName) {
const pack = game.packs.get("fvtt-crucible-rpg.rolltables")
const index = await pack.getIndex()
const entry = index.find(e => e.name === rollTableName)
let table = await pack.getDocument(entry._id)
const draw = await table.draw({ displayChat: true, rollMode: "gmroll"})
return draw.results.length > 0 ? draw.results[0] : undefined
}
}
/* -------------------------------------------- */