2022-11-28 11:31:19 +01:00
|
|
|
import { CompendiumTable, CompendiumTableHelpers, SystemCompendiums } from "./settings/system-compendiums.js";
|
2022-11-06 21:39:47 +01:00
|
|
|
|
2020-11-11 04:31:17 +01:00
|
|
|
export class RdDRollTables {
|
2020-11-12 18:42:41 +01:00
|
|
|
|
2020-11-11 04:31:17 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-12 18:42:41 +01:00
|
|
|
static async genericGetTableResult(tableName, toChat) {
|
2022-10-14 00:48:05 +02:00
|
|
|
let table = RdDRollTables.getWorldTable(tableName) ?? (await RdDRollTables.getSystemTable(tableName));
|
2022-11-26 03:13:45 +01:00
|
|
|
const draw = await table.draw({ displayChat: toChat, rollMode: "gmroll" });
|
2021-05-11 21:21:33 +02:00
|
|
|
return draw.results.length > 0 ? draw.results[0] : undefined;
|
2022-10-08 14:25:31 +02:00
|
|
|
}
|
|
|
|
|
2022-10-14 00:48:05 +02:00
|
|
|
static getWorldTable(tableName) {
|
2022-10-08 14:25:31 +02:00
|
|
|
return game.tables.find(table => table.name.toLowerCase() == tableName.toLowerCase());
|
|
|
|
}
|
|
|
|
|
|
|
|
static async getSystemTable(tableName) {
|
2022-11-06 21:39:47 +01:00
|
|
|
const pack = SystemCompendiums.getPack("tables-diverses");
|
2022-10-08 14:25:31 +02:00
|
|
|
const index = await pack.getIndex();
|
|
|
|
const entry = index.find(e => e.name === tableName);
|
|
|
|
return await pack.getDocument(entry._id);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
2020-11-12 18:42:41 +01:00
|
|
|
|
2020-12-17 02:20:03 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-05-11 21:21:33 +02:00
|
|
|
static async drawItemFromRollTable(tableName, toChat = false) {
|
|
|
|
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
|
2022-06-12 12:14:55 +02:00
|
|
|
const pack = game.packs.get(drawResult.documentCollection)
|
2022-11-06 21:39:47 +01:00
|
|
|
return await pack.getDocument(drawResult.documentId)
|
2020-12-17 02:20:03 +01:00
|
|
|
}
|
2022-11-26 03:13:45 +01:00
|
|
|
|
2020-12-17 12:29:54 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async drawTextFromRollTable(tableName, toChat) {
|
2021-05-11 21:21:33 +02:00
|
|
|
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
|
2022-09-24 00:31:51 +02:00
|
|
|
return drawResult.text;
|
2020-12-17 12:29:54 +01:00
|
|
|
}
|
|
|
|
|
2021-02-11 02:48:27 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static async getCompetence(toChat = false) {
|
2022-11-26 03:13:45 +01:00
|
|
|
if (toChat == 'liste') {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('competences', 'Item', ['competence'], toChat, it => 1);
|
2022-11-26 03:13:45 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return await RdDRollTables.drawItemFromRollTable("Détermination aléatoire de compétence", toChat);
|
|
|
|
}
|
2021-02-11 02:48:27 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 04:31:17 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-05 01:10:54 +01:00
|
|
|
static async getSouffle(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('souffles-de-dragon', 'Item', ['souffle'], toChat);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-05 01:10:54 +01:00
|
|
|
static async getQueue(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', ['queue'], toChat);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
|
|
|
|
2021-02-28 01:40:32 +01:00
|
|
|
static async getDesirLancinant(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', ['queue'], toChat,
|
2022-11-28 11:31:19 +01:00
|
|
|
it => it.system.frequence,
|
|
|
|
it => it.system.categorie == 'lancinant');
|
2021-02-28 01:40:32 +01:00
|
|
|
}
|
2022-11-26 03:13:45 +01:00
|
|
|
|
2021-02-28 01:40:32 +01:00
|
|
|
static async getIdeeFixe(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', ['queue'], toChat,
|
2022-11-28 11:31:19 +01:00
|
|
|
it => it.system.frequence,
|
|
|
|
it => it.system.categorie == 'ideefixe');
|
2021-02-28 01:40:32 +01:00
|
|
|
}
|
|
|
|
|
2020-11-11 04:31:17 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-26 01:15:08 +01:00
|
|
|
static async getTeteHR(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('tetes-de-dragon-pour-haut-revants', 'Item', ['tete'], toChat);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
2020-11-12 18:42:41 +01:00
|
|
|
|
2020-11-11 04:31:17 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-26 01:15:08 +01:00
|
|
|
static async getTete(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('tetes-de-dragon-pour-tous-personnages', 'Item', ['tete'], toChat);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2021-02-05 01:10:54 +01:00
|
|
|
static async getOmbre(toChat = false) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('ombres-de-thanatos', 'Item', ['ombre'], toChat);
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-11-12 18:42:41 +01:00
|
|
|
static async getTarot(toChat = true) {
|
2022-11-30 01:11:31 +01:00
|
|
|
return await RdDRollTables.listOrRoll('tarot-draconique', 'Item', ['tarot'], toChat);
|
2022-11-26 03:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2022-11-30 01:11:31 +01:00
|
|
|
static async listOrRoll(compendium, type, subTypes, toChat, itemFrequence = it => it.system.frequence, filter = it => true) {
|
|
|
|
const table = new CompendiumTable(compendium, type, subTypes);
|
2022-11-26 03:13:45 +01:00
|
|
|
if (toChat == 'liste') {
|
2022-11-28 11:31:19 +01:00
|
|
|
return await table.toChatMessage(itemFrequence, filter);
|
2022-11-26 03:13:45 +01:00
|
|
|
}
|
2022-11-28 11:31:19 +01:00
|
|
|
const row = await table.getRandom(itemFrequence, filter);
|
|
|
|
if (row) {
|
|
|
|
await CompendiumTableHelpers.tableRowToChatMessage(row, type);
|
2022-12-17 17:59:13 +01:00
|
|
|
return row.document;
|
2022-11-28 11:31:19 +01:00
|
|
|
}
|
2022-12-17 17:59:13 +01:00
|
|
|
return undefined;
|
2020-11-11 04:31:17 +01:00
|
|
|
}
|
2020-12-17 12:29:54 +01:00
|
|
|
|
2020-12-17 23:07:04 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-11-26 03:13:45 +01:00
|
|
|
static async getMaladresse(options = { toChat: false, arme: false }) {
|
2020-12-17 12:29:54 +01:00
|
|
|
return await RdDRollTables.drawTextFromRollTable(
|
|
|
|
options.arme ? "Maladresse armé" : "Maladresses non armé",
|
|
|
|
options.toChat);
|
|
|
|
}
|
2022-11-26 03:13:45 +01:00
|
|
|
|
2020-11-12 18:42:41 +01:00
|
|
|
}
|