Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Forbidden Lands system #461

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions apps/savingthrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
3 changes: 3 additions & 0 deletions monks-tokenbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
61 changes: 61 additions & 0 deletions systems/fbl-rolls.js
Original file line number Diff line number Diff line change
@@ -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")
}
}
}