Added a worker script for updating hesitation on change of will or

will_shade. Changes according to pg 545 in the BWG.
This commit is contained in:
alder
2017-05-14 14:19:07 +02:00
parent ab13e6e2ec
commit 21bbc5fb2c
+40 -1
View File
@@ -446,7 +446,7 @@
<table class="page2" style="vertical-align: top;">
<tr>
<td class="statname italic">Hesitation</td><td style="float:right;"><input type="number" class="underline" name="attr_hesitation" disabled="disabled" value="10-@{will}"></td>
<td class="statname italic">Hesitation</td><td style="float:right;"><input type="number" class="underline" name="attr_hesitation" disabled="disabled" title="@{hesitation}"></td>
</tr>
<tr class="spacer"></tr>
<tr>
@@ -2128,3 +2128,42 @@
{{/rollGreater() stat wounddice}}
</div>
</rolltemplate>
<!-- WORKERS -->
<script type="text/worker">
on("sheet:opened", function() {
updateHesitation();
}
// Script for updating hesitation
on("change:will change:will_shade", function() {
updateHesitation();
});
var updateHesitation = function() {
getAttrs(['will', 'will_shade'], function(v) {
if(v.will_shade && v.will) {
var will = isNaN(parseInt(v.will, 10)) === false ? parseInt(v.will, 10) : 0;
// See shade calculations for Will/Hesitation pg 545 of the BWG book
if(v.will_shade === "3") { //Gray Shade
hesitation = 8 - will;
}
else if(v.will_shade === "2") { //White Shade
hesitation = 7 - will;
}
else { //Black Shade
hesitation = 10 - will;
}
if(hesitation < 0) {
hesitation = 0;
}
setAttrs({
hesitation: hesitation
});
}
});
}
</script>