|
|
(14 intermediate revisions by 2 users not shown) |
Line 2: |
Line 2: |
| * Code for calculators. | | * Code for calculators. |
| */ | | */ |
− | var Calculator = Class.extend({
| + | function Calculator(content, id, title, columns) { |
− | init: function(content, id, title, columns) {
| + | var location = document.getElementById(id); |
− | var location = document.getElementById(id);
| + | |
| | | |
− | var table = document.createElement('table');
| + | var table = document.createElement('table'); |
− | table.className = 'uoguidetable open';
| + | table.className = 'uoguidetable open'; |
| | | |
− | var calcTableBody = document.createElement('tbody');
| + | var calcTableBody = document.createElement('tbody'); |
− | table.appendChild(calcTableBody);
| + | table.appendChild(calcTableBody); |
| | | |
− | var calcTableRow = document.createElement('tr');
| + | var calcTableRow = document.createElement('tr'); |
− | calcTableBody.appendChild(calcTableRow);
| + | calcTableBody.appendChild(calcTableRow); |
| | | |
− | var calcTableHeader = document.createElement('th');
| + | var calcTableHeader = document.createElement('th'); |
− | calcTableHeader.colSpan = columns;
| + | calcTableHeader.colSpan = columns; |
− | calcTableHeader.appendChild(document.createTextNode(title));
| + | calcTableHeader.appendChild(document.createTextNode(title)); |
− | calcTableRow.appendChild(calcTableHeader);
| + | calcTableRow.appendChild(calcTableHeader); |
| | | |
− | calcTableRow = content;
| + | calcTableRow = content; |
− | calcTableBody.appendChild(calcTableRow);
| + | calcTableBody.appendChild(calcTableRow); |
| | | |
− | location.appendChild(table);
| + | location.appendChild(table); |
− | }
| + | } |
− | });
| + | |
− | | + | |
− | /**
| + | |
− | * Calculator that calculates your percentage chance for more and better loot given a specified Luck value.
| + | |
− | */
| + | |
− | var LuckToChanceCalculator = Calculator.extend({
| + | |
− | init: function() {
| + | |
− | var calculate = function(input, label) {
| + | |
− | if (input.value) {
| + | |
− | if (isNumeric(input.value)) {
| + | |
− | var percentChance = Math.pow(input.value, (5 / 9));
| + | |
− | if (percentChance > 100) {
| + | |
− | percentChance = 100;
| + | |
− | }
| + | |
− | percentChance = percentChance.toFixed(3);
| + | |
− | removeChildren(label);
| + | |
− | label.appendChild(document.createTextNode(percentChance + '% Chance'));
| + | |
− | }
| + | |
− | }
| + | |
− | };
| + | |
− | var calcTableRow = document.createElement('tr');
| + | |
− | var calcTableCell = document.createElement('td');
| + | |
− | var luckInput = document.createElement('input');
| + | |
− | var calculateButton = document.createElement('input');
| + | |
− | var percentChanceLabel = document.createElement('div');
| + | |
− | | + | |
− | calcTableCell.style.textAlign = 'right';
| + | |
− | calcTableCell.appendChild(document.createTextNode('Luck:'));
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | luckInput.id = 'luckInput';
| + | |
− | luckInput.maxLength = '4';
| + | |
− | luckInput.type = 'text';
| + | |
− | luckInput.style.width = '35px';
| + | |
− | luckInput.onkeyup = function(keyEvent) {
| + | |
− | var keyID = window.event ? event.keyCode : keyEvent.keyCode;
| + | |
− | if (keyID == 13)
| + | |
− | calculate(luckInput, percentChanceLabel);
| + | |
− | };
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(luckInput);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | calculateButton.type = 'button';
| + | |
− | calculateButton.value = 'Calculate >>';
| + | |
− | calculateButton.onclick = function() {
| + | |
− | calculate(luckInput, percentChanceLabel);
| + | |
− | };
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(calculateButton);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | percentChanceLabel.appendChild(document.createTextNode('0.000% Chance'));
| + | |
− | percentChanceLabel.style.textAlign = 'right';
| + | |
− | percentChanceLabel.style.width = '110px';
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(percentChanceLabel);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | this._super(calcTableRow, 'LuckToChance', 'Luck to Chance', 4);
| + | |
− | }
| + | |
− | });
| + | |
− | | + | |
− | /**
| + | |
− | * Calculator that calculates the amount of Luck required to achieve a specified percentage chance for more and better loot.
| + | |
− | */
| + | |
− | var ChanceToLuckCalculator = Calculator.extend({
| + | |
− | init: function() {
| + | |
− | var calculate = function(input, label) {
| + | |
− | if (input.value) {
| + | |
− | if (input.value > 100) {
| + | |
− | input.value = '100';
| + | |
− | }
| + | |
− | if (isNumeric(input.value)) {
| + | |
− | var luckAmount = Math.ceil(Math.pow(input.value, (9 / 5)));
| + | |
− | removeChildren(label);
| + | |
− | label.appendChild(document.createTextNode(luckAmount + ' Luck'));
| + | |
− | }
| + | |
− | }
| + | |
− | };
| + | |
− | var calcTableRow = document.createElement('tr');
| + | |
− | var calcTableCell = document.createElement('td');
| + | |
− | var chanceInput = document.createElement('input');
| + | |
− | var calculateButton = document.createElement('input');
| + | |
− | var luckAmountLabel = document.createElement('div');
| + | |
− | | + | |
− | calcTableCell.style.textAlign = 'right';
| + | |
− | calcTableCell.appendChild(document.createTextNode('Chance:'));
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | chanceInput.id = 'chanceInput';
| + | |
− | chanceInput.maxLength = '3';
| + | |
− | chanceInput.type = 'text';
| + | |
− | chanceInput.style.width = '25px';
| + | |
− | chanceInput.onkeyup = function(keyEvent) {
| + | |
− | var keyID = window.event ? event.keyCode : keyEvent.keyCode;
| + | |
− | if (keyID == 13)
| + | |
− | calculate(chanceInput, luckAmountLabel);
| + | |
− | };
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(chanceInput);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | calculateButton.type = 'button';
| + | |
− | calculateButton.value = 'Calculate >>';
| + | |
− | calculateButton.onclick = function() {
| + | |
− | calculate(chanceInput, luckAmountLabel);
| + | |
− | };
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(calculateButton);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | luckAmountLabel.appendChild(document.createTextNode('0 Luck'));
| + | |
− | luckAmountLabel.style.textAlign = 'right';
| + | |
− | luckAmountLabel.style.width = '60px';
| + | |
− | calcTableCell = document.createElement('td');
| + | |
− | calcTableCell.appendChild(luckAmountLabel);
| + | |
− | calcTableRow.appendChild(calcTableCell);
| + | |
− | | + | |
− | this._super(calcTableRow, 'ChanceToLuck', 'Chance to Luck', 4);
| + | |
− | }
| + | |
− | });
| + | |
− | | + | |
− | function searchForCalculators() {
| + | |
− | var calculators = document.getElementsByTagName('div');
| + | |
| | | |
− | for (var i in calculators) {
| + | switch (wgPageName) { |
− | if (calculators[i].id == 'LuckToChance') {
| + | case 'Luck': |
− | new LuckToChanceCalculator();
| + | importScript('MediaWiki:Calculator.js/Luck.js'); |
− | } else if (calculators[i].id == 'ChanceToLuck') {
| + | break; |
− | new ChanceToLuckCalculator();
| + | case 'Mana_Regeneration': |
− | }
| + | importScript('MediaWiki:Calculator.js/Mana_Regeneration.js'); |
− | } | + | break; |
| + | case 'Swing_Speed': |
| + | case 'Swing_Speed_Increase': |
| + | importScript('MediaWiki:Calculator.js/Swing_Speed_Increase.js'); |
| + | break; |
| } | | } |
− | addOnloadHook(searchForCalculators);
| |