Skip to content

Commit

Permalink
fix(death-saves): Don't moan about negative HP
Browse files Browse the repository at this point in the history
fixes #422
  • Loading branch information
symposion committed Mar 24, 2017
1 parent 33b567d commit 2c63292
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 36 deletions.
65 changes: 31 additions & 34 deletions lib/entry-point.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,42 @@ roll20.on('ready', () => {
logger.info('-=> ShapedScripts %%GULP_INJECT_VERSION%% <=-');
const character = roll20.createObj('character', { name: 'SHAPED_VERSION_TESTER' });
const campaignSize = roll20.findObjs({}).length;
const delay = Math.max(2000, Math.floor(campaignSize / 20));
logger.debug('Campaign size: $$$', campaignSize);
roll20.createAttrWithWorker(character.id, 'sheet_opened', 1, () => {
setTimeout(() => {
const version = roll20.getAttrByName(character.id, 'version');
const sheetAPIVersion = roll20.getAttrByName(character.id, 'script_compatibility_version');
logger.info('Detected sheet version as : $$$', version);

const ed = new EventDispatcher(roll20, errorHandler, logger, reporter);
const cw = new ChatWatcher(roll20, logger, ed);
const commandProc = makeCommandProc('shaped', roll20, errorHandler, ed, version, logger);

if (Utils.versionCompare(version, MINIMUM_SHEET_VERSION) < 0) {
const error = `Incompatible sheet version ${version}. You need at least version ${MINIMUM_SHEET_VERSION} to ` +
'use this script. Please install an updated sheet.';
reporter.reportError(error);
logger.error(error);
commandProc.setDefaultCommandHandler(() => reporter.reportError(error));
return;
}
const version = roll20.getAttrByName(character.id, 'version');
const sheetAPIVersion = roll20.getAttrByName(character.id, 'script_compatibility_version');
logger.info('Detected sheet version as : $$$', version);

const ed = new EventDispatcher(roll20, errorHandler, logger, reporter);
const cw = new ChatWatcher(roll20, logger, ed);
const commandProc = makeCommandProc('shaped', roll20, errorHandler, ed, version, logger);

if (Utils.versionCompare(version, MINIMUM_SHEET_VERSION) < 0) {
const error = `Incompatible sheet version ${version}. You need at least version ${MINIMUM_SHEET_VERSION} to ` +
'use this script. Please install an updated sheet.';
reporter.reportError(error);
logger.error(error);
commandProc.setDefaultCommandHandler(() => reporter.reportError(error));
return;
}


if (SHEET_API_VERSION !== sheetAPIVersion) {
const error = 'WARNING: Character sheet has been updated with breaking changes that this version of the ' +
'Companion Script does not yet support. Some features may not work as expected. Please check for an ' +
'updated version of the script.';
reporter.reportError(error);
logger.error(error);
}
if (SHEET_API_VERSION !== sheetAPIVersion) {
const error = 'WARNING: Character sheet has been updated with breaking changes that this version of the ' +
'Companion Script does not yet support. Some features may not work as expected. Please check for an ' +
'updated version of the script.';
reporter.reportError(error);
logger.error(error);
}

const sc = new ShapedConfig({ roll20, reporter, logger, myState });
sc.configure(commandProc, cw, ed);
sc.runStartupSequence(commandProc, () => {
commandProc.setDefaultCommandHandler(cmd =>
reporter.reportError(`Unknown command ${cmd}`));
moduleList.forEach(module => module.configure(commandProc, cw, ed));
_.invoke(roll20.findObjs({ type: 'character', name: 'SHAPED_VERSION_TESTER' }), 'remove');
});
}, delay);
const sc = new ShapedConfig({ roll20, reporter, logger, myState });
sc.configure(commandProc, cw, ed);
sc.runStartupSequence(commandProc, () => {
commandProc.setDefaultCommandHandler(cmd =>
reporter.reportError(`Unknown command ${cmd}`));
moduleList.forEach(module => module.configure(commandProc, cw, ed));
_.invoke(roll20.findObjs({ type: 'character', name: 'SHAPED_VERSION_TESTER' }), 'remove');
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions lib/modules/death-save-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ module.exports = class DeathSaveManager extends ShapedModule {
if (this.roll20.getAttrByName(options.character.id, 'shaped_d20') === '1d20') {
return; // Sheet is set to Roll 2 - we don't know if the character has (dis)advantage so automation isn't possible
}
const currentHP = this.roll20.getAttrByName(options.character.id, 'HP');
if (currentHP !== 0 && currentHP !== '0') {
const currentHP = parseInt(this.roll20.getAttrByName(options.character.id, 'HP'), 10);
if (currentHP > 0) {
this.reportResult('Death Saves', `${options.character.get('name')} has more than 0 HP and shouldn't be rolling ` +
'death saves', options);
return;
Expand Down

0 comments on commit 2c63292

Please sign in to comment.