Gestion des maladresses #68

This commit is contained in:
2020-12-17 12:29:54 +01:00
parent 84b4063789
commit 3627d05599
3 changed files with 94 additions and 60 deletions

View File

@ -8,7 +8,6 @@ export class RdDRollTables {
const table = await pack.getEntity(entry._id);
const draw = await table.draw({ displayChat: toChat });
console.log("RdDRollTables", tableName, toChat, ":", draw);
console.log("RdDRollTables", tableName, toChat, ":", draw.roll, draw.results);
return draw;
}
@ -16,9 +15,25 @@ export class RdDRollTables {
static async drawItemFromRollTable(tableName, toChat) {
const draw = await RdDRollTables.genericGetTableResult(tableName, toChat);
const drawnItemRef = draw.results.length > 0 ? draw.results[0] : undefined;
const pack = game.packs.get(drawnItemRef.collection);
return await pack.getEntity(drawnItemRef.resultId);
if (drawnItemRef.collection) {
const pack = game.packs.get(drawnItemRef.collection);
return await pack.getEntity(drawnItemRef.resultId);
}
ui.notifications.warn("le tirage ne correspond pas à une entrée d'un Compendium")
return drawnItemRef.text;
}
/* -------------------------------------------- */
static async drawTextFromRollTable(tableName, toChat) {
const draw = await RdDRollTables.genericGetTableResult(tableName, toChat);
const drawnItemRef = draw.results.length > 0 ? draw.results[0] : undefined;
if (drawnItemRef.collection) {
ui.notifications.warn("le tirage correspond à une entrée d'un Compendium, on attendait un texte")
return await pack.getEntity(drawnItemRef.resultId);
}
return drawnItemRef.text;
}
/* -------------------------------------------- */
static async getSouffle(toChat = true) {
return await RdDRollTables.drawItemFromRollTable("Souffles de Dragon", toChat);
@ -48,4 +63,10 @@ export class RdDRollTables {
static async getTarot(toChat = true) {
return await RdDRollTables.drawItemFromRollTable("Tarot Draconique", toChat);
}
static async getMaladresse(options = {toChat: false, arme: false}) {
return await RdDRollTables.drawTextFromRollTable(
options.arme ? "Maladresse armé" : "Maladresses non armé",
options.toChat);
}
}