MediaWiki:Calculator.js/Mana Regeneration.js

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Clear the cache in Tools → Preferences
/**
 * 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) {
            var medBonus = 1.0;
            if (!meditation.value || !isNumeric(meditation.value)) {
                meditation.value = '0.0';
            } else if (meditation.value >= 100) {
                medBonus = 1.1;
                if (meditation.value > 120) {
                    meditation.value = '120.0'
                }
            }

            if (!focus.value || !isNumeric(focus.value)) {
                focus.value = '0.0';
            } else if (focus.value > 120) {
                focus.value = '120.0';
            }

            if (!int.value || !isNumeric(int.value)) {
                int.value = '0';
            } else if (int.value > 200) {
                int.value = '200';
            }

            if (!mr.value || !isNumeric(mr.value)) {
                mr.value = '0';
            } else if (mr.value > 18) {
                mr.value = '18';
            }

            var manaPerSecond = ((2 + ((medBonus * ((parseFloat(meditation.value) * 3) + parseInt(int.value, 10))) / 40)) + (parseFloat(focus.value) / 20) + parseInt(mr.value)) / 10;
            manaPerSecond = manaPerSecond.toFixed(3);
            removeChildren(label);
            label.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
        };
        var detectEnter = function(keyEvent) {
            var keyID = window.event ? event.keyCode : keyEvent.keyCode;
            if (keyID == 13)
                calculate(meditationInput, focusInput, intInput, mrInput, manaPerSecondLabel);
        };
        var innerBody = document.createElement('tbody');
        var innerRow = document.createElement('tr');
        var innerCell = 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');

        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Meditation:'));
        innerRow.appendChild(innerCell);

        meditationInput.maxLength = '5';
        meditationInput.type = 'text';
        meditationInput.style.width = '50px';
        meditationInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'left';
        innerCell.appendChild(meditationInput);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Focus:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        focusInput.maxLength = '5';
        focusInput.type = 'text';
        focusInput.style.width = '50px';
        focusInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(focusInput);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Intelligence:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        intInput.maxLength = '3';
        intInput.type = 'text';
        intInput.style.width = '50px';
        intInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(intInput);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'right';
        innerCell.appendChild(document.createTextNode('Equipped MR:'));
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        mrInput.maxLength = '3';
        mrInput.type = 'text';
        mrInput.style.width = '50px';
        mrInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.appendChild(mrInput);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

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

        manaPerSecondLabel.appendChild(document.createTextNode('0 MPS'));
        manaPerSecondLabel.style.textAlign = 'right';
        manaPerSecondLabel.style.width = '100px';
	innerCell = document.createElement('td');
        innerCell.appendChild(manaPerSecondLabel);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

        var innerTable = document.createElement('table');
        innerTable.style.borderCollapse = 'collapse';
        innerTable.appendChild(innerBody);
        var calcTableRow = document.createElement('tr');
        calcTableRow.appendChild(innerTable);

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

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

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