forked from public/foundryvtt-reve-de-dragon
Tirer dans les compendiums selon les fréquences
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
import { Grammar } from "./grammar.js";
|
||||
import { SystemCompendiums } from "./settings/system-compendiums.js";
|
||||
|
||||
export class RdDRollTables {
|
||||
@ -5,10 +6,8 @@ export class RdDRollTables {
|
||||
/* -------------------------------------------- */
|
||||
static async genericGetTableResult(tableName, toChat) {
|
||||
let table = RdDRollTables.getWorldTable(tableName) ?? (await RdDRollTables.getSystemTable(tableName));
|
||||
const draw = await table.draw({ displayChat: toChat, rollMode: "gmroll"});
|
||||
//console.log("RdDRollTables", tableName, toChat, ":", draw);
|
||||
const draw = await table.draw({ displayChat: toChat, rollMode: "gmroll" });
|
||||
return draw.results.length > 0 ? draw.results[0] : undefined;
|
||||
|
||||
}
|
||||
|
||||
static getWorldTable(tableName) {
|
||||
@ -28,7 +27,7 @@ export class RdDRollTables {
|
||||
const pack = game.packs.get(drawResult.documentCollection)
|
||||
return await pack.getDocument(drawResult.documentId)
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async drawTextFromRollTable(tableName, toChat) {
|
||||
const drawResult = await RdDRollTables.genericGetTableResult(tableName, toChat);
|
||||
@ -37,58 +36,67 @@ export class RdDRollTables {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getCompetence(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Détermination aléatoire de compétence", toChat);
|
||||
if (toChat == 'liste') {
|
||||
return await SystemCompendiums.chatTableItems('competences', 'Item', 'competence', it => 1);
|
||||
}
|
||||
else {
|
||||
return await RdDRollTables.drawItemFromRollTable("Détermination aléatoire de compétence", toChat);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getSouffle(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Souffles de Dragon", toChat);
|
||||
return await RdDRollTables.listOrRoll('souffles-de-dragon', 'Item', 'souffle', toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getQueue(toChat = false) {
|
||||
let queue = await RdDRollTables.drawItemFromRollTable("Queues de dragon", toChat);
|
||||
if (queue.name.toLowerCase().includes('lancinant') ) {
|
||||
return await RdDRollTables.getDesirLancinant(toChat);
|
||||
}
|
||||
if (queue.name.toLowerCase().includes('fixe') ) {
|
||||
return await RdDRollTables.getIdeeFixe(toChat);
|
||||
}
|
||||
return queue;
|
||||
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', 'queue', toChat);
|
||||
}
|
||||
|
||||
static async getDesirLancinant(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Désirs lancinants", toChat);
|
||||
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', 'queue', toChat, it => it.system.frequence,
|
||||
it => Grammar.toLowerCaseNoAccent(it.name).includes('desir lancinant') /* it.system.lancinant */);
|
||||
}
|
||||
|
||||
|
||||
static async getIdeeFixe(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Idées fixes", toChat);
|
||||
return await RdDRollTables.listOrRoll('queues-de-dragon', 'Item', 'queue', toChat, it => it.system.frequence,
|
||||
it => Grammar.toLowerCaseNoAccent(it.name).includes('idee fixe') /* it.system.ideefixe */);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getTeteHR(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Têtes de Dragon pour haut-rêvants", toChat);
|
||||
return await RdDRollTables.listOrRoll('tetes-de-dragon-pour-haut-revants', 'Item', 'tete', toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getTete(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Têtes de Dragon pour tous personnages", toChat);
|
||||
return await RdDRollTables.listOrRoll('tetes-de-dragon-pour-tous-personnages', 'Item', 'tete', toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getOmbre(toChat = false) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Ombre de Thanatos", toChat);
|
||||
return await RdDRollTables.listOrRoll('ombres-de-thanatos', 'Item', 'ombre', toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getTarot(toChat = true) {
|
||||
return await RdDRollTables.drawItemFromRollTable("Tarot Draconique", toChat);
|
||||
return await RdDRollTables.listOrRoll('tarot-draconique', 'Item', 'tarot', toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getMaladresse(options = {toChat: false, arme: false}) {
|
||||
static async listOrRoll(compendium, type, subType, toChat, itemFrequence = it => it.system.frequence, filter = it => true) {
|
||||
if (toChat == 'liste') {
|
||||
return await SystemCompendiums.chatTableItems(compendium, type, subType, itemFrequence, filter);
|
||||
}
|
||||
return await SystemCompendiums.getRandom(compendium, type, subType, toChat, itemFrequence, filter);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static async getMaladresse(options = { toChat: false, arme: false }) {
|
||||
return await RdDRollTables.drawTextFromRollTable(
|
||||
options.arme ? "Maladresse armé" : "Maladresses non armé",
|
||||
options.toChat);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user