function calculateCaptureRate() {
var pokemonHP = parseFloat(document.getElementById("pokemonHP").value);
var currentHP = parseFloat(document.getElementById("currentHP").value);
var statusCondition = parseInt(document.getElementById("statusCondition").value);
var ballType = parseFloat(document.getElementById("ballType").value);
var level = parseFloat(document.getElementById("level").value);
var captureRateBase = parseFloat(document.getElementById("captureRateBase").value);
var resultElement = document.getElementById("result");
if (isNaN(pokemonHP) || isNaN(currentHP) || isNaN(statusCondition) || isNaN(ballType) || isNaN(level) || isNaN(captureRateBase) ||
pokemonHP <= 0 || currentHP <= 0 || level <= 0 || captureRateBase 255) {
resultElement.textContent = "Please enter valid positive numbers for all fields, and ensure Base Capture Rate is between 0 and 255.";
return;
}
var hpFactor = (2 * pokemonHP – currentHP) / (2 * pokemonHP);
var statusFactor = 1;
if (statusCondition === 1) {
statusFactor = 2;
} else if (statusCondition === 2) {
statusFactor = 1.5;
}
var catchFactor = ((captureRateBase * 3 * hpFactor) + statusFactor) * ballType;
// Ensure catchFactor doesn't exceed the maximum possible value for a single shake
var maxCatchFactor = 255;
if (catchFactor > maxCatchFactor) {
catchFactor = maxCatchFactor;
}
// The actual probability involves simulating the shake mechanics,
// which is quite complex and involves random numbers.
// This calculator provides the "catch factor" which is a primary determinant.
// A higher catch factor increases the probability of capture.
// For simplicity, we'll display the catch factor as an indicator.
// A common threshold for a good chance is a catch factor around 100 or more.
// The actual calculation for a specific shake involves comparing this
// to a random number generated for each stage of the shake animation.
resultElement.textContent = "Calculated Catch Factor: " + catchFactor.toFixed(2);
resultElement.textContent += ". Higher values increase capture chance.";
}