Skip to content

Commit f45613a

Browse files
committed
Bug fix & tokenMod integration
Bug fix: if the CON modifier was greater than the DC, the script would crash due to a negative number in the crit success/fail target in the dice roll tokenMod integration: added TM observer so TM changes to hit points will now trigger Concentration script
1 parent 14558ed commit f45613a

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Concentration/Concentration.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -259,11 +259,15 @@ var Concentration = Concentration || (function() {
259259
},
260260

261261
roll = (represents, DC, con_save_mod, name, target, advantage) => {
262-
sendChat(script_name, '[[1d20cf<'+(DC-con_save_mod-1)+'cs>'+(DC-con_save_mod-1)+'+'+con_save_mod+']]', results => {
262+
// Bound the crit success and fail targets so negatives stop wrecking the roll --Oosh
263+
const criticalFail = Math.max(DC-con_save_mod-1, 0),
264+
criticalSuccess = Math.max(DC-con_save_mod, 0),
265+
rollString = `[[1d20cf<${criticalFail}cs>${criticalSuccess} + (${con_save_mod})]]`;
266+
sendChat(script_name, rollString, results => {
263267
let title = 'Concentration Save <br> <b style="font-size: 10pt; color: gray;">'+name+'</b>',
264268
advantageRollResult;
265-
266-
let rollresult = results[0].inlinerolls[0].results.rolls[0].results[0].v;
269+
// Error check the results object and debug for any future issues --Oosh
270+
let rollresult = results ? results[0].inlinerolls[0].results.rolls[0].results[0].v : `Roll error! DC: "${DC}", con_sav_mod: "${con_save_mod}"`;
267271
let result = rollresult;
268272

269273
if(advantage){
@@ -438,6 +442,8 @@ var Concentration = Concentration || (function() {
438442
on('chat:message', handleInput);
439443
on('change:graphic:bar'+state[state_name].config.bar+'_value', handleGraphicChange);
440444
on('change:graphic:statusmarkers', handleStatusMarkerChange);
445+
// Add tokenMod observer so changes made with TM will trigger a conc. check --Oosh
446+
if (typeof(TokenMod) === 'object') TokenMod.ObserveTokenChange(handleGraphicChange);
441447
},
442448

443449
setDefaults = (reset) => {

0 commit comments

Comments
 (0)