Widget:AdventurerPageStatsCalculator

 // Constants const MIN_LEVEL = 1; const MAX_LEVEL = 80; const SPIRAL_MAX_LEVEL = 100; const MIN_HP = [,,]; const MAX_HP = ; const ADD_MAX_HP = ; const MIN_STR = [,,]; const MAX_STR = ; const ADD_MAX_STR = ; const NAT_RARITY = ; const HAS_SPIRAL_LIMIT_BREAK = == 5;

// Load modules, init, etc. document.addEventListener("DOMContentLoaded", function(event) {  init;  calcStats; });

// Initialize the empty divs with content function init { let maxLevel = MAX_LEVEL; if (HAS_SPIRAL_LIMIT_BREAK) { maxLevel = SPIRAL_MAX_LEVEL; }

// Create the rarity radio buttons if (NAT_RARITY == 3) { document.getElementById("adv-rarity-input-3").innerHTML = '3★ '; document.getElementById("adv-rarity-input-4").innerHTML = '4★ '; } else if (NAT_RARITY == 4) { document.getElementById("adv-rarity-input-4").innerHTML = '4★ '; } document.getElementById("adv-rarity-input-5").innerHTML = '5★ '; document.getElementById("adv-level-input").innerHTML = 'Level '; }

// Calculate the HP and STR stats function calcStats { // Get the level and rarity let levelInput = document.getElementById('adv-level-input-field'); let level = levelInput.value; let rarity = document.querySelector('input[name = "rarity"]:checked').value;

// Manually set the level cap if we're dealing with a lower rarity switch (rarity) { case "3": if (level > 60) { level = 60; levelInput.value = "60"; }     break; case "4": if (level > 70) { level = 70; levelInput.value = "70"; }     break; case "5": if (level > MAX_LEVEL) { if (HAS_SPIRAL_LIMIT_BREAK) { if (level > SPIRAL_MAX_LEVEL) { level = SPIRAL_MAX_LEVEL; levelInput.value = SPIRAL_MAX_LEVEL; }       } else { level = MAX_LEVEL; levelInput.value = MAX_LEVEL; }     }  }  // Validate the level and rarity before calculating HP and Str if(validateLevel(level) && validateRarity(rarity)) { if (HAS_SPIRAL_LIMIT_BREAK) { // Level 80+ after Mana Spiral is unlocked has a different calc setHP(calculateSpiralHP(level, rarity), level); setStr(calculateSpiralStr(level, rarity), level); } else { setHP(calculateHP(level, rarity), level); setStr(calculateStr(level, rarity), level); } } else { setHP("-"); setStr("-"); } }

// Check if level is a number we can calculate with function validateLevel(value) { if(isNaN(value) || value == "") { return false; } return true; }

// Check if rarity is either 3, 4, or 5 function validateRarity(rarity) { if(rarity == 3 || rarity == 4 || rarity == 5 || rarity == "3" || rarity == "4" || rarity == "5") { return true; } return false; }

// Set the HP value in the display function setHP(value, level) { if (value != "-") { document.getElementById("adv-hp-label").innerHTML = "Level " + level + " HP" } else { document.getElementById("adv-hp-label").innerHTML = "HP" } document.getElementById("adv-hp").innerHTML = value; }

// Set the Str value in the display function setStr(value, level) { if (value != "-") { document.getElementById("adv-str-label").innerHTML = "Level " + level + " Str" } else { document.getElementById("adv-str-label").innerHTML = "Str" } document.getElementById("adv-str").innerHTML = value; }

// Calculate the HP function calculateHP(level, rarity) { let levelDiff = MAX_LEVEL - MIN_LEVEL; let steps = (MAX_HP - MIN_HP[2]) / levelDiff; let statGain = (level-1) * steps; return Math.ceil(MIN_HP[rarity-3] + statGain); }

// Calculate the Str function calculateStr(level, rarity) { let levelDiff = MAX_LEVEL - MIN_LEVEL; let steps = (MAX_STR - MIN_STR[2]) / levelDiff; let statGain = (level-1) * steps; return Math.ceil(MIN_STR[rarity-3] + statGain); }

// Calculate the HP for Level 80+ function calculateSpiralHP(level, rarity) { let levelDiff = SPIRAL_MAX_LEVEL - MAX_LEVEL; let steps = (ADD_MAX_HP - MAX_HP) / levelDiff; let statGain = (level-80) * steps; return Math.ceil(MAX_HP + statGain); }

// Calculate the Str for Level 80+ function calculateSpiralStr(level, rarity) { let levelDiff = SPIRAL_MAX_LEVEL - MAX_LEVEL; let steps = (ADD_MAX_STR - MAX_STR) / levelDiff; let statGain = (level-80) * steps; return Math.ceil(MAX_STR + statGain); }   Max 5★ HP:   Max 5★ Str: 