Calculator Script

<p><b>Welcome to Battle Cats Stats Calculator!</b></p><p><b></b></p><div class="separator" style="clear: both; text-align: center;"><b><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEg3CkzsF-i7d7dgirBMrQ6rX1I24peWXtoEEXWyitczQy2TUr_VwMh9NhsYVumKlzKiaXn9AJngq1Vej5Zb0Pzgf6hBXT4q6_XS--D4KrR-m4F9mrw3Hqzo5XgBA2PKAiJJAdy7feVpQ2f5NDIWLyN3QZdDmQe05t1DcSa3kxrPe7sEo3KHz9brhkMbrw" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="1080" data-original-width="1920" src="https://blogger.googleusercontent.com/img/a/AVvXsEg3CkzsF-i7d7dgirBMrQ6rX1I24peWXtoEEXWyitczQy2TUr_VwMh9NhsYVumKlzKiaXn9AJngq1Vej5Zb0Pzgf6hBXT4q6_XS--D4KrR-m4F9mrw3Hqzo5XgBA2PKAiJJAdy7feVpQ2f5NDIWLyN3QZdDmQe05t1DcSa3kxrPe7sEo3KHz9brhkMbrw=s16000" /></a></div></b></div><p></p><p>Before we get started, there are some few things to understand how to use the calculator.<br />The aim of the calculator is to calculate the base HP, base DAMAGE, cooldown and cost of a unit. The calculator is design only for battle dogs and custom units.<br /><br />Let's go to the example.<br /><br />Example: <b>Chickful A (Angel)</b></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEgXW_eXDVGkBHUwk5XP3X1ieU20rS7kD7YdXQ5DY838gU32RhnDtSYL1LX0-EHMGnWkxRpUm8d4JcI1inRUbsZmG8MVN3FXPWb-lEIXaJHqNSaL4YDCSG0DI8qwQTK0oGaqtcz9e-hE9XtHdI0EM3ZxwK9r1QqyUwpVS8etThbRKuWq0o_NHSSFcQkv9Q" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="315" data-original-width="269" height="240" src="https://blogger.googleusercontent.com/img/a/AVvXsEgXW_eXDVGkBHUwk5XP3X1ieU20rS7kD7YdXQ5DY838gU32RhnDtSYL1LX0-EHMGnWkxRpUm8d4JcI1inRUbsZmG8MVN3FXPWb-lEIXaJHqNSaL4YDCSG0DI8qwQTK0oGaqtcz9e-hE9XtHdI0EM3ZxwK9r1QqyUwpVS8etThbRKuWq0o_NHSSFcQkv9Q" width="205" /></a></div><br /><b>Steps</b>:<br /><ul style="text-align: left;"><li>Lists the unit <b>final HP and final Damage</b> (stick to 100% buffness).</li><li>We can see that he has <b>160,000 HP</b> and <b>13,000 DMG</b>. These are final damage and final HP of the unit.</li></ul><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjb9dYc7oWZobFG_8DSM__OX1sDaGyipBVRgPMOy7i8Gh6kvQSu75C7QS9pst-PKgXu0gPzs5t3hQ-zciCq6H_Y99FaCj_EMiNM0FKA3k3PearxKJUtlLjaDDzcy-0gupYjvVbFLlS8j32n8Hqc72Yr2e78hDhF6ESXCZiYbmOPghWfE0jDqDd4FJI7aQ" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="128" data-original-width="191" height="214" src="https://blogger.googleusercontent.com/img/a/AVvXsEjb9dYc7oWZobFG_8DSM__OX1sDaGyipBVRgPMOy7i8Gh6kvQSu75C7QS9pst-PKgXu0gPzs5t3hQ-zciCq6H_Y99FaCj_EMiNM0FKA3k3PearxKJUtlLjaDDzcy-0gupYjvVbFLlS8j32n8Hqc72Yr2e78hDhF6ESXCZiYbmOPghWfE0jDqDd4FJI7aQ" width="320" /></a></div><ul style="text-align: left;"><li>Choose a battle cats unit where you want to replace this enemy unit.</li><li>Example we will replace this to Kotatsu Cat</li></ul><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEg8Vrmyeiw2oS4IaopGSTkYPWPjlEJUHludHj5T5ZTjaLBzR44gQrRhJBPBR6U2vWzOyV8n4pwsRt3ZMqmLGA_A7CMxnfU5mibnqbRHhkdZrQoCHphqdqxB1rHfEhIY7J3QFKOtsSY9IQyedRB-Nxg2FK1Ba0G4uDPeg1PKHcN_cCbafj4S9njXBD91xQ" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="128" data-original-width="128" height="240" src="https://blogger.googleusercontent.com/img/a/AVvXsEg8Vrmyeiw2oS4IaopGSTkYPWPjlEJUHludHj5T5ZTjaLBzR44gQrRhJBPBR6U2vWzOyV8n4pwsRt3ZMqmLGA_A7CMxnfU5mibnqbRHhkdZrQoCHphqdqxB1rHfEhIY7J3QFKOtsSY9IQyedRB-Nxg2FK1Ba0G4uDPeg1PKHcN_cCbafj4S9njXBD91xQ" width="240" /></a><br /></div><p></p><p></p><ul style="text-align: left;"><li>Check Kotatsu Cat's, <b>final level</b> which is 50+70 = 120.</li></ul><p></p><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhlpvYcMsK-dM6u7-breWLAnoj60mZVX5HQ9cf0uGUGbgosFt5QeFCtGJxPw9X6YykcWNWmjhGQl2XQZPUtMGRIFPcCjPzqu_7Sl4-yAVStOIX1a1ORs1E-Vj5inEZP5-bkYJXISl_xIhc3reY3jev6G1Cmnn4WqCOSa-lC2Fnw5yW_DPLZzjSRPa6LcA" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="154" data-original-width="138" height="240" src="https://blogger.googleusercontent.com/img/a/AVvXsEhlpvYcMsK-dM6u7-breWLAnoj60mZVX5HQ9cf0uGUGbgosFt5QeFCtGJxPw9X6YykcWNWmjhGQl2XQZPUtMGRIFPcCjPzqu_7Sl4-yAVStOIX1a1ORs1E-Vj5inEZP5-bkYJXISl_xIhc3reY3jev6G1Cmnn4WqCOSa-lC2Fnw5yW_DPLZzjSRPa6LcA" width="215" /></a></div><div><ul style="text-align: left;"><li>Check the <b>Initial Damage (dmg at Lvl 1)</b> and <b>Final Damage (dmg at max level)</b>&nbsp;of the cat to be replaced which is Kotatsu Cat having 100, and 4,200 damages respectively.</li></ul><div class="separator" style="clear: both; text-align: center;"><div class="separator" style="clear: both; text-align: left;"><div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEhYqxf9cfrlzsxTpRIfana_9f1vSXTFbs0w-ZErQiihVpS0fmpxf9fWZFwv6h3pbC43LgGiFtPOc_hmJObaAMkM8x5tFI3ysXboTHziwgzNKum9qazC5caUQjRX6Tg5gD1LE9AUHdSWGEkI1PBKMFK6Enc1c_VQZ0ZRIv4nfVEq-6lrMczzjbAMrmcXnw" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="142" data-original-width="266" height="171" src="https://blogger.googleusercontent.com/img/a/AVvXsEhYqxf9cfrlzsxTpRIfana_9f1vSXTFbs0w-ZErQiihVpS0fmpxf9fWZFwv6h3pbC43LgGiFtPOc_hmJObaAMkM8x5tFI3ysXboTHziwgzNKum9qazC5caUQjRX6Tg5gD1LE9AUHdSWGEkI1PBKMFK6Enc1c_VQZ0ZRIv4nfVEq-6lrMczzjbAMrmcXnw" width="320" /></a></div></div></div></div><ul style="text-align: left;"><li>Once you have gathered these inputs, then you can now use the calculator. We know before using the calculator you need to know the final HP and final DAMAGE of the enemy unit and the max level of the cat unit to be replaced.</li><li>The <b>buff allows you to multiply</b> the HP and DMG into some type of percentage. You can multiply it by 2 by changing buffness to 200. The original stats is 100%.</li></ul><div><b>Algorithm</b></div>

<script async="" crossorigin="anonymous" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6328531102448868"></script>

<!--PTC SQUARE FIXED-->

<ins class="adsbygoogle" data-ad-client="ca-pub-6328531102448868" data-ad-slot="4340730995" style="display: inline-block; height: 250px; width: 300px;"></ins>

<script>

     (adsbygoogle = window.adsbygoogle || []).push({});

</script>

<div>The calculator uses a formula (general formula) to compute these stats about levelling and mechanics.<br />Please refer to this website to <a href="https://thanksfeanor.pythonanywhere.com/guides/documents/levelling-and-stat-mechanics.html" target="_blank">know more.</a><br /><br /> 

  <div class="separator" style="clear: both; text-align: center;"><a href="https://blogger.googleusercontent.com/img/a/AVvXsEjHqF5UeiY8hsOm_DehhGyLmfDsIPRIznjT6unxKeIO66Tnpcx7UjZPwDhGpce9F5hYEfSFhIryBS26c8tYnPqZEwnFSBhJd0S9yUD02sDAcjODz7WwfM1lTN97STb1rRumzwS5_5z6o7CIu8A7EG4_sVnio0-eK-XLwusJYg4vvTa4qgOM2JqgFbsQsg" style="margin-left: 1em; margin-right: 1em;"><img alt="" data-original-height="51" data-original-width="455" src="https://blogger.googleusercontent.com/img/a/AVvXsEjHqF5UeiY8hsOm_DehhGyLmfDsIPRIznjT6unxKeIO66Tnpcx7UjZPwDhGpce9F5hYEfSFhIryBS26c8tYnPqZEwnFSBhJd0S9yUD02sDAcjODz7WwfM1lTN97STb1rRumzwS5_5z6o7CIu8A7EG4_sVnio0-eK-XLwusJYg4vvTa4qgOM2JqgFbsQsg=s16000" /></a><br /><div style="text-align: left;"><br /></div></div></div>


<blockquote>You can find the stats of cat units in the <a href="https://battle-cats.fandom.com/wiki/Cat_Release_Order" target="_blank">battle cats wiki fandom.</a></blockquote>


<div id='ptc_calculator' style="background-color: black; color: white; display: inline-block; height: auto; padding-bottom: 20px; text-align: center; width: 100%;">

  <h1 style="color: white; margin-bottom: -1px; margin-top: 20px;">The Battle Cats Calculator</h1>

  <small>By PTC Reborn Feb. 27, 2023</small>

  <div style="display: block; margin-left: 20px; margin-top: 10px; text-align: center;">

    <p style="display: inline-block; margin: auto;">Chosen Enemy HP: </p>

    <input placeholder='Final HP' class="inputDesign" id="finalHP" style="background-color: black; color: white; display: inline-block; font-size: 14px; margin: auto; text-align: center; width: 50%;" type="text" />

  </div>

  <div style="display: block; margin-left: 20px; margin-top: 10px; text-align: center;">

    <p style="display: inline-block; margin: auto;">Chosen Enemy DMG: </p>

    <input placeholder='Final DMG' class="inputDesign" id="finalDMG" style="background-color: black; color: white; display: inline-block; font-size: 14px; margin: auto; text-align: center; width: 50%;" type="text" />

  </div>

  <div style="display: block; margin-left: 20px; margin-top: 10px; text-align: center;">

    <p style="display: inline-block; margin: auto;">Chosen Enemy DPS: </p>

    <input placeholder='DPS' class="inputDesign" id="finalDPS" style="background-color: black; color: white; display: inline-block; font-size: 14px; margin: auto; text-align: center; width: 50%;" type="text" />

  </div>

  <div style="display: block; margin-left: 20px; margin-top: 10px; text-align: center;">    

    <p style="display: inline-block;">Cat Rarity: </p>

    <select id="Rarity" name="rarity" style='display: inline-block; text-align: center; width: 50%; background-color: black; color: white;'>

      <option value="nc">Normal Cats</option>

      <option value="sc">Special Cats</option>

      <option value="bc">Bahamut Cats</option>

      <option value="rc">Rare Cats</option>

      <option value="src">Super Rare Cats</option>

      <option value="cc">Crazed Cats</option>

      <option value="usrc">Uber Super Rare Cats</option>

      <option value="oc">Other Cats</option>      

  </select>

  </div>

  <div style="display: block; margin: 5px 0px 0px 20px; text-align: center;">

    <p style="display: inline-block; margin: auto;">Cat Number of levels: </p>

    <input placeholder='Levels' class="inputDesign" id="numLevels" style="background-color: black; color: white; display: inline-block; font-size: 14px; margin: auto; text-align: center; width: 50%;" type="number" />

  </div>

  <div style="display: block; margin: 5px 0px 0px 20px; text-align: center;">

    <p style="display: inline-block; margin: auto;">Buffness(100% is original): </p>

    <input placeholder='Buffness' class="inputDesign" id="buffness" style="background-color: black; color: white; display: inline-block; font-size: 14px; margin: auto; text-align: center; width: 50%;" type="number" />

  </div>

  <div style="display: block; margin: 5px 0px 0px 20px; text-align: center;">

    <p>Base HP: <span id="baseHP" style="color: #09ff00;">unknown</span>

    </p>

    <p>Base DMG: <span id="baseDMG" style="color: #09ff00;">unknown</span>

    </p>

    <p>Cooldown: <span id="cooldown" style="color: #09ff00;">unknown</span>

    </p>

    <p>Cost: <span id="cost" style="color: #09ff00;">unknown</span>

    </p>

    <p>Buffed: <span id="buff" style="color: #09ff00;">unknown</span>

    </p>

  </div>

  <div height="400px" style="display: block; height: 300px; width: 100%;" width="100%">

    <script async="" crossorigin="anonymous" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6328531102448868"></script>

    <!--PTC SQUARE FIXED-->

    <ins class="adsbygoogle" data-ad-client="ca-pub-6328531102448868" data-ad-slot="4340730995" style="display: inline-block; height: 250px; width: 300px;"></ins>

    <script>

      (adsbygoogle = window.adsbygoogle || []).push({});

    </script>

  </div>

  <div style="display: block; text-align: center;">

    <button class="button-13" id="calculateBHP" role="button" style="font-size: 12px; margin-top: 10px; width: 40%;"> Calculate </button>

    <button class="button-13" id="reset" role="button" style="font-size: 12px; margin-top: 10px; width: 40%;"> Reset </button>

  </div>

</div>


<script>

  let healthLists = [1000, 2500, 5000, 7500, 10000, 20000, 25000, 50000, 100000, 250000, 500000, 1000000, 5000000, 10000000, 25000000, 500000000, 100000000, 250000000, 500000000, 750000000, 1000000000];

  let costLists = [75, 90, 120, 150, 180, 300, 450, 600, 750, 900, 1200, 1500, 1800, 2400, 3000, 4500, 6000, 7500, 9000, 12000, 15000];

  let rarity = ['nc', 'sc', 'bc', 'rc', 'src', 'cc', 'usrc', 'oc'];

  let firstReduction = [60, 60, 30, 70, 60, 20, 60, 0];

  let secondReduction = [0, 0, 0, 90, 80, 0, 80, 0];

  document.getElementById('calculateBHP').addEventListener('click', checkInputs, false);

  getElemById('reset').addEventListener('click', resetFields, false);

  getElemById('finalHP').addEventListener('keyup', (event) => {

    getElemById('finalHP').value = numberWithCommas(getElemById('finalHP').value.replaceAll(",", ""));

  }, false);

  getElemById('finalDMG').addEventListener('keyup', (event) => {

    getElemById('finalDMG').value = numberWithCommas(getElemById('finalDMG').value.replaceAll(",", ""));

  }, false);

  getElemById('finalDPS').addEventListener('keyup', (event) => {

    getElemById('finalDPS').value = numberWithCommas(getElemById('finalDPS').value.replaceAll(",", ""));

  }, false);

  

  function returnReductionLevel(index, redPos) {

if (redPos == 1) return firstReduction[index];

    else if (redPos == 2) return secondReduction[index];

  }

  function calculateNormal(finalStat, numLevels) {    

    return Math.floor(finalStat / (((numLevels + 4)/5)*2.5));

  }

  function calculateFirstRed(finalStat, numLevels, index) {

    let m = returnReductionLevel(index, 1);

    return Math.floor(finalStat /((((m + 4) / 5) + ((numLevels - m) / 10)) * 2.5));

  }

  function calculateSecondRed(finalStat, numLevels, index) {

    let m = returnReductionLevel(index, 1);

    let p = returnReductionLevel(index, 2);

    return Math.floor(finalStat /((((m+4)/5) + ((p-m)/10) + ((numLevels-p)/20)) * 2.5));

  }

  

  function calculateStats(finalStat, numLevels, rarity) {

    let statsCalc = 0;

    let index = 0;

    switch(rarity) {

      case 'nc': 

        if(numLevels < returnReductionLevel(0, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 0);

        index = 0;

      break;

      case 'sc': 

        if(numLevels < returnReductionLevel(1, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 1);

        index = 1;

        break;

      case 'bc': 

        if(numLevels < returnReductionLevel(2, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 2);

        index = 2;

        break;

      case 'rc': 

        if(numLevels > returnReductionLevel(3, 2)) statsCalc=calculateSecondRed(finalStat, numLevels, 3);

        else if(numLevels < returnReductionLevel(3, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 3);

        index = 3;

        break;

      case 'src': 

        if(numLevels > returnReductionLevel(4, 2)) statsCalc=calculateSecondRed(finalStat, numLevels, 4);

        else if(numLevels < returnReductionLevel(4, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 4);

        index = 4;

        break;

      case 'cc': 

        if(numLevels < returnReductionLevel(5, 0)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 5);

        index = 5;

        break;

      case 'usrc': 

        if(numLevels > returnReductionLevel(6, 2)) statsCalc=calculateSecondRed(finalStat, numLevels, 6);

        else if(numLevels < returnReductionLevel(6, 1)) statsCalc= calculateNormal(finalStat, numLevels);

        else statsCalc = calculateFirstRed(finalStat, numLevels, 6);

        index = 6;

        break;

      case 'oc': 

        statsCalc= calculateNormal(finalStat, numLevels);

        index = 7;

        break;

    }

    console.log(index);

    return statsCalc;

  }


  function getElemById(id) {

    return document.getElementById(id);

  }


  function resetFields() {

    getElemById('finalHP').value = '';

    getElemById('numLevels').value = '';

    getElemById('finalDMG').value = '';

    getElemById('finalDPS').value = '';

    getElemById('initDMG').value = '';

    getElemById('maxDMG').value = '';

    getElemById('buffness').value = '';

    getElemById('baseHP').innerText = 'unknown';

    getElemById('baseDMG').innerText = 'unknown';

    getElemById('cooldown').innerText = 'unknown';

    getElemById('cost').innerText = 'unknown';

    getElemById('buff').innerText = 'unknown';

  }


  function getBuyCost(finalHP) {

    //if((int)(baseHP / 6.17 / 2) >= 9000) return 8250;

    let cost = 75;

    for (let a = 0; a < healthLists.length; a++) {

      if (finalHP < healthLists[a]) {

        cost = costLists[a];

        break;

      }

    }

    return cost;

    //if((int)(baseHP * 0.0005556) >= 11000) return 11000;

    //else return (int)(baseHP / 6.17 / 2);

    //else return (int)(baseHP * 0.0005556);

  }


  function checkInputs() {

    if (getElemById('finalHP').value.replaceAll(",", "") > 0 && getElemById('numLevels').value > 0 && getElemById('finalDMG').value.replaceAll(",", "") > 0 && getElemById('buffness').value.replaceAll(",", "") > 0 && getElemById('finalDPS').value.replaceAll(",", "") > 0) {

      calculateBHP(getElemById('finalHP').value.replaceAll(",", ""), 

                   getElemById('numLevels').value, getElemById('finalDMG').value.replaceAll(",", ""),

                  getElemById('Rarity').value);

    } else {

      window.alert('Complete all the fields and enter only numeric value greater than 0!');

    }

  }


  function multiplier(level) {

    return (2 + (level / 2.0));

  }


  function getCooldown(finalDPS) {

    //if (Math.ceil(baseHP / 308.5) >= 950) return 950;

    return Math.floor(finalDPS / 53.24);

  }


  function getBaseDMG(maxDMG, initDMG, finalDmg) {

    let baseDMG = Math.ceil((finalDmg * (getElemById('buffness').value / 100)) - (maxDMG - initDMG));

    if (baseDMG <= 100) return initDMG;

    else return baseDMG;

    //return Math.ceil(finalDmg / multiplier(numOfLvl));

    //return (long)(finalDmg - ((numOfLvl-1) * additive));

  }


  function calculateBHP(finalHP, numOfLvl, finalDMG, rarity) {    

    let buffmult = getElemById('buffness').value / 100;

    finalHP = Math.floor(parseInt(finalHP) * buffmult);

    numOfLvl = Math.floor(parseInt(numOfLvl) * buffmult);

    finalDMG = Math.floor(parseInt(finalDMG) * buffmult);

    let baseHP = Math.floor(calculateStats(finalHP, numOfLvl, rarity));

    let baseDMG = Math.floor(calculateStats(finalDMG, numOfLvl, rarity));

    let incHp = Math.floor((finalHP - baseHP) / (numOfLvl - 1));

    let incDmg = Math.floor((finalDMG - baseDMG) / (numOfLvl - 1));

    let baseHP1 = Math.ceil(finalHP / multiplier(numOfLvl) * (buffmult / 100));    

    let DPS = Math.floor(getElemById('finalDPS').value.replaceAll(",","") * buffmult);

    getElemById('baseHP').innerText = '[' + numberWithCommas(baseHP) + '] each lvl+1 ~ (+' + numberWithCommas(incHp) + ' hp.)';

    getElemById('baseDMG').innerText = '[' + numberWithCommas(baseDMG) + '] each lvl+1 ~ (+' + numberWithCommas(incDmg) + ' dmg.)';

    getElemById('cooldown').innerText = numberWithCommas(getCooldown(DPS)) + ' seconds / ' +  numberWithCommas(getCooldown(DPS) * 15) + ' frames.';

    getElemById('cost').innerHTML = '₵' + numberWithCommas(getBuyCost(finalHP));

    getElemById('buff').innerHTML = getElemById('buffness').value + '% | Final HP: ' +  numberWithCommas(finalHP) + ' | Final DMG: ' + numberWithCommas(finalDMG);

  }


  function numberWithCommas(x) {

    return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");

  }

</script>