(() => { const level_cap = 99; // @todo: verify that initial stats are indeed 1 across the board const initial_stats = { "Level": 1, "Pw": 5, "Sk": 5, "Df": 5, "Mg": 5, "Hp": 5, "Sp": 5, "Ch": 5, }; const weapon_tables = { "Swords": {"Pw": 1, "Sk": 1, "Df": 1, "Mg": .75, "Hp": .75, "Sp": .75, "Ch": .75}, "2H Swords": {"Pw": 1.25, "Sk": 1, "Df": .5, "Mg": .75, "Hp": .75, "Sp": .5, "Ch": .75}, "Knives": {"Pw": .75, "Sk": 1.25, "Df": .75, "Mg": .75, "Hp": .5, "Sp": 1, "Ch": 1}, "Axes": {"Pw": 1, "Sk": .75, "Df": 1, "Mg": .75, "Hp": .75, "Sp": 1, "Ch": .5}, "2H Axes": {"Pw": 1.25, "Sk": 1.25, "Df": .75, "Mg": .75, "Hp": .5, "Sp": .75, "Ch": .5}, "Staves": {"Pw": .5, "Sk": .75, "Df": .75, "Mg": 1.25, "Hp": .5, "Sp": .75, "Ch": 1.25}, "Bows": {"Pw": .5, "Sk": 1.75, "Df": .75, "Mg": .75, "Hp": .5, "Sp": .75, "Ch": 1}, "Spears": {"Pw": .75, "Sk": 1.25, "Df": 1, "Mg": .75, "Hp": .5, "Sp": .75, "Ch": 1}, "Flails": {"Pw": .75, "Sk": 1.25, "Df": .5, "Mg": .75, "Hp": .5, "Sp": .75, "Ch": 1.25}, "Hammers": {"Pw": 1.75, "Sk": .75, "Df": .5, "Mg": .75, "Hp": .75, "Sp": .75, "Ch": .75}, "Gloves": {"Pw": 1.25, "Sk": .75, "Df": .75, "Mg": .5, "Hp": 1, "Sp": .75, "Ch": .75}, }; const decimals = document.forms[0]["Decimals"]; const outputs = { "Level": document.forms[0]["Level"], "Pw": document.forms[0]["Pw"], "Sk": document.forms[0]["Sk"], "Df": document.forms[0]["Df"], "Mg": document.forms[0]["Mg"], "Hp": document.forms[0]["Hp"], "Sp": document.forms[0]["Sp"], "Ch": document.forms[0]["Ch"], }; const inputs = { "Swords": document.forms[1]["Swords"], "2H Swords": document.forms[1]["2H Swords"], "Knives": document.forms[1]["Knives"], "Axes": document.forms[1]["Axes"], "2H Axes": document.forms[1]["2H Axes"], "Staves": document.forms[1]["Staves"], "Bows": document.forms[1]["Bows"], "Spears": document.forms[1]["Spears"], "Flails": document.forms[1]["Flails"], "Hammers": document.forms[1]["Hammers"], "Gloves": document.forms[1]["Gloves"], }; const preflight_check = function() { let level = 0; for (const key in inputs) { if (inputs[key].value == "") { inputs[key].value = 0; } if (!Number.isInteger(inputs[key].value)) { inputs[key].value = Math.trunc(inputs[key].value); } level += Number.parseInt(inputs[key].value); } if (level > (level_cap - 1)) { document.activeElement.value = Number.parseInt(document.activeElement.value) + ((level_cap - 1) - level); } }; const recalculating = function() { preflight_check(); for (const key in outputs) { outputs[key].value = initial_stats[key]; } for (const key in inputs) { const tally = Number.parseInt(inputs[key].value); if (tally > 0) { outputs["Level"].value = Number(outputs["Level"].value) + tally; for (const attribute in weapon_tables[key]) { outputs[attribute].value = Number(outputs[attribute].value) + (tally * weapon_tables[key][attribute]); } } } if (decimals.checked) { for (const key in outputs) { outputs[key].value = Math.trunc(outputs[key].value); } } }; for (const key in inputs) { inputs[key].oninput = recalculating; } decimals.onchange = recalculating; recalculating(); })();