User:Crime Pope/global.js

function getStats { var statKeys = ["LVL", "STR", "CON", "DEX", "PER", "LEA", "WIL", "MAG", "LIF", "MAN"]; var statNames = ["LVL", "STR", "CON", "DEX", "PER", "LEA", "WIL", "MAG", "LIF", "MAN"]; var stats = {} for (var i in statKeys){ var dom_elem = document.getElementById(statKeys[i]); if ( dom_elem !== null ) { stats[statNames[i]] = parseInt(dom_elem.innerText); } else { stats[statNames[i]] = 0; }   }    return stats; }

function setStat(statID, val) { var result = document.getElementById(statID); if ( result !== null ) { result.innerText = val; } else { result.innerText = 0; } }

function calcHP(stats) { var Level = getStat("LVL"); var Str = getStat("STR"); var Con = getStat("CON"); var Will = getStat("WIL"); var Life = getStat("LIF"); return (5 + Life * ( Level * ( 2 * Con + Str + Will / 3 ) / 25 + Con ) / 100 ); }

function calcMP(stats) { var Level = getStat("LVL"); var Lea = getStat("LEA"); var Will = getStat("WIL"); var Mag = getStat("MAG"); var Mana = getStat("MAN"); return (Mana * (Mag + Level * (6 * Mag + 3 * Will + Lea) / 75) / 100); }

function calcINI(stats) { var Life = getStat("LIF"); var Mana = getStat("MAN"); var Str = getStat("STR"); var Con = getStat("CON"); var Dex = getStat("DEX"); var Per = getStat("PER"); var Lea = getStat("LEA"); var Wil = getStat("WIL"); var Mag = getStat("MAG"); var Cha = getStat("CHA"); var StatINI = Str + Con + Dex + Per + Lea + Wil + Mag + Cha; var LMINI = Math.min((2*Life + Mana/2), 500); return StatINI + LMINI; }

(function testCalc{   console.log(getStats);    //setStat("HP", calcHP);    //setStat("MP", calcMP);    //setStat("INI", calcINI); });