SHARE
TWEET

Calc_Snipe_Bt_(Cowboy Soberano)-

CowboySoberano Jun 8th, 2017 (edited) 594 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.     Editor  : Marcos Vinicius Dos Santos Marques
  3.     Author  : Fluffy88   ---   Cowboy Soberano
  4.     Email   : marcosvinicius.santosmarques@gmail.com
  5.     Website : http://fluffy88.com   ---   https://forum.tribalwars.ae/member.php?38997-Abu-Rajih
  6.      
  7.  
  8.     changelog:
  9.     *6 Nov 2013 - redirect to combined overview if on another page - cheesasaurus
  10.     *29 Nov 2013 - removed the old frame setup. Just set win = window.
  11.      Modificado
  12.     TODO: save settings in a cookie
  13. */
  14. if (game_data.player.premiu===false) {
  15.     alert('Para utilizar esse script é necessário uma Conta Premium.');
  16.    end();
  17. }
  18. unitnames = {
  19.   "Lanceiro":"lança",
  20.   "sword":"espada",
  21.   "axe":"Barbaro",
  22.   "spy":";Spy",
  23.   "light":"Cavalaria_leve",
  24.   "heavy":"Cavalaria_pesada",
  25.   "ram":"Ariete",
  26.   "catapult":"Catapulta",
  27.   "knight":"Paladino",
  28.   "snob":"Nobre"
  29. };
  30. function fnInjectOverviewBar(){
  31.     /* Default to your own currently active village */
  32.     var defaultCoords = fnExtractCoords(win.$("title").html());
  33.      
  34.     /* Default to midnight of next day */
  35.     var defaultDate = new Date();
  36.     defaultDate.setTime(((Math.floor(defaultDate.getTime()/msPerDay)+1)*minsPerDay + defaultDate.getTimezoneOffset())*msPerMin);
  37.     defaultDate = defaultDate.toString().replace(/\w+\s*/i,"").replace(/(\d*:\d*:\d*)(.*)/i,"$1");
  38.      
  39.     /* Perform the injection */
  40.     fnInjectUnits();
  41.     win.$('<tr><td colspan="3">Aldeia Alvo:<input id="snipe_coord" value="'+defaultCoords+'" class="text-input inactive" size="8" onFocus="this.select()" /></td><td colspan="1">Horario Do Ataque:<input id="arrival_time" size="25" class="text-input inactive" value="'+defaultDate+'" onFocus="this.select()" /></td><td><input type="button" value="OK"   onClick="fnCalculateBackTime()" /></td></tr>').insertAfter(win.$('#menu_row2'));
  42.     win.$('<div id="snipe_output"><br/><hr><h3><a href="http://www.br.twstats.com/br82/index.php?page=player&id=8270061" target="_blank"><span style=\"color:blue;\">Calculadora Snipe -\</span><span style=\"color:magenta;\"> Cowboy Soberano</span><br/><span><sub>(marcosvinicius.santosmarques@gmail.com ' + version + ')</hr></h3></sub><hr></span><br/></div>').insertAfter(win.$('body'));
  43. }
  44.  
  45. function fnExtractCoords(src){
  46.     var vv=src.match(/\d+\|\d+/ig);
  47.     return (vv?vv[vv.length-1]:null);
  48. }
  49.  
  50. function fnCalculateDistance(to,from){
  51.     var target = fnExtractCoords(to).match(/(\d+)\|(\d+)/);
  52.     var source = fnExtractCoords(from).match(/(\d+)\|(\d+)/);
  53.     var fields = Math.sqrt(Math.pow(source[1]-target[1],2)+Math.pow(source[2]-target[2],2));
  54.      
  55.     return fields;
  56. }
  57.  
  58. function fnDebugLog(msg){win.$("body").append("<span>"+msg+"</span><br/>");}
  59.  
  60. /* sendMethod = "GET" || "POST", params = json, type = xml,json,text */
  61. function fnAjaxRequest(url,sendMethod,params,type){
  62.     var error=null,payload=null;
  63.  
  64.     win.$.ajax({
  65.         "async":false,
  66.         "url":url,
  67.         "data":params,
  68.         "dataType":type,
  69.         "type":String(sendMethod||"GET").toUpperCase(),
  70.         "error":function(req,status,err){error="ajax: " + status;},
  71.         "success":function(data,status,req){payload=data;}
  72.     });
  73.  
  74.     if(error){
  75.         throw(error);
  76.     }
  77.  
  78.     return payload;
  79. }
  80.  
  81. function fnCreateConfig(name){return win.$(fnAjaxRequest("/interface.php","GET",{"func":name},"xml")).find("config");}
  82. function fnCreateUnitConfig(){return fnCreateConfig("get_unit_info");}
  83. function fnCreateWorldConfig(){return fnCreateConfig("get_config");}
  84.  
  85. function fnCalculateLaunchTime(source,target,unit,landingTime){
  86.     var distance = fnCalculateDistance(target,source);
  87.     var unitSpeed = unitConfig.find(unit+" speed").text();
  88.  
  89.     /* Convert minutes to milli-seconds */
  90.     var unitTime = distance*unitSpeed*msPerMin;
  91.      
  92.     /* Truncate milli-second portion of the time */
  93.     var launchTime = new Date();
  94.     launchTime.setTime(Math.round((landingTime.getTime() - unitTime)/msPerSec)*msPerSec);
  95.  
  96.     return launchTime;
  97. }
  98.  
  99. function fnWriteCookie(ele){
  100.     var snipeConfig="";
  101.  
  102.     win.$("#combined_table tr:first th img[src*=unit_]").each(function(i,e){
  103.         snipeConfig+=win.$("#view_"+e.src.match(/unit\_(.+)\.png?/i)[1]).is(':checked')?"1":"0";
  104.     });
  105.  
  106.     var cookie_date=new Date(2099,11,11);
  107.     win.document.cookie='$snipe='+snipeConfig+';expires='+cookie_date.toGMTString();
  108. }
  109.  
  110. function fnInjectUnits(){
  111.     var twCookie=win.document.cookie.match(/\$snipe\=([0|1]*)/i);
  112.     if(twCookie){
  113.         twCookie=twCookie[1];
  114.         for(var ii=0;ii<twCookie.length;ii++){
  115.         }
  116.     }
  117.  
  118.     win.$("#combined_table tr:first th img[src*=unit_]").each(function(i,e){
  119.         if(this.parentNode.nodeName=="A")
  120.         {
  121.             win.$('<input type="checkbox" '+((!twCookie||(twCookie[i]=="1"))?'checked="true"':'')+' id="view_'+e.src.match(/unit\_(.+)\.png?/i)[1]+'" OnClick="fnWriteCookie(this);"/>').insertBefore(win.$(this.parentNode));
  122.         }
  123.         else
  124.         {
  125.             win.$('<input type="checkbox" '+((!twCookie||(twCookie[i]=="1"))?'checked="true"':'')+' id="view_'+e.src.match(/unit\_(.+)\.png?/i)[1]+'" OnClick="fnWriteCookie(this);"/>').insertBefore(win.$(this));
  126.         }
  127.     });
  128.     win.$("#combined_table tr:first th:has(img[src*=unit_])").attr("style","background-color:yellow");
  129. }
  130.      
  131. function fnExtractUnits(){
  132.     var units=[];
  133.  
  134.     win.$("#combined_table tr:first th img[src*=unit_]").each(function(i,e){
  135.         units.push(e.src.match(/unit\_(.+)\.png?/i)[1]);
  136.     });
  137.      
  138.     return units;
  139. }
  140.      
  141. function fnCalculateBackTime(){
  142.     var worldConfig = fnCreateWorldConfig();
  143.     var hasChurch = worldConfig && parseInt(worldConfig.find("game church").text()||"0", 10);
  144.     /*var arrivalTime = new Date(win.$("#arrival_time").attr("value").split(":").slice(0,3).join(":"));
  145.     var target = win.$("#snipe_coord").attr("value");*/
  146.     var arrivalTime = new Date(document.getElementById("arrival_time").value.split(":").slice(0,3).join(":"));
  147.     var target = document.getElementById("snipe_coord").value;
  148.     var servertime = win.$("#serverTime").html().match(/\d+/g);
  149.     var serverDate = win.$("#serverDate").html().match(/\d+/g);
  150.     serverTime = new Date(serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]+" "+servertime.join(":"));
  151.     var output = [];
  152.     var ii,troop_count,source,launchTime;
  153.     var units=fnExtractUnits();
  154.      
  155.     /* Loop through your own villages */
  156.     win.$("#combined_table tr:gt(0)").each(function(i,e){
  157.         source = fnExtractCoords($(this).find("td:eq(1)").html());      
  158.         if(source != target){
  159.             var isVisible = false;
  160.              
  161.             /* Process Each Unit */
  162.             for(ii=0;ii<units.length;ii++){
  163.                 if(win.$("#view_"+units[ii]).is(':checked')){
  164.                     troop_count = parseInt($(this).find("td:eq("+(ii+(hasChurch?9:8))+")").text(),10);
  165.                  
  166.                     /* Do we have Units currently Available */
  167.                     if(troop_count > 0){
  168.                         launchTime=fnCalculateLaunchTime(source,target,units[ii],arrivalTime);
  169.                      
  170.                         /* Cache Units that can reach the target on time */
  171.                         if(launchTime.getTime() > serverTime.getTime()){
  172.                             isVisible = true;
  173.                             output.push([launchTime.getTime(),"[b]Enviar[/b] "+units[ii]+"(" + troop_count + ") [b]De[/b] [coord]"+source+"[/coord] [b]Em[/b] [coord]"+target+"[/coord] As "+launchTime.toString().replace(/(\d*:\d*:\d*)(.*)/i,"$1"),e]);
  174.                         }
  175.                     }
  176.                 }
  177.             }
  178.         }
  179.  
  180.         win.$(e).attr("style","display:"+(unitnames?"table-row":"none"));
  181.     });
  182.  
  183.     /* Sort by Launch Time in Ascending Order */      
  184.     output = output.sort(function(a,b){return (a[0]-b[0]);});
  185.     for(var qq=0;qq<output.length;qq++){win.$("#combined_table").get(0).tBodies[0].appendChild(output[qq][2]);}
  186.  
  187.     /* Clear existing messages and display version */
  188.     var srcHTML = "";
  189.     srcHTML += "<br/>";
  190.     srcHTML += "<span style=\"color:blue;\">'Calculadora Snipe'\ Cowboy Soberano</span>";
  191.     srcHTML += "<br/>";
  192.     srcHTML += "<span><sub>(marcosvinicius.santosmarques@gmail.com " + version + ")</sub><hr></span>";
  193.     srcHTML += "<br/>";
  194.  
  195.     if(output.length > 0){      
  196.         srcHTML += "<div align=\"center\"><textarea wrap=\"off\" readonly=\"yes\" cols=\"80\" rows=\"" + (output.length+1) + "\" style=\"width:95%;background-color:transparent;\" onfocus=\"this.select();\">";
  197.  
  198.         for(ii=0;ii<output.length;ii++){
  199.             srcHTML += output[ii][1] + "\n";
  200.         }
  201.  
  202.         srcHTML += "</textarea></div>";
  203.     }
  204.     else{
  205.         srcHTML += "<span style=\"color:blue;\">Impossivel chegar a tempo</span>";
  206.     }
  207.  
  208.     srcHTML += "<br/><br/><br/>";
  209.      
  210.     win.$("#snipe_output").html("");
  211.     win.$("#snipe_output").append(win.$(srcHTML));
  212. }
  213.  
  214.  
  215. try{
  216.     if(game_data.screen == 'overview_villages' && game_data.mode == 'combined')
  217.     {
  218.         var author="marcosvinicius.santosmarques@gmail.com";
  219.         var minVer="7.0";
  220.         //var win=(window.frames.length>0)?window.main:window;
  221.         var win = window;
  222.  
  223.         var ver=win.game_data.version.match(/[\d|\.]+/g);
  224.         if(!ver||(parseFloat(ver[1])<minVer)){
  225.             alert("This script requires v"+minVer+" or higher.\nYou are running: v"+ver[1]);
  226.         }
  227.         else if(win.$("#snipe_output").length <= 0){
  228.             var msPerSec=1000;
  229.             var secsPerMin=60;
  230.             var minsPerHour=60;
  231.             var hrsPerDay=24;
  232.             var msPerMin=msPerSec*secsPerMin;
  233.             var msPerHour=msPerMin*minsPerHour;
  234.             var msPerDay=msPerHour*hrsPerDay;
  235.             var minsPerDay=hrsPerDay*minsPerHour;
  236.  
  237.             var version='v5.0Br';
  238.  
  239.             var unitConfig=fnCreateUnitConfig();
  240.  
  241.             fnInjectOverviewBar();
  242.         }
  243.     }
  244.     else
  245.     {
  246.         UI.InfoMessage('Iremos lhe Redirecionar para Visualizacoes Gerais /Comandos...', 3000, 'success');
  247.         window.location = game_data.link_base_pure + 'overview_villages&mode=combined';
  248.     }
  249. }
  250. catch(objError){
  251.     var dbgMsg="Error: " + String(objError.message||objError);
  252.     alert(dbgMsg);
  253. }
  254.  
  255. void(0);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top