Skip to content

Commit

Permalink
Prevented evaluate crashing when given duff abilityMod strings
Browse files Browse the repository at this point in the history
  • Loading branch information
ThaumRystra committed May 6, 2015
1 parent 39f7548 commit 7430c2c
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions rpg-docs/lib/functions/evaluate.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,27 @@ evaluate = function(charId, string){
}
//ability modifiers
var abilityMods = [
"STRENGTHMOD",
"DEXTERITYMOD",
"CONSTITUTIONMOD",
"INTELLIGENCEMOD",
"WISDOMMOD",
"CHARISMAMOD",
"strengthMod",
"dexterityMod",
"constitutionMod",
"intelligenceMod",
"wisdomMod",
"charismaMod",
];
if (_.contains(abilityMods, sub.toUpperCase())){
if (_.contains(abilityMods, sub)){
var slice = sub.slice(0, -3);
return char.abilityMod(slice);
try {
return char.abilityMod(slice);
} catch (e){
return sub;
}
}
//class levels
if (/\w+levels?\b/gi.test(sub)){
//strip out "level"
var className = sub.replace(/levels?\b/gi, "");
var cls = Classes.findOne({charId: charId, name: className});
return cls && cls.level;
return cls && cls.level || sub;
}
//character level
if (sub.toUpperCase() === "LEVEL"){
Expand Down

0 comments on commit 7430c2c

Please sign in to comment.