[Drakar och Demoner 6.0 Expert] Automatic calculation of memorized spell points. (#5887)

* [DoD6.0] Fixed base characteristics roll.

* Improved DoD6 character sheet

* [Drakar och Demoner 6.0] Finished layout overhaul.

* [Drakar och Demoner 6.0] Overhaul of layout

* [Drakar och Demoner 6.0] Finished documentation.

* Update readme

Changed format to make more readable.

* [Drakar och Demoner 6.0] Fixed number handling.

* [Drakar och Demoner 6.0] Removed sample text.

* [Drakar och Demoner 6.0 Expert]
- Magic type separation
- Hit point calculation

* [Drakar och Demoner 6.0] Added memorized spell points.
This commit is contained in:
Erik-Johansson
2020-02-24 13:53:36 -06:00
committed by GitHub
parent d4bc5aa116
commit ef5916e971
2 changed files with 45 additions and 2 deletions
@@ -318,6 +318,12 @@
<input type="number" name="attr_maxspip" min="0" class="sheet-fardighetstabell">
</td>
</tr>
<tr>
<td class="sheet-box_alternate_row"><span>Memorerade poäng</span></td>
<td>
<input type="number" name="attr_spimem" min="0" class="sheet-fardighetstabell">
</td>
</tr>
</table>
</div>
<div>
@@ -998,7 +1004,7 @@
</div>
</div>
<div class="sheet-row">
<div class="sheet-col sheet-dod-min">Version 2.1</div>
<div class="sheet-col sheet-dod-min">Version 2.2</div>
</div>
</div>
@@ -1055,9 +1061,43 @@
});
};
/* ===== PARAMETERS ==========
destination = the name of the attribute that stores the total quantity
section = name of repeating fieldset, without the repeating_
fields = the name of the attribute field to be summed
can be a single attribute: 'weight'
or an array of attributes: ['weight','number','equipped']
multiplier (optional) = a multiplier to the entire fieldset total. For instance, if summing coins of weight 0.02, might want to multiply the final total by 0.02.
*/
const repeatingSum = (destination, section, fields, additional, additionalCheckbox, multiplier = 1) => {
if (!Array.isArray(fields)) fields = [fields];
getSectionIDs(`repeating_${section}`, idArray => {
const attrArray = idArray.reduce( (m,id) => [...m, ...(fields.map(field => `repeating_${section}_${id}_${field}`))],[]);
getAttrs(attrArray, v => {
console.log("===== values of v: "+ JSON.stringify(v) +" =====");
// getValue: if not a number, returns 1 if it is 'on' (checkbox), otherwise returns 0..
const getValue = (section, id,field) => parseFloat(v[`repeating_${section}_${id}_${field}`]) || (v[`repeating_${section}_${id}_${field}`] === 'on' ? 1 : 0);
console.log("===== values of additional: "+ JSON.stringify(additional) +" =====");
console.log("===== values of additionalCheckbox: "+ JSON.stringify(additionalCheckbox) +" =====");
getAttrs([additional, additionalCheckbox], function(values) {
console.log("===== values of values: "+ JSON.stringify(values) +" =====");
let add = parseFloat(values[additional]) * parseFloat(values[additionalCheckbox]);
const sumTotal = idArray.reduce((total, id) => total + fields.reduce((subtotal,field) => subtotal * getValue(section, id,field),1),0) + add;
setAttrs({[destination]: sumTotal * multiplier});
});
});
});
};
on('change:repeating_utrustning remove:repeating_utrustning change:totviktrustning change:utrustningantal_display change:utrustningvikt_display change:mynttot', function() {
beraknaVikt("utrustningtotalla","utrustning",["utrustningvikt","utrustningantal"]);
});
on('change:repeating_magi remove:repeating_magi change:magikost_display change:magimemorerad_display', function() {
repeatingSum("spimem", "magi",["magikost","magimemorerad"], "magikost_display", "magimemorerad_display");
});
</script>
<rolltemplate class="sheet-rolltemplate-DoDFardighet">
+4 -1
View File
@@ -24,4 +24,7 @@ Character sheet in Swedish for Drakar och Demoner 6.0 Expert based on the Stars
### v2.1 (2020-02-08)
- Separated divine and arcane magic skills.
- Magic skill values now calculated from characteristics.
- Hit points are now calculated from base characteristics.
- Hit points are now calculated from base characteristics.
### v2.2 (2020-02-23)
- Added automatic calculation of memorized spell points.