Atalhos

Itens
Atalhos aventuras.png
Atalhos conjuntos.png
Atalhos cidades.png
Atalhos trabalhos.png
Atalhos ofícios.png
Atalhos fortes.png
Atalhos mpi.png
Atalhos duelos.png
Atalhos sucessos.png


InnoGames

IconTheWest.png IconElvenar.png IconForgeofEmpires.png IconGodKings.png

IconGrepolis.png IconTribos.png IconTribalWars2.png IconWarlordsofAternum.png


Segue-nos

IconFórumTW.jpg IconFB.png IconTwitter.png IconYT.png

Da wiki Wiki The-West PT
Ir para: navegação, pesquisa
m
m
Linha 216: Linha 216:
 
                 img: "/images/thumb/b/b8/Cavalo_de_corrida.png/40px-Cavalo_de_corrida.png"
 
                 img: "/images/thumb/b/b8/Cavalo_de_corrida.png/40px-Cavalo_de_corrida.png"
 
             }
 
             }
 +
        },
 +
        sorting: {
 +
            'Strength':'{"str":1}',
 +
            'Mobility':'{"mob":1}',
 +
            'Dexterity':'{"dex":1}',
 +
            'Charisma':'{"cha":1}',
 +
            'Construction':'{"str":1,"con":1}',
 +
            'Vigor':'{"str":1,"vig":1}',
 +
            'Toughness':'{"str":1,"tou":1}',
 +
            'Stamina':'{"str":1,"sta":1}',
 +
            'Health Points':'{"str":1,"hea":1}',
 +
            'Horseback Riding':'{"mob":1,"rid":1}',
 +
            'Reflex':'{"mob":1,"ref":1}',
 +
            'Dodging':'{"mob":1,"dod":1}',
 +
            'Hiding':'{"mob":1,"hid":1}',
 +
            'Swimming':'{"mob":1,"swi":1}',
 +
            'Aiming':'{"dex":1,"aim":1}',
 +
            'Shooting':'{"dex":1,"sho":1}',
 +
            'Setting traps':'{"dex":1,"pit":1}',
 +
            'Fine Motor Skills':'{"dex":1,"fin":1}',
 +
            'Repairing':'{"dex":1,"rep":1}',
 +
            'Leadership':'{"cha":1,"lea":1}',
 +
            'Tactics':'{"cha":1,"tac":1}',
 +
            'Trading':'{"cha":1,"tra":1}',
 +
            'Animal Instinct':'{"cha":1,"ani":1}',
 +
            'Appearance':'{"cha":1,"app":1}',
 +
            'Labor points towards building':'{"str":3,"con":3,"dex":1,"rep":1,"cha":1,"lea":1}',
 +
            'Experience from jobs, duels, and fort battles (%)':'{"xp":1}',
 +
            'Money from jobs and duels (%)':'{"money":1}',
 +
            'Increased Luck (%)':'{"luck":1}',
 +
            'Regeneration (%)':'{"regen":1}',
 +
            'Improved drop chance (%)':'{"drop":1}',
 +
            'Speed (%)':'{"spd":1,"hspd":1,"mob":1,"rid":1}',
 +
            'Average damage':'{"dmg_min":0.5,"dmg_max":0.5,"dmglvl":1}',
 +
            'Maximum damage':'{"dmg_max":1,"dmglvl":1}',
 
         }
 
         }
 
     },
 
     },
 +
 +
 
     initPage: function () {
 
     initPage: function () {
 
         //Append input level
 
         //Append input level
Linha 261: Linha 298:
 
             });
 
             });
 
         }
 
         }
       
+
 
 
         //Switch products
 
         //Switch products
 
         if ($("#switch_prod").length === 1) {
 
         if ($("#switch_prod").length === 1) {
Linha 282: Linha 319:
 
             $('.item_container img').on('dblclick', function () {
 
             $('.item_container img').on('dblclick', function () {
 
                 window.location = '/wiki/' + mw.config.get('wgFormattedNamespaces')[10] + ':Item_' + JSON.parse($(this).parent().attr('data-popup')).id / 1000;
 
                 window.location = '/wiki/' + mw.config.get('wgFormattedNamespaces')[10] + ':Item_' + JSON.parse($(this).parent().attr('data-popup')).id / 1000;
 +
            });
 +
        }
 +
        if (westui.config.link_on_dblclick) {
 +
            $('.item_container img').on('dblclick', function () {
 +
                window.location = '/wiki/' + $(this).parent().attr('data-link');
 
             });
 
             });
 
         }
 
         }
Linha 514: Linha 556:
 
         itemStatus: {},
 
         itemStatus: {},
 
         getData: function () {
 
         getData: function () {
            //Get bonuses from all item sets
 
 
             $('.set_container').each(function () {
 
             $('.set_container').each(function () {
 
                 var set_id = $(this).attr('data-set-id');
 
                 var set_id = $(this).attr('data-set-id');
Linha 522: Linha 563:
 
                     set: {}
 
                     set: {}
 
                 };
 
                 };
                $(this).find('.item_container').each(function () {
 
                    var json = JSON.parse($(this).attr('data-popup'));
 
                    if ($(this).is(":hidden")) {
 
                        westui.set_calc.itemStatus[set_id][json.id] = false;
 
                    } else {
 
                        westui.set_calc.itemStatus[set_id][json.id] = 0;
 
                    }
 
                    for (var prop in json) {
 
                        if (json.hasOwnProperty(prop) && westui.config.set_bonus.hasOwnProperty(prop)) {
 
                            if (!westui.set_calc.data[set_id].items[prop]) {
 
                                westui.set_calc.data[set_id].items[prop] = {};
 
                            }
 
                            westui.set_calc.data[set_id].items[prop][json.id] = json[prop];
 
                        }
 
                    }
 
                });
 
 
             });
 
             });
 
             //Get bonuses from all sets
 
             //Get bonuses from all sets
Linha 561: Linha 586:
 
                 });
 
                 });
 
             });
 
             });
 
+
            //Get bonuses from all item sets
 +
            $('.set_container').each(function () {
 +
                var set_id = $(this).attr('data-set-id');
 +
                $(this).find('.item_container').each(function () {
 +
                    var json = JSON.parse($(this).attr('data-popup'));
 +
                    if ($(this).is(":hidden")) {
 +
                        westui.set_calc.itemStatus[set_id][json.id] = false;
 +
                    } else {
 +
                        westui.set_calc.itemStatus[set_id][json.id] = 0;
 +
                    }
 +
                    for (var prop in json) {
 +
                        if (json.hasOwnProperty(prop) && (westui.config.set_bonus.hasOwnProperty(prop) || westui.set_calc.bonus.extra_set_bonus.hasOwnProperty(prop))) {
 +
                            if (!westui.set_calc.data[set_id].items[prop]) {
 +
                                westui.set_calc.data[set_id].items[prop] = {};
 +
                            }
 +
                            westui.set_calc.data[set_id].items[prop][json.id] = json[prop];
 +
                        }
 +
                    }
 +
                });
 +
            });
 
         },
 
         },
 
         calc: function () {
 
         calc: function () {
Linha 593: Linha 637:
 
                                             total[key] += Math.round(1e6 * (value * 1 + Math.round(Math.max(1, value * 1000 * lvl)) / 10000)) / 1e6;
 
                                             total[key] += Math.round(1e6 * (value * 1 + Math.round(Math.max(1, value * 1000 * lvl)) / 10000)) / 1e6;
 
                                         } else {
 
                                         } else {
                                             total[key] += Math.round(Math.max(1, value * 0.1 * lvl));
+
                                             total[key] += value + Math.round(Math.max(1, value * 0.1 * lvl));
 
                                         }
 
                                         }
 
                                     } else {
 
                                     } else {
Linha 684: Linha 728:
 
             if ($('#input_level').length === 0)
 
             if ($('#input_level').length === 0)
 
                 westui.set_calc.calc();
 
                 westui.set_calc.calc();
 +
        }
 +
    },
 +
    sorting: {
 +
        sortItems: function(param){
 +
            $('.item_container').removeAttr('data-sort');
 +
            function calcSortVal(el){
 +
                var data = JSON.parse($(el).attr('data-popup'));
 +
                var val = 0;
 +
                for (var prop in param){
 +
                    if (data[prop]){
 +
                        if (data[prop]<0){
 +
                            val+=Math.ceil(-data[prop]*($('#input_level input').val()?$('#input_level input').val():150))*param[prop];
 +
                        } else {
 +
                            val+=data[prop]*param[prop];
 +
                        }
 +
                    }
 +
                }
 +
                $(el).attr('data-sort',val);
 +
                if ($(el).find('p.number').length!==0){
 +
                    $(el).find('p.number').html(val);
 +
                } else {
 +
                    $(el).append('<p class="number">'+val+'</p>');
 +
                }
 +
            }
 +
            $('#mw-content-text').find('.sorting_hidden').hide();
 +
            $('#mw-content-text').find('.item_container').sort(function(a, b) {
 +
                if (!$(a).attr('data-sort')){calcSortVal(a);}
 +
                if (!$(b).attr('data-sort')){calcSortVal(b);}
 +
                return $(b).attr('data-sort') - $(a).attr('data-sort');
 +
            }).appendTo('#mw-content-text');
 +
        },
 +
        init:function(){
 +
            if ($('div#sort_items').length===1){
 +
                var html = "<div id='input_search'><select id='sort_items' class='west'><option selected disabled>Order by :</option>";
 +
                for (var prop in westui.config.sorting){
 +
                    html+= "<option value='"+westui.config.sorting[prop]+"'>"+prop+"</option>";
 +
                }
 +
                html += "</select></div>";
 +
                $('div#sort_items').html(html);
 +
                $('select#sort_items').on('change',function(){
 +
                    westui.sorting.sortItems(JSON.parse($(this).find("option:selected").attr('value')));
 +
                });
 +
            }
 
         }
 
         }
 
     },
 
     },
Linha 689: Linha 776:
 
         westui.initPage();
 
         westui.initPage();
 
         westui.popup.init();
 
         westui.popup.init();
 +
        if (westui.config.enable_sorting)
 +
            westui.sorting.init();
 
         if (westui.config.enable_set_calc && $('.infoSet').length !== 0) {
 
         if (westui.config.enable_set_calc && $('.infoSet').length !== 0) {
 
             westui.set_calc.init();
 
             westui.set_calc.init();

Revisão das 18h38min de 30 de novembro de 2019

westui = {

   lang: {
       input_level: "Nível",
       input_search: "Procurar",
       damages: "Dano",
       per_level: "por Nível",
       speed: "Velocidade",
       level: "Nível",
       unsalable: "Não pode ser vendido",
       auction: "Leiloável",
       not_auction: "Não é leiloável",
       not_upgrade: "Não é possível melhorar o item",
       upgrade: "Melhorável",
       total: "Total",
       popup: {
           dmg: {

dmglvl: '

'

           },
           skills: {

str: '

', mob: '

', dex: '

', cha: '

', con: '

', vig: '

', tou: '

', sta: '

', hea: '

', rid: '

', ref: '

', dod: '

', hid: '

', swi: '

', aim: '

', sho: '

', pit: '

', fin: '

', rep: '

', lea: '

', tac: '

', tra: '

', ani: '

', app: '

'

           },
           fb: {

fbdef: '

', fboff: '

', fbres: '

', fbdefs: '

', fboffs: '

', fbdmgs: '

'

           },
           special: {

xp: '

', money: '

', luck: '

', regen: '

', drop: '

', labor_pts: '

', spd: '

'

           }
       }
   },
   config: {
       enable_set_calc: true,
       plain_popup: true,
       redirect_on_dblclick: false,
       cdn: "https://westzz.innogamescdn.com",
       img_buyprice: "/images/5/57/Buy_price.png",
       img_sellprice: "/images/f/fc/Sell_price.png",
       img_male: "/images/7/72/Masculino.png",
       img_female: "/images/2/24/Feminino.png",
       set_bonus: {
           str: {
               name: "Força",
               img: "/images/thumb/6/65/For%C3%A7a.png/40px-For%C3%A7a.png"
           },
           mob: {
               name: "Mobilidade",
               img: "/images/thumb/f/fb/Mobilidade.png/40px-Mobilidade.png"
           },
           dex: {
               name: "Destreza",
               img: "/images/thumb/5/5d/Destreza.png/40px-Destreza.png"
           },
           cha: {
               name: "Carisma",
               img: "/images/thumb/6/6a/Carisma.png/40px-Carisma.png"
           },
           con: {
               name: "Construção",
               img: "/images/thumb/e/e9/Constru%C3%A7%C3%A3o.png/40px-Constru%C3%A7%C3%A3o.png"
           },
           vig: {
               name: "Vigor",
               img: "/images/thumb/f/f4/Vigor.png/40px-Vigor.png"
           },
           tou: {
               name: "Resistência",
               img: "/images/thumb/d/d5/Resist%C3%AAncia.png/40px-Resist%C3%AAncia.png"
           },
           sta: {
               name: "Tolerância",
               img: "/images/thumb/6/67/Toler%C3%A2ncia.png/40px-Toler%C3%A2ncia.png"
           },
           hea: {
               name: "Pontos de vida",
               img: "/images/thumb/0/01/Pontos_de_vida.png/40px-Pontos_de_vida.png"
           },
           rid: {
               name: "Andar a cavalo",
               img: "/images/thumb/4/47/Andar_a_cavalo.png/40px-Andar_a_cavalo.png"
           },
           ref: {
               name: "Reflexos",
               img: "/images/thumb/7/76/Reflexos.png/40px-Reflexos.png"
           },
           dod: {
               name: "Evasão",
               img: "/images/thumb/5/57/Evas%C3%A3o.png/40px-Evas%C3%A3o.png"
           },
           hid: {
               name: "Esconder",
               img: "/images/thumb/2/25/Esconder.png/40px-Esconder.png"
           },
           swi: {
               name: "Nadar",
               img: "/images/thumb/f/fa/Nadar.png/40px-Nadar.png"
           },
           aim: {
               name: "Mira",
               img: "/images/thumb/2/2a/Mira.png/40px-Mira.png"
           },
           sho: {
               name: "Tiroteio",
               img: "/images/thumb/0/01/Tiroteio.png/40px-Tiroteio.png"
           },
           pit: {
               name: "Colocar armadilhas",
               img: "/images/thumb/6/6e/Colocar_armadilhas.png/40px-Colocar_armadilhas.png"
           },
           fin: {
               name: "Perícia",
               img: "/images/thumb/7/7c/Per%C3%ADcia.png/40px-Per%C3%ADcia.png"
           },
           rep: {
               name: "Reparar",
               img: "/images/thumb/f/f3/Reparar.png/40px-Reparar.png"
           },
           lea: {
               name: "Liderança",
               img: "/images/thumb/a/aa/Lideran%C3%A7a.png/40px-Lideran%C3%A7a.png"
           },
           tac: {
               name: "Táticas",
               img: "/images/thumb/4/44/T%C3%A1tica.png/40px-T%C3%A1tica.png"
           },
           tra: {
               name: "Comércio",
               img: "/images/thumb/f/f8/Com%C3%A9rcioHabilidade.png/40px-Com%C3%A9rcioHabilidade.png"
           },
           ani: {
               name: "Instinto animal",
               img: "/images/thumb/e/e6/Instinto_animal.png/40px-Instinto_animal.png"
           },
           app: {
               name: "Aparência",
               img: "/images/thumb/c/c9/Apar%C3%AAncia.png/40px-Apar%C3%AAncia.png"
           },
           fbdef: {
               name: "Defesa (Bónus de batalha no forte)",
               img: "/images/8/82/Set_Fb_defense.png"
           },
           fboff: {
               name: "Ataque (Bónus de batalha no forte)",
               img: "/images/3/30/Set_Fb_offense.png"
           },
           fbres: {
               name: "Resistência (Bónus de batalha no forte)",
               img: "/images/4/4b/Resistance.png"
           },
           fbdefs: {
               name: "Defesa (Bónus de setor de batalha no forte)",
               img: "/images/1/1a/Set_Fb_defense_sec.png"
           },
           fboffs: {
               name: "Ataque (Bónus de setor de batalha no forte)",
               img: "/images/f/fe/Set_Fb_offense_sec.png"
           },
           fbdmgs: {
               name: "Dano (Bónus de setor de batalha no forte)",
               img: "/images/b/b3/Damages_sector.png"
           },
           xp: {
               name: "experiência em trabalhos, duelos e batalhas de forte (%)",
               img: "/images/7/71/Set_xp.png"
           },
           money: {
               name: "salário nos trabalhos e duelos (%)",
               img: "/images/d/df/Set_money.png"
           },
           luck: {
               name: "Aumento de Sorte",
               img: "/images/c/c1/Set_luck.png"
           },
           regen: {
               name: "regeneração",
               img: "/images/5/53/Regeneration.png",
           },
           drop: {
               name: "aumento de hipóteses de drop",
               img: "/images/b/b8/Drop.png"
           },
           spd: {
               name: "Velocidade",
               img: "/images/thumb/b/b8/Cavalo_de_corrida.png/40px-Cavalo_de_corrida.png"
           }
       },
       sorting: {
           'Strength':'{"str":1}',
           'Mobility':'{"mob":1}',
           'Dexterity':'{"dex":1}',
           'Charisma':'{"cha":1}',
           'Construction':'{"str":1,"con":1}',
           'Vigor':'{"str":1,"vig":1}',
           'Toughness':'{"str":1,"tou":1}',
           'Stamina':'{"str":1,"sta":1}',
           'Health Points':'{"str":1,"hea":1}',
           'Horseback Riding':'{"mob":1,"rid":1}',
           'Reflex':'{"mob":1,"ref":1}',
           'Dodging':'{"mob":1,"dod":1}',
           'Hiding':'{"mob":1,"hid":1}',
           'Swimming':'{"mob":1,"swi":1}',
           'Aiming':'{"dex":1,"aim":1}',
           'Shooting':'{"dex":1,"sho":1}',
           'Setting traps':'{"dex":1,"pit":1}',
           'Fine Motor Skills':'{"dex":1,"fin":1}',
           'Repairing':'{"dex":1,"rep":1}',
           'Leadership':'{"cha":1,"lea":1}',
           'Tactics':'{"cha":1,"tac":1}',
           'Trading':'{"cha":1,"tra":1}',
           'Animal Instinct':'{"cha":1,"ani":1}',
           'Appearance':'{"cha":1,"app":1}',
           'Labor points towards building':'{"str":3,"con":3,"dex":1,"rep":1,"cha":1,"lea":1}',
           'Experience from jobs, duels, and fort battles (%)':'{"xp":1}',
           'Money from jobs and duels (%)':'{"money":1}',
           'Increased Luck (%)':'{"luck":1}',
           'Regeneration (%)':'{"regen":1}',
           'Improved drop chance (%)':'{"drop":1}',
           'Speed (%)':'{"spd":1,"hspd":1,"mob":1,"rid":1}',
           'Average damage':'{"dmg_min":0.5,"dmg_max":0.5,"dmglvl":1}',
           'Maximum damage':'{"dmg_max":1,"dmglvl":1}',
       }
   },


   initPage: function () {
       //Append input level
       if ($("#input_level").length === 1) {
           var input_level = $('<input type="number" style="width:80px;" class="west" placeholder="' + westui.lang.input_level + '" min="0" max="150">').bind("propertychange keyup input paste", function () {
               if (this.value > 150) {
                   this.value = 150;
               } else if (this.value < 0) {
                   this.value = 0;
               }
               $(".calc").each(function () {
                   if (input_level.val() == 0) {
                       $(this).html(this.id);
                       $('.per_level_off').addClass('per_level').removeClass('per_level_off');
                   } else {
                       $(this).html(Math.ceil(Number(this.id) * input_level.val()));
                       $('.per_level').addClass('per_level_off').removeClass('per_level');
                   }
               });
           }).appendTo($("#input_level"));
       }
       //Search
       if ($("#input_search").length === 1) {
           var input_search = $('<input type="search" class="west" placeholder="' + westui.lang.input_search + '">').bind("propertychange keyup input paste", function () {
               var val = this.value.toLowerCase();
               if (val === ) {
                   $('.item_container').show();
               } else {
                   $('.item_container').hide();
                   $('.item_container').filter(function () {
                       return $(this).attr('data-popup').toLowerCase().indexOf(val) > -1;
                   }).show();
               }
           }).appendTo($("#input_search"));
       }
       //Switch weapons
       if ($("#switch").length === 1) {
           $("#fire").hide();
           $("#switch").on("click", function () {
               $('#melee, #fire').toggle();
           });
       }
       //Switch products
       if ($("#switch_prod").length === 1) {
           $("#prod2").hide();
           $("#switch_prod").on("click", function () {
               $('#prod, #prod2').toggle();
           });
       }
       //Show a "plain text" popup in the template
       if (westui.config.plain_popup && (new RegExp(mw.config.get('wgFormattedNamespaces')[10] + '\:Item\_*').test(mw.config.get('wgPageName'))) && ($('.item_container').length === 1)) {

$('#mw-content-text').append('

');

           $('#popup_plain').hide();
           $('#popup_plain_contents').append(westui.popup.createPopup($('.item_container').attr('data-popup'), $('.item_container').attr('data-cdn-cat'), $('.item_container').attr('data-cdn-img'), 0));
           $('#popup_plain').slideDown();
       }
       //On dbl click on item, redirect the user to the template
       if (westui.config.redirect_on_dblclick) {
           $('.item_container img').on('dblclick', function () {
               window.location = '/wiki/' + mw.config.get('wgFormattedNamespaces')[10] + ':Item_' + JSON.parse($(this).parent().attr('data-popup')).id / 1000;
           });
       }
       if (westui.config.link_on_dblclick) {
           $('.item_container img').on('dblclick', function () {
               window.location = '/wiki/' + $(this).parent().attr('data-link');
           });
       }
   },
   popup: {
       content: "",
       delay: 200,
       active: false,
       show: function (obj) {
           westui.popup.content = westui.popup.createPopup($(obj).attr('data-popup'), $(obj).attr('data-cdn-cat'), $(obj).attr('data-cdn-img'), parseInt($(obj).attr('data-lvl')));
           westui.popup.active = true;
           westui.popup.setTimeout();
           westui.popup.getContainer().html(westui.popup.content);
       },
       hide: function () {
           westui.popup.getEl().css({
               display: 'none',
               top: 0,
               left: 0
           });
           westui.popup.active = false;
           westui.popup.clearTimeout();
       },
       setTimeout: function () {
           westui.popup.clearTimeout();
           westui.popup.timer = window.setTimeout(function () {
               westui.popup.getEl().css('display', 'block');
           }, westui.popup.delay);
       },
       clearTimeout: function () {
           if (westui.popup.timer) window.clearTimeout(westui.popup.timer);
       },
       getEl: function () {
           return $('#popup_window');
       },
       getContainer: function () {
           return $('#popup_contents');
       },
       createPopup: function (data, cdn_cat, cdn_name, lvl) {
           data = JSON.parse(data);

var html = '


';

           var upgraded = false;
           if ((lvl >= 1) && (lvl <= 5)) {
               upgraded = true;
               data.auc = false;
           }
           if (data.dmg_min && data.dmg_max) {
               if (upgraded) {
                   data.dmg_min += Math.round(Math.max(1, data.dmg_min * 0.1 * lvl));
                   data.dmg_max += Math.round(Math.max(1, data.dmg_max * 0.1 * lvl));
               }

html += '

';

           }
           if (data.text) {
               for (var i = 0; i < data.text.length; i++) {

html += '

';

               }
               html += '
'; } for (var cat in westui.lang.popup) { var cnt = 0; for (var key in westui.lang.popup[cat]) { if (data.hasOwnProperty(key)) { cnt++; var per_level = ""; if (data[key] < 0) { if ($('#input_level input').val() > 0) { data[key] = Math.ceil($('#input_level input').val() * -data[key]); if (upgraded) { data[key] += Math.round(Math.max(1, data[key] * 0.1 * lvl)); } } else { data[key] = -data[key]; per_level = " (" + westui.lang.per_level + ")"; if (upgraded) { data[key] = Math.round(1e6 * (data[key] * 1 + Math.round(Math.max(1, data[key] * 1000 * lvl)) / 10000)) / 1e6; } } } else if (upgraded) { if (data[key] < 1) { data[key] = Math.round(1e6 * (data[key] * 1 + Math.round(Math.max(1, data[key] * 1000 * lvl)) / 10000)) / 1e6; } else { data[key] += Math.round(Math.max(1, data[key] * 0.1 * lvl)); } } html += westui.lang.popup[cat][key].replace('#1', data[key]).replace('#2', per_level); } } if (cnt > 0) { html += '
'; } } if (data.textjob) { for (var i = 0; i < data.textjob.length; i++) {

html += '

';

               }
               html += '
'; } if (data.bonus) { for (var i = 0; i < data.bonus.length; i++) {

html += '

';

               }
               html += '
'; } if (data.jobs) {

html += '

';
               for (var i = 0; i < data.jobs.length; i++) {
html += '';
               }
html += '

';

           }
           if (data.craft) {

html += '

';

           }

html += '

';

           return html;
       },
       setPosition: function (e) {
           var window_width = $(window).width();
           var window_height = $(window).height();
           var popup_width = westui.popup.getEl().outerWidth();
           var popup_height = westui.popup.getEl().outerHeight();
           var pos_x = e.clientX;
           var pos_y = e.clientY;
           var top;
           var left;
           var margin_top = 20;
           var margin_left = 20;
           if (pos_x + popup_width + margin_left > window_width) {
               left = pos_x - popup_width - margin_left + (e.pageX - e.clientX);
           } else {
               left = pos_x + margin_left + (e.pageX - e.clientX);
           }
           if (pos_y + popup_height + margin_top > window_height) {
               top = window_height - popup_height + (e.pageY - e.clientY);
           } else {
               top = pos_y + margin_top + (e.pageY - e.clientY);
           }
           westui.popup.getEl().css({
               top: top,
               left: left
           });
       },
       init: function () {
           //Append popup container

$('body').append('

');

           //Set events
           $(document).on('mouseenter', '.item_container', function (e) {
               westui.popup.show(this);
               westui.popup.setPosition(e);
           });
           $(document).on('mouseleave', '.item_container', function () {
               westui.popup.hide();
           });
           $(document).on('mousemove', '.item_container', function (e) {
               westui.popup.setPosition(e);
           });
           $('.item_level').mousedown(function (e) {
               e.preventDefault();
           });
           $(document).on('click', '.upgrade', function () {
               var container = $(this).closest('.item_container');
               var lvl = parseInt(container.attr('data-lvl'));
               if (lvl !== 5) {
                   container.attr('data-lvl', lvl + 1);
                   container.find('.level').html(lvl + 1);
               }
               westui.popup.show(container[0]);
           });
           $(document).on('click', '.downgrade', function () {
               var container = $(this).closest('.item_container');
               var lvl = parseInt(container.attr('data-lvl'));
               if (lvl !== 0) {
                   container.attr('data-lvl', lvl - 1);
                   container.find('.level').html(lvl - 1);
               }
               westui.popup.show(container[0]);
           });
       }
   },
   set_calc: {
       bonus: {
           //If there are any other "special" bonuses, they will be dynamically retrieved and stored there
           extra_set_bonus: {}
       },
       //Bonuses from all sets / items :
       data: {},
       //Status of all items (item lvl, activated or not)
       itemStatus: {},
       getData: function () {
           $('.set_container').each(function () {
               var set_id = $(this).attr('data-set-id');
               westui.set_calc.itemStatus[set_id] = {};
               westui.set_calc.data[set_id] = {
                   items: {},
                   set: {}
               };
           });
           //Get bonuses from all sets
           $('.infoSet').each(function () {
               var set_id = $(this).attr('data-set-id');
               $(this).find('.infosetatt').each(function () {
                   var nb = $(this).attr('data-nb');
                   westui.set_calc.data[set_id].set[nb] = {};
                   $(this).find('.set_bonus').each(function () {
                       key = $(this).attr('data-type');
                       if ($(this).find('.calc').length !== 0) {
                           westui.set_calc.data[set_id].set[nb][key] = -parseFloat($(this).find('.calc').attr('id'));
                       } else {
                           westui.set_calc.data[set_id].set[nb][key] = parseFloat($(this).find('.val').text());
                       }
                       if (!westui.config.set_bonus.hasOwnProperty(key)) {
                           westui.set_calc.bonus.extra_set_bonus[key] = {
                               img: $(this).find('img').attr('src'),
                               name: $(this).find('#tooltip_content').text()
                           };
                       }
                   });
               });
           });
           //Get bonuses from all item sets
           $('.set_container').each(function () {
               var set_id = $(this).attr('data-set-id');
               $(this).find('.item_container').each(function () {
                   var json = JSON.parse($(this).attr('data-popup'));
                   if ($(this).is(":hidden")) {
                       westui.set_calc.itemStatus[set_id][json.id] = false;
                   } else {
                       westui.set_calc.itemStatus[set_id][json.id] = 0;
                   }
                   for (var prop in json) {
                       if (json.hasOwnProperty(prop) && (westui.config.set_bonus.hasOwnProperty(prop) || westui.set_calc.bonus.extra_set_bonus.hasOwnProperty(prop))) {
                           if (!westui.set_calc.data[set_id].items[prop]) {
                               westui.set_calc.data[set_id].items[prop] = {};
                           }
                           westui.set_calc.data[set_id].items[prop][json.id] = json[prop];
                       }
                   }
               });
           });
       },
       calc: function () {
           //Only calc if a player level is provided
           if ($('#input_level').length === 0 | $('#input_level input').val() !== "") {
               var level = parseInt($('#input_level input').val());
               total = {};
               for (var set_id in westui.set_calc.data) {
                   for (var key in westui.set_calc.data[set_id].items) {
                       for (var item_id in westui.set_calc.data[set_id].items[key]) {
                           if (westui.set_calc.itemStatus[set_id][item_id] !== false) {
                               lvl = westui.set_calc.itemStatus[set_id][item_id];
                               if (!total[key]) {
                                   total[key] = 0;
                               }
                               var value = westui.set_calc.data[set_id].items[key][item_id];
                               if (westui.set_calc.data[set_id].items[key][item_id] < 0) {
                                   //If bonus (per Level)
                                   value = -value;
                                   if (westui.set_calc.itemStatus[set_id][item_id] > 0) {
                                       //If item upgraded
                                       total[key] += Math.ceil(value * level) + Math.round(Math.max(1, Math.ceil(value * level) * 0.1 * lvl));
                                   } else {
                                       total[key] += Math.ceil(value * level);
                                   }
                               } else {
                                   if (westui.set_calc.itemStatus[set_id][item_id] > 0) {
                                       if (value < 1) {
                                           total[key] += Math.round(1e6 * (value * 1 + Math.round(Math.max(1, value * 1000 * lvl)) / 10000)) / 1e6;
                                       } else {
                                           total[key] += value + Math.round(Math.max(1, value * 0.1 * lvl));
                                       }
                                   } else {
                                       total[key] += value;
                                   }
                               }
                           }
                       }
                   }
                   var item_nb = 0;
                   for (var item_id in westui.set_calc.itemStatus[set_id]) {
                       if (westui.set_calc.itemStatus[set_id][item_id] !== false) {
                           item_nb++;
                       }
                   }
                   for (var key in westui.set_calc.data[set_id].set[item_nb]) {
                       if (!total[key]) {
                           total[key] = 0;
                       }
                       if (westui.set_calc.data[set_id].set[item_nb][key] < 0) {
                           total[key] += Math.ceil(-westui.set_calc.data[set_id].set[item_nb][key] * level);
                       } else {
                           total[key] += westui.set_calc.data[set_id].set[item_nb][key];
                       }
                   }
               }
               //Create the html table

var html = '

<tbody>

' + westui.lang.total + '
';
               for (var key in westui.config.set_bonus) {
                   if (total.hasOwnProperty(key)) {
html += '
<img src="' + westui.config.set_bonus[key].img + '">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + '
' + westui.config.set_bonus[key].name + '
';
                   }
               }
               for (var key in westui.set_calc.bonus.extra_set_bonus) {
                   if (total.hasOwnProperty(key)) {
html += '
<img src="' + westui.set_calc.bonus.extra_set_bonus[key].img + '">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + '
' + westui.set_calc.bonus.extra_set_bonus[key].name + '
';
                   }
               }
               //Display the result at the bottom of the page
               $('#set_calc').html(html);
           } else {
               $('#set_calc').html("");
           }
       },
       initEvents: function () {
           //Deactivate / activate item on click
           $('.item_container > img').on('click', function () {
               var item_container = $(this).closest('.item_container');
               item_container.toggleClass('item_off');
               var set_id = item_container.closest('.set_container').attr('data-set-id');
               var item_id = JSON.parse(item_container.attr('data-popup')).id;
               if (item_container.hasClass('item_off') || item_container.is(":hidden")) {
                   westui.set_calc.itemStatus[set_id][item_id] = false;
               } else {
                   westui.set_calc.itemStatus[set_id][item_id] = parseInt(item_container.attr('data-lvl'));
               }
               westui.set_calc.calc();
           });
           //Update item level on upgrade / downgrade
           $(document).on('click', '.upgrade, .downgrade', function () {
               var item = $(this).closest('.item_container');
               var set_id = item.closest('.set_container').attr('data-set-id');
               if (!item.hasClass('item_off') && !item.is(":hidden")) {
                   westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl'));
                   westui.set_calc.calc();
               }
           });
           //Calc again when player level changes
           $("#input_level").bind("propertychange keyup input paste", function () {
               westui.set_calc.calc();
           });
           //Activate/deactivate melee/fire weapon when the switch btn is clicked
           $("#switch").on('click', function () {
               $('#melee, #fire').each(function () {
                   var item = $(this).find('.item_container');
                   var set_id = $(this).closest('.set_container').attr('data-set-id');
                   if ($(this).is(":hidden")) {
                       westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = false;
                   } else {
                       westui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl'));
                   }
               });
               westui.set_calc.calc();
           });
       },
       init: function () {
           westui.set_calc.initEvents();
           westui.set_calc.getData();
$('#mw-content-text').append('
');
           if ($('#input_level').length === 0)
               westui.set_calc.calc();
       }
   },
   sorting: {
       sortItems: function(param){
           $('.item_container').removeAttr('data-sort');
           function calcSortVal(el){
               var data = JSON.parse($(el).attr('data-popup'));
               var val = 0;
               for (var prop in param){
                   if (data[prop]){
                       if (data[prop]<0){
                           val+=Math.ceil(-data[prop]*($('#input_level input').val()?$('#input_level input').val():150))*param[prop];
                       } else {
                           val+=data[prop]*param[prop];
                       }
                   }
               }
               $(el).attr('data-sort',val);
               if ($(el).find('p.number').length!==0){
                   $(el).find('p.number').html(val);
               } else {
$(el).append('

'+val+'

');
               }
           }
           $('#mw-content-text').find('.sorting_hidden').hide();
           $('#mw-content-text').find('.item_container').sort(function(a, b) {
               if (!$(a).attr('data-sort')){calcSortVal(a);}
               if (!$(b).attr('data-sort')){calcSortVal(b);}
               return $(b).attr('data-sort') - $(a).attr('data-sort');
           }).appendTo('#mw-content-text');
       },
       init:function(){
           if ($('div#sort_items').length===1){
var html = "";
               $('div#sort_items').html(html);
               $('select#sort_items').on('change',function(){
                   westui.sorting.sortItems(JSON.parse($(this).find("option:selected").attr('value')));
               });
           }
       }
   },
   init: function () {
       westui.initPage();
       westui.popup.init();
       if (westui.config.enable_sorting)
           westui.sorting.init();
       if (westui.config.enable_set_calc && $('.infoSet').length !== 0) {
           westui.set_calc.init();
       }
   }

}; westui.init();