Difference between revisions of "Widget:AdventurerPageStatsCalculator"
Jump to navigation
Jump to search
imported>Elaeagnifolia |
imported>Elaeagnifolia |
||
| Line 2: | Line 2: | ||
// Constants | // Constants | ||
const MIN_LEVEL = 1; | const MIN_LEVEL = 1; | ||
| − | const MAX_LEVEL = | + | const MAX_LEVEL = 90; |
| − | const | + | const MIN_BP = 0; |
| − | const MIN_HP = | + | const MAX_BP = 99; |
| − | const | + | const MIN_HP = <!--{$minHP}-->; |
| − | const | + | const HP_COEFF = <!--{$hpCoeff}-->; |
| − | const | + | const MIN_ATK = <!--{$minATK}-->; |
| − | const | + | const ATK_COEFF = <!--{$atkCoeff}-->; |
| − | const | + | const MIN_MATK = <!--{$minMATK}-->; |
| − | const | + | const MATK_COEFF = <!--{$matkCoeff}-->; |
| − | const | + | const MIN_DEF = <!--{$minDEF}-->; |
| + | const DEF_COEFF = <!--{$defCoeff}-->; | ||
| + | const MIN_MDEF = <!--{$minMDEF}-->; | ||
| + | const MDEF_COEFF = <!--{$mdefCoeff}-->; | ||
| + | const BONUS_POINT_COEFF = '<!--{$bonusPointCoeff}-->'; | ||
// Load modules, init, etc. | // Load modules, init, etc. | ||
document.addEventListener("DOMContentLoaded", function(event) { | document.addEventListener("DOMContentLoaded", function(event) { | ||
init(); | init(); | ||
| − | calcStats(); | + | //calcStats(); |
}); | }); | ||
// Initialize the empty divs with content | // Initialize the empty divs with content | ||
function init() { | function init() { | ||
| − | + | document.getElementById("adv-level-input").innerHTML = '<label id="level-label" for="adv-level-input-field" style="font-weight:bold;">Level</label><input type="number" id="level-number-input" value=' + MIN_LEVEL + ' min=1 max=' + MAX_LEVEL + ' style="width: 50px; margin-left: 0.5em;" oninput="updateLevelInput()"><br/><input type="range" id="adv-level-input-field" list="levels" value=' + MIN_LEVEL + ' min=1 max=' + MAX_LEVEL + ' style="margin-top: 0.5em; width:100%;" oninput="calcStats()">'; | |
| − | + | document.getElementById("bonus-points-input").innerHTML = '<label id="bonus-points-label" for="bonus-points-input-field" style="font-weight:bold;">Bonus Points</label><input type="number" id="bp-number-input" value=0 min=' + MIN_BP + ' max=' + MAX_BP + ' style="width: 50px; margin-left: 0.5em;" oninput="updateBPInput()"><br/><input type="range" id="bonus-points-input-field" list="bonus-points" value=0 min=' + MIN_BP + ' max=' + MAX_BP + ' style="margin-top: 0.5em; width:100%;" oninput="calcStats()">'; | |
| − | + | } | |
| − | + | ||
| + | function updateLevelInput() { | ||
| + | var level = document.getElementById('level-number-input').value; | ||
| + | document.getElementById('adv-level-input-field').value = level; | ||
| + | calcStats(); | ||
| + | } | ||
| − | + | function updateBPInput() { | |
| − | + | var bp = document.getElementById('bp-number-input').value; | |
| − | + | document.getElementById('bonus-points-input-field').value = bp; | |
| − | + | calcStats(); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
// Calculate the HP and STR stats | // Calculate the HP and STR stats | ||
function calcStats() { | function calcStats() { | ||
| − | // Get the level | + | // Get the level |
let levelInput = document.getElementById('adv-level-input-field'); | let levelInput = document.getElementById('adv-level-input-field'); | ||
| + | let bpInput = document.getElementById('bonus-points-input-field'); | ||
let level = levelInput.value; | let level = levelInput.value; | ||
| − | let | + | let bonusPoints = bpInput.value; |
| + | let parsedJSON = JSON.parse(BONUS_POINT_COEFF); | ||
| + | let bonusPointsCoeff = 0; | ||
| + | |||
| + | if (level > MAX_LEVEL) { | ||
| + | level = MAX_LEVEL; | ||
| + | levelInput.value = MAX_LEVEL; | ||
| + | } | ||
| − | + | if (bonusPoints > MAX_BP) { | |
| − | + | bonusPoints = MAX_BP; | |
| − | + | bpInput.value = MAX_BP; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | + | ||
| − | // Validate the level | + | // Validate the level before calculating HP and Str |
| − | if(validateLevel(level) | + | if(validateLevel(level)) { |
| − | + | setLevel(level); | |
| − | + | setBonusPoints(bonusPoints); | |
| − | + | setCell( | |
| − | + | "hp", | |
| − | + | calculateStat( | |
| − | + | MIN_HP, | |
| − | + | HP_COEFF, | |
| − | + | level, | |
| + | getBonusPointCoeff(parsedJSON[bonusPoints], "HP") | ||
| + | ) | ||
| + | ); | ||
| + | setCell( | ||
| + | "atk", | ||
| + | calculateStat( | ||
| + | MIN_ATK, | ||
| + | ATK_COEFF, | ||
| + | level, | ||
| + | getBonusPointCoeff(parsedJSON[bonusPoints], "ATK") | ||
| + | ) | ||
| + | ); | ||
| + | setCell( | ||
| + | "matk", | ||
| + | calculateStat( | ||
| + | MIN_MATK, | ||
| + | MATK_COEFF, | ||
| + | level, | ||
| + | getBonusPointCoeff(parsedJSON[bonusPoints], "MATK") | ||
| + | ) | ||
| + | ); | ||
| + | setCell( | ||
| + | "def", | ||
| + | calculateStat( | ||
| + | MIN_DEF, | ||
| + | DEF_COEFF, | ||
| + | level, | ||
| + | getBonusPointCoeff(parsedJSON[bonusPoints], "DEF") | ||
| + | ) | ||
| + | ); | ||
| + | setCell( | ||
| + | "mdef", | ||
| + | calculateStat( | ||
| + | MIN_MDEF, | ||
| + | MDEF_COEFF, | ||
| + | level, | ||
| + | getBonusPointCoeff(parsedJSON[bonusPoints], "MDEF") | ||
| + | ) | ||
| + | ); | ||
} else { | } else { | ||
| − | + | setCell("hp", "-"); | |
| − | + | setCell("atk", "-"); | |
| + | setCell("matk", "-"); | ||
| + | setCell("def", "-"); | ||
| + | setCell("mdef", "-"); | ||
} | } | ||
| + | } | ||
| + | |||
| + | function getBonusPointCoeff(bonusPointValues, stat) { | ||
| + | if (bonusPointValues) { | ||
| + | return bonusPointValues[0][stat]; | ||
| + | } | ||
| + | return 0; | ||
} | } | ||
| Line 96: | Line 134: | ||
} | } | ||
| − | // | + | //Set cell to specified display value |
| − | function | + | function setCell(stat, value) { |
| − | + | document.getElementById(stat + "-cell").innerHTML = value; | |
| − | |||
| − | |||
| − | |||
} | } | ||
| − | + | function setLevel(level) { | |
| − | function | + | document.getElementById("level-number-input").value = level; |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | + | function setBonusPoints(bp) { | |
| − | function | + | document.getElementById("bp-number-input").value = bp; |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
} | } | ||
| − | // Calculate the | + | // Calculate the stat |
| − | function | + | function calculateStat(min, coeff, level, bonusPointCoeff) { |
| − | let | + | let initStat = Math.ceil( |
| − | + | (min * coeff * (level-1)) + min | |
| − | + | ); | |
| − | + | let bonusPointStat = Math.floor(initStat * bonusPointCoeff); | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | let | ||
| − | |||
| − | |||
| − | + | return initStat + bonusPointStat; | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | return | ||
} | } | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
</script> | </script> | ||
| − | <div id="adv-level-input-container" style="display:inline-block; text-align:center;"> | + | <div id="adv-level-input-container" style="display:inline-block; text-align:center; width: 100%;"> |
| − | < | + | <div id="adv-level-input" style="display:inline-block; width:100%;"></div> |
| − | < | + | <datalist id="levels"> |
| − | < | + | <option value="1" label="1"></option> |
| − | < | + | <option value="10" label="10"></option> |
| − | + | <option value="20" label="20"></option> | |
| − | + | <option value="30" label="30"></option> | |
| − | + | <option value="40" label="40"></option> | |
| − | < | + | <option value="50" label="50"></option> |
| − | < | + | <option value="60" label="60"></option> |
| − | + | <option value="70" label="70"></option> | |
| − | </ | + | <option value="80" label="80"></option> |
| − | < | + | <option value="90" label="90"></option> |
| − | < | + | </datalist> |
| − | < | + | <div id="bonus-points-input" style="display:inline-block; width:100%;"></div> |
| − | </ | + | <datalist id="bonus-points"> |
| − | </ | + | <option value="0" label="0"></option> |
| + | <option value="10" label="10"></option> | ||
| + | <option value="20" label="20"></option> | ||
| + | <option value="30" label="30"></option> | ||
| + | <option value="40" label="40"></option> | ||
| + | <option value="50" label="50"></option> | ||
| + | <option value="60" label="60"></option> | ||
| + | <option value="70" label="70"></option> | ||
| + | <option value="80" label="80"></option> | ||
| + | <option value="90" label="90"></option> | ||
| + | </datalist> | ||
</div></includeonly> | </div></includeonly> | ||