From 0e53f157d200fe0ffe9881eba229b808e70730dc Mon Sep 17 00:00:00 2001 From: Jacob Date: Wed, 19 Jul 2017 12:13:49 +0100 Subject: [PATCH] Spell attack bonus and DC are now available in spell attacks. --- .../attacks/attackView/attackView.html | 8 +-- .../attacks/attackView/attackView.js | 28 ++++++++++ .../attacksViewList/attacksViewList.html | 4 +- .../views/character/features/features.html | 52 ++++++++++--------- .../views/character/features/features.js | 46 +++++++++++++--- rpg-docs/lib/functions/evaluate.js | 6 +++ 6 files changed, 107 insertions(+), 37 deletions(-) create mode 100644 rpg-docs/client/views/character/attacks/attackView/attackView.js diff --git a/rpg-docs/client/views/character/attacks/attackView/attackView.html b/rpg-docs/client/views/character/attacks/attackView/attackView.html index d06683af..abbd7c22 100644 --- a/rpg-docs/client/views/character/attacks/attackView/attackView.html +++ b/rpg-docs/client/views/character/attacks/attackView/attackView.html @@ -1,15 +1,15 @@ + + \ No newline at end of file diff --git a/rpg-docs/client/views/character/features/features.js b/rpg-docs/client/views/character/features/features.js index 33c0e459..2ab8f277 100644 --- a/rpg-docs/client/views/character/features/features.js +++ b/rpg-docs/client/views/character/features/features.js @@ -82,13 +82,6 @@ Template.features.events({ element: event.currentTarget.parentElement, }); }, - "click .attack": function(event){ - openParentDialog({ - parent: this.parent, - charId: this.charId, - element: event.currentTarget, - }); - }, "click .useFeature": function(event){ var featureId = this._id; Features.update(featureId, {$inc: {used: 1}}); @@ -154,3 +147,42 @@ Template.resource.events({ }); }, }); + +Template.attackListItem.helpers({ + evaluateAttackBonus: function(charId, attack) { + if (attack.parent.collection == "Spells") { + var spell = Spells.findOne(attack.parent.id); + if (spell) { + bonus = evaluate(charId, attack.attackBonus, {"spellListId": spell.parent.id}); + } + } else { + var bonus = evaluate(charId, attack.attackBonus); + } + + if (_.isFinite(bonus)) { + return bonus > 0 ? "+" + bonus : "" + bonus; + } else { + return bonus; + } + }, + evaluateDamage: function(charId, attack) { + if (attack.parent.collection == "Spells") { + var spell = Spells.findOne(attack.parent.id); + if (spell) { + return evaluateSpellString(charId, spell.parent.id, attack.damage); + } + } else { + return evaluateString(charId, attack.damage); + } + }, +}); + +Template.attackListItem.events({ + "click .attack": function(event, instance){ + openParentDialog({ + parent: instance.data.attack.parent, + charId: instance.data.charId, + element: event.currentTarget, + }); + }, +}); diff --git a/rpg-docs/lib/functions/evaluate.js b/rpg-docs/lib/functions/evaluate.js index a66eed27..83778e8a 100644 --- a/rpg-docs/lib/functions/evaluate.js +++ b/rpg-docs/lib/functions/evaluate.js @@ -49,6 +49,12 @@ evaluate = function(charId, string, opts){ if (list && list.saveDC){ return evaluate(charId, list.saveDC); } + } + if (spellListId && sub.toUpperCase() === "ATTACKBONUS") { + var list = SpellLists.findOne(spellListId); + if (list && list.attackBonus){ + return evaluate(charId, list.attackBonus); + } } return sub; });