Diferencia entre revisiones de «Popup.js»
Sin resumen de edición |
Sin resumen de edición |
||
(No se muestran 223 ediciones intermedias de 3 usuarios) | |||
Línea 1: | Línea 1: | ||
ui = { | |||
lang: { | |||
$( | input_level: "Tu nivel", | ||
$( | input_search: "Buscar", | ||
damages: "Rango de daño:", | |||
per_level: "por nivel", | |||
speed: "Velocidad", | |||
level: "Nivel", | |||
unsalable: "Invendible", | |||
auction: "Subastable", | |||
not_auction: "No Subastable", | |||
not_upgrade: "No mejorable", | |||
upgrade: "Mejorable", | |||
total: "Suma total", | |||
popup: { | |||
dmg: { | |||
dmglvl:'<p class="popup_dmg">+#1 Daño #2</p>' | |||
}, | |||
skills: { | |||
str: '<p class="popup_attribute">+ #1 Fuerza#2</p>', | |||
mob: '<p class="popup_attribute">+ #1 Movilidad#2</p>', | |||
dex: '<p class="popup_attribute">+ #1 Destreza#2</p>', | |||
cha: '<p class="popup_attribute">+ #1 Carisma#2</p>', | |||
con: '<p class="popup_skill">+ #1 Construcción#2</p>', | |||
vig: '<p class="popup_skill">+ #1 Vigor#2</p>', | |||
tou: '<p class="popup_skill">+ #1 Tenacidad#2</p>', | |||
sta: '<p class="popup_skill">+ #1 Condición#2</p>', | |||
hea: '<p class="popup_skill">+ #1 Puntos de vida#2</p>', | |||
rid: '<p class="popup_skill">+ #1 Montar a caballo#2</p>', | |||
ref: '<p class="popup_skill">+ #1 Reflejo#2</p>', | |||
dod: '<p class="popup_skill">+ #1 Eludir#2</p>', | |||
hid: '<p class="popup_skill">+ #1 Esconder#2</p>', | |||
swi: '<p class="popup_skill">+ #1 Nadar#2</p>', | |||
aim: '<p class="popup_skill">+ #1 Apuntar#2</p>', | |||
sho: '<p class="popup_skill">+ #1 Disparar#2</p>', | |||
pit: '<p class="popup_skill">+ #1 Poner trampas#2</p>', | |||
fin: '<p class="popup_skill">+ #1 Destreza de manos#2</p>', | |||
rep: '<p class="popup_skill">+ #1 Reparar#2</p>', | |||
lea: '<p class="popup_skill">+ #1 Liderazgo#2</p>', | |||
tac: '<p class="popup_skill">+ #1 Táctica#2</p>', | |||
tra: '<p class="popup_skill">+ #1 Comerciar#2</p>', | |||
ani: '<p class="popup_skill">+ #1 Instinto animal#2</p>', | |||
app: '<p class="popup_skill">+ #1 Apariencia#2</p>' | |||
}, | |||
fb: { | |||
fboff: '<p class="popup_fb">+ #1 <b>Ataque</b> (Bonus de batalla)</p>', | |||
fbdef: '<p class="popup_fb">+ #1 <b>Defensa</b> (Bonus de batalla)</p>', | |||
fbres: '<p class="popup_fb">+ #1 <b>Resistencia</b> (Bonus de batalla)</p>', | |||
fboffs: '<p class="popup_fb">+ #1 <b>Ataque</b> (Bonus de sector de batalla)</p>', | |||
fbdefs: '<p class="popup_fb">+ #1 <b>Defensa</b> (Bonus de sector de batalla )</p>', | |||
fbdmgs: '<p class="popup_fb">+ #1 <b>Daño</b> (Bonus de sector de batalla)</p>' | |||
}, | |||
special: { | |||
xp: '<p class="popup_skill">+ #1% Experiencia de trabajos, duelos y batallas de fuertes#2</p>', | |||
money: '<p class="popup_skill">+ #1% Dinero de trabajos y duelos#2</p>', | |||
luck: '<p class="popup_skill">+ #1% mas posibilidades de ganar #2</p>', | |||
regen: '<p class="popup_skill">+ #1% Regeneración#2</p>', | |||
drop: '<p class="popup_skill">+ #1 mas posibilidades de sacar productos#2</p>', | |||
labor_pts: '<p class="popup_skill">+ #1 Puntos de trabajo#2</p>', | |||
spd: '<p class="popup_txtgreen">+ #1% Velocidad #2</p>' | |||
} | |||
} | |||
}, | |||
config: { | |||
enable_set_calc: true, | |||
redirect_on_dblclick: true, | |||
cdn: "https://westes.innogamescdn.com", | |||
img_buyprice: "/images/5/56/Bp.png", | |||
img_sellprice: "/images/c/ce/Sp.png", | |||
img_male: "/images/c/c5/Gender_m.png", | |||
img_female: "/images/4/41/Gender_f.png", | |||
set_bonus: { | |||
str: { | |||
name:"Fuerza",img:"/images/thumb/f/fd/Fuerza.png/40px-Fuerza.png"}, | |||
mob: { | |||
name:"Movilidad",img:"https://wiki.the-west.es/images/thumb/9/98/Movilidad.png/40px-Movilidad.png"}, | |||
dex: { | |||
name:"Destreza",img:"https://wiki.the-west.es/images/thumb/3/36/Ma%C3%B1a.png/40px-Ma%C3%B1a.png"}, | |||
cha: { | |||
name:"Carisma",img:"https://wiki.the-west.es/images/thumb/6/6a/Carisma.png/40px-Carisma.png"}, | |||
con: { | |||
name:"Construcción",img:"https://wiki.the-west.es/images/b/b2/Construir.png"}, | |||
vig: { | |||
name:"Vigor",img:"https://wiki.the-west.es/images/f/f4/Vigor.png"}, | |||
tou: { | |||
name:"Tenacidad",img:"https://wiki.the-west.es/images/2/21/Tenacidad.png"}, | |||
sta: { | |||
name:"Condición",img:"https://wiki.the-west.es/images/7/7e/Condici%C3%B3n.png"}, | |||
hea: { | |||
name:"Puntos de vida",img:"https://wiki.the-west.es/images/a/aa/Salud.png"}, | |||
rid: { | |||
name:"Montar a caballo",img:"https://wiki.the-west.es/images/b/b7/Montar_a_caballo.png"}, | |||
ref: { | |||
name:"Reflejo",img:"https://wiki.the-west.es/images/a/a8/Reflejo.png"}, | |||
dod: { | |||
name:"Eludir",img:"https://wiki.the-west.es/images/e/e3/Eludir.png"}, | |||
hid: { | |||
name:"Esconder",img:"https://wiki.the-west.es/images/2/25/Esconder.png"}, | |||
swi: { | |||
name:"Nadar",img:"https://wiki.the-west.es/images/f/fa/Nadar.png"}, | |||
aim: { | |||
name:"Apuntar",img:"https://wiki.the-west.es/images/c/c9/Apuntar.png"}, | |||
sho: { | |||
name:"Disparar",img:"https://wiki.the-west.es/images/f/f8/Disparar.png"}, | |||
pit: { | |||
name:"Poner trampas",img:"https://wiki.the-west.es/images/1/1e/Poner_trampas.png"}, | |||
fin: { | |||
name:"Destreza de manos",img:"https://wiki.the-west.es/images/b/b5/Destreza_de_manos.png"}, | |||
rep: { | |||
name:"Reparar",img:"https://wiki.the-west.es/images/f/f3/Reparar.png"}, | |||
lea: { | |||
name:"Liderazgo",img:"https://wiki.the-west.es/images/7/7c/Dirigir.png"}, | |||
tac: { | |||
name:"Táctica",img:"https://wiki.the-west.es/images/4/48/T%C3%A1ctica.png"}, | |||
tra: { | |||
name:"Comerciar",img:"https://wiki.the-west.es/images/3/39/Comerciar.png"}, | |||
ani: { | |||
name:"Instinto animal",img:"https://wiki.the-west.es/images/2/26/Trato_con_animales.png"}, | |||
app: { | |||
name:"Apariencia",img:"https://wiki.the-west.es/images/1/16/Presencia.png"}, | |||
fbdef: { | |||
name:"<b>Defensa</b> (Bonus de batalla)",img:"https://wiki.the-west.es/images/8/82/Set_Fb_defense.png"}, | |||
fboff: { | |||
name:"<b>Ataque</b> (Bonus de batalla)",img:"https://wiki.the-west.es/images/3/30/Set_Fb_offense.png"}, | |||
fbres: { | |||
name:"<b>Resistencia</b> (Bonus de batalla)",img:"https://wiki.the-west.es/images/a/a5/Resistenciafb.png"}, | |||
fbdefs: { | |||
name:"<b>Defensa</b> (Bonus de batalla de sector)",img:"https://wiki.the-west.es/images/1/1a/Set_Fb_defense_sec.png"}, | |||
fboffs: { | |||
name:"<b>Ataque</b> (Bonus de batalla de sector)", | |||
img:"https://wiki.the-west.es/images/f/fe/Set_Fb_offense_sec.png" | |||
}, | |||
fbdmgs: { | |||
name:"<b>Daño</b> (Bonus de batalla de sector)", | |||
img:"https://wiki.the-west.es/images/b/b3/Damages_sector.png" | |||
}, | |||
xp: { | |||
name: "Experiencia de trabajos, duelos y batallas de fuertes(%)", | |||
img: "/images/7/71/Set_xp.png" | |||
}, | |||
money: { | |||
name: "Dinero de trabajos y duelos(%)", | |||
img: "https://wiki.the-west.net/images/d/df/Set_money.png" | |||
}, | |||
luck: { | |||
name:"% más posibilidades de ganar", | |||
img:"https://wiki.the-west.es/images/c/c1/Set_luck.png" | |||
}, | |||
regen: { | |||
name:"Aumento de regeneración (%)", | |||
img:"https://wiki.the-west.net/images/5/53/Regeneration.png", | |||
}, | |||
drop:{ | |||
name:"Aumento probabilidad de salidad de productos", | |||
img:"https://wiki.the-west.net/images/thumb/b/b8/Drop.png/40px-Drop.png" | |||
}, | |||
spd: { | |||
name: "Velocidad", | |||
img: "https://wiki.the-west.net/images/thumb/1/1a/QuarterHorse.png/40px-QuarterHorse.png" | |||
} | |||
} | |||
}, | |||
initPage: function () { | |||
//Append input level | |||
if ($("#input_level").length === 1) { | |||
var input_level = $('<input type="number" style="width:80px;" class="west" placeholder="' + ui.lang.input_level + '" min="0" max="250">').bind("propertychange keyup input paste", function () { | |||
if (this.value > 250) { | |||
this.value = 250; | |||
} 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="' + ui.lang.input_search + '">').bind("propertychange keyup input paste", function () { | |||
var val = this.value.toLowerCase(); | |||
console.log($('.craft_recipe').length); | |||
if ($('.craft_recipe').length) { | |||
if (val === '') { | |||
$('.craft_recipe').show().css('opacity', '1'); | |||
} else { | |||
}); | $('.craft_recipe').css('opacity', '0') | ||
$( | setTimeout(function() { | ||
$('.craft_recipe').filter(function() { | |||
if($(this).find('[data-popup]').filter(function() { | |||
return $(this).attr('data-popup').toLowerCase().indexOf(val) > -1; | |||
}).length > 0){ | |||
$(this).css('opacity', '1').show(); | |||
}else{ | |||
$(this).hide(); | |||
} | } | ||
}) | |||
}, 300); | |||
} | |||
} else { | |||
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(); | |||
}); | |||
} | |||
if ($("# | //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 ((new RegExp(mw.config.get('wgFormattedNamespaces')[10] + '\:Item\_*').test(mw.config.get('wgPageName'))) && ($('.item_container').length === 1)) { | |||
$('#mw-content-text').append('<center><div id="popup_plain" class="popup_window"><div class="popup_front"><div class="tw_bg_tl"></div><div class="tw_bg_tr"></div><div class="tw_bg_bl"></div><div class="tw_bg_br"></div></div><div id="popup_plain_contents" class="popup_contents"></div></div></center>'); | |||
$('#popup_plain').hide(); | |||
$('#popup_plain_contents').append(ui.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 ( | if (ui.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; | |||
}); | |||
} | |||
} | } | ||
}, | }, | ||
hide: function() { | popup: { | ||
content: "", | |||
delay: 200, | |||
active: false, | |||
show: function (obj) { | |||
ui.popup.content = ui.popup.createPopup($(obj).attr('data-popup'), $(obj).attr('data-cdn-cat'), $(obj).attr('data-cdn-img'), parseInt($(obj).attr('data-lvl'))); | |||
ui.popup.active = true; | |||
ui.popup.setTimeout(); | |||
ui.popup.getContainer().html(ui.popup.content); | |||
}, | |||
hide: function () { | |||
ui.popup.getEl().css({ | |||
display: 'none', | |||
top: 0, | |||
left: 0 | |||
}); | |||
ui.popup.active = false; | |||
ui.popup.clearTimeout(); | |||
}, | |||
setTimeout: function () { | |||
ui.popup.clearTimeout(); | |||
ui.popup.timer = window.setTimeout(function () { | |||
ui.popup.getEl().css('display', 'block'); | |||
}, ui.popup.delay); | |||
}, | |||
clearTimeout: function () { | |||
if (ui.popup.timer) window.clearTimeout(ui.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 = '<div class="popup_image"><img src="' + ui.config.cdn + '/images/items/' + data.cdn_cat + '/' + data.cdn_img + '.png' + '"/></div><div class="popup_divider"></div><p class="popup_name">' + data.name + '</p><p class="popup_type">' + data.type + '</p><br/>'; | |||
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 += '<p class="popup_dmg">' + data.dmg_min + '-' + data.dmg_max + ' ' + ui.lang.damages + '</p>'; | |||
} | } | ||
for (var cat in ui.lang.popup) { | |||
var cnt = 0; | |||
for (var key in ui.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 = " (" + ui.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 { | } else if (upgraded) { | ||
data[key] | if (data[key] < 1) { | ||
data[key] = Math.round(1e6 * (data[key] * 1 + Math.round(Math.max(1, data[key] * 1000 * lvl)) / 10000)) / 1e6; | 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 += ui.lang.popup[cat][key].replace('#1', data[key]).replace('#2', per_level); | |||
} | } | ||
html += | } | ||
if (cnt > 0) { | |||
html += '<br/>'; | |||
} | } | ||
} | } | ||
if ( | if (data.textjob) { | ||
for (var i = 0; i < data.textjob.length; i++) { | |||
html += '<p class="popup_skill">' + data.textjob[i] + '</p>'; | |||
} | |||
html += '<br/>'; | html += '<br/>'; | ||
} | } | ||
if (data.text) { | |||
html += '<center>'; | |||
for (var i = 0; i < data.text.length; i++) { | |||
html += '<p class="popup_text">' + data.text[i] + '</p>'; | |||
} | |||
html += '</center><br/>'; | |||
} | } | ||
html+='</ | if (data.bonus) { | ||
for (var i = 0; i < data.bonus.length; i++) { | |||
html += '<p class="popup_bonus">' + data.bonus[i] + '</p>'; | |||
} | |||
html += '< | html += '<br/>'; | ||
} | |||
if (data.jobs) { | |||
html += '<div style="text-align:center;"><table class="popup_job">'; | |||
for (var i = 0; i < data.jobs.length; i++) { | |||
html += '<tr><td><img src="' + ui.config.cdn + '/images/jobs/' + data.jobs[i][1] + '.png"/></td><td><span> ' + data.jobs[i][0] + '</span></td></tr>'; | |||
} | |||
html += '</table></div>'; | |||
} | |||
if (data.craft) { | |||
html += '<div style="text-align:center;"><table class="popup_crafteditem"><tr><td><img src="' + ui.config.cdn + '/images/crafting/profsymbol_' + data.craft.id + '_small.png"/></td><td><table><tr>'; | |||
for (var i = 0; i < data.craft.req.length; i++) { | |||
html += '<td><img style="width:36px;height:36px;" src="' + ui.config.cdn + '/images/items/yield/' + data.craft.req[i][0] + '.png"/></td>'; | |||
} | |||
html += '</tr><tr>'; | |||
for (var i = 0; i < data.craft.req.length; i++) { | |||
html += '<td><span>x' + data.craft.req[i][1] + '</span></td>'; | |||
} | |||
html += '</tr></table></td></tr></table></div>'; | |||
} | |||
html += '<div class="popup_infos">'; | |||
if (data.hspd) { | |||
if (upgraded) { | |||
data.hspd += Math.round(Math.max(1, data.hspd * 0.1 * lvl)); | |||
} | |||
html += '<p class="popup_speed">' + ui.lang.speed + ': +' + data.hspd + '%</p><br/>'; | |||
} | |||
if (data.set) html += '<p><a class="popup_set" href="/wiki/' + data.set + '">' + data.set + '</a></p><br/>'; | |||
if (data.sp) { | |||
html += '<img src="' + ui.config.img_buyprice + '"/>' + data.bp + ' <img src="' + ui.config.img_sellprice + '"/> ' + data.sp + '<br/><br/>'; | |||
} else { | |||
html += '<i>' + ui.lang.unsalable + '</i><br/><br/>'; | |||
} | |||
if (data.lvl) html += ui.lang.level + ' <b>' + data.lvl + '</b><br/>'; | |||
if (data.sex) { | |||
if (data.sex == 0) { | |||
html += '<img src="' + ui.config.img_male + '"/> '; | |||
} else { | |||
html += '<img src="' + ui.config.img_female + '"/> '; | |||
} | |||
} | |||
if (data.auc == 1) { | |||
html += '<span class="popup_txtgreen">' + ui.lang.auction + '</span><br/>'; | |||
} else { | |||
html += '<span class="popup_txtred">' + ui.lang.not_auction + '</span><br/>'; | |||
} | } | ||
if (data.upg == 0) { | |||
html += '<span class="popup_txtred">' + ui.lang.not_upgrade + '</span><br/>'; | |||
} else { | |||
html += '<span class="popup_txtgreen">' + ui.lang.upgrade + '</span><br/>'; | |||
html += '< | |||
} | } | ||
html += '</ | html += '<br/><p class="popup_id">[item=<b>' + data.id + '</b>]</p></div>'; | ||
return html; | |||
}, | |||
setPosition: function (e) { | |||
var window_width = $(window).width(); | |||
var window_height = $(window).height(); | |||
var popup_width = ui.popup.getEl().outerWidth(); | |||
var popup_height = ui.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); | |||
} | } | ||
ui.popup.getEl().css({ | |||
top: top, | |||
left: left | |||
}); | |||
}, | |||
init: function () { | |||
//Append popup container | |||
$('body').append('<div id="popup_window" class="popup_window"><div class="popup_front"><div class="tw_bg_tl"></div><div class="tw_bg_tr"></div><div class="tw_bg_bl"></div><div class="tw_bg_br"></div></div><div id="popup_contents" class="popup_contents"></div></div>'); | |||
//Set events | |||
$(document).on('mouseenter', '.item_container', function (e) { | |||
ui.popup.show(this); | |||
ui.popup.setPosition(e); | |||
}); | |||
$(document).on('mouseleave', '.item_container', function () { | |||
ui.popup.hide(); | |||
}); | |||
$(document).on('mousemove', '.item_container', function (e) { | |||
ui.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); | |||
} | |||
ui.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); | |||
} | |||
ui.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 : | |||
if ( | data: {}, | ||
//Status of all items (item lvl, activated or not) | |||
itemStatus: {}, | |||
getData: function () { | |||
//Get bonuses from all item sets | |||
$('.set_container').each(function () { | |||
var set_id = $(this).attr('data-set-id'); | |||
ui.set_calc.itemStatus[set_id] = {}; | |||
ui.set_calc.data[set_id] = { | |||
items: {}, | |||
set: {} | |||
}; | |||
$(this).find('.item_container').each(function () { | |||
var json = JSON.parse($(this).attr('data-popup')); | |||
if ($(this).is(":hidden")) { | |||
ui.set_calc.itemStatus[set_id][json.id] = false; | |||
} else { | |||
ui.set_calc.itemStatus[set_id][json.id] = 0; | |||
} | |||
for (var prop in json) { | |||
if (json.hasOwnProperty(prop) && ui.config.set_bonus.hasOwnProperty(prop)) { | |||
if (!ui.set_calc.data[set_id].items[prop]) { | |||
ui.set_calc.data[set_id].items[prop] = {}; | |||
} | |||
ui.set_calc.data[set_id].items[prop][json.id] = json[prop]; | |||
} | |||
} | |||
}); | |||
}); | |||
//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'); | |||
ui.set_calc.data[set_id].set[nb] = {}; | |||
$(this).find('.set_bonus').each(function () { | |||
key = $(this).attr('data-type'); | |||
if ($(this).find('.calc').length !== 0) { | |||
ui.set_calc.data[set_id].set[nb][key] = -parseFloat($(this).find('.calc').attr('id')); | |||
} else { | |||
ui.set_calc.data[set_id].set[nb][key] = parseFloat($(this).find('.val').text()); | |||
} | |||
if (!ui.config.set_bonus.hasOwnProperty(key)) { | |||
ui.set_calc.bonus.extra_set_bonus[key] = { | |||
img: $(this).find('img').attr('src'), | |||
name: $(this).find('#tooltip_content').text() | |||
}; | |||
} | |||
}); | |||
}); | |||
}); | |||
}, | |||
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 ui.set_calc.data) { | |||
for (var key in ui.set_calc.data[set_id].items) { | |||
for (var item_id in ui.set_calc.data[set_id].items[key]) { | |||
if (ui.set_calc.itemStatus[set_id][item_id] !== false) { | |||
lvl = ui.set_calc.itemStatus[set_id][item_id]; | |||
if (!total[key]) { | |||
total[key] = 0; | |||
} | |||
var value = ui.set_calc.data[set_id].items[key][item_id]; | |||
if (ui.set_calc.data[set_id].items[key][item_id] < 0) { | |||
//If bonus (per Level) | |||
value = -value; | |||
if (ui.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 (ui.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] += Math.round(Math.max(1, value * 0.1 * lvl)); | |||
} | |||
} else { | |||
total[key] += value; | |||
} | |||
} | |||
} | |||
} | |||
} | |||
var item_nb = 0; | |||
for (var item_id in ui.set_calc.itemStatus[set_id]) { | |||
if (ui.set_calc.itemStatus[set_id][item_id] !== false) { | |||
item_nb++; | |||
} | |||
} | |||
for (var key in ui.set_calc.data[set_id].set[item_nb]) { | |||
if (!total[key]) { | |||
total[key] = 0; | |||
} | |||
if (ui.set_calc.data[set_id].set[item_nb][key] < 0) { | |||
total[key] += Math.ceil(-ui.set_calc.data[set_id].set[item_nb][key] * level); | |||
} else { | |||
total[key] += ui.set_calc.data[set_id].set[item_nb][key]; | |||
} | |||
} | |||
} | |||
//Create the html table | |||
var html = '<center><table class="infoSet"><caption><br><big><b>' + ui.lang.total + '</b></big></caption><tbody><tr><td style=" background: #20140c !important; color: #ffdead !important; padding: 5px;">Nivel '+ level +'</td><td></center>'; for (var key in ui.config.set_bonus) { | |||
if (total.hasOwnProperty(key)) { | |||
if(key == "con" || key == "vig" || key == "tou" || key == "sta" || key == "hea" | |||
|| key == "rid" || key == "ref" || key == "dod" || key == "hid" || key == "swi" | |||
|| key == "aim" || key == "sho" || key == "pit" || key == "fin" || key == "rep" | |||
|| key == "lea" || key == "tac" || key == "tra" || key == "ani" || key == "app"){ | |||
html += '<div class="set_bonus tooltip_container" style="width: 70px;"><img src="' + ui.config.set_bonus[key].img + '" style="width: 70px;" ><b style="width: 100%; display: block; background: #312215; color: #ffe7b1;">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + '</b><div class="tooltip_outer"><div class="tooltip"><div class="tt_bg_tl"></div><div class="tt_bg_tr"></div><div class="tt_bg_bl"></div><div class="tt_bg_br"></div><div id="tooltip_content">' + ui.config.set_bonus[key].name + '</div></div></div></div>'; | |||
}else{ | |||
html += '<div class="set_bonus tooltip_container"><img src="' + ui.config.set_bonus[key].img + '"><b style="width: 100%; display: block; background: #312215; color: #ffe7b1;">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + '</b><div class="tooltip_outer"><div class="tooltip"><div class="tt_bg_tl"></div><div class="tt_bg_tr"></div><div class="tt_bg_bl"></div><div class="tt_bg_br"></div><div id="tooltip_content">' + ui.config.set_bonus[key].name + '</div></div></div></div>'; | |||
} | |||
} | |||
} | |||
for (var key in ui.set_calc.bonus.extra_set_bonus) { | |||
if (total.hasOwnProperty(key)) { | |||
html += '<div class="set_bonus tooltip_container"><img src="' + ui.set_calc.bonus.extra_set_bonus[key].img + '"><b style="width: 100%; display: block; background: #312215; color: #ffe7b1;">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + '</b><div class="tooltip_outer"><div class="tooltip"><div class="tt_bg_tl"></div><div class="tt_bg_tr"></div><div class="tt_bg_bl"></div><div class="tt_bg_br"></div><div id="tooltip_content">' + ui.set_calc.bonus.extra_set_bonus[key].name + '</div></div></div></div>'; | |||
} | |||
} | |||
//Display the result at the bottom of the page | |||
$('#set_calc').html(html); | |||
} else { | } else { | ||
html | $('#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")) { | |||
ui.set_calc.itemStatus[set_id][item_id] = false; | |||
} else { | |||
ui.set_calc.itemStatus[set_id][item_id] = parseInt(item_container.attr('data-lvl')); | |||
} | |||
ui.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")) { | |||
ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); | |||
ui.set_calc.calc(); | |||
} | |||
}); | |||
//Calc again when player level changes | |||
$("#input_level").bind("propertychange keyup input paste", function () { | |||
ui.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")) { | |||
ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = false; | |||
} else { | |||
ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); | |||
} | |||
}); | |||
ui.set_calc.calc(); | |||
}); | |||
}, | |||
init: function () { | |||
ui.set_calc.initEvents(); | |||
ui.set_calc.getData(); | |||
$('#mw-content-text').append('<div id="set_calc"></div>'); | |||
if ($('#input_level').length === 0) | |||
ui.set_calc.calc(); | |||
} | } | ||
}, | }, | ||
init: function () { | |||
ui.initPage(); | |||
ui.popup.init(); | |||
if (ui.config.enable_set_calc && $('.infoSet').length !== 0) { | |||
ui.set_calc.init(); | |||
} | } | ||
} | } | ||
}; | }; | ||
ui.init(); | |||
Revisión actual - 04:11 2 ene 2024
ui = {
lang: { input_level: "Tu nivel", input_search: "Buscar", damages: "Rango de daño:", per_level: "por nivel", speed: "Velocidad", level: "Nivel", unsalable: "Invendible", auction: "Subastable", not_auction: "No Subastable", not_upgrade: "No mejorable", upgrade: "Mejorable", total: "Suma total", popup: { dmg: {
dmglvl:'
+#1 Daño #2
'
}, skills: {
str: '
+ #1 Fuerza#2
', mob: '
+ #1 Movilidad#2
', dex: '
+ #1 Destreza#2
', cha: '
+ #1 Carisma#2
', con: '
+ #1 Construcción#2
', vig: '
+ #1 Vigor#2
', tou: '
+ #1 Tenacidad#2
', sta: '
+ #1 Condición#2
', hea: '
+ #1 Puntos de vida#2
', rid: '
+ #1 Montar a caballo#2
', ref: '
+ #1 Reflejo#2
', dod: '
+ #1 Eludir#2
', hid: '
+ #1 Esconder#2
', swi: '
+ #1 Nadar#2
', aim: '
+ #1 Apuntar#2
', sho: '
+ #1 Disparar#2
', pit: '
+ #1 Poner trampas#2
', fin: '
+ #1 Destreza de manos#2
', rep: '
+ #1 Reparar#2
', lea: '
+ #1 Liderazgo#2
', tac: '
+ #1 Táctica#2
', tra: '
+ #1 Comerciar#2
', ani: '
+ #1 Instinto animal#2
', app: '
+ #1 Apariencia#2
'
}, fb: {
fboff: '
+ #1 Ataque (Bonus de batalla)
', fbdef: '
+ #1 Defensa (Bonus de batalla)
', fbres: '
+ #1 Resistencia (Bonus de batalla)
', fboffs: '
+ #1 Ataque (Bonus de sector de batalla)
', fbdefs: '
+ #1 Defensa (Bonus de sector de batalla )
', fbdmgs: '
+ #1 Daño (Bonus de sector de batalla)
'
},
special: {
xp: '
+ #1% Experiencia de trabajos, duelos y batallas de fuertes#2
', money: '
+ #1% Dinero de trabajos y duelos#2
', luck: '
+ #1% mas posibilidades de ganar #2
', regen: '
+ #1% Regeneración#2
', drop: '
+ #1 mas posibilidades de sacar productos#2
', labor_pts: '
+ #1 Puntos de trabajo#2
', spd: '
+ #1% Velocidad #2
'
}
} }, config: { enable_set_calc: true, redirect_on_dblclick: true, cdn: "https://westes.innogamescdn.com", img_buyprice: "/images/5/56/Bp.png", img_sellprice: "/images/c/ce/Sp.png", img_male: "/images/c/c5/Gender_m.png", img_female: "/images/4/41/Gender_f.png", set_bonus: {
str: { name:"Fuerza",img:"/images/thumb/f/fd/Fuerza.png/40px-Fuerza.png"}, mob: { name:"Movilidad",img:"https://wiki.the-west.es/images/thumb/9/98/Movilidad.png/40px-Movilidad.png"}, dex: { name:"Destreza",img:"https://wiki.the-west.es/images/thumb/3/36/Ma%C3%B1a.png/40px-Ma%C3%B1a.png"}, cha: { name:"Carisma",img:"https://wiki.the-west.es/images/thumb/6/6a/Carisma.png/40px-Carisma.png"}, con: { name:"Construcción",img:"https://wiki.the-west.es/images/b/b2/Construir.png"}, vig: { name:"Vigor",img:"https://wiki.the-west.es/images/f/f4/Vigor.png"}, tou: { name:"Tenacidad",img:"https://wiki.the-west.es/images/2/21/Tenacidad.png"}, sta: { name:"Condición",img:"https://wiki.the-west.es/images/7/7e/Condici%C3%B3n.png"}, hea: { name:"Puntos de vida",img:"https://wiki.the-west.es/images/a/aa/Salud.png"}, rid: { name:"Montar a caballo",img:"https://wiki.the-west.es/images/b/b7/Montar_a_caballo.png"}, ref: { name:"Reflejo",img:"https://wiki.the-west.es/images/a/a8/Reflejo.png"}, dod: { name:"Eludir",img:"https://wiki.the-west.es/images/e/e3/Eludir.png"}, hid: { name:"Esconder",img:"https://wiki.the-west.es/images/2/25/Esconder.png"}, swi: { name:"Nadar",img:"https://wiki.the-west.es/images/f/fa/Nadar.png"}, aim: { name:"Apuntar",img:"https://wiki.the-west.es/images/c/c9/Apuntar.png"}, sho: { name:"Disparar",img:"https://wiki.the-west.es/images/f/f8/Disparar.png"}, pit: { name:"Poner trampas",img:"https://wiki.the-west.es/images/1/1e/Poner_trampas.png"}, fin: { name:"Destreza de manos",img:"https://wiki.the-west.es/images/b/b5/Destreza_de_manos.png"}, rep: { name:"Reparar",img:"https://wiki.the-west.es/images/f/f3/Reparar.png"}, lea: { name:"Liderazgo",img:"https://wiki.the-west.es/images/7/7c/Dirigir.png"}, tac: { name:"Táctica",img:"https://wiki.the-west.es/images/4/48/T%C3%A1ctica.png"}, tra: { name:"Comerciar",img:"https://wiki.the-west.es/images/3/39/Comerciar.png"}, ani: { name:"Instinto animal",img:"https://wiki.the-west.es/images/2/26/Trato_con_animales.png"}, app: { name:"Apariencia",img:"https://wiki.the-west.es/images/1/16/Presencia.png"}, fbdef: { name:"Defensa (Bonus de batalla)",img:"https://wiki.the-west.es/images/8/82/Set_Fb_defense.png"}, fboff: { name:"Ataque (Bonus de batalla)",img:"https://wiki.the-west.es/images/3/30/Set_Fb_offense.png"}, fbres: { name:"Resistencia (Bonus de batalla)",img:"https://wiki.the-west.es/images/a/a5/Resistenciafb.png"}, fbdefs: { name:"Defensa (Bonus de batalla de sector)",img:"https://wiki.the-west.es/images/1/1a/Set_Fb_defense_sec.png"}, fboffs: { name:"Ataque (Bonus de batalla de sector)", img:"https://wiki.the-west.es/images/f/fe/Set_Fb_offense_sec.png" }, fbdmgs: { name:"Daño (Bonus de batalla de sector)", img:"https://wiki.the-west.es/images/b/b3/Damages_sector.png" },
xp: { name: "Experiencia de trabajos, duelos y batallas de fuertes(%)", img: "/images/7/71/Set_xp.png" }, money: { name: "Dinero de trabajos y duelos(%)", img: "https://wiki.the-west.net/images/d/df/Set_money.png" }, luck: { name:"% más posibilidades de ganar", img:"https://wiki.the-west.es/images/c/c1/Set_luck.png" }, regen: { name:"Aumento de regeneración (%)", img:"https://wiki.the-west.net/images/5/53/Regeneration.png", }, drop:{ name:"Aumento probabilidad de salidad de productos", img:"https://wiki.the-west.net/images/thumb/b/b8/Drop.png/40px-Drop.png" }, spd: { name: "Velocidad", img: "https://wiki.the-west.net/images/thumb/1/1a/QuarterHorse.png/40px-QuarterHorse.png" } } }, initPage: function () { //Append input level if ($("#input_level").length === 1) { var input_level = $('<input type="number" style="width:80px;" class="west" placeholder="' + ui.lang.input_level + '" min="0" max="250">').bind("propertychange keyup input paste", function () { if (this.value > 250) { this.value = 250; } 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="' + ui.lang.input_search + '">').bind("propertychange keyup input paste", function () { var val = this.value.toLowerCase(); console.log($('.craft_recipe').length); if ($('.craft_recipe').length) { if (val === ) { $('.craft_recipe').show().css('opacity', '1'); } else { $('.craft_recipe').css('opacity', '0') setTimeout(function() { $('.craft_recipe').filter(function() { if($(this).find('[data-popup]').filter(function() { return $(this).attr('data-popup').toLowerCase().indexOf(val) > -1; }).length > 0){ $(this).css('opacity', '1').show(); }else{ $(this).hide(); } }) }, 300); } } else { 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 ((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(ui.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 (ui.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; }); }
}, popup: { content: "", delay: 200, active: false, show: function (obj) { ui.popup.content = ui.popup.createPopup($(obj).attr('data-popup'), $(obj).attr('data-cdn-cat'), $(obj).attr('data-cdn-img'), parseInt($(obj).attr('data-lvl'))); ui.popup.active = true; ui.popup.setTimeout(); ui.popup.getContainer().html(ui.popup.content); }, hide: function () { ui.popup.getEl().css({ display: 'none', top: 0, left: 0 }); ui.popup.active = false; ui.popup.clearTimeout(); }, setTimeout: function () { ui.popup.clearTimeout(); ui.popup.timer = window.setTimeout(function () { ui.popup.getEl().css('display', 'block'); }, ui.popup.delay); }, clearTimeout: function () { if (ui.popup.timer) window.clearTimeout(ui.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 = '
' + data.name + '
' + data.type + '
';
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 += '
' + data.dmg_min + '-' + data.dmg_max + ' ' + ui.lang.damages + '
';
} for (var cat in ui.lang.popup) { var cnt = 0; for (var key in ui.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 = " (" + ui.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 += ui.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 += '
' + data.textjob[i] + '
';
} html += '
'; } if (data.text) {
html += '
for (var i = 0; i < data.text.length; i++) {html += '
' + data.text[i] + '
';}html += '
';
} if (data.bonus) { for (var i = 0; i < data.bonus.length; i++) {
html += '
' + data.bonus[i] + '
';
} html += '
'; } if (data.jobs) {
html += '
for (var i = 0; i < data.jobs.length; i++) {html += '';
}html += '
<img src="' + ui.config.cdn + '/images/jobs/' + data.jobs[i][1] + '.png"/> | ' + data.jobs[i][0] + ' |
';
} if (data.craft) {
html += '
<img src="' + ui.config.cdn + '/images/crafting/profsymbol_' + data.craft.id + '_small.png"/> | ';
for (var i = 0; i < data.craft.req.length; i++) {html += ''; }html += ''; for (var i = 0; i < data.craft.req.length; i++) { html += ''; }html += '
|
';
}
html += '
if (data.hspd) { if (upgraded) { data.hspd += Math.round(Math.max(1, data.hspd * 0.1 * lvl)); }html += '
' + ui.lang.speed + ': +' + data.hspd + '%
';
}
if (data.set) html += '<a class="popup_set" href="/wiki/' + data.set + '">' + data.set + '</a>
';
if (data.sp) { html += '<img src="' + ui.config.img_buyprice + '"/>' + data.bp + ' <img src="' + ui.config.img_sellprice + '"/> ' + data.sp + 'html += '
'; } else { html += '' + ui.lang.unsalable + '
'; } if (data.lvl) html += ui.lang.level + ' ' + data.lvl + '
'; if (data.sex) { if (data.sex == 0) { html += '<img src="' + ui.config.img_male + '"/> '; } else { html += '<img src="' + ui.config.img_female + '"/> '; } } if (data.auc == 1) { html += '' + ui.lang.auction + '
'; } else { html += '' + ui.lang.not_auction + '
'; } if (data.upg == 0) { html += '' + ui.lang.not_upgrade + '
'; } else { html += '' + ui.lang.upgrade + '
'; }
[item=' + data.id + ']
';
return html; }, setPosition: function (e) { var window_width = $(window).width(); var window_height = $(window).height(); var popup_width = ui.popup.getEl().outerWidth(); var popup_height = ui.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); } ui.popup.getEl().css({ top: top, left: left }); }, init: function () {
//Append popup container
$('body').append('
');
//Set events $(document).on('mouseenter', '.item_container', function (e) { ui.popup.show(this); ui.popup.setPosition(e); }); $(document).on('mouseleave', '.item_container', function () { ui.popup.hide(); }); $(document).on('mousemove', '.item_container', function (e) { ui.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); } ui.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); } ui.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 () { //Get bonuses from all item sets $('.set_container').each(function () { var set_id = $(this).attr('data-set-id'); ui.set_calc.itemStatus[set_id] = {}; ui.set_calc.data[set_id] = { items: {}, set: {} }; $(this).find('.item_container').each(function () { var json = JSON.parse($(this).attr('data-popup')); if ($(this).is(":hidden")) { ui.set_calc.itemStatus[set_id][json.id] = false; } else { ui.set_calc.itemStatus[set_id][json.id] = 0; } for (var prop in json) { if (json.hasOwnProperty(prop) && ui.config.set_bonus.hasOwnProperty(prop)) { if (!ui.set_calc.data[set_id].items[prop]) { ui.set_calc.data[set_id].items[prop] = {}; } ui.set_calc.data[set_id].items[prop][json.id] = json[prop]; } } }); }); //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'); ui.set_calc.data[set_id].set[nb] = {}; $(this).find('.set_bonus').each(function () { key = $(this).attr('data-type'); if ($(this).find('.calc').length !== 0) { ui.set_calc.data[set_id].set[nb][key] = -parseFloat($(this).find('.calc').attr('id')); } else { ui.set_calc.data[set_id].set[nb][key] = parseFloat($(this).find('.val').text()); } if (!ui.config.set_bonus.hasOwnProperty(key)) { ui.set_calc.bonus.extra_set_bonus[key] = { img: $(this).find('img').attr('src'), name: $(this).find('#tooltip_content').text() }; } }); }); });
}, 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 ui.set_calc.data) { for (var key in ui.set_calc.data[set_id].items) { for (var item_id in ui.set_calc.data[set_id].items[key]) { if (ui.set_calc.itemStatus[set_id][item_id] !== false) { lvl = ui.set_calc.itemStatus[set_id][item_id]; if (!total[key]) { total[key] = 0; } var value = ui.set_calc.data[set_id].items[key][item_id];
if (ui.set_calc.data[set_id].items[key][item_id] < 0) { //If bonus (per Level) value = -value;
if (ui.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 (ui.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] += Math.round(Math.max(1, value * 0.1 * lvl)); } } else { total[key] += value; } } } } } var item_nb = 0; for (var item_id in ui.set_calc.itemStatus[set_id]) { if (ui.set_calc.itemStatus[set_id][item_id] !== false) { item_nb++; } } for (var key in ui.set_calc.data[set_id].set[item_nb]) { if (!total[key]) { total[key] = 0; } if (ui.set_calc.data[set_id].set[item_nb][key] < 0) { total[key] += Math.ceil(-ui.set_calc.data[set_id].set[item_nb][key] * level); } else { total[key] += ui.set_calc.data[set_id].set[item_nb][key]; } } } //Create the html table
var html = '
Nivel '+ level +' | '; for (var key in ui.config.set_bonus) {
if (total.hasOwnProperty(key)) { if(key == "con" || key == "vig" || key == "tou" || key == "sta" || key == "hea" || key == "rid" || key == "ref" || key == "dod" || key == "hid" || key == "swi" || key == "aim" || key == "sho" || key == "pit" || key == "fin" || key == "rep" || key == "lea" || key == "tac" || key == "tra" || key == "ani" || key == "app"){html += ' <img src="' + ui.config.set_bonus[key].img + '" style="width: 70px;" >+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + ' ';
' + ui.config.set_bonus[key].name + ' }else{html += ' <img src="' + ui.config.set_bonus[key].img + '">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + ' ';
' + ui.config.set_bonus[key].name + ' } } } for (var key in ui.set_calc.bonus.extra_set_bonus) { if (total.hasOwnProperty(key)) {html += ' <img src="' + ui.set_calc.bonus.extra_set_bonus[key].img + '">+' + total[key] + (['xp', 'money', 'luck', 'spd', 'regen', 'drop'].indexOf(key) !== -1 ? "%" : "") + ' ';
' + ui.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")) { ui.set_calc.itemStatus[set_id][item_id] = false; } else { ui.set_calc.itemStatus[set_id][item_id] = parseInt(item_container.attr('data-lvl')); } ui.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")) { ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); ui.set_calc.calc(); } }); //Calc again when player level changes $("#input_level").bind("propertychange keyup input paste", function () { ui.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")) { ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = false; } else { ui.set_calc.itemStatus[set_id][JSON.parse(item.attr('data-popup')).id] = parseInt(item.attr('data-lvl')); } }); ui.set_calc.calc(); }); }, init: function () { ui.set_calc.initEvents(); ui.set_calc.getData();$('#mw-content-text').append(''); if ($('#input_level').length === 0) ui.set_calc.calc(); } }, init: function () { ui.initPage(); ui.popup.init(); if (ui.config.enable_set_calc && $('.infoSet').length !== 0) { ui.set_calc.init(); } } }; ui.init(); |