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(meditation, focus, int, mr, label) {
+
         var calculate = function(meditation, focus, int, mr, passive, active, nonMed) {
 
             var medBonus = 1.0;
 
             var medBonus = 1.0;
 
             if (!meditation.value || !isNumeric(meditation.value)) {
 
             if (!meditation.value || !isNumeric(meditation.value)) {
Line 14: Line 14:
 
                 }
 
                 }
 
             }
 
             }
 
 
             if (!focus.value || !isNumeric(focus.value)) {
 
             if (!focus.value || !isNumeric(focus.value)) {
 
                 focus.value = '0.0';
 
                 focus.value = '0.0';
Line 20: Line 19:
 
                 focus.value = '120.0';
 
                 focus.value = '120.0';
 
             }
 
             }
 
 
             if (!int.value || !isNumeric(int.value)) {
 
             if (!int.value || !isNumeric(int.value)) {
 
                 int.value = '0';
 
                 int.value = '0';
Line 26: Line 24:
 
                 int.value = '168';
 
                 int.value = '168';
 
             }
 
             }
 
 
             if (!mr.value || !isNumeric(mr.value)) {
 
             if (!mr.value || !isNumeric(mr.value)) {
 
                 mr.value = '0';
 
                 mr.value = '0';
 
             }
 
             }
  
             var manaPerSecond = 0.2;
+
             var baseRate = 0.2;
 
             var focusBonus = parseFloat(focus.value) / 200;
 
             var focusBonus = parseFloat(focus.value) / 200;
 
             var medBonus = medBonus * ((0.0075 * parseFloat(meditation.value)) + (0.0025 * parseFloat(int.value)));
 
             var medBonus = medBonus * ((0.0075 * parseFloat(meditation.value)) + (0.0025 * parseFloat(int.value)));
Line 37: Line 34:
 
             var intensityBonus = Math.min(Math.sqrt(parseFloat(mr.value)), 5.5);
 
             var intensityBonus = Math.min(Math.sqrt(parseFloat(mr.value)), 5.5);
 
             var finalItemBonus = ((baseItemBonus * intensityBonus) - (baseItemBonus - 1)) / 10;
 
             var finalItemBonus = ((baseItemBonus * intensityBonus) - (baseItemBonus - 1)) / 10;
             manaPerSecond = manaPerSecond + focusBonus + medBonus + finalItemBonus;
+
             var manaPerSecond = baseRate + focusBonus + medBonus + finalItemBonus;
 
             manaPerSecond = manaPerSecond.toFixed(4);
 
             manaPerSecond = manaPerSecond.toFixed(4);
             removeChildren(label);
+
             removeChildren(passive);
             label.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
+
             passive.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
 +
            manaPerSecond = baseRate + focusBonus + (2 * medBonus) + finalItemBonus;
 +
            removeChildren(active);
 +
            active.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
 +
            manaPerSecond = baseRate + focusBonus + finalItemBonus;
 +
            removeChildren(nonMed);
 +
            nonMed.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
 
         };
 
         };
 
         var detectEnter = function(keyEvent) {
 
         var detectEnter = function(keyEvent) {
Line 161: Line 164:
 
innerCell = document.createElement('td');
 
innerCell = document.createElement('td');
 
         innerCell.appendChild(passivePerSecond);
 
         innerCell.appendChild(passivePerSecond);
 +
        innerRow.appendChild(innerCell);
 +
        innerBody.appendChild(innerRow);
 +
 +
        var activeLabel = document.createElement('div');
 +
        activeLabel.appendChild(document.createTextNode('Active:'));
 +
        innerCell = document.createElement('td');
 +
        innerCell.appendChild(activeLabel);
 +
        innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
 +
 +
        var activePerSecond = document.createElement('div');
 +
        activePerSecond.appendChild(document.createTextNode('0.0000 MPS'));
 +
        activePerSecond.style.textAlign = 'right';
 +
        activePerSecond.style.width = '75px';
 +
innerCell = document.createElement('td');
 +
        innerCell.appendChild(activePerSecond);
 +
        innerRow.appendChild(innerCell);
 +
        innerBody.appendChild(innerRow);
 +
 +
        var nonMedLabel = document.createElement('div');
 +
        nonMedLabel.appendChild(document.createTextNode('Non-Meddable Armor:'));
 +
        innerCell = document.createElement('td');
 +
        innerCell.appendChild(nonMedLabel);
 +
        innerRow = document.createElement('tr');
 +
        innerRow.appendChild(innerCell);
 +
 +
        var nonMedPerSecond = document.createElement('div');
 +
        nonMedPerSecond.appendChild(document.createTextNode('0.0000 MPS'));
 +
        nonMedPerSecond.style.textAlign = 'right';
 +
        nonMedPerSecond.style.width = '75px';
 +
innerCell = document.createElement('td');
 +
        innerCell.appendChild(nonMedPerSecond);
 
         innerRow.appendChild(innerCell);
 
         innerRow.appendChild(innerCell);
 
         innerBody.appendChild(innerRow);
 
         innerBody.appendChild(innerRow);

Revision as of 11:00, 21 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, passive, active, nonMed) {
            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 > 168) {
                int.value = '168';
            }
            if (!mr.value || !isNumeric(mr.value)) {
                mr.value = '0';
            }

            var baseRate = 0.2;
            var focusBonus = parseFloat(focus.value) / 200;
            var medBonus = medBonus * ((0.0075 * parseFloat(meditation.value)) + (0.0025 * parseFloat(int.value)));
            var baseItemBonus = ((((parseFloat(meditation.value) / 2) + (parseFloat(focus.value) / 4)) / 90) * 0.65) + 2.35;
            var intensityBonus = Math.min(Math.sqrt(parseFloat(mr.value)), 5.5);
            var finalItemBonus = ((baseItemBonus * intensityBonus) - (baseItemBonus - 1)) / 10;
            var manaPerSecond = baseRate + focusBonus + medBonus + finalItemBonus;
            manaPerSecond = manaPerSecond.toFixed(4);
            removeChildren(passive);
            passive.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
            manaPerSecond = baseRate + focusBonus + (2 * medBonus) + finalItemBonus;
            removeChildren(active);
            active.appendChild(document.createTextNode(manaPerSecond + ' MPS'));
            manaPerSecond = baseRate + focusBonus + finalItemBonus;
            removeChildren(nonMed);
            nonMed.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 calcTableRow = document.createElement('tr');
        var calcTableCell = document.createElement('td');
        calcTableRow.appendChild(calcTableCell);

        var innerTable = document.createElement('table');
        innerTable.style.borderCollapse = 'collapse';
        calcTableCell.appendChild(innerTable);

        var innerBody = document.createElement('tbody');
        innerTable.appendChild(innerBody);

        var innerRow = document.createElement('tr');

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

        var meditationInput = document.createElement('input');
        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);

        var focusInput = document.createElement('input');
        focusInput.maxLength = '5';
        focusInput.type = 'text';
        focusInput.style.width = '50px';
        focusInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'left';
        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);

        var intInput = document.createElement('input');
        intInput.maxLength = '3';
        intInput.type = 'text';
        intInput.style.width = '50px';
        intInput.onkeyup = function(keyEvent) {
            detectEnter(keyEvent);
        };
	innerCell = document.createElement('td');
        innerCell.style.textAlign = 'left';
        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);

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

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

        var passiveLabel = document.createElement('div');
        passiveLabel.appendChild(document.createTextNode('Passive:'));
        innerCell = document.createElement('td');
        innerCell.appendChild(passiveLabel);
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        var passivePerSecond = document.createElement('div');
        passivePerSecond.appendChild(document.createTextNode('0.0000 MPS'));
        passivePerSecond.style.textAlign = 'right';
        passivePerSecond.style.width = '75px';
	innerCell = document.createElement('td');
        innerCell.appendChild(passivePerSecond);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

        var activeLabel = document.createElement('div');
        activeLabel.appendChild(document.createTextNode('Active:'));
        innerCell = document.createElement('td');
        innerCell.appendChild(activeLabel);
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        var activePerSecond = document.createElement('div');
        activePerSecond.appendChild(document.createTextNode('0.0000 MPS'));
        activePerSecond.style.textAlign = 'right';
        activePerSecond.style.width = '75px';
	innerCell = document.createElement('td');
        innerCell.appendChild(activePerSecond);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

        var nonMedLabel = document.createElement('div');
        nonMedLabel.appendChild(document.createTextNode('Non-Meddable Armor:'));
        innerCell = document.createElement('td');
        innerCell.appendChild(nonMedLabel);
        innerRow = document.createElement('tr');
        innerRow.appendChild(innerCell);

        var nonMedPerSecond = document.createElement('div');
        nonMedPerSecond.appendChild(document.createTextNode('0.0000 MPS'));
        nonMedPerSecond.style.textAlign = 'right';
        nonMedPerSecond.style.width = '75px';
	innerCell = document.createElement('td');
        innerCell.appendChild(nonMedPerSecond);
        innerRow.appendChild(innerCell);
        innerBody.appendChild(innerRow);

        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);