Trefferpunkte aus Einzelwuerfen berechnen (1W4 + 1W je Stufe + KON)
This commit is contained in:
parent
216a62191e
commit
6a6ce7b197
11 changed files with 277 additions and 11 deletions
|
|
@ -61,6 +61,63 @@
|
|||
update();
|
||||
});
|
||||
|
||||
// Trefferpunkte: Einzelwürfe live zu TP max zusammenrechnen und auswürfeln
|
||||
const hpInput = document.querySelector('[data-hp-rolls]');
|
||||
if (hpInput) {
|
||||
const totalField = document.querySelector('[data-hp-total]');
|
||||
const label = document.querySelector('[data-hp-label]');
|
||||
const die = parseInt(hpInput.getAttribute('data-hp-die'), 10) || 4;
|
||||
const baseDie = parseInt(hpInput.getAttribute('data-hp-base'), 10) || 4;
|
||||
const slots = parseInt(hpInput.getAttribute('data-hp-slots'), 10) || 1;
|
||||
const con = parseInt(hpInput.getAttribute('data-hp-con'), 10) || 0;
|
||||
const signedText = function (value) {
|
||||
return value > 0 ? '+' + value : String(value);
|
||||
};
|
||||
const parseRolls = function () {
|
||||
return (hpInput.value.match(/[0-9]+/g) || []).map(function (token) {
|
||||
return parseInt(token, 10) || 0;
|
||||
}).slice(0, slots);
|
||||
};
|
||||
const update = function () {
|
||||
const rolls = parseRolls();
|
||||
let sum = 0;
|
||||
const levelDice = [];
|
||||
for (let slot = 0; slot < slots; slot++) {
|
||||
const value = rolls[slot] || 0;
|
||||
if (value > 0) {
|
||||
sum += value;
|
||||
}
|
||||
if (slot > 0) {
|
||||
levelDice.push(value > 0 ? String(value) : '–');
|
||||
}
|
||||
}
|
||||
const total = Math.max(1, sum + con);
|
||||
if (totalField) {
|
||||
totalField.value = String(total);
|
||||
}
|
||||
if (label) {
|
||||
const base = rolls[0] > 0 ? String(rolls[0]) : '–';
|
||||
label.textContent = '1W' + baseDie + ' ' + base + ' · W' + die + ' ' + (levelDice.join(' ') || '–')
|
||||
+ ' · KON ' + signedText(con) + ' = ' + total;
|
||||
}
|
||||
};
|
||||
hpInput.addEventListener('input', update);
|
||||
const rollButton = document.querySelector('[data-hp-roll]');
|
||||
if (rollButton) {
|
||||
rollButton.addEventListener('click', function () {
|
||||
const rolls = parseRolls();
|
||||
const next = [];
|
||||
for (let slot = 0; slot < slots; slot++) {
|
||||
const value = rolls[slot] || 0;
|
||||
next.push(value > 0 ? value : 1 + Math.floor(Math.random() * (slot === 0 ? baseDie : die)));
|
||||
}
|
||||
hpInput.value = next.join(' ');
|
||||
update();
|
||||
});
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
// Zauberdetails im Bogen: Klick auf den Namen füllt den Detail-Schirm
|
||||
const spellDetail = document.querySelector('#spell-detail');
|
||||
if (spellDetail) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue