From 23b7ea63e0c6b8643ffe4e7a4762b2b013c4a80d Mon Sep 17 00:00:00 2001 From: Jeff Coquery Date: Thu, 15 Feb 2024 09:28:00 +0100 Subject: [PATCH] Add support for Forbidden Lands system --- apps/savingthrow.js | 18 ++++++++++--- monks-tokenbar.js | 3 +++ systems/fbl-rolls.js | 61 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 systems/fbl-rolls.js diff --git a/apps/savingthrow.js b/apps/savingthrow.js index cee3b5b..9680c36 100644 --- a/apps/savingthrow.js +++ b/apps/savingthrow.js @@ -764,21 +764,31 @@ export class SavingThrow { if (update.roll) { let tooltip = ''; + let actualRoll = null; + let successField = 'total'; + if (update.roll instanceof Roll) { - msgtoken.roll = update.roll.toJSON(); + actualRoll = update.roll; + } else if(update.roll.roll && update.roll.roll.constructor.name === 'FBLRoll') { + actualRoll = update.roll.roll; + successField = 'successCount' + } + + if (actualRoll !== null) { + msgtoken.roll = actualRoll.toJSON(); if (msgtoken.roll.terms.length) msgtoken.roll.terms = duplicate(msgtoken.roll.terms); for (let i = 0; i < msgtoken.roll.terms.length; i++) { if (msgtoken.roll.terms[i] instanceof RollTerm) msgtoken.roll.terms[i] = msgtoken.roll.terms[i].toJSON(); } - msgtoken.total = update.roll.total; + msgtoken.total = actualRoll[successField]; msgtoken.reveal = update.reveal || reveal; msgtoken.request = update.request; - tooltip = await update.roll.getTooltip(); + tooltip = await actualRoll.getTooltip(); Hooks.callAll('tokenBarUpdateRoll', this, message, update.id, msgtoken.roll); - } + } if ($.isNumeric(dc)) Object.assign(msgtoken, MonksTokenBar.system.rollSuccess(msgtoken.roll, dc, msgtoken.actorid, msgtoken.request || requests[0])); diff --git a/monks-tokenbar.js b/monks-tokenbar.js index ad2465b..99c3f44 100644 --- a/monks-tokenbar.js +++ b/monks-tokenbar.js @@ -21,6 +21,7 @@ import { SwadeRolls } from "./systems/swade-rolls.js"; import { SW5eRolls } from "./systems/sw5e-rolls.js"; import { CoC7Rolls } from "./systems/coc7-rolls.js"; import { T2K4ERolls } from "./systems/t2k4e-rolls.js"; +import { FBLRolls } from "./systems/fbl-rolls.js"; export let debug = (...args) => { if (MonksTokenBar.debugEnabled > 1) console.log("DEBUG: monks-tokenbar | ", ...args); @@ -1177,6 +1178,8 @@ Hooks.on("setup", () => { MonksTokenBar.system = new CoC7Rolls(); break; case 't2k4e': MonksTokenBar.system = new T2K4ERolls(); break; + case 'forbidden-lands': + MonksTokenBar.system = new FBLRolls(); break; } MonksTokenBar.system.constructor.activateHooks(); diff --git a/systems/fbl-rolls.js b/systems/fbl-rolls.js new file mode 100644 index 0000000..9adcf86 --- /dev/null +++ b/systems/fbl-rolls.js @@ -0,0 +1,61 @@ +import { BaseRolls } from "./base-rolls.js" +import { i18n, MonksTokenBar, log, setting } from "../monks-tokenbar.js" + +export class FBLRolls extends BaseRolls { + constructor() { + super(); + + this._config = CONFIG['fbl']; + + let attributes = {}; + for (let [k, v] of Object.entries(game.model.Actor.character.attribute)) + attributes[k] = v.label; + + let skills = {}; + for (let [k, v] of Object.entries(game.model.Actor.character.skill)) + skills[k] = v.label; + + this._requestoptions = [ + { id: "attribute", text: "MonksTokenBar.Skill", groups: attributes }, + { id: "skill", text: "MonksTokenBar.Ability", groups: skills }, + ]; + } + + get _supportedSystem() { + return true; + } + + rollSuccess(roll, dc, actorId, request) { + let passed = roll.total >= dc; + return { passed }; +; + } + + + roll({ id, actor, request, rollMode, fastForward = false }, callback, e) { + let rollfn = null; + let options = { rollMode: rollMode, fastForward: fastForward, chatMessage: false, event: e }; + let context = actor.sheet; + if (request.type == 'attribute') { + rollfn = actor.sheet.rollAttribute + } else if (request.type == 'skill') { + rollfn = actor.sheet.rollSkill + } + + if (rollfn != undefined) { + try { + return rollfn.call(context, request.key, options).then((roll) => { + return callback(roll); + }).catch((e) => { + console.error(e); + return { id: id, error: true, msg: i18n("MonksTokenBar.UnknownError") } + }); + } catch (e) { + console.error(e); + return { id: id, error: true, msg: i18n("MonksTokenBar.UnknownError") } + } + } else + return { id: id, error: true, msg: i18n("MonksTokenBar.ActorNoRollFunction") + } + } +} \ No newline at end of file