Spell attack bonus and DC are now available in spell attacks.

This commit is contained in:
Jacob
2017-07-19 12:13:49 +01:00
parent 24cc4fd2b1
commit 0e53f157d2
6 changed files with 107 additions and 37 deletions

View File

@@ -1,15 +1,15 @@
<template name="attackView">
<div class="attackView layout horizontal">
<div class="paper-font-headline layout horizontal center" style="margin-right: 16px;">
{{evaluateSigned charId attackBonus}}
{{evaluateAttackBonus charId attack}}
</div>
<div class="layout vertical">
<div>
{{evaluateString charId damage}}&nbsp;{{damageType}}
{{evaluateDamage charId attack}}&nbsp;{{damageType}}
</div>
{{#if details}}
{{#if attack.details}}
<div class="paper-font-caption">
{{details}}
{{attack.details}}
</div>
{{/if}}
</div>

View File

@@ -0,0 +1,28 @@
Template.attackView.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);
}
},
})

View File

@@ -3,8 +3,8 @@
<hr style="margin: 16px 0 16px 0;">
<div class="attacks">
<div class="spaceAfter paper-font-title">Attacks</div>
{{#each attacks}}
{{> attackView}}
{{#each attack in attacks}}
{{> attackView attack=attack charId=charId}}
{{/each}}
</div>
{{/if}}

View File

@@ -19,30 +19,8 @@
Attacks
</div>
<div class="bottom list">
{{#each attacks}}
<div class="item-slot">
<div class="flexible attack item">
<div class="layout horizontal">
<div class="paper-font-headline layout horizontal center"
style="margin-right: 16px;">
{{evaluateSigned ../_id attackBonus}}
</div>
<div class="flex layout vertical">
<div class="paper-font-body2">
{{name}}
</div>
<div>
{{evaluateString ../_id damage}}&nbsp;{{damageType}}
</div>
{{#if details}}
<div>
{{details}}
</div>
{{/if}}
</div>
</div>
</div>
</div>
{{#each attack in attacks}}
{{>attackListItem attack=attack charId=_id}}
{{/each}}
</div>
</paper-material>
@@ -156,3 +134,29 @@
</div>
{{/if}}
</template>
<template name="attackListItem">
<div class="item-slot">
<div class="flexible attack item">
<div class="layout horizontal">
<div class="paper-font-headline layout horizontal center"
style="margin-right: 16px;">
{{evaluateAttackBonus charId attack}}
</div>
<div class="flex layout vertical">
<div class="paper-font-body2">
{{attack.name}}
</div>
<div>
{{evaluateDamage charId attack}}&nbsp;{{attack.damageType}}
</div>
{{#if attack.details}}
<div>
{{attack.details}}
</div>
{{/if}}
</div>
</div>
</div>
</div>
</template>

View File

@@ -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,
});
},
});

View File

@@ -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;
});