Calculators/Code

//

```
/*jslint devel: true, browser: true, white: true, indent: 2, plusplus: true, bitwise: true*/
/*global $, wgUserName, mw */
(function () {
//__NOWYSIWYG__
  calculator_numcs = function (n) { n = String(n); while ((/\d{4}/).test(n)) { n = n.replace(/(\d{3},|\d{3}$)/, ',$1'); } return n; },
  calculator_btn_m = function (o) { $(o).prev().val(parseInt($(o).prev().val(), 10) - 1); $(o).prev().keyup(); },
  calculator_btn_p = function (o) { $(o).prev().prev().val(parseInt($(o).prev().prev().val(), 10) + 1); $(o).prev().prev().keyup(); },

  calculator_array_sort = function (inputArr, numeric, by_key, reverse, sub_key) {
    var tmp_arr = {}, valArr = [], keyArr = [], keys = [], sorter, i, k, populateArr = [],
    is_numeric = function (v) { v = parseFloat(v); return (typeof v === 'number' && !isNaN(v)); },
    bubbleSort = function (keyArr, inputArr, sub_key) {
      var i, j, tempValue, tempKeyVal, ret; for (i = inputArr.length - 2; i >= 0; i--) { for (j = 0; j <= i; j++) {
        ret = (sub_key === '') ? sorter(inputArr[j + 1], inputArr[j]) : sorter((typeof inputArr[j + 1].resist[sub_key] === 'undefined' ? inputArr[j + 1][sub_key] : inputArr[j + 1].resist[sub_key]), (typeof inputArr[j].resist[sub_key] === 'undefined' ? inputArr[j][sub_key] : inputArr[j].resist[sub_key]));
        if (ret < 0) { tempValue = inputArr[j]; inputArr[j] = inputArr[j + 1]; inputArr[j + 1] = tempValue; tempKeyVal = keyArr[j]; keyArr[j] = keyArr[j + 1]; keyArr[j + 1] = tempKeyVal; }
      } }
    };
    if (typeof numeric === 'undefined') { numeric = false; }
    if (typeof by_key === 'undefined') { by_key = false; }
    if (typeof reverse === 'undefined') { reverse = false; }
    if (typeof sub_key === 'undefined') { sub_key = ''; }
    if (numeric) { sorter = function (a, b) { return (reverse ? b - a : a - b); }; }
    else {
      sorter = function (a, b) {
        var x = a, y = b, tmp;
        if (!is_numeric(a) && !is_numeric(b)) {
          tmp = (function (a, b) {a = a.search(/[a-z]/); b = b.search(/[a-z]/); if ((a !== 0 && b !== 0) || a === b) {return 0; } if (a === 0) {return -1; } if (b === 0) {return 1; } }(x, y));
          if (tmp !== 0) { return tmp * (reverse ? -1 : 1); }
          if (a === b) { return 0; }
          if (a > b) { return (reverse ? -1 : 1); }
          return (reverse ? 1 : -1);
        }
        a = parseFloat(a) || 0;
        b = parseFloat(b) || 0;
        return (reverse ? b - a : a - b);
      };
    }
    if (by_key) {
      for (k in inputArr) { if (inputArr.hasOwnProperty(k)) { keys.push(k); } }/*Make a list of key names*/
      keys.sort(sorter);
      for (i = 0; i < keys.length; i++) { k = keys[i]; tmp_arr[k] = inputArr[k]; }/*Rebuild array with sorted key names*/
      for (i in tmp_arr) { if (tmp_arr.hasOwnProperty(i)) { populateArr[i] = tmp_arr[i]; } }
    }
    else {
      for (k in inputArr) { if (inputArr.hasOwnProperty(k)) { valArr.push(inputArr[k]); keyArr.push(k); } }/*Get key and value*/
      try { bubbleSort(keyArr, valArr, sub_key); } catch (e) { return false; }/*Sort our new temporary arrays*/
      for (i = 0; i < valArr.length; i++) { populateArr[keyArr[i]] = valArr[i]; }/*Repopulate the old array*/
    }
    return populateArr;
  };

  $('body:first').append(
    '<style type="text/css">' +
    '#calculators_container{width:100%;}' +
    '#calculators_container>div {border:1px solid #bfcfcf; background:#122026; margin:25px auto; padding:20px; width:350px; clear:both;}' +
    '.text_align_left {text-align:left;}' +
    '.text_align_center {text-align:center;}' +
    '.text_align_right {text-align:right;}' +
    '.valign_top {vertical-align:top;}' +
    '.center_tables table {margin-left: auto; margin-right: auto;}' +
    '#calculator_looti1 {width:600px;}' +
    '#calculator_exp {width:250px;}' +
    '#calculator_armor td {vertical-align:top;}' +
    '#calculator_armor_damages, #calculator_armor_compare {width:100%;}' +
    '#calculator_armor_damages td, #calculator_armor_compare td {width: 9%;vertical-align:middle;}' +
    '#calculator_armor_damages th, #calculator_armor_compare th {width: 19%;vertical-align:middle;}' +
    '#calculator_armor_compare th {font-weight:normal;}' +
    '#calculator_armor_body_main {background:url(\'http://images4.wikia.nocookie.net/tibia/en/images/3/39/Tibia_Client_Background_Light.gif\');margin:0px 10px;position:relative;display:inline-block;width:112px;height:149px;border:1px black solid;}' +
    '#calculator_armor_body_main div {position:absolute; width:32px; height:32px;background:url(\'http://images2.wikia.nocookie.net/tibia/en/images/b/b3/Set_Background.gif\');padding: 1px;}' +
    '#calculator_armor_body_main img {border:none;cursor:pointer;}' +
    '#calculator_armor_tt_items {display:none;z-index:999;position:absolute;width:auto;height:auto;background:#DDDDDD;border:1px black solid;padding:4px;}' +
    '</style>'
  );
/*Exp*/
(function () {
  $('#calculator_exp')
  .append('<table border="0" cellpadding="5" align="center"><tr><td>')
  .append('Level: ')
  .append('<input type="text" size="8" maxlength="4" id="calculator_expi1" value="1" /> ')
  .append($('<input type="button" value="-" />').click(function () { calculator_btn_m(this); })).append(' ')
  .append($('<input type="button" value="+" />').click(function () { calculator_btn_p(this); }))
  .append('<span id="calculator_expr1"></span>')
  .append('</tr></td>');
  $('#calculator_expi1').keyup(function () {
    if ($(this).val() === '') { $(this).val(1).select(); }
    var exp, lvl = Math.abs(parseInt($(this).val(), 10) || 1);
    $(this).val(lvl);
    exp = String((50 * Math.pow(lvl - 1, 3) - 150 * Math.pow(lvl - 1, 2) + 400 * (lvl - 1)) / 3);
    while ((/\d{4}/).test(exp)) { exp = exp.replace(/(\d{3},|\d{3}$)/, ',$1'); }
    $('#calculator_expr1').html(
    	'<tr>' +
		'<td colspan="2">' +
    			'Experience for level ' + lvl + ': <b>' + exp + '</b>' +
    		'</td>' +
    	'</tr>' +
    '</table>'
  );
  });
  $('#calculator_expi1').keyup();
}());

/*Stats*/
(function () {
  var x, tmp = '',
  calculator_stats_voc = {'Swordsman': [14, 5, 23],'Berserker': [14, 5, 23], 'Wildheart': [16, 3, 23],'Defender': [20, 4, 30],'Hunter': [10, 12, 15],'Shadowstriker': [9, 9, 11],'Spearman': [13, 6, 20],'Marksman': [10, 3, 12],'Necromancer': [6, 30, 10],'Saint': [6, 35, 10],'Spellcaster': [6, 30, 10],'Rookstayer': [5, 5, 15]},
  calculator_sats_rook = {'Rook': [5,5,15]},
  calculator_stats_update = function () {
    var x, lvl, rooklvl;
    for (x = 2; x <= 4; x++) {
      if ($('#calculator_statsi' + x).val() === '') { $('#calculator_statsi' + x).val(8).select(); }
      $('#calculator_statsi' + x).val(Math.abs(parseInt($('#calculator_statsi' + x).val(), 10) || 8));
    }
    lvl = parseInt($('#calculator_statsi2').val(), 10);
    rooklvl = 8;
    x = calculator_stats_voc[$('#calculator_statsi1').val()][0];
    $('#calculator_statsr1').text(145 + (rooklvl * 5) + ((lvl - rooklvl) * x));
    x = calculator_stats_voc[$('#calculator_statsi1').val()][1];
    $('#calculator_statsr2').text(50 + (5 * Math.min(rooklvl, lvl)) + (Math.max(0, lvl - rooklvl) * x));
    x = calculator_stats_voc[$('#calculator_statsi1').val()][2];
    $('#calculator_statsr3').text(390 + (rooklvl * 10) + ((lvl - rooklvl) * x));
    $('#calculator_statsr4').text(220 + (2 * (lvl - 1)));
  };

  for (x in calculator_stats_voc) { if (calculator_stats_voc.hasOwnProperty(x)) { tmp += '<option value="' + x + '">' + x + '</option>'; } }
  $('#calculator_stats').html(
    '<table width="300" border="0" cellpadding="5" align="center">' +
    	'<tr>' +
			'<td colspan="1">' +
				'<p align="left"><b>Class:</b></p>' +
			'</td>' +
			'<td colspan="2">' +
    			'<select id="calculator_statsi1" size="1">' + tmp + '</select>' +
    		'</td>' +
    	'</tr>' +
    	'<tr>' +
    		'<td class="text_align_right">' +
    			'<p align="left"><b>Target level:</b></p>' +
    		'</td>' +
    		'<td class="text_align_left">' +
    			'<input type="text" size="8" maxlength="4" id="calculator_statsi2" value="8" /> <input type="button" value="-" /> <input type="button" value="+" />' +
    		'</td>' +
    	'</tr>' +
		'<tr>' +
			'<td colspan="4"><hr></hr></td>' +
		'</tr>' +
		'<tr>' +
			'<td colspan="1">' +
				'<p align="left"><b>Hp :<b></p>' +
				'<p align="left"><b>Mana :<b></p>' +
				'<p align="left"><b>Cap :<b></p>' +
			'</td>' +
			'<td colspan="1" id="calculator_statsrs">' +
				'<p><span id="calculator_statsr1"></span></p>' +
				'<p><span id="calculator_statsr2"></span></p>' +
				'<p><span id="calculator_statsr3"></span></p>' +
			'</td>' +
		'</tr>' +
    '</table>'
  );

  $('#calculator_statsi2').keyup(calculator_stats_update)
  .next().click(function () {calculator_btn_m(this); calculator_stats_update(); })
  .next().click(function () {calculator_btn_p(this); calculator_stats_update(); });
  $('#calculator_statsi1').change(calculator_stats_update);
  calculator_stats_update();
}());

  /*General*/
  $('#calculators_loading').hide();
  $('#calculators_container').show();
}());
//
```