Difference between revisions of "Widget:AdventurerPageStatsCalculator"
Jump to navigation
Jump to search
imported>Elaeagnifolia |
imported>Elaeagnifolia (Undo revision 81125 by Elaeagnifolia (talk)) |
||
| (12 intermediate revisions by the same user not shown) | |||
| Line 3: | Line 3: | ||
const MIN_LEVEL = 1; | const MIN_LEVEL = 1; | ||
const MAX_LEVEL = 80; | const MAX_LEVEL = 80; | ||
| + | const SPIRAL_MAX_LEVEL = 100; | ||
const MIN_HP = [<!--{$minHp3}-->,<!--{$minHp4}-->,<!--{$minHp5}-->]; | const MIN_HP = [<!--{$minHp3}-->,<!--{$minHp4}-->,<!--{$minHp5}-->]; | ||
const MAX_HP = <!--{$maxHp}-->; | const MAX_HP = <!--{$maxHp}-->; | ||
| + | const ADD_MAX_HP = <!--{$addMaxHp1}-->; | ||
const MIN_STR = [<!--{$minStr3}-->,<!--{$minStr4}-->,<!--{$minStr5}-->]; | const MIN_STR = [<!--{$minStr3}-->,<!--{$minStr4}-->,<!--{$minStr5}-->]; | ||
const MAX_STR = <!--{$maxStr}-->; | const MAX_STR = <!--{$maxStr}-->; | ||
| − | const NAT_RARITY = <!--{$rarity}-->;; | + | const ADD_MAX_STR = <!--{$addMaxAtk1}-->; |
| + | const NAT_RARITY = <!--{$rarity}-->; | ||
| + | const HAS_SPIRAL_LIMIT_BREAK = <!--{$maxLimitBreakCount}--> == 5; | ||
// Load modules, init, etc. | // Load modules, init, etc. | ||
| − | + | 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() { | ||
| + | let maxLevel = MAX_LEVEL; | ||
| + | if (HAS_SPIRAL_LIMIT_BREAK) { | ||
| + | maxLevel = SPIRAL_MAX_LEVEL; | ||
| + | } | ||
| + | |||
| + | // Create the rarity radio buttons | ||
if (NAT_RARITY == 3) { | if (NAT_RARITY == 3) { | ||
document.getElementById("adv-rarity-input-3").innerHTML = '<input type="radio" value=3 name="rarity" oninput="calcStats()"><label for="adv-rarity-input-3">3★</label>'; | document.getElementById("adv-rarity-input-3").innerHTML = '<input type="radio" value=3 name="rarity" oninput="calcStats()"><label for="adv-rarity-input-3">3★</label>'; | ||
| Line 27: | Line 34: | ||
} | } | ||
document.getElementById("adv-rarity-input-5").innerHTML = '<input type="radio" value=5 name="rarity" oninput="calcStats()" checked=1><label for="adv-rarity-input-5">5★</label>'; | document.getElementById("adv-rarity-input-5").innerHTML = '<input type="radio" value=5 name="rarity" oninput="calcStats()" checked=1><label for="adv-rarity-input-5">5★</label>'; | ||
| − | document.getElementById("adv-level-input").innerHTML = '<label for="adv-level-input-field" style="font-weight:bold;">Level</label><input type="number" id="adv-level-input-field" value= | + | document.getElementById("adv-level-input").innerHTML = '<label for="adv-level-input-field" style="font-weight:bold;">Level</label><input type="number" id="adv-level-input-field" value=' + maxLevel + ' min=1 max=' + maxLevel + ' style="width:40px; text-align:center; margin-left:5px;" oninput="calcStats()">'; |
} | } | ||
| Line 33: | Line 40: | ||
function calcStats() { | function calcStats() { | ||
// Get the level and rarity | // 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 | // Manually set the level cap if we're dealing with a lower rarity | ||
| Line 53: | Line 60: | ||
case "5": | case "5": | ||
if (level > MAX_LEVEL) { | if (level > MAX_LEVEL) { | ||
| − | 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; | ||
| + | } | ||
} | } | ||
} | } | ||
| Line 60: | Line 74: | ||
// Validate the level and rarity before calculating HP and Str | // Validate the level and rarity before calculating HP and Str | ||
if(validateLevel(level) && validateRarity(rarity)) { | if(validateLevel(level) && validateRarity(rarity)) { | ||
| − | setHP(calculateHP(level, rarity), level) | + | 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 { | } else { | ||
setHP("-"); | setHP("-"); | ||
| Line 106: | Line 126: | ||
// Calculate the HP | // Calculate the HP | ||
function calculateHP(level, rarity) { | 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); | return Math.ceil(MIN_HP[rarity-3] + statGain); | ||
} | } | ||
| Line 114: | Line 134: | ||
// Calculate the Str | // Calculate the Str | ||
function calculateStr(level, rarity) { | 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); | 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); | ||
} | } | ||
</script> | </script> | ||