Difference between revisions of "MediaWiki:Calculator.js/Mana Regeneration.js"

m
m
Line 4: Line 4:
 
var ManaPerSecondCalculator = Calculator.extend({
 
var ManaPerSecondCalculator = Calculator.extend({
 
     init: function() {
 
     init: function() {
         var calculate = function(input, label) {
+
         var calculate = function(meditation, focus, int, mr, label) {
             if (input.value) {
+
             if (!meditation.value || !isNumeric(meditation.value)) meditation.value = '0.0';
                if (isNumeric(input.value)) {
+
            if (!focus.value || !isNumeric(focus.value)) focus.value = '0.0';
                    var percentChance = Math.pow(input.value, (5 / 9));
+
            if (!int.value || !isNumeric(int.value)) int.value = '0';
                    if (percentChance > 100) {
+
            if (!mr.value || !isNumeric(mr.value)) mr.value = '0';
                        percentChance = 100;
+
            var manaPerSecond = 2 / 10;
                    }
+
            removeChildren(label);
                    percentChance = percentChance.toFixed(3);
+
            label.appendChild(document.createTextNode(manaPerSecond + ' Mana Per Second'));
                    removeChildren(label);
+
        };
                    label.appendChild(document.createTextNode(percentChance + '% Chance'));
+
        var detectEnter = function(keyEvent) {
                }
+
             var keyID = window.event ? event.keyCode : keyEvent.keyCode;
             }
+
            if (keyID == 13)
 +
                calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
         };
 
         };
 
         var calcTableRow = document.createElement('tr');
 
         var calcTableRow = document.createElement('tr');
 
         var calcTableCell = document.createElement('td');
 
         var calcTableCell = document.createElement('td');
         var luckInput = document.createElement('input');
+
         var meditationInput = document.createElement('input');
 +
        var focusInput = document.createElement('input');
 +
        var intInput = document.createElement('input');
 +
        var mrInput = document.createElement('input');
 
         var calculateButton = document.createElement('input');
 
         var calculateButton = document.createElement('input');
         var percentChanceLabel = document.createElement('div');
+
         var manaPerSecondLabel = document.createElement('div');
  
 
         calcTableCell.style.textAlign = 'right';
 
         calcTableCell.style.textAlign = 'right';
         calcTableCell.appendChild(document.createTextNode('Luck:'));
+
         calcTableCell.appendChild(document.createTextNode('Meditation:'));
 
         calcTableRow.appendChild(calcTableCell);
 
         calcTableRow.appendChild(calcTableCell);
  
         luckInput.id = 'luckInput';
+
         meditationInput.maxLength = '5';
        luckInput.maxLength = '4';
+
         meditationInput.type = 'text';
         luckInput.type = 'text';
+
         meditationInput.style.width = '45px';
         luckInput.style.width = '35px';
+
         meditationInput.onkeyup = function() {
         luckInput.onkeyup = function(keyEvent) {
+
             detectEnter(keyEvent);
             var keyID = window.event ? event.keyCode : keyEvent.keyCode;
+
            if (keyID == 13)
+
                calculate(luckInput, percentChanceLabel);
+
 
         };
 
         };
 
calcTableCell = document.createElement('td');
 
calcTableCell = document.createElement('td');
         calcTableCell.appendChild(luckInput);
+
         calcTableCell.appendChild(meditationInput);
 
         calcTableRow.appendChild(calcTableCell);
 
         calcTableRow.appendChild(calcTableCell);
  
Line 43: Line 44:
 
         calculateButton.value = 'Calculate >>';
 
         calculateButton.value = 'Calculate >>';
 
         calculateButton.onclick = function() {
 
         calculateButton.onclick = function() {
             calculate(luckInput, percentChanceLabel);
+
             calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
 
         };
 
         };
 
calcTableCell = document.createElement('td');
 
calcTableCell = document.createElement('td');
Line 49: Line 50:
 
         calcTableRow.appendChild(calcTableCell);
 
         calcTableRow.appendChild(calcTableCell);
  
         percentChanceLabel.appendChild(document.createTextNode('0.000% Chance'));
+
         manaPerSecondLabel.appendChild(document.createTextNode('0 Mana Per Second'));
         percentChanceLabel.style.textAlign = 'right';
+
         manaPerSecondLabel.style.textAlign = 'right';
         percentChanceLabel.style.width = '110px';
+
         manaPerSecondLabel.style.width = '120px';
 
calcTableCell = document.createElement('td');
 
calcTableCell = document.createElement('td');
 
         calcTableCell.appendChild(percentChanceLabel);
 
         calcTableCell.appendChild(percentChanceLabel);

Revision as of 12:04, 4 May 2010

/**
 * Calculator that calculates your mana regenerated per second based on Meditation, Focus, Intelligence, and equipped MR.
 */
var ManaPerSecondCalculator = Calculator.extend({
    init: function() {
        var calculate = function(meditation, focus, int, mr, label) {
            if (!meditation.value || !isNumeric(meditation.value)) meditation.value = '0.0';
            if (!focus.value || !isNumeric(focus.value)) focus.value = '0.0';
            if (!int.value || !isNumeric(int.value)) int.value = '0';
            if (!mr.value || !isNumeric(mr.value)) mr.value = '0';
            var manaPerSecond = 2 / 10;
            removeChildren(label);
            label.appendChild(document.createTextNode(manaPerSecond + ' Mana Per Second'));
        };
        var detectEnter = function(keyEvent) {
            var keyID = window.event ? event.keyCode : keyEvent.keyCode;
            if (keyID == 13)
                calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
        };
        var calcTableRow = document.createElement('tr');
        var calcTableCell = document.createElement('td');
        var meditationInput = document.createElement('input');
        var focusInput = document.createElement('input');
        var intInput = document.createElement('input');
        var mrInput = document.createElement('input');
        var calculateButton = document.createElement('input');
        var manaPerSecondLabel = document.createElement('div');

        calcTableCell.style.textAlign = 'right';
        calcTableCell.appendChild(document.createTextNode('Meditation:'));
        calcTableRow.appendChild(calcTableCell);

        meditationInput.maxLength = '5';
        meditationInput.type = 'text';
        meditationInput.style.width = '45px';
        meditationInput.onkeyup = function() {
            detectEnter(keyEvent);
        };
	calcTableCell = document.createElement('td');
        calcTableCell.appendChild(meditationInput);
        calcTableRow.appendChild(calcTableCell);

        calculateButton.type = 'button';
        calculateButton.value = 'Calculate >>';
        calculateButton.onclick = function() {
            calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
        };
	calcTableCell = document.createElement('td');
        calcTableCell.appendChild(calculateButton);
        calcTableRow.appendChild(calcTableCell);

        manaPerSecondLabel.appendChild(document.createTextNode('0 Mana Per Second'));
        manaPerSecondLabel.style.textAlign = 'right';
        manaPerSecondLabel.style.width = '120px';
	calcTableCell = document.createElement('td');
        calcTableCell.appendChild(percentChanceLabel);
        calcTableRow.appendChild(calcTableCell);

        this._super(calcTableRow, 'ManaPerSecond', 'Mana Per Second', 4);
    }
});

function searchForCalculators() {
    var calculators = document.getElementsByTagName('div');

    for (var i in calculators) {
         if (calculators[i].id == 'ManaPerSecond') {
             new ManaPerSecondCalculator();
         }
    }
}
addOnloadHook(searchForCalculators);