MediaWiki:Bestiary/Code.js

// /*jslint devel: true, browser: true, white: true, indent: 2, plusplus: true, bitwise: true*/ /*global $, wgUserName, mw */ $(window).load(function {   //__NOWYSIWYG__    'use strict';    /*$('#bestiary_creature_img').html( '' );*/   var bestiary_creature_info,    bestiary_difficulty = ['harmless', 'trivial', 'easy', 'medium', 'hard'],    fpath = 'https://tibia.fandom.com/wiki/Special:FilePath?file=',    //Get data from DPL table when page is loaded.     bestiary_get_creature_info = function (difficulty) {        var ret = {},        x, p, h = $('#bestiary_list_' + difficulty).html.replace(/ /gi, ).replace(/<\/p>/gi, );        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) {            ret[p[x].toLowerCase] = {                ur: fpath + p[x] + '.gif',//bestiary_get_link_for_name(p[x], difficulty), name: p[x++], hp: p[x++] || '?', exp: p[x++] || '?', armor: p[x++] || '?', speed: p[x++] || '?', bestiaryclass: p[x++].toLowerCase, bestiarylevel: p[x++], occurrence: p[x++], physicalDmgMod: (parseInt(p[x++], 10) || 100), earthDmgMod: (parseInt(p[x++], 10) || 100), fireDmgMod: (parseInt(p[x++], 10) || 100), energyDmgMod: (parseInt(p[x++], 10) || 100), iceDmgMod: (parseInt(p[x++], 10) || 100), deathDmgMod: (parseInt(p[x++], 10) || 100), holyDmgMod: (parseInt(p[x++], 10) || 100), healMod: (parseInt(p[x++], 10) || 100), location: p[x++], loot: p[x++] };       }        return ret; },   bestiary_level_imgs = {harmless: 'https://vignette.wikia.nocookie.net/tibia/images/a/ab/Bestiary_Level_Harmless.gif/revision/latest?cb=20180618025240&path-prefix=en', trivial: 'https://vignette.wikia.nocookie.net/tibia/images/d/d1/Bestiary_Level_Trivial.gif/revision/latest?cb=20171226161649&path-prefix=en', easy: 'https://vignette.wikia.nocookie.net/tibia/images/b/bf/Bestiary_Level_Easy.gif/revision/latest?cb=20171226161648&path-prefix=en', medium: 'https://vignette.wikia.nocookie.net/tibia/images/f/ff/Bestiary_Level_Medium.gif/revision/latest?cb=20171226161649&path-prefix=en', hard: 'https://vignette.wikia.nocookie.net/tibia/images/4/46/Bestiary_Level_Hard.gif/revision/latest?cb=20171226161648&path-prefix=en'}, bestiary_occurrence_imgs = {common: 'https://vignette.wikia.nocookie.net/tibia/images/2/2c/Bestiary_Occurrence_Common.gif/revision/latest?cb=20180618025920&path-prefix=en', uncommon: 'https://vignette.wikia.nocookie.net/tibia/images/2/2f/Bestiary_Occurrence_Uncommon.gif/revision/latest?cb=20180618025920&path-prefix=en', rare: 'https://vignette.wikia.nocookie.net/tibia/images/d/d5/Bestiary_Occurrence_Rare.gif/revision/latest?cb=20180618025921&path-prefix=en', veryrare: 'https://vignette.wikia.nocookie.net/tibia/images/0/08/Bestiary_Occurrence_Very_Rare.gif/revision/latest?cb=20180618025921&path-prefix=en'}, bestiary_populate_ui = function(creature) { var data = bestiary_creature_info[creature], minKills = {harmless: 25, trivial: 250, easy: 500, medium: 1000, hard: 2500}, charmPts = {harmless: 1, trivial: 5, easy: 15, medium: 25, hard: 50}, charmPtsvr = {harmless: 5, trivial: 10, easy: 30, medium: 50, hard: 100}, dmgMods = ['physicalDmgMod', 'earthDmgMod', 'fireDmgMod', 'energyDmgMod', 'iceDmgMod','deathDmgMod', 'holyDmgMod', 'healMod'], dmgNames = ['physical', 'earth', 'fire', 'energy', 'ice', 'death', 'holy', 'heal'], occurr = data.occurrence.toLowerCase.replace(/\s/, ''), itemcounter = {}, rareness = ['common', 'uncommon', 'semirare', 'rare', 'veryrare']; $('#bestiary_creature_img').html(''); $('#bestiary_creature_name').html('' + data.name + ''); $('#bestiary_creature_hp').html(data.hp); $('#bestiary_creature_exp').html(data.exp); $('#bestiary_creature_speed').html(data.speed); $('#bestiary_creature_armor').html(data.armor); //       if (data.bestiarylevel !== "") { $('#bestiary_creature_bestiarylevel').html(''); $('#bestiary_creature_bestiarylevel').attr('title', 'Difficulty: ' + data.bestiarylevel); } else { $('#bestiary_creature_bestiarylevel').empty; }       if (data.occurrence !== "") { $('#bestiary_creature_occurrence').html(''); $('#bestiary_creature_occurrence').attr('title', 'Occurrence: ' + data.occurrence); } else { $('#bestiary_creature_occurrence').empty; }       if (data.occurrence == "Very Rare") { $('#bestiary_creature_charms').html(charmPtsvr[data.bestiarylevel.toLowerCase]); } else { $('#bestiary_creature_charms').html(charmPts[data.bestiarylevel.toLowerCase]); }       //        $('#bestiary_kills2').html(data.bestiarylevel == "Very Rare" ? 5 : minKills[data.bestiarylevel.toLowerCase]); $('#bestiary_kills2').attr('title', minKills[data.bestiarylevel.toLowerCase] + ' / ' + minKills[data.bestiarylevel.toLowerCase] + ' (fully unlocked)');

$.each(dmgMods, function (i, v) {           var tmp = '#bestiary_creature_' + v;            var val = data[v];            if (val === 0) {                $(tmp).attr('class', 'bestiary_dmg_immune');                $(tmp).parent.attr('title', 'Sensitive to ' + dmgNames[i] + ': ' + val + '% (immune)');            } else if (val < 100) {                $(tmp).attr('class', 'bestiary_dmg_strong');                $(tmp).parent.attr('title', 'Sensitive to ' + dmgNames[i] + ': ' + val + '% (strong)');            } else if (val ==100) {                $(tmp).attr('class', 'bestiary_dmg_neutral');                $(tmp).parent.attr('title', 'Sensitive to ' + dmgNames[i] + ': ' + val + '% (neutral)');            } else if (val > 100) {                $(tmp).attr('class', 'bestiary_dmg_weak');                $(tmp).parent.attr('title', 'Sensitive to ' + dmgNames[i] + ': ' + val + '% (weak)'); }           val += val > 100 ? 5 : 0; //Adds 5 if weak to account for 1px border between neutral and weak. $(tmp).width(21 + val/5); });       //        $('#bestiary_creature_locations').html(data.location);        //        $.each(rareness, function(i, v) { $('#bestiary_loot_' + v).empty; itemcounter[v] = 0; });       $('#bestiary_loot_common').empty;        $('#bestiary_loot_uncommon').empty;        if (typeof(data.loot) == "undefined") {}        $.each($($.parseHTML(data.loot)).find('li'), function(i, v) { //Removes x symbol and  tag var item, amount, name, rarity; item = v.innerHTML.replace(/×\s/, '').replace(//, '/').replace(/<\/a>\s?/, '/').split('/'); if (item.length != 3) { console.log("Error parsing item."); console.log(item); } else { amount = item[0] || 1; name = item[1]; rarity = item[2].replace(/[\(\)\-\s]/g, ''); if (rarity == 'always' || rarity === '') { rarity = 'common'; }               $('#bestiary_loot_' + rarity).append(' ' + amount + '  '); itemcounter[rarity]++; }       });        $.each(rareness, function(i, v) { if (itemcounter[v] === 0) { $('#bestiary_loot_' + v).parent.hide; } else { $('#bestiary_loot_' + v).parent.show; var rows = Math.ceil(itemcounter[v] / 14); var itemsleft = rows*14 - itemcounter[v]; for (i = 0; i < itemsleft; i++) { $('#bestiary_loot_' + v).append(' '); }               $('#bestiary_loot_' + v).parent.height(rows * 32 + 'px'); $($('#bestiary_loot_' + v).parent.find('span')[0]).css('line-height', rows * 32 + 'px'); }       });    };    $.each(bestiary_difficulty, function (i, v) { bestiary_creature_info = {...bestiary_creature_info, ...bestiary_get_creature_info(v)}; });   $('#bestiary_search').html( '' );   $('#bestiary_search_btn').click(function { var query = $('#bestiary_input').val.toLowerCase; if (query === '') { return; }       var results = []; $.each(bestiary_creature_info, function (i, v) {           if (v.name.toLowerCase.includes(query)) {                results.push(v);            }         }); if (results.length == 1) { bestiary_populate_ui(results[0].name.toLowerCase); $('#bestiary_creature_namebar').show; $('#bestiary_search_results').hide; } else { $('#bestiary_creature_namebar').hide; $('#bestiary_search_results').empty; $('#bestiary_search_results').show; $.each(results, function(i, v) {               var nm = v.name, title = , vr = ;                if (nm.length > 15) {                    title = ' title="' + nm + '"';                    nm = nm.substr(0, 13) + "...";                }                 if (v.occurrence == 'Very Rare') {                    vr = ' <img src="' + fpath + 'Bestiary Occurrence Icon.gif"> ';                }                $('#bestiary_search_results').append( '<div class="bestiary_search_box">' + '<div class="bestiary_search_name bestiary_bgdark"' + title + '>' + nm + ' ' + '<div class="bestiary_search_img" name="'+ v.name.toLowerCase + '">' + '<img src="' + fpath + v.name + '.gif"> ' + ' <img src="' + fpath + 'Check_Mark.gif"> ' + vr + ' '               );            });        }     });    $(document).on('click', '.bestiary_search_img', function  { $('#bestiary_creature_namebar').show; $('#bestiary_search_results').hide; bestiary_populate_ui($(this).attr('name')); });   $('#bestiary_input').keypress(function(e) { if (e.which == 13) { //Enter key $('#bestiary_search_btn').click; }   });    bestiary_populate_ui('orc'); });