Difference between revisions of "Widget:AdventurerPageStatsCalculator"

From Dragalia Lost Wiki
Jump to navigation Jump to search
imported>Elaeagnifolia
imported>Elaeagnifolia
Line 1: Line 1:
 +
<includeonly><script type="text/javascript">const MIN_LEVEL = 1;
 +
const MAX_LEVEL = 80;
 +
const MIN_HP = [1,15,30];
 +
const MAX_HP = 81;
 +
const MIN_STR = [5,30,50];
 +
const MAX_STR = 159;
 +
const NAT_RARITY = 3;
 +
const PROMO_HP_4 = 27;
 +
const PROMO_HP_5 = 16;
 +
const PROMO_STR_4 = 27;
 +
const PROMO_STR_5 = 16;
 +
 +
calcStats();
 +
 +
function calcStats() {
 +
  var levelInput = document.getElementById('adv-level-input-field');
 +
  var level = levelInput.value;
 +
  var rarity = document.querySelector('input[name = "rarity"]:checked').value;
 +
  switch (rarity) {
 +
    case "3":
 +
      level = 60;
 +
      levelInput.value = "60";
 +
      break;
 +
    case "4":
 +
      level = 70;
 +
      levelInput.value = "70";
 +
      break;
 +
  }
 +
 
 +
  if(validateLevel(level)) {
 +
    setHP(calculateHP(level, rarity))
 +
    setStr(calculateStr(level, rarity))
 +
  } else {
 +
    setHP("-");
 +
    setStr("-");
 +
  }
 +
}
 +
 +
function validateLevel(value) {
 +
  if(isNaN(value) || value == "") {
 +
    return false;
 +
  }
 +
  return true;
 +
}
 +
 +
function setHP(value) {
 +
  document.getElementById("adv-hp").innerHTML = value;
 +
}
 +
 +
function setStr(value) {
 +
  document.getElementById("adv-str").innerHTML = value;
 +
}
 +
 +
function calculateHP(level, rarity) {
 +
  var levelDiff = MAX_LEVEL - MIN_LEVEL;
 +
  var steps = (MAX_HP - MIN_HP[rarity-3]) / levelDiff;
 +
  var statGain = (level-1) * steps;
 +
  return Math.ceil(MIN_HP[rarity-3] + statGain);
 +
}
 +
 +
function calculateStr(level, rarity) {
 +
  var levelDiff = MAX_LEVEL - MIN_LEVEL;
 +
  var steps = (MAX_STR - MIN_STR[rarity-3]) / levelDiff;
 +
  var statGain = (level-1) * steps;
 +
  return Math.ceil(MIN_STR[rarity-3] + statGain);
 +
}
 +
</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;">
 
   <form id="adv-rarity-select" style="display:inline;">
 
   <form id="adv-rarity-select" style="display:inline;">

Revision as of 15:32, 16 October 2018