Widget:Calculator/Combat/Max Hit: Difference between revisions

No edit summary
No edit summary
 
(One intermediate revision by the same user not shown)
Line 18: Line 18:
         <td>
         <td>
           <span class="max-hit-calc__stat-label">
           <span class="max-hit-calc__stat-label">
            <img src="/w/images/thumb/1/1b/Strength_icon.png/20px-Strength_icon.png" alt="Strength icon" width="20" height="20">
             Strength Level
             Strength Level
           </span>
           </span>
Line 29: Line 28:
         <td>
         <td>
           <span class="max-hit-calc__stat-label">
           <span class="max-hit-calc__stat-label">
            <img src="/w/images/thumb/c/c5/Strength_bonus_icon.png/20px-Strength_bonus_icon.png" alt="Strength bonus icon" width="20" height="20">
             Strength Bonus
             Strength Bonus
           </span>
           </span>
Line 40: Line 38:
         <td>
         <td>
           <span class="max-hit-calc__stat-label">
           <span class="max-hit-calc__stat-label">
            <img src="/w/images/thumb/4/4b/Training_icon.png/20px-Training_icon.png" alt="Training icon" width="20" height="20">
             Training Style
             Training Style
           </span>
           </span>
Line 71: Line 68:
     let strengthBonus = parseInt(strengthBonusInput.value, 10) || 0;
     let strengthBonus = parseInt(strengthBonusInput.value, 10) || 0;
     const trainingStyle = trainingStyleSelect.value;
     const trainingStyle = trainingStyleSelect.value;
   
 
    // Check for the specific base case
     // Clamp values
    if (strengthLevel === 1 && strengthBonus === 0) {
      maxHitResultEl.textContent = 1;
      return;
    }
   
     // Ensure inputs are within valid range
     strengthLevel = Math.max(1, Math.min(100, strengthLevel));
     strengthLevel = Math.max(1, Math.min(100, strengthLevel));
     strengthBonus = Math.max(0, strengthBonus);
     strengthBonus = Math.max(0, strengthBonus);
   
 
     // Apply training style bonus
     // Base effective strength
     let effectiveStrength;
     let effectiveStrength = strengthLevel + 8;
 
    // Extra +3 only if "Strength" training style is selected
     if (trainingStyle === 'strength') {
     if (trainingStyle === 'strength') {
       effectiveStrength = strengthLevel + 3;
       effectiveStrength += 3;
    } else if (trainingStyle === 'all') {
      effectiveStrength = strengthLevel + 1;
    } else {
      effectiveStrength = strengthLevel;
     }
     }


     const calculatedHit = (
    // Apply formula
        1.70 +  
     const calculatedHit = 1 + ((effectiveStrength * (strengthBonus + 64)) / 640);
        0.1085 * effectiveStrength +
     const maxHit = Math.floor(calculatedHit);
        0.0131 * strengthBonus -
        0.0003 * (effectiveStrength ** 2) +
        0.0020 * effectiveStrength * strengthBonus -
        0.0002 * (strengthBonus ** 2)
     );


    const maxHit = Math.max(1, Math.round(calculatedHit));
   
     maxHitResultEl.textContent = maxHit;
     maxHitResultEl.textContent = maxHit;
   }
   }


  // Attach event listeners to all inputs and the select dropdown
   document.addEventListener('DOMContentLoaded', () => {
   document.addEventListener('DOMContentLoaded', () => {
     strengthLevelInput.addEventListener('input', calculateMaxHit);
     strengthLevelInput.addEventListener('input', calculateMaxHit);
     strengthBonusInput.addEventListener('input', calculateMaxHit);
     strengthBonusInput.addEventListener('input', calculateMaxHit);
     trainingStyleSelect.addEventListener('change', calculateMaxHit);
     trainingStyleSelect.addEventListener('change', calculateMaxHit);
     calculateMaxHit(); // Initial calculation on page load
     calculateMaxHit();
   });
   });
})();
})();
</script>
</script>