Ordenar aldeias por distancia do Alvo - Ordena todas suas aldeias em visualizações pela distancia da aldeia alvo, exibe o tempo de cada unidade até lá e abre um atalho para a praça, ideal para envio de fakes e outras coisas

javascript:var alvo = 123123; var targetCoord = prompt('Insira a coordenada da aldeia:', ''); if (targetCoord) { var info_xml = $.ajax({ url: "interface.php?func=get_unit_info", async: false }).responseText; var units = { spear: { visible: true, speed: $('spear speed', info_xml).text(), name: '<img src="graphic/unit/unit_spear.png"' }, sword: { visible: true, speed: $('sword speed', info_xml).text(), name: '<img src="graphic/unit/unit_sword.png"' }, archer: { visible: true, speed: $('archer speed', info_xml).text(), name: '<img src="graphic/unit/unit_archer.png"' }, axe: { visible: true, speed: $('axe speed', info_xml).text(), name: '<img src="graphic/unit/unit_axe.png"' }, spy: { visible: true, speed: $('spy speed', info_xml).text(), name: '<img src="graphic/unit/unit_spy.png"' }, light: { visible: true, speed: $('light speed', info_xml).text(), name: '<img src="graphic/unit/unit_light.png"' }, marcher: { visible: true, speed: $('marcher speed', info_xml).text(), name: '<img src="graphic/unit/unit_marcher.png"' }, heavy: { visible: true, speed: $('heavy speed', info_xml).text(), name: '<img src="graphic/unit/unit_heavy.png"' }, ram: { visible: true, speed: $('ram speed', info_xml).text(), name: '<img src="graphic/unit/unit_ram.png"' }, catapult: { visible: true, speed: $('catapult speed', info_xml).text(), name: '<img src="graphic/unit/unit_catapult.png"' }, knight: { visible: true, speed: $('knight speed', info_xml).text(), name: '<img src="graphic/unit/unit_knight.png"' }, snob: { visible: true, speed: $('snob speed', info_xml).text(), name: '<img src="graphic/unit/unit_snob.png"' } }; function fnDistance(a, b) { a = a.split('|'); b = b.split('|'); var c = b[0] - a[0]; var d = b[1] - a[1]; return Math.sqrt(c * c + d * d) } function zeroPad(number, length) { var n = number.toString(); while (n.length < length) { n = '0' + n; } return n; } function fnHour(time) { return zeroPad(Math.floor(time / 3600), 2); } function fnMinute(time) { return zeroPad(Math.floor(time / 60) % 60, 2); } function fnSecond(time) { return zeroPad(Math.round(time % 60), 2); } var win = (window.main || self), $ = win.$; $('.dsm').remove(); var table = $('[id$="_table"]').filter(':not(#group_table)').get(0); var ii = ($('[src*="note.png"],[class*="note-icon"]').length > 0) ? 1 : 0; var rows = []; var row, coords, distance, unitDistance, villageID, rowHTML; var hdrHTML = '<th class="dsm"><b><img src="graphic/buildings/place.png"</b></th>'; for (var q = 1; q < table.tBodies[0].rows.length; q++) { rowHTML = ''; row = table.tBodies[0].rows[q]; coords = $.trim($(row.cells[ii]).text()).match(/\d+\|\d+/g); coords = coords ? coords[coords.length - 1] : null; distance = fnDistance(coords, targetCoord); for (var unit in units) { if (units[unit].visible) { if (q == 1) { hdrHTML += '<th class="dsm"><b>' + units[unit].name + '</b></th>'; } unitDistance = distance * units[unit].speed * 60; rowHTML += '<td class="dsm"><b>' + fnHour(unitDistance) + ':' + fnMinute(unitDistance) + ':' + fnSecond(unitDistance) + '</b></td>'; } } villageID = ($(row).find('a:eq(0)').attr('href') || '').match(/village\=\d+/); row.innerHTML += '<td class="dsm"><a href="' + win.game_data.link_base_pure.replace(/village\=\d*/i, villageID).replace(/screen\=\w*/i, 'screen=place&target='+alvo) + '" target="_blank"><img src="graphic/buildings/place.png" alt="Rally point" width="16" height="16"/></a></td>'; row.innerHTML += rowHTML; rows[q - 1] = [coords, row]; } table.tBodies[0].rows[0].innerHTML += hdrHTML; rows = rows.sort(function (a, b) { return fnDistance(a[0], targetCoord) - fnDistance(b[0], targetCoord) }); for (var q = 0; q < rows.length; q++) { table.tBodies[0].appendChild(rows[q][1]); } }
Nenhum comentário:
Postar um comentário