Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. javascript:
  2. /*Dates must be your time
  3. n,mode,min
  4.  
  5. 0,1,200 will send ALL minus 0 IF there are more than 200
  6. 20,1,3000 will send ALL minus 20 IF there are more than 3000
  7. 20,2,30 will send 20 IF there are more than 30
  8.  
  9. mode 1 - if there are less troops than the number to leave behind, don't send any
  10. mode 2 - if there are less troops than the number to send, send all
  11.  
  12. put config of slowest troop first
  13. */
  14. var startWindow=new Date("10 June 2011 00:00:00");
  15. var endWindow=new Date("30 July 2012 00:00:00");
  16. var coords = '';
  17. var options ={
  18.     fakeLeave:10,
  19.     scouts:1,
  20.     alertOnNoTroops:0,
  21.     useFirstTroop:0,
  22.     alertOnTroops:0
  23. };
  24. var config = {
  25.    ram: [0,0,0],
  26.    catapult: [30,2,35],
  27.    spear: [0,0,0],
  28.    sword: [0,0,0],
  29.    axe: [0,0,0],
  30.    archer: [0,0,0],
  31.    light: [0,0,0],
  32.    marcher: [0,0,0],
  33.    heavy: [30,2,35],
  34.    spy: [1,2,0]
  35. };
  36. var speeds= {
  37.     spear:1080,
  38.     sword:1320,
  39.     axe:1080,
  40.     archer:1080,
  41.     light:600,
  42.     marcher:600,
  43.     heavy:660,
  44.     ram:1800,
  45.     catapult:1800,
  46.     spy: 500
  47. };
  48. curTime=new Date();
  49. function dist(x1,y1,x2,y2){
  50.     x=x1-x2;
  51.     y=y1-y2;
  52.     return Math.sqrt(x*x+y*y);
  53. }
  54. curSec=curTime.getTime()/1000;
  55. firstSec=startWindow.getTime()/1000;
  56. finalSec=endWindow.getTime()/1000;
  57.  
  58. var newCoords=[];
  59. var nCSpd=[];
  60. var d=0;
  61. var win = (window.frames.length > 0) ? window.main : window;
  62. var eleForm = win.document.getElementById('units_form');
  63. var coord = coords.split(' ');
  64. var curVill=win.document.getElementsByTagName("b")[0].innerText.split("|");
  65. var xCo=curVill[0].split("(")[1];
  66. var yCo=curVill[1].split(")")[0];
  67. win.$("input[class=unitsInput]").attr("value", "0");
  68. var number=[];
  69. /* check if the troops config is present */
  70. var configSpeed=0;
  71. var successful=1;
  72. for(var unit in config){
  73.     number[unit]=parseInt(eleForm[unit].nextSibling.nextSibling.innerHTML.match(/\d+/));
  74.     if(number[unit]<config[unit][2]){
  75.         successful=0;
  76.     }else{
  77.         configSpeed=Math.max(configSpeed,speeds[unit]);
  78.     }
  79. }
  80. if(successful==1){
  81.     if(options.alertOnTroops){
  82.         alert("Config found");
  83.     }
  84.     /* fill out the troops, and it's at the assigned speed speed */
  85.     for(var unit in config){
  86.         mode=config[unit][1];
  87.         n=config[unit][0];
  88.         nUnits=number[unit];
  89.         unitsToSend=0;
  90.         if(mode==1){
  91.             /* leave behind  */
  92.             unitsToSend=Math.max(nUnits-n,0);
  93.         }
  94.         if(mode==2){
  95.             unitsToSend=Math.min(n,nUnits);
  96.         }
  97.         eleForm[unit].value=unitsToSend;
  98.     }
  99.     for(var target in coord){
  100.         tCo=coord[target].split("|");
  101.         tX=tCo[0];
  102.         tY=tCo[1];
  103.         travelTime=dist(tX,tY,xCo,yCo)*configSpeed;
  104.         arriveTime=curSec+travelTime;
  105.         if(arriveTime>firstSec&&arriveTime<finalSec){
  106.             newCoords[d]=coord[target];
  107.             d++;
  108.         }
  109.     }
  110. }else{
  111.     if(options.alertOnNoTroops){
  112.         alert("Troops do not meet config requirements");
  113.     }
  114.     for(var unit in config){
  115.         if(newCoords.length>0&&options.useFirstTroop==1){
  116.        
  117.         }else{
  118.             if(number[unit]>options.fakeLeave+1){
  119.                 for(var target in coord){
  120.                     tCo=coord[target].split("|");
  121.                     tX=tCo[0];
  122.                     tY=tCo[1];
  123.                     travelTime=dist(tX,tY,xCo,yCo)*speeds[unit];
  124.                     arriveTime=curSec+travelTime;
  125.                     if(arriveTime>firstSec&&arriveTime<finalSec){
  126.                         newCoords[d]=coord[target];
  127.                         nCSpd[d]=unit;
  128.                         d++;
  129.                     }
  130.                 }
  131.             }/*else, there are not enough, leave all behind*/
  132.         }
  133.     }
  134. }
  135. if(newCoords.length>0){
  136.     nC=Math.floor(Math.random()*newCoords.length);
  137.     tCoord=newCoords[nC].split("|");
  138.     eleForm.x.value = tCoord[0];
  139.     eleForm.y.value = tCoord[1];
  140. }else{
  141.     alert("Cannot reach in time window, either no units in village fakeLeave set too high");
  142. }
  143. if(successful==0){
  144.     eleForm[nCSpd[nC]].value=1;
  145.     eleForm['spy'].value=Math.min(options.scouts,number['spy']);
  146. }
  147. void(0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement