MediaWiki:Gadget-HiddenPowerCalculator.js: Difference between revisions

From Squidgy
Jump to navigation Jump to search
Created page with "<form id="dvForm"> <label>Attack DV: <input type="number" id="atk" min="0" max="15" required></label><br> <label>Defense DV: <input type="number" id="def" min="0" max="15" required></label><br> <label>Speed DV: <input type="number" id="spe" min="0" max="15" required></label><br> <label>Special DV: <input type="number" id="spa" min="0" max="15" required></label><br> <button type="button" onclick="calculate()">Calculate</button> </form> <p id="results"></p> <sc..."
 
No edit summary
Line 1: Line 1:
<form id="dvForm">
$(function () {
   <label>Attack DV: <input type="number" id="atk" min="0" max="15" required></label><br>
   const container = document.getElementById('hp-calc-container');
  <label>Defense DV: <input type="number" id="def" min="0" max="15" required></label><br>
   if (!container) return;
  <label>Speed DV: <input type="number" id="spe" min="0" max="15" required></label><br>
   <label>Special DV: <input type="number" id="spa" min="0" max="15" required></label><br>
  <button type="button" onclick="calculate()">Calculate</button>
</form>


<p id="results"></p>
  container.innerHTML = `
    <form id="dvForm">
      <label>Attack DV: <input type="number" id="atk" min="0" max="15" required></label><br>
      <label>Defense DV: <input type="number" id="def" min="0" max="15" required></label><br>
      <label>Speed DV: <input type="number" id="spe" min="0" max="15" required></label><br>
      <label>Special DV: <input type="number" id="spa" min="0" max="15" required></label><br>
      <button type="button" id="calculateBtn">Calculate</button>
    </form>
    <p id="results"></p>
  `;


<script>
  document.getElementById("calculateBtn").addEventListener("click", function () {
function calculate() {
    const atk = parseInt(document.getElementById("atk").value);
  const atk = parseInt(document.getElementById("atk").value);
    const def = parseInt(document.getElementById("def").value);
  const def = parseInt(document.getElementById("def").value);
    const spe = parseInt(document.getElementById("spe").value);
  const spe = parseInt(document.getElementById("spe").value);
    const spa = parseInt(document.getElementById("spa").value);
  const spa = parseInt(document.getElementById("spa").value);


  if ([atk, def, spe, spa].some(n => isNaN(n) || n < 0 || n > 15)) {
    if ([atk, def, spe, spa].some(n => isNaN(n) || n < 0 || n > 15)) {
    document.getElementById("results").innerText = "All values must be between 0 and 15.";
      document.getElementById("results").innerText = "All values must be between 0 and 15.";
    return;
      return;
  }
    }


  // HP DV
    // HP DV
  const hp = ((atk & 1) << 3) | ((def & 1) << 2) | ((spe & 1) << 1) | (spa & 1);
    const hp = ((atk & 1) << 3) | ((def & 1) << 2) | ((spe & 1) << 1) | (spa & 1);


  // Hidden Power Type
    // Hidden Power Type
  const typeId = 4 * (atk % 4) + (def % 4);
    const typeId = 4 * (atk % 4) + (def % 4);
  const hpTypes = [
    const hpTypes = [
    "Fighting", "Flying", "Poison", "Ground", "Rock", "Bug", "Ghost", "Steel",
      "Fighting", "Flying", "Poison", "Ground", "Rock", "Bug", "Ghost", "Steel",
    "Fire", "Water", "Grass", "Electric", "Psychic", "Ice", "Dragon", "Dark"
      "Fire", "Water", "Grass", "Electric", "Psychic", "Ice", "Dragon", "Dark"
  ];
    ];
  const hpType = hpTypes[typeId];
    const hpType = hpTypes[typeId];


  // Hidden Power Power
    // Hidden Power Power
  const v = spa >= 8 ? 1 : 0;
    const v = spa >= 8 ? 1 : 0;
  const w = spe >= 8 ? 1 : 0;
    const w = spe >= 8 ? 1 : 0;
  const x = def >= 8 ? 1 : 0;
    const x = def >= 8 ? 1 : 0;
  const y = atk >= 8 ? 1 : 0;
    const y = atk >= 8 ? 1 : 0;
  const z = spa % 4;
    const z = spa % 4;
  const power = Math.floor((5 * (v + 2 * w + 4 * x + 8 * y) + z) * 40 / 63);
    const power = Math.floor((5 * (v + 2 * w + 4 * x + 8 * y) + z) * 40 / 63);


  // Shininess check
    // Shininess
  const shiny = [2,3,6,7,10,11,14,15].includes(atk) && def === 10 && spe === 10 && spa === 10;
    const shiny = [2, 3, 6, 7, 10, 11, 14, 15].includes(atk) && def === 10 && spe === 10 && spa === 10;


  document.getElementById("results").innerHTML = `
    document.getElementById("results").innerHTML = `
    <strong>HP DV:</strong> ${hp}<br>
      <strong>HP DV:</strong> ${hp}<br>
    <strong>Hidden Power:</strong> ${hpType} (${power} Power)<br>
      <strong>Hidden Power:</strong> ${hpType} (${power} Power)<br>
    <strong>Shiny:</strong> ${shiny ? "Yes ✨" : "No"}
      <strong>Shiny:</strong> ${shiny ? "Yes ✨" : "No"}
  `;
    `;
}
  });
</script>
});

Revision as of 13:55, 14 May 2025

$(function () {
  const container = document.getElementById('hp-calc-container');
  if (!container) return;

  container.innerHTML = `
    <form id="dvForm">
      <label>Attack DV: <input type="number" id="atk" min="0" max="15" required></label><br>
      <label>Defense DV: <input type="number" id="def" min="0" max="15" required></label><br>
      <label>Speed DV: <input type="number" id="spe" min="0" max="15" required></label><br>
      <label>Special DV: <input type="number" id="spa" min="0" max="15" required></label><br>
      <button type="button" id="calculateBtn">Calculate</button>
    </form>
    <p id="results"></p>
  `;

  document.getElementById("calculateBtn").addEventListener("click", function () {
    const atk = parseInt(document.getElementById("atk").value);
    const def = parseInt(document.getElementById("def").value);
    const spe = parseInt(document.getElementById("spe").value);
    const spa = parseInt(document.getElementById("spa").value);

    if ([atk, def, spe, spa].some(n => isNaN(n) || n < 0 || n > 15)) {
      document.getElementById("results").innerText = "All values must be between 0 and 15.";
      return;
    }

    // HP DV
    const hp = ((atk & 1) << 3) | ((def & 1) << 2) | ((spe & 1) << 1) | (spa & 1);

    // Hidden Power Type
    const typeId = 4 * (atk % 4) + (def % 4);
    const hpTypes = [
      "Fighting", "Flying", "Poison", "Ground", "Rock", "Bug", "Ghost", "Steel",
      "Fire", "Water", "Grass", "Electric", "Psychic", "Ice", "Dragon", "Dark"
    ];
    const hpType = hpTypes[typeId];

    // Hidden Power Power
    const v = spa >= 8 ? 1 : 0;
    const w = spe >= 8 ? 1 : 0;
    const x = def >= 8 ? 1 : 0;
    const y = atk >= 8 ? 1 : 0;
    const z = spa % 4;
    const power = Math.floor((5 * (v + 2 * w + 4 * x + 8 * y) + z) * 40 / 63);

    // Shininess
    const shiny = [2, 3, 6, 7, 10, 11, 14, 15].includes(atk) && def === 10 && spe === 10 && spa === 10;

    document.getElementById("results").innerHTML = `
      <strong>HP DV:</strong> ${hp}<br>
      <strong>Hidden Power:</strong> ${hpType} (${power} Power)<br>
      <strong>Shiny:</strong> ${shiny ? "Yes ✨" : "No"}
    `;
  });
});