diff --git a/rpg-docs/client/globalHelpers/evaluate.js b/rpg-docs/client/globalHelpers/evaluate.js
index d986b1f0..65ad0240 100644
--- a/rpg-docs/client/globalHelpers/evaluate.js
+++ b/rpg-docs/client/globalHelpers/evaluate.js
@@ -24,6 +24,10 @@ Template.registerHelper("evaluateString", function(charId, string) {
return evaluateString(charId, string);
});
+Template.registerHelper("evaluateSpellString", function(charId, spellListId, string) {
+ return evaluateSpellString(charId, spellListId, string);
+});
+
Template.registerHelper("evaluateShortString", function(charId, string) {
if (_.isString(string)){
return evaluateString(
diff --git a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
index 07d9faa7..7de0fdd8 100644
--- a/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
+++ b/rpg-docs/client/views/character/spells/spellDialog/spellDialog.html
@@ -36,7 +36,7 @@
{{/if}}
-
{{#markdown}}{{evaluateString charId description}}{{/markdown}}
+ {{#markdown}}{{evaluateSpellString charId parent.id description}}{{/markdown}}
{{> attacksViewList charId=charId parentId=_id}}
diff --git a/rpg-docs/lib/functions/evaluate.js b/rpg-docs/lib/functions/evaluate.js
index 9fce8c79..77cb34bb 100644
--- a/rpg-docs/lib/functions/evaluate.js
+++ b/rpg-docs/lib/functions/evaluate.js
@@ -8,7 +8,8 @@
})();
//evaluates a calculation string
-evaluate = function(charId, string){
+evaluate = function(charId, string, opts){
+ var spellListId = opts && opts.spellListId;
if (!string) return string;
string = string.replace(/\b[a-z]+\b/gi, function(sub){
//fields
@@ -43,6 +44,12 @@ evaluate = function(charId, string){
if (sub.toUpperCase() === "LEVEL"){
return Characters.calculate.level(charId);
}
+ if (spellListId && sub.toUpperCase() === "DC") {
+ var list = SpellLists.findOne(spellListId);
+ if (list && list.saveDC){
+ return evaluate(charId, list.saveDC);
+ }
+ }
return sub;
});
try {
@@ -66,6 +73,17 @@ evaluateString = function(charId, string){
return result;
};
+evaluateSpellString = function (charId, spellListId, string) {
+ //define brackets as curly brackets around anything that isn't a curly bracket
+ if (!string) return string;
+ var brackets = /\{[^\{\}]*\}/g;
+ var result = string.replace(brackets, function(exp){
+ exp = exp.replace(/(\{|\})/g, ""); //remove curly brackets
+ return evaluate(charId, exp, {spellListId});
+ });
+ return result;
+}
+
//returns the value of the effect if it exists,
//otherwise returns the result of the calculation if it exists,
//otherwise returns 0