ФЭНДОМ


Шаблон:Protected
(function(){
/*General*/
$('body:first').append('<style type="text/css">'+
'#calculators_container{width:100%;}'+
'#calculators_container>div {text-align:center;display:inline-block;border:1px solid #bfcfcf; background-color:#f9fcff;padding:8px 10px;}'+
'.text_align_left {text-align:left;}'+
'.text_align_center {text-align:center;}'+
'.text_align_right {text-align:right;}'+
'.valign_top {vertical-align:top;}'+
'#calculator_statsrs {display:block;width:296px;position:relative;}'+
'#calculator_statsrs div {position:absolute;color:#bfbfbf;font:bold 14px Tahoma;}'+
'#calculator_statsr1 {top:64px;right:30px;}'+
'#calculator_statsr2 {top:90px;right:30px;}'+
'#calculator_statsr3 {top:30px;left:165px;}'+
'#calculator_statsr4 {top:30px;left:23px;}'+
'#calculator_looti1 {width:600px;}'+
'#calculator_exp {width:250px;}'+
'#calculator_armor td {vertical-align:top;}'+
'#calculator_armor_damages {width:100%;}'+
'#calculator_armor_damages td, #calculator_armor_damages th {width: 10%;vertical-align:middle;}'+
'#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>');
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 = [];
  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 = '';}
  var is_numeric = function(v) { v = parseFloat(v); return (typeof v === 'number' && !isNaN(v)); };
  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);
      }
      else { 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 {
    var 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; }
      } }
    };
    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;
};


/*Exp*/
$('#calculator_exp')
.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('<br /><br /><span id="calculator_expr1"></span>');
$('#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('Experience for level '+lvl+': <b>'+exp+'</b>');
});
$('#calculator_expi1').keyup();

/*Stats*/
var x, tmp = '';
calculator_stats_voc = {'Druid':[5, 30, 10], 'Knight':[15, 5, 25], 'Paladin':[10, 15, 20], 'Sorcerer':[5, 30, 10], 'Rookstayer':[5, 5, 10]};//[hp, mana, cap]


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 = parseInt($('#calculator_statsi3').val(), 10);
  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(-5+(rooklvl*5)+((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><tr>'+
'<td class="text_align_right">Vocation:</td>'+
'<td class="text_align_left"><select id="calculator_statsi1" size="1">'+tmp+'</select></td>'+
'</tr><tr>'+
'<td class="text_align_right">Target level:</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 class="text_align_right">Level on which <br />you left rookgard:</td>'+
'<td class="text_align_left"><input type="text" size="8" maxlength="4" id="calculator_statsi3" value="8" /> <input type="button" value="-" /> <input type="button" value="+" /></td>'+
'</tr><tr><td colspan="2">'+
'<div id="calculator_statsrs"><img src="http://images1.wikia.nocookie.net/tibia/en/images/5/55/Calculator_Stats.png" alt="Stats" />'+
'<div id="calculator_statsr1"></div>'+
'<div id="calculator_statsr2"></div>'+
'<div id="calculator_statsr3"></div>'+
'<div id="calculator_statsr4"></div>'+
'</div>'+
'</td></tr>'+
'</table>');

$('#calculator_statsi2, #calculator_statsi3').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();

/*Loot*/
$('#calculator_loot').append(
'<div id="calculator_loot_tg1">'+
'<textarea cols="60" rows="10" id="calculator_looti1"></textarea>'+
'<br />'+
'<input type="button" id="calculator_lootb1" value="Process" />'+
' '+
'<input type="button" id="calculator_lootb2" value="Clear" />'+
'</div>'+
'<div id="calculator_loot_tg2" style="display:none;">'+
'<input type="button" id="calculator_lootb3" value="Back" />'+
'<table><tr><td class="valign_top">'+
'<div id="calculator_lootr3"></div>'+
'</td>'+
'<td class="valign_top">'+
'<table class="wikitable"><tbody><tr><th>NPCs to visit</th></tr></tbody><tbody id="calculator_lootr2"><tr><td>-</td></tr></tbody></table>'+
'</td>'+
'<td class="valign_top" id="calculator_lootrc">'+
'<table class="wikitable"><tr><th>Total "looks"</th></tr><tr><td id="calculator_lootr1">-</td></tr></table>'+
'<table class="wikitable"><tbody><tr><th>Skipped Items</th></tr></tbody><tbody id="calculator_lootr5"><tr><td>None</td></tr></tbody></table>'+
'</td></tr></table>'+
'</div>'
);





calculator_loot_process2 = function() {
  var ucwords = function(str) {
    str = String(str).replace(/^(.)|\s(.)|-(.)/g, function ($1) { return $1.toUpperCase(); });
    return str.replace(' Of The ', ' of the ').replace(' Of A ', ' of a ').replace(' Of An ', ' of an ').replace(' Of ', ' of ').replace(' The ', ' the ');
  },
  get_wiki_data = function() {
    var ret = {}, x, p, i = 0;
    var tdata = ['', '', '', ''];//npc, item, weight, value
    var h = '|npc=Magic Shopkeeper NPCs|Empty Potion Flask|0|5'+
            '|npc=Banker NPCs|Gold Coin|0.1|1|Platinum Coin|0.1|100|Crystal Coin|0.1|10000'+
            ($('#calculator_loot_dpl').text());
    while (h.search(/\s\s/) !== -1) { h = h.replace(/\s\s/g, ' '); } h = h.replace(/npc\s*=\s*/, 'npc='); p = h.split('|');
    for (x=0;x<p.length;x++) { p[x] = $.trim(p[x]); }
    while (p[0] === '') { p = p.slice(1); }
  //item_name={weight,sellto,npcvalue}
    for (x=0;x<p.length;x++) {
      if (p[x].substr(0, 4) === 'npc=') { tdata[0] = p[x].substr(4); i = 0; }
      else {
        tdata[i] = p[x];
        if (i === 3) {
          tdata[3] = (tdata[3].substr(0, 1)==='-'?0:parseInt(tdata[3], 10));
          if (typeof ret[tdata[1]] === 'undefined' || ret[tdata[1]].npcvalue < tdata[3]) {
            ret[tdata[1]] = {'weight':parseFloat(tdata[2]), 'sellto':tdata[0], 'npcvalue':tdata[3]};
          }
          i = 0;
        }
      }
      i++;
    }
    return ret;
  },
  loot_to_singular = function(t) {
    var calculator_loot_p_words = {
      'Cookies':'Cookie', '*Pieces of *':'Piece of ', '*Bundles of *':'Bundle of ', '*Strands of *':'Strand of ',
      '*Bunches of *':'Bunch of ', '* Toes':' Toe', '*Flasks of *':'Flask of ', '* Teeth':' Tooth',
      'Globs of *':'Glob of ', 'Essences of *':'Essence of ', 'Books of *':'Book of ', 'Piles of *':'Pile of ',
      'Lumps of *':'Lump of ', '*Ears of *':'Ear of ', '*s of Corruption':' of Corruption', 'Sabreteeth':'Sabretooth',
      'Scrolls of *':'Scroll of ', '* Feet':' Foot'
    };/*Exceptions*/
    var calculator_loot_p_ends = {'she':'sh', 'ie':'y', 've':'fe', 'oe':'o', 'ze':'z', 'che':'ch', 'sse':'ss'};/*Exceptions of endings (after removing the last 's')*/
    var x; for (x in calculator_loot_p_words) { if (calculator_loot_p_words.hasOwnProperty(x)) {
      if ((new RegExp('^'+x.replace(/\*/g,'.*?')+'$')).test(t)) { return t.replace(x.replace(/\*/g, ''), calculator_loot_p_words[x]); }
    } }
    var lastletter = t.slice(t.length - 1);
    if (lastletter === 's') {
      t = t.slice(0, t.length - 1);/*remove the s*/
      lastletter = t.slice(t.length - 3);/*check last 3 letters*/
      if (typeof calculator_loot_p_ends[lastletter] !== 'undefined') { t = t.slice(0, t.length - 3) + calculator_loot_p_ends[lastletter]; }
      lastletter = t.slice(t.length - 2);/*check last 2 letters*/
      if (typeof calculator_loot_p_ends[lastletter] !== 'undefined') { t = t.slice(0, t.length - 2) + calculator_loot_p_ends[lastletter]; }
    }
    return t;
  };
  var x, line, amount, tmp, data, data_items = {}, d = get_wiki_data(), skip, skiplist = [];
  var totalsee = 0;
  data = $.trim($('#calculator_looti1').val()).split('\n');
  for (x in data) { if (data.hasOwnProperty(x)) {
    line = data[x].indexOf('You see ');
    if (line !== -1 &&
        data[x].match(/You see (?:.*? \(Level \d{1,3}\)\. .{1,2}e is a|a closed door.|an open door.)/) === null
      ) {
      skip = false;
      line = data[x].substr(line + 8);
      amount = parseInt(line.match(/^a[n]? /i) ? 1 : (line.match(/^\d+ /i) ? line.match(/^\d+ /i) : 0), 10);
      line = $.trim(line.replace(/(?:\(|It is empty|that is brand-new|that will expire in).*/, ''));
      if (line.substr(line.length - 1) === '.') { line = line.substr(0, line.length - 1); }
      line = ucwords($.trim(line));//item name
      if (amount === 0) {
        try {
          tmp = data[parseInt(x, 10)+1].match(/weigh[s]? (\d{1,4}\.\d{1,2}) oz/);
          if (tmp === null) {
            tmp = data[parseInt(x, 10)+2].match(/weigh[s]? (\d{1,4}\.\d{1,2}) oz/);
          }
        }
        catch(e) { tmp = null; }
        tmp = (tmp === null || tmp[1] === 'undefined' ? 0 : parseFloat(tmp[1]));
        if (typeof d[line] === 'undefined' || d[line].npcvalue === 0) { skiplist.push(line); skip = true; }//not in list or 0gp
        else {
          amount = Math.round(tmp / d[line].weight) || 0;
          if (amount === 0) { skiplist.push(line); alert(line + ' will be omitted, couldn\'t find the weight.'); skip = true; }
        }
      }
      else {
        line = line.substr(line.indexOf(' ') + 1);
        if (amount > 1) { line = loot_to_singular(line); }
      }
      if (!skip) {
        if (typeof d[line] === 'undefined' || d[line].npcvalue === 0) { skiplist.push(line); skip = true; }//not in list or 0 gp
      }
      if (!skip) {
      //Item is included
        totalsee++;
        if (typeof data_items[line] === 'undefined') {
          tmp = (!d[line].sellto.match(/You can return the/gi) && !d[line].sellto.match(/player/gi)) ? d[line].sellto : '';
          data_items[line] = [0, d[line].npcvalue, tmp];
        }//[name][amount, price, npc/'']
        data_items[line][0] += amount;
      }
    }
  } }

  calculator_loot_sum = function() {
    var tmp = 0, npcs = {}, npcso = '', x, skipped = '';
    $('.calculator_loot_includecb').each(function() { if ($(this).attr('checked')) {
      tmp += (Number($(this).parent().nextAll(':eq(3)').html().replace(/,/g, '')) || 0);
      npcs[data_items[$(this).parent().nextAll(':eq(1)').text()][2]] = 0;
    }});
    npcs = calculator_array_sort(npcs, false, true);
    for (x in npcs) { if (npcs.hasOwnProperty(x)) { npcso += '<tr><td><a href="/wiki/'+escape(x)+'">'+x+'</a></td></tr>'; } }
    $('#calculator_lootr2').html(npcso || '<tr><td>None</td></tr>');
    $('#calculator_lootr4').html(calculator_numcs(tmp)+' gp');
    $('#calculator_lootr1').html(totalsee);
    for (x in skiplist) { if (skiplist.hasOwnProperty(x)) { skipped += '<tr><td><a href="/wiki/'+escape(skiplist[x].replace(/ /g, '_'))+'">'+skiplist[x]+'</a></td></tr>'; } }
    $('#calculator_lootr5').html(skipped || '<tr><td>None</td></tr>');
    $('#calculator_lootrc a, #calculator_lootr2 a').click(function(){window.open(this.href); return false;});
  };

  data_items = calculator_array_sort(data_items, false, true);
  $('#calculator_lootr3').empty().append(
    '<table class="wikitable"><tr><th>Total:</th></tr><tr><td id="calculator_lootr4">0 gp</td></tr></table>'+
    '<table id="calculator_loot_table" class="wikitable sortable"><tbody><tr><th class="unsortable">Sum<br /><input type="checkbox" checked="checked" /></th><th>Amount<br /></th><th>Item Name<br /></th><th>Price<br /></th><th>Total<br /></th></tr></tbody>'+
    '<tbody id="calculator_loot_tableb"></tbody>'+
    '</table>'
  );
  for (x in data_items) { if (data_items.hasOwnProperty(x)) {
    $('#calculator_loot_tableb').append($('<tr title="NPC that buys: '+(data_items[x][2].replace(/<a.*?>(.*?)<\/a>/gi, '$1').replace(/</g, ''))+'"></tr>').append('<td><input type="checkbox" class="calculator_loot_includecb" checked="checked" /></td><td>'+data_items[x][0]+'</td><td>'+
    '<a href="/wiki/'+escape(x.replace(/ /g, '_'))+'">'+x+'</a>'+
    '</td><td>'+calculator_numcs(data_items[x][1])+'</td><td>'+calculator_numcs(data_items[x][0] * data_items[x][1])+'</td>'));
  } }
  $('#calculator_loot_tableb a').click(function(){window.open(this.href); return false;});
  calculator_loot_sum();
  $('.calculator_loot_includecb').click(function() { calculator_loot_sum(); });
  $('#calculator_loot_table :checkbox:first').click(function(){ $('#calculator_loot_table :checkbox').attr('checked', $(this).attr('checked')); calculator_loot_sum(); });
  $('#calculator_loot_tg1').hide(); $('#calculator_loot_tg2').show();
  try{ts_makeSortable($('#calculator_loot_table')[0]);}catch(er){}
};

calculator_loot_process = function() {
  if ($.trim($('#calculator_loot_dpl').text()) === '') {
    if (!$('#calculator_loot_blackout').size()) {
      $('body:first').append(
        $('<div>Loading items data</div>').attr('id', 'calculator_loot_blackout').css({
          'position':'absolute','font-size':'xx-large','font-weight':'bolder','font-family':'Arial','color':'white','text-align':'center','background-color':'#666666','z-index':'2'
        })
      );
    }
    var cl = $('#calculator_loot');
    $('#calculator_loot_blackout').css({top:cl.offset().top, left:cl.offset().left, width:cl.width(), height:cl.height(), 'padding-top':cl.css('padding-top'), 'padding-right':cl.css('padding-right'), 'padding-bottom':cl.css('padding-bottom'), 'padding-left':cl.css('padding-left'), border:cl.css('border')})
    .fadeTo('slow', 0.8);
    $.get('/index.php?title=Calculators/Lootdata&action=render', function(data) {/*For wiki*/
//    $.get('data.php', function(data) {/*For local*/
      data = data.replace(/<p>|<\/p>|<!--[\s\S]*?-->|<\s*pre[\s\S]*?<\/pre>|<\s*script[\s\S]*?<\/script>/gi, '').replace(/\s/g, ' ');
      data = data.replace(/<a.*?>(.*?)<\/a>/gi, '0');
      $('#calculator_loot_dpl').text(data);
      $('#calculator_loot_blackout').fadeOut();
      calculator_loot_process2();
    }, 'text');
  }
  else { calculator_loot_process2(); }
};

$('#calculator_lootb1').click(function() { calculator_loot_process(); });
$('#calculator_lootb2').click(function(){ $('#calculator_looti1').val(''); });
$('#calculator_lootb3').click(function(){
  $('#calculator_loot_tg2').hide(); $('#calculator_loot_tg1').show();
  $('#calculator_lootb2').click();
});


/*Armor*/
$('#calculator_armor').append(
'<table class="wikitable" width="100%">'+
'<tr><td style="vertical-align:middle;width:132px">'+
'<div id="calculator_armor_body_main">'+
'  <div style="top:2px;left:39px;"><img id="calculator_armor_body_helmet" alt="" src="" width="32" height="32" /></div>'+
'  <div style="top:39px;left:39px;"><img id="calculator_armor_body_armor" alt="" src="" width="32" height="32" /></div>'+
'  <div style="top:76px;left:39px;"><img id="calculator_armor_body_legs" alt="" src="" width="32" height="32" /></div>'+
'  <div style="top:113px;left:39px;"><img id="calculator_armor_body_boots" alt="" src="" width="32" height="32" /></div>'+
'  <div style="top:17px;left:2px;"><img id="calculator_armor_body_amulet" alt="" src="" width="32" height="32" /></div>'+
'  <div style="top:91px;left:2px;"><img id="calculator_armor_body_ring" alt="" src="" width="32" height="32" /></div>'+
'</div>'+
'</td><td colspan="3">'+
'  <div id="calculator_armor_items_div" class="text_align_left" style="overflow:auto;width:100%;height:165px;"></div>'+
'</td></tr><tr><td>'+
'  <div id="calculator_armor_links"></div>'+
'</td><td class="text_align_left" style="width:180px;">'+
'  <table>'+
'  <tr><th colspan="2">Sort by:</th></tr>'+
'  <tr><td colspan="2"><input type="radio" value="name" name="calculator_armor_items_sort" />Name <input type="radio" value="oz" name="calculator_armor_items_sort" />Oz <input type="radio" value="arm" name="calculator_armor_items_sort" />Armor<br />'+
'  </td></tr><tr><th colspan="2">Protection:</th></tr>'+
'  <tr><td><input type="radio" value="physical" name="calculator_armor_items_sort" checked="checked" />Physical</td><td><input type="radio" value="fire" name="calculator_armor_items_sort" />Fire</td></tr>'+
'  <tr><td><input type="radio" value="earth" name="calculator_armor_items_sort" />Earth</td><td><input type="radio" value="energy" name="calculator_armor_items_sort" />Energy</td></tr>'+
'  <tr><td><input type="radio" value="ice" name="calculator_armor_items_sort" />Ice</td><td><input type="radio" value="holy" name="calculator_armor_items_sort" />Holy</td></tr>'+
'  <tr><td><input type="radio" value="death" name="calculator_armor_items_sort" />Death</td><td></td></tr></table>'+
'</td><td style="width:115px;">'+
'  <b>Damage type:</b><br /><select id="calculator_armor_damage_type" size="1"><option value="physical" selected="selected">Physical</option><option value="fire">Fire</option><option value="earth">Earth</option><option value="energy">Energy</option><option value="ice">Ice</option><option value="holy">Holy</option><option value="death">Death</option></select>'+
'  <br /><br />'+
'  <b>Show items for:</b><br />'+
'  <select id="calculator_armor_voc" size="1"><option value="0">All</option><option value="1" selected="selected">Druid</option><option value="2">Knight</option>  <option value="4">Paladin</option><option value="8">Sorcerer</option></select>'+
'  <br /><br />'+
'  <input type="checkbox" value="1" id="calculator_armor_np" /> Show non <br />protective items'+

'</td><td style="width:179px;">'+
'  Required Level: <span id="calculator_armor_req_level">None</span><br />'+
'  Needed Cap: <span id="calculator_armor_set_oz">0.00 oz</span><br />'+
'  Total Armor: <span id="calculator_armor_set_arm">0</span><br />'+
'  <span id="calculator_armor_set_prot">Physical protection: 0%</span>'+
'</td></tr></table>'+
'<table id="calculator_armor_damages" class="wikitable">'+
'<tr><th>Hit with <span id="calculator_armor_damage_type_ind">Physical</span></th><td>10</td><td>20</td><td>50</td><td>100</td><td>200</td><td>300</td><td>400</td><td>800</td><td><input type="text" id="calculator_armor_custom_damage" value="100" size="5" maxlength="4" /></td></tr>'+
'<tr><th>Will hit</th><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>'+
'</table>'
);
calculator_armor_vocv = 1;
calculator_armor_current_part = 0;
calculator_armor_parts_names = ['amulet', 'ring', 'helmet', 'armor', 'legs', 'boots'];
calculator_armor_names_parts = {'amulet':0, 'ring':1, 'helmet':2, 'armor':3, 'legs':4, 'boots':5};
calculator_armor_template_translate = {'helmet':'head','armor':'torso','boots':'feet','amulet':'neck','ring':'ring','legs':'legs','lefthand':'lefthand','righthand':'righthand','shoulders':'shoulders','belt':'belt'};
calculator_armor_get_link_for_name = function(item, part) {
  var r = $('#calculator_armor_list_'+calculator_armor_parts_names[part]+'_img img').filter(function() {
    var a = $(this).attr('src').split('/');
    return (unescape(a[a.length -1]) === unescape(item.replace(/ /g, '_')+'.gif') ? true : false);
  }).first().attr('src');
  return r;
};
var get_items_data = function(name) {
  var part = calculator_armor_names_parts[name];
  var ret = {}, x, p, h = $('#calculator_armor_list_'+name).html().replace(/<p>/gi, '').replace(/<\/p>/gi, '');
  var get_vocation_number = function(t) {
    t = t.toLowerCase();
    return (t.match(/druid/i)?1:0)+(t.match(/knight/i)?2:0)+(t.match(/paladin/i)?4:0)+(t.match(/sorcerer/i)?8:0);
  };
  while (h.search(/\s\s/) !== -1) { h = h.replace(/\s\s/g, ' '); }
  h = h.replace(/\s/g, ' ');
  p = h.split('|');
  for (x in p) { if (p.hasOwnProperty(x)) { p[x] = $.trim(p[x]); } }
  while (p[0] === '') { p = p.slice(1); }
  for (x = 0; x < p.length; x = x + 7) {
    ret[p[x].toLowerCase()] = {
      name:p[x], arm:(parseInt(p[x+1], 10) || 0), oz:parseFloat(p[x+2]) || 0, lvl:(parseInt(p[x+5], 10) || 0),
      att:$.trim(p[x+3].replace(/none\.?/gi, '').replace(/<a.*?>(.*?)<\/a>/gi, '$1').replace(/</g, '')),
      voc:get_vocation_number(p[x+6]), ur:calculator_armor_get_link_for_name(p[x], part),
      resist:{
        physical:(parseInt((' '+p[x+4]).split(/physical/i)[1], 10) || 0), fire:(parseInt((' '+p[x+4]).split(/fire/i)[1], 10) || 0),
        earth:(parseInt((' '+p[x+4]).split(/earth/i)[1], 10) || 0), energy:(parseInt((' '+p[x+4]).split(/energy/i)[1], 10) || 0),
        ice:(parseInt((' '+p[x+4]).split(/ice/i)[1], 10) || 0), holy:(parseInt((' '+p[x+4]).split(/holy/i)[1], 10) || 0),
        death:(parseInt((' '+p[x+4]).split(/death/i)[1], 10) || 0)
      }
    };
  }
  x = 'No'+name.slice(0, 1).toUpperCase()+name.slice(1);
  ret[x.toLowerCase()] = {name:x, arm:0, oz:0, att:'', lvl:0, voc:0, resist:{physical:0, fire:0, earth:0, energy:0, ice:0, holy:0, death:0}};
  ret[x.toLowerCase()].ur = calculator_armor_get_link_for_name(x, part);
  $('#calculator_armor_body_'+calculator_armor_parts_names[part]).attr('src', ret[x.toLowerCase()].ur);
  return ret;
};

calculator_armor_do_items_sorted = function(part, key) {
  if (typeof key === 'undefined') { key = $('[name=calculator_armor_items_sort]:checked').val(); }
  calculator_armor_items_sorted = calculator_armor_items_data[part];
  if (key === 'name') { calculator_armor_items_sorted = calculator_array_sort(calculator_armor_items_sorted, false, true); }
  else { calculator_armor_items_sorted = calculator_array_sort(calculator_armor_items_sorted, false, false, true, key); }
};

calculator_armor_calculate = function() {
  var x, lvl = 0, oz = 0, arm = 0, dmg_prot = [], tmp, dmg_type = $('#calculator_armor_damage_type :selected').text();
  $('#calculator_armor_links').html('<b>Links to items</b><br />');
  for (x=0;x<calculator_armor_parts_names.length;x++) {
    tmp = unescape($('#calculator_armor_body_'+calculator_armor_parts_names[x]).attr('src').replace(/.*\/([^\/]*)\..*/, '$1').replace(/_/g,' ').toLowerCase());
    if (tmp) {
      arm += calculator_armor_items_data[x][tmp].arm;
      oz += calculator_armor_items_data[x][tmp].oz;
      lvl = (calculator_armor_items_data[x][tmp].lvl > lvl ? calculator_armor_items_data[x][tmp].lvl : lvl);
      if ('no'+calculator_armor_parts_names[x] !== tmp.toLowerCase()) {
        $('#calculator_armor_links').append('<a href="/wiki/'+escape(calculator_armor_items_data[x][tmp].name.replace(/ /g, '_'))+'">'+calculator_armor_items_data[x][tmp].name+'</a><br />');
      }
      if ((tmp = calculator_armor_items_data[x][tmp].resist[dmg_type.toLowerCase()]) !== 0) { dmg_prot.push(tmp); }
    }
  }
  $('#calculator_armor_links a').click(function(){window.open(this.href); return false;});
  tmp = []; for (x=0;x<dmg_prot.length;x++) { tmp.push(dmg_prot[x]+'%'); }
  $('#calculator_armor_set_prot').text(dmg_type+' protection: '+(!tmp.length ? '0%' : tmp.join(', ')));
  var calculate_damage = function(total_arm, damage, prot) {
    var r1 = 0, r2 = 0, r3; damage = parseInt(damage, 10);
    if ($('#calculator_armor_damage_type').val() === 'physical') {
      $.each(prot, function(i, v) { damage = parseInt(((100 - v)/100)*damage, 10); });
      r1 += (total_arm < 2 ? total_arm : Math.floor(total_arm / 2));
      r2 += (total_arm < 2 ? total_arm : (total_arm % 2 === 0 ? total_arm - 1 : total_arm - 2));
      r1 = r1 > damage ? damage : r1; r2 = r2 > damage ? damage : r2;
      r3 = (r2+r1)/2;
      // min/max (avg)
      return (r2 > damage ? 0 : (damage - r2))+'/'+(r1 > damage ? 0 : (damage - r1))+' ('+ (r3 > damage ? 0 : (damage - r3)) +')';
    }
    else { r1 = damage; $.each(prot, function(i, v) { r1 = parseInt(((100 - v)/100)*r1, 10); }); return r1; }
  };
  $('#calculator_armor_damages tr:eq(1) td').text(function(i) {
    if (i !== 8) { return calculate_damage(arm, $('#calculator_armor_damages tr:eq(0) td:eq('+i+')').text(), dmg_prot); }
    return calculate_damage(arm, $('#calculator_armor_damages input').val(), dmg_prot);
  });
  $('#calculator_armor_req_level').html(lvl || 'None');
  oz = String(oz);
  $('#calculator_armor_set_oz').html(oz + (oz.match(/\.\d/) ? '0' : (oz.match(/\.\d\d/) ? '' : '.00')) +' oz');
  $('#calculator_armor_set_arm').html(arm);
};

$('#calculator_armor_damage_type').change(function() {
  $('[name=calculator_armor_items_sort][value='+$('#calculator_armor_damage_type').val()+']').attr('checked', 'checked');
  $('#calculator_armor_damage_type_ind').text($('#calculator_armor_damage_type :selected').text());
  $('#calculator_armor_body_'+calculator_armor_parts_names[calculator_armor_current_part]).click();
  calculator_armor_calculate();
});

$('#calculator_armor_voc').change(function() {
  var need_clear = false;
  $.each(calculator_armor_parts_names, function(i, v) {
    var tmp = unescape($('#calculator_armor_body_'+v).attr('src').replace(/.*\/([^\/]*)\..*/, '$1').replace(/_/g,' ').toLowerCase());
    if (!tmp) { return; }
    if (calculator_armor_items_data[i][tmp].voc !== 0 && !(calculator_armor_items_data[i][tmp].voc & parseInt($('#calculator_armor_voc').val(), 10))) { need_clear = true; return false; }
  });
  if (need_clear) {
    if (confirm('This will reset the set, continue?')) {
      $.each(calculator_armor_parts_names, function(i, v) {
        var x = 'No'+v.slice(0, 1).toUpperCase()+v.slice(1);
        $('#calculator_armor_body_'+v).attr('src', calculator_armor_get_link_for_name(x, i)).attr('alt', '');
      });
      calculator_armor_vocv = parseInt($('#calculator_armor_voc').val(), 10);
    }
    else { $('#calculator_armor_voc').val(calculator_armor_vocv); }
  }
  else { calculator_armor_vocv = parseInt($('#calculator_armor_voc').val(), 10); }
  $('#calculator_armor_body_'+calculator_armor_parts_names[calculator_armor_current_part]).click();
  calculator_armor_calculate();
});


$('#calculator_armor_custom_damage').keyup(function(){ $(this).val(parseInt($(this).val(), 10) || 0); if ($(this).val()==='0') { $(this).select(); }calculator_armor_calculate(); });

calculator_armor_tt_html = function(d) {
  var arm_att_resist, att_resist, oz, x, voc_lvl = [], resist = [];
  for (x in d.resist) { if (d.resist.hasOwnProperty(x)) {
    if (d.resist[x] !== 0) { resist.push(x + ' '+(d.resist[x] > 0?'+':'')+d.resist[x]+'%'); }
  } }
  resist = resist.length ? 'protection '+resist.join(', ') : '';
  if (d.voc & 1) { voc_lvl.push('druids'); } if (d.voc & 2) { voc_lvl.push('knights'); }
  if (d.voc & 4) { voc_lvl.push('paladins'); } if (d.voc & 8) { voc_lvl.push('sorcerers'); }
  voc_lvl = (voc_lvl.length || d.lvl) ? '<br />It can only be wielded properly by '+(voc_lvl.length ? voc_lvl.join(' and ') : 'players')+(d.lvl ? ' of level '+d.lvl+' or higher' : '')+'.' : '';
  att_resist = (d.att ? (resist.length ? [d.att, resist] : [d.att]) : (resist.length ? [resist] : [])).join(', ');
  arm_att_resist = (d.arm ? 'Arm:' + d.arm + (att_resist.length ? ', ' : '') : '');
  arm_att_resist += (att_resist ? att_resist : '');
  oz = String(d.oz);
  oz = oz + (oz.match(/\.\d/) ? '0' : (oz.match(/\.\d\d/) ? '' : '.00'));
  return '<b>'+d.name+'</b>' + (arm_att_resist ? ' ('+arm_att_resist+')' : '')+ voc_lvl + (d.oz ? '<br />It weighs '+oz+' oz.' : '');
};
$('#calculator_armor_body_main img').click(function(e) {
  var tmp, x, y, t = parseInt(calculator_armor_names_parts[$(this).attr('id').split('_')[3]], 10);
  calculator_armor_current_part = t; calculator_armor_do_items_sorted(calculator_armor_current_part);
  $('#calculator_armor_items_div').html('');
  for (x in calculator_armor_items_sorted) { if (calculator_armor_items_sorted.hasOwnProperty(x)) {
    tmp = true; for (y in calculator_armor_items_sorted[x].resist) { if (calculator_armor_items_sorted[x].resist.hasOwnProperty(y)) {
      if (calculator_armor_items_sorted[x].resist[y] !== 0) { tmp = false; break; }
    } }
    if (
       (('no'+calculator_armor_parts_names[t] === x.toLowerCase()) || $('#calculator_armor_np').is(':checked') || !tmp || calculator_armor_items_sorted[x].arm !== 0)
       && (calculator_armor_items_sorted[x].voc === 0 || calculator_armor_vocv === 0 || (calculator_armor_items_sorted[x].voc & calculator_armor_vocv))
    ) {
      $('#calculator_armor_items_div').append(
        $('<img class="item_img" '+'src="'+calculator_armor_items_sorted[x].ur+'" '+
          'alt="'+calculator_armor_items_sorted[x].name+'" '+
          'width="32" height="32" />'));
    }
    } }
  $('.item_img').css('cursor', 'pointer')
  .click(function(){
    $('#calculator_armor_body_'+calculator_armor_parts_names[calculator_armor_current_part]).attr('src', $(this).attr('src')).attr('alt', $(this).attr('alt'));
    calculator_armor_calculate();
  })
  .mousemove(function(e) {
    if ($(this).attr('alt') === '') { return; }
    var t = calculator_armor_items_data[calculator_armor_current_part][unescape($(this).attr('src').replace(/.*\/([^\/]*)\..*/, '$1').replace(/_/g,' ').toLowerCase())];
    $('#calculator_armor_tt_items').show().css({top:(e.pageY+20)+'px', left:(e.pageX+10)+'px'}).html(calculator_armor_tt_html(t));
  })
  .mouseout(function(e){$('#calculator_armor_tt_items').hide();});
  if ($('#calculator_armor_tt_items').size() === 0) {
    $('body:eq(0)').append($('<div id="calculator_armor_tt_items"> </div>'));
  }
})
.mousemove(function(e) {
  if ($(this).attr('alt') === '') { return; }
  var t = calculator_armor_items_data[calculator_armor_names_parts[$(this).attr('id').split('_')[3]]][unescape($(this).attr('src').replace(/.*\/([^\/]*)\..*/, '$1').replace(/_/g,' ').toLowerCase())];
  $('#calculator_armor_tt_items').show().css({top:(e.pageY+20)+'px', left:(e.pageX+10)+'px'}).html(calculator_armor_tt_html(t));
})
.mouseout(function(e){$('#calculator_armor_tt_items').hide();});

$('#calculator_armor_np').click(function(){ $('#calculator_armor_body_'+calculator_armor_parts_names[calculator_armor_current_part]).click(); });
$('[name=calculator_armor_items_sort]').click(function() { $('#calculator_armor_body_'+calculator_armor_parts_names[calculator_armor_current_part]).click(); });

calculator_armor_items_data = [get_items_data('amulet'), get_items_data('ring'), get_items_data('helmet'), get_items_data('armor'), get_items_data('legs'), get_items_data('boots')];

$('#calculator_armor_body_helmet').click();
calculator_armor_calculate();

$('#calculator_armor_links').after('<hr />Code for your ',(wgUserName?$('<a href="http://tibia.wikia.com/wiki/User:'+wgUserName+'?action=edit">user page</a>').click(function(){window.open($(this).attr('href'));return false;}):'user page'),' ',$('<input type="button" value="Get" />').click(function(){calculator_armor_template='Copy after this:\n\n{{Equips_Set';$.each( calculator_armor_parts_names.concat(['lefthand','righthand','shoulders','belt']),function(i,v){calculator_armor_template+='\n  |'+calculator_armor_template_translate[v]+'='+($('#calculator_armor_body_'+v).attr('alt')||'None');});calculator_armor_template+='\n}}';alert(calculator_armor_template);}));

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

}());

Обнаружено использование расширения AdBlock.


Викия — это свободный ресурс, который существует и развивается за счёт рекламы. Для блокирующих рекламу пользователей мы предоставляем модифицированную версию сайта.

Викия не будет доступна для последующих модификаций. Если вы желаете продолжать работать со страницей, то, пожалуйста, отключите расширение для блокировки рекламы.

Также на ФЭНДОМЕ

Случайная вики