RaidTab

Raid Tab

This script should not be not be installed directly. It is a library for other scripts to include with the meta directive // @require https://update.greatest.deepsurf.us/scripts/399268/787098/RaidTab.js

  1. /********************************* Raid Tab ***********************************/
  2. // @tabversion 20171101
  3.  
  4. Tabs.Raid = {
  5. tabDisabled : false,
  6. tabOrder : 8000,
  7. tabColor : 'brown',
  8. myDiv : null,
  9. tabLabel : unsafeWindow.g_js_strings.commonstr.raid,
  10. rallypointlevel:null,
  11. knt:{},
  12. Troops:{},
  13. city:0,
  14. raidtimer:null,
  15. rslt:{},
  16. save:{},
  17. stopping:false,
  18. resuming:false,
  19. deleting:false,
  20. stopprogress:0,
  21. stopcount:0,
  22. activecount:0,
  23. count:0,
  24. Options : {
  25. RemoveDeleteTab : false,
  26. foodreport : false,
  27. MsgInterval : 1,
  28. LastReport : 0,
  29. raidbtns : false,
  30. Foodstatus : {1:0,2:0,3:0,4:0,5:0,6:0,7:0,8:0},
  31. },
  32. init : function (div){
  33. var t = Tabs.Raid;
  34. t.myDiv = div;
  35.  
  36. if (!Options.RaidOptions) {
  37. Options.RaidOptions = t.Options;
  38. }
  39. else {
  40. for (var y in t.Options) {
  41. if (!Options.RaidOptions.hasOwnProperty(y)) {
  42. Options.RaidOptions[y] = t.Options[y];
  43. }
  44. }
  45. }
  46.  
  47. setInterval(t.lookup, 2500);
  48. setInterval(t.sendreport, 1*60*1000);
  49. if(Options.RaidOptions.raidbtns) {
  50. AddMainTabLink('Raids: S', 'pboldraidtab', t.StopAllRaids);
  51. AddMainTabLink('R', 'pboldraidtabRes', t.ResumeAllRaids);
  52. if (!Options.RaidOptions.RemoveDeleteTab) AddMainTabLink('D', 'pboldraidtabDel', t.DeleteAllRaids);
  53. document.getElementById('pboldraidtabRes').style.marginLeft = '0px';
  54. if (!Options.RaidOptions.RemoveDeleteTab) document.getElementById('pboldraidtabDel').style.marginLeft = '0px';
  55. document.getElementById('pboldraidtab').title = 'Click to Stop Active Raids';
  56. document.getElementById('pboldraidtabRes').title = 'Click to Resume Stopped Raids';
  57. if (!Options.RaidOptions.RemoveDeleteTab) document.getElementById('pboldraidtabDel').title = 'Click to Delete Stopped Raids';
  58. };
  59. var m = '<DIV class=divHeader align=center>RAID FUNCTIONS</div><TABLE width=100% height=0% class=xtab><TR align="center">';
  60. m += '<TD>&nbsp;</td>';
  61. m += '<TD><INPUT id=pbRaidBut type=checkbox '+ (Options.RaidOptions.raidbtns?'CHECKED ':'') +'/></td><TD>'+translate("Raid toggle buttons on top of screen")+'</td><TD><INPUT id=pbDeleteTab type=checkbox '+ (Options.RaidOptions.RemoveDeleteTab?'CHECKED':'') +'\> Remove Delete Tab ';
  62. m += '<TD><INPUT id=pbsendraidreport type=checkbox '+ (Options.RaidOptions.foodreport?'CHECKED':'') +'\> Send raid report every ';
  63. m += '<INPUT id=pbsendreportint value='+ Options.RaidOptions.MsgInterval +' type=text size=3 \> hours </td>';
  64. m += '</tr></table></div>';
  65. m += '<DIV class=divHeader align=center>ACTIVE RAIDS</div><TABLE width=100% height=0% class=xtab><TR align="center">';
  66. m += '<TD><DIV style="margin-bottom:10px;"><span id=ptRaidCity></span></div></td></tr>';
  67. m +='<TR><TD><DIV style="margin-bottom:10px;"><span id=ptRaidTimer></span></div></td></tr></table>';
  68. m += '<DIV id=PaintRaids></div>';
  69. m += '<DIV class=divHeader align=center>SAVED RAIDS</div><TABLE width=100% height=0% class=xtab><TR align="center">';
  70. m += '<DIV id=SavedRaids></div>';
  71. t.myDiv.innerHTML = m;
  72. t.from = new CdispCityPicker ('ptRaidpicker', document.getElementById('ptRaidCity'), true, t.clickCitySelect, 0);
  73.  
  74. document.getElementById('pbRaidBut').addEventListener('change', function(){
  75. Options.RaidOptions.raidbtns = document.getElementById('pbRaidBut').checked;
  76. saveOptions();
  77. }, false);
  78. document.getElementById('pbDeleteTab').addEventListener('change', function(){
  79. Options.RaidOptions.RemoveDeleteTab = document.getElementById('pbDeleteTab').checked;
  80. saveOptions();
  81. }, false);
  82. document.getElementById('pbsendraidreport').addEventListener('change', function(){
  83. Options.RaidOptions.foodreport = document.getElementById('pbsendraidreport').checked;
  84. saveOptions();
  85. }, false);
  86. document.getElementById('pbsendreportint').addEventListener('change', function(){
  87. Options.RaidOptions.MsgInterval = parseInt(document.getElementById('pbsendreportint').value);
  88. saveOptions();
  89. }, false);
  90. var serverID = getServerId();
  91. t.save = GM_getValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID);
  92. if (t.save == null) t.save = GM_getValue ('SavedRaids_'+serverID);
  93. if (t.save != undefined) t.save = JSON2.parse (t.save);
  94. setInterval (t.paint,1000);
  95. },
  96. lookup : function (){
  97. var t = Tabs.Raid;
  98. t.activecount=0;
  99. t.stopcount=0;
  100. for (c=0; c< Seed.cities.length;c++) {
  101. cityID = 'city' + Seed.cities[c][0];
  102. for (b in Seed.queue_atkp[cityID]){
  103. destinationUnixTime = Seed.queue_atkp[cityID][b]['destinationUnixTime'];
  104. MarchStatus = Seed.queue_atkp[cityID][b]['marchStatus'];
  105. MarchType = Seed.queue_atkp[cityID][b]['marchType'];
  106. botMarchStatus = Seed.queue_atkp[cityID][b]['botMarchStatus'];
  107. if (MarchType == 9 && (MarchStatus == 3 || MarchStatus==10)) t.stopcount++;
  108. else if (MarchType == 9) t.activecount++;
  109. }
  110. }
  111.  
  112. if(!Options.RaidOptions.raidbtns)return;
  113. if (t.resuming == false && t.stopping == false && t.deleting == false && t.activecount != 0)
  114. document.getElementById('pboldraidtab').innerHTML = '<span style="color: #ff6">Raids: S ('+ t.activecount + ')</span>'
  115. else if (t.resuming == false && t.stopping == false && t.deleting == false)
  116. document.getElementById('pboldraidtab').innerHTML = '<span style="color: #CCC">Raids: S ('+ t.activecount + ')</span>'
  117. if (t.resuming == false && t.resuming == false && t.deleting == false && t.stopcount !=0)
  118. document.getElementById('pboldraidtabRes').innerHTML = '<span style="color: #ff6">R ('+ t.stopcount + ')</span>'
  119. else if (t.resuming == false && t.stopping == false && t.deleting == false)
  120. document.getElementById('pboldraidtabRes').innerHTML = '<span style="color: #CCC">R ('+ t.stopcount + ')</span>'
  121. if (!Options.RaidOptions.RemoveDeleteTab) {
  122. if (t.resuming == false && t.stopping == false && t.deleting == false && t.stopcount !=0)
  123. document.getElementById('pboldraidtabDel').innerHTML = '<span style="color: #ff6">D ('+ t.stopcount + ')</span>'
  124. else if (t.resuming == false && t.stopping == false && t.deleting == false)
  125. document.getElementById('pboldraidtabDel').innerHTML = '<span style="color: #CCC">D ('+ t.stopcount + ')</span>'
  126. }
  127. },
  128. paint : function () {
  129. var t = Tabs.Raid;
  130. var botMarchStat = {0:'Inactive',
  131. 1:'Raiding',
  132. 2:'Returning',
  133. 3:'Stopped',
  134. 4:'Resting',
  135. 5:'Unknown',
  136. 7:'Situation Changed',
  137. 8:'Returning',
  138. 9:'Aborting'};
  139. var botStat = { 0:'Undefined',
  140. 1:'Marching',
  141. 2:'Returning',
  142. 3:'Stopped',
  143. 4:'Insufficient Troops',
  144. 5:'Max Raids Exceeded',
  145. 7:'Timed out',
  146. 8:'Resting'};
  147. var o = '';
  148. if (t.rslt.settings != undefined) o+= '<FONT size=2px><B>Raid Timer: '+ timestr( 86400 - ( unixTime() - t.rslt.settings.lastUpdated )) +'</b></font>';
  149. document.getElementById('ptRaidTimer').innerHTML = o;
  150. var z ='<TABLE class=xtab><TR><TD width=60px align=center><A onclick="pbStopAll('+t.cityId+')">STOP</a></td><TD width=70px>Time</td><TD width=85px>Coords</td><TD width=50px>Level</td><TD width=50px></td><TD width=50px><A onclick="pbDeleteAll('+t.cityId+')">DELETE</a></td></TR>';
  151. if (t.rslt['queue'] != ""){
  152. for (y in t.rslt['queue']) {
  153. if (t.rslt['queue'][y]['botMarches'] != undefined) {
  154. for (k in Seed.queue_atkp['city' + t.cityId]){
  155. if (Seed.queue_atkp['city' + t.cityId][k]['marchId'] == t.rslt['queue'][y]['botMarches']['marchId']) {
  156. botMarchStatus = Seed.queue_atkp['city' + t.cityId][k]['botMarchStatus'];
  157. MarchStatus = Seed.queue_atkp['city' + t.cityId][k]['marchStatus'];
  158. restPeriod = (Seed.queue_atkp['city' + t.cityId][k]['restPeriod']/60);
  159. destinationUnixTime = Seed.queue_atkp['city' + t.cityId][k]['destinationUnixTime'];
  160. returnUnixTime = Seed.queue_atkp['city' + t.cityId][k]['returnUnixTime']
  161. now = unixTime();
  162. z+='<TR>';
  163. if (MarchStatus ==1) z+='<TD align=center><img src='+IMGURL+'attacking.jpg></td>';
  164. else if (MarchStatus ==8 && (destinationUnixTime - now) <= 0 && botMarchStatus !=3 && returnUnixTime > now) z+='<TD align=center><img src='+IMGURL+'returning.jpg></td>';
  165. else if (MarchStatus == 3) z+='<TD align=center><img src='+IMGURL+'autoAttack/raid_stopped_desat.png></td>';
  166. else if (MarchStatus == 4 || (returnUnixTime < now && botMarchStatus !=3)) z+='<TD align=center><img src='+IMGURL+'autoAttack/raid_resting.png></td>';
  167. else z+='<TD align=center><img src='+IMGURL+'autoAttack/raid_stopped_desat.png></td>';
  168. if (destinationUnixTime >= now) z+='<TD>'+ timestr(Seed.queue_atkp['city' + t.cityId][k]['destinationUnixTime'] - unixTime())+'</td>';
  169. if (destinationUnixTime <= now) {
  170. if ((destinationUnixTime - now) <= 0 && returnUnixTime > now) z+='<TD>'+ timestr(returnUnixTime - now)+'</td>';
  171. if (returnUnixTime <= now) z+='<TD>'+ timestr(now - returnUnixTime)+'</td>';
  172. }
  173. }
  174. }
  175. z+='<TD>('+ t.rslt['queue'][y]['botMarches']['toXCoord'] +','+ t.rslt['queue'][y]['botMarches']['toYCoord']+')</td>';
  176. z+='<TD align=center>'+ t.rslt['queue'][y]['botMarches']['toTileLevel'] +'</td>';
  177. if (botMarchStatus == 3) z+='<TD><A onclick="pbEditRaid('+ y +')">Edit</a></td>';
  178. else z+='<TD><FONT COLOR= "CCCCCC">Edit</font></td>';
  179. if (botMarchStatus == 3) z+='<TD align=center><A onclick="pbDeleteRaid('+ t.rslt['queue'][y]['botMarches']['marchId']+')">Delete</a></td>';
  180. else z+='<TD align=center><FONT COLOR= "CCCCCC">Delete</font></td>';
  181. z +='<TD width=25px></td><TD>Rest Time: '+ timestr(restPeriod) +'</td>';
  182. z+='</tr>';
  183. }
  184. }
  185. }
  186. z+='</table>';
  187. if (t.rslt['queue'] == "") z ='<TABLE class=xtab><TR><TD>No Raids in city!</td></TR>';
  188. document.getElementById('PaintRaids').innerHTML = z;
  189. var check = true;
  190. if (t.save != ""){
  191. var a ='<TABLE class=xtab><TR><TD width=60px></td><TD width=70px></td><TD width=85px>Coords</td><TD width=50px>Level</td><TD width=50px></td><TD width=50px></td></tr>';
  192. for (y in t.save){
  193. if (t.save[y] != undefined && t.cityId == t.save[y]['cityId']){
  194. a +='<TR><TD align=center><A onclick="pbDeleteSavedRaid('+ t.save[y]['marchId'] +')">X</a></td>';
  195. a +='<TD></td><TD><FONT COLOR= "CC0000">('+t.save[y]['toXCoord']+','+t.save[y]['toYCoord']+')</font></td>';
  196. a +='<TD align=center>'+t.save[y]['toTileLevel']+'</td>';
  197. a +='<TD><A onclick="pbEditSavedRaid('+ y +')">Edit</a></td>';
  198. a +='<TD align=center><A onclick="pbAddRaid('+ t.save[y]['marchId']+')">Add</a></td></tr>';
  199. check = false;
  200. }
  201. }
  202. m+='</table>';
  203. }
  204. if (check) a ='<TABLE class=xtab><TR><TD>No Saved Raids in city!</td></TR>';
  205. document.getElementById('SavedRaids').innerHTML = a;
  206. unsafeWindow.pbDeleteRaid = t.DeleteRaid;
  207. unsafeWindow.pbEditRaid = t.EditRaid;
  208. unsafeWindow.pbAddRaid = t.AddRaid;
  209. unsafeWindow.pbDeleteSavedRaid = t.DeleteSavedRaid;
  210. unsafeWindow.pbEditSavedRaid = t.EditSavedRaid;
  211. unsafeWindow.pbStopAll = t.StopCityRaids;
  212. unsafeWindow.pbDeleteAll = t.DeleteCityRaids;
  213. },
  214. DeleteSavedRaid : function (Id){
  215. var t = Tabs.Raid;
  216. for (yy=0;yy<t.save.length;yy++){
  217. if (t.save[yy]['marchId'] == Id){
  218. t.save.splice (yy,1);
  219. }
  220. }
  221. var serverID = getServerId();
  222. setTimeout (function (){GM_setValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, JSON2.stringify(t.save));}, 0);
  223. t.paint();
  224. },
  225. EditSavedRaid : function (y){
  226. var t = Tabs.Raid;
  227. var pop = new CPopup ('pbEditRaid', 0,0, 750,350, true);
  228. if (t.popFirst){
  229. pop.centerMe (mainPop.getMainDiv());
  230. t.popFirst = false;
  231. }
  232. pop.getTopDiv().innerHTML = '<CENTER><B>Edit Saved Raid</b></center>';
  233. cityId = t.save[y]['cityId'];
  234. var m = '<BR><TABLE id=pbRaidAdd height=0% class=xtab><TR align="center">';
  235. m+='<TR></tr><TR><TD width=25px>X= <INPUT id=toXCoord type=text size=3 maxlength=3 value='+t.save[y]['toXCoord']+'></td>';
  236. m+='<TD width=10px></td><TD widht=25px>Y= <INPUT id=toYCoord type=text size=3 maxlength=3 value='+ t.save[y]['toYCoord'] +'></td>';
  237. m+='<TD width=25px></td><TD>Round Trip: '+ timestr((t.save[y]['returnUnixTime'] - t.save[y]['destinationUnixTime'])*2)+ '</td></tr></table>';
  238.  
  239. m += '<BR><TABLE id=pbRaidAdd width=100% height=0% class=xtab><TR align="center">';
  240.  
  241. var rowcounter = 0;
  242. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  243. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  244. rowcounter++;
  245. if (rowcounter > 4) {
  246. m += '</tr><tr align="center">';
  247. rowcounter = 1;
  248. }
  249. m += '<td><table class=xtab><tr><td rowspan=2><img src="'+IMGURL+'units/unit_'+i+'_50.jpg?6545"></td><td>'+ addCommas(Seed.units['city'+cityId]['unt'+i]) +'</td></tr><tr><td><INPUT id=Unit'+i+' type=text size=6 maxlength=6 value="'+t.save[y]['unit'+i+'Count']+'"></td></tr></table></td>';
  250. }
  251. m += '</tr></table>';
  252. m += '<BR><CENTER><SELECT id=AddKnights type=list></select></center>';
  253. m+= '<BR><CENTER>'+ strButton20('Save', 'id=pbSaveRaid') +'</center>';
  254. pop.getMainDiv().innerHTML = m;
  255. t.getKnights(cityId);
  256. document.getElementById ('AddKnights').value = t.save[y]['knightId'];
  257. document.getElementById ('pbSaveRaid').addEventListener ('click', function(){
  258. t.save[y]['knightId'] = parseInt(document.getElementById ('AddKnights').value);
  259. t.save[y]['toXCoord'] = parseInt(document.getElementById ('toXCoord').value);
  260. t.save[y]['toYCoord'] = parseInt(document.getElementById ('toYCoord').value);
  261. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  262. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  263. t.save[y]['unit'+i+'Count'] = parseInt(document.getElementById ('Unit'+i).value);
  264. }
  265. var serverID = getServerId();
  266. setTimeout (function (){GM_setValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, JSON2.stringify(t.save));}, 0);
  267. pop.show (false);
  268. }, false);
  269. pop.show (true);
  270. },
  271. EditRaid : function (y){
  272. var t = Tabs.Raid;
  273. var pop = new CPopup ('pbEditRaid', 0,0, 750,430, true);
  274. if (t.popFirst){
  275. pop.centerMe (mainPop.getMainDiv());
  276. t.popFirst = false;
  277. }
  278. pop.getTopDiv().innerHTML = '<CENTER><B>Edit Raid</b></center>';
  279. cityId = t.rslt['queue'][y]['botMarches']['cityId'];
  280. var m = '<BR><TABLE id=pbRaidAdd height=0% class=xtab><TR align="center">';
  281. m+='<TR></tr><TR><TD width=25px>X= <INPUT id=toXCoord type=text size=3 maxlength=3 value='+t.rslt['queue'][y]['botMarches']['toXCoord']+'></td>';
  282. m+='<TD width=10px></td><TD widht=25px>Y= <INPUT id=toYCoord type=text size=3 maxlength=3 value='+ t.rslt['queue'][y]['botMarches']['toYCoord'] +'></td>';
  283. m+='<TD width=25px></td><TD>Round Trip: '+ timestr((t.rslt['queue'][y]['botMarches']['returnUnixTime'] - t.rslt['queue'][y]['botMarches']['destinationUnixTime'])*2)+ '</td></tr></table>';
  284.  
  285. m += '<BR><TABLE id=pbRaidAdd width=100% height=0% class=xtab><TR align="center">';
  286.  
  287. var rowcounter = 0;
  288. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  289. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  290. rowcounter++;
  291. if (rowcounter > 4) {
  292. m += '</tr><tr align="center">';
  293. rowcounter = 1;
  294. }
  295. m += '<td><table class=xtab><tr><td rowspan=2><img src="'+IMGURL+'units/unit_'+i+'_50.jpg?6545"></td><td>'+ addCommas(Seed.units['city'+cityId]['unt'+i]) +'</td></tr><tr><td><INPUT id=Unit'+i+' type=text size=6 maxlength=6 value="'+t.rslt['queue'][y]['botMarches']['unit'+i+'Count']+'"></td></tr></table></td>';
  296. }
  297. m += '</tr></table>';
  298. m += '<BR><CENTER><SELECT id=AddKnights type=list></select></center>';
  299. m+= '<BR><CENTER>'+ strButton20('Save', 'id=pbRaidSave') +'</center>';
  300. pop.getMainDiv().innerHTML = m;
  301. t.getKnights(cityId);
  302. document.getElementById ('AddKnights').value = t.rslt['queue'][y]['botMarches']['knightId'];
  303. document.getElementById ('pbRaidSave').addEventListener ('click', function(){
  304. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  305. params.pf = 0;
  306. params.ctrl = 'BotManager';
  307. params.action = 'editMarch';
  308. params.settings = {};
  309. params.settings.cityId = t.rslt['queue'][y]['botMarches']['fromCityId'];
  310. params.queue = {0:{botMarches:{botMarchStatus:1,botState:1},cityMarches:{}}};
  311. params.queue[0].cityMarches.knightId = parseInt(document.getElementById ('AddKnights').value);
  312. params.queue[0].cityMarches.toXCoord = parseInt(document.getElementById ('toXCoord').value);
  313. params.queue[0].cityMarches.toYCoord = parseInt(document.getElementById ('toYCoord').value);
  314. params.queue[0].cityMarches.unit0Count = 0; //document.getElementById ('Unit0').value;
  315. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  316. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  317. params.queue[0]['cityMarches']['unit'+i+'Count'] = parseIntNan(document.getElementById ('Unit'+i).value);
  318. }
  319. params.queue[0].cityMarches.marchId = t.rslt['queue'][y]['botMarches']['marchId'];
  320. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  321. method: "post",
  322. parameters: params,
  323. loading: true,
  324. onSuccess: function(rslt){
  325. if (rslt.ok) {
  326. pop.show (false);
  327. unsafeWindow.cityinfo_army();
  328. setTimeout(unsafeWindow.update_seed_ajax, 250);
  329. setTimeout(t.GetRaids, (750),Seed.cities[i][0]);
  330. }
  331. },
  332. },true);
  333. }, false);
  334. pop.show (true);
  335. },
  336. DeleteRaid : function (Id){
  337. var t = Tabs.Raid;
  338. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  339. for (y in t.rslt['queue']) {
  340. if (t.rslt['queue'][y]['botMarches'] != undefined) {
  341. if (t.rslt['queue'][y]['botMarches']['marchId'] == Id) {
  342. marchId = t.rslt['queue'][y]['botMarches']['marchId'];
  343. cityId = t.rslt['queue'][y]['botMarches']['cityId'];
  344. knightId = t.rslt['queue'][y]['botMarches']['knightId'];
  345. toTileLevel = t.rslt['queue'][y]['botMarches']['toTileLevel'];
  346. returnUnixTime = t.rslt['queue'][y]['botMarches']['returnUnixTime'];
  347. destinationUnixTime = t.rslt['queue'][y]['botMarches']['destinationUnixTime'];
  348. toXCoord = t.rslt['queue'][y]['botMarches']['toXCoord'];
  349. toYCoord = t.rslt['queue'][y]['botMarches']['toYCoord'];
  350. var units = {};
  351. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  352. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  353. units[i] = t.rslt['queue'][y]['botMarches']['unit'+i+'Count'];
  354. }
  355. }
  356. }
  357. }
  358. params.pf = 0;
  359. params.ctrl = 'BotManager';
  360. params.action = 'deleteMarch';
  361. params.marchId = marchId;
  362. params.settings = {};
  363. params.settings.cityId = cityId;
  364. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  365. method: "post",
  366. parameters: params,
  367. loading: true,
  368. onSuccess: function(rslt){
  369. if (rslt.ok) {
  370. var serverID = getServerId();
  371. t.save = GM_getValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID);
  372. if (t.save == null) t.save = GM_getValue ('SavedRaids_'+serverID);
  373. if (t.save == undefined) t.save =new Array();
  374. else t.save = JSON2.parse (t.save);
  375. var RaidObj = {};
  376. RaidObj.marchId = marchId;
  377. RaidObj.cityId = cityId;
  378. RaidObj.knightId = knightId;
  379. RaidObj.toTileLevel = toTileLevel;
  380. RaidObj.returnUnixTime = destinationUnixTime;
  381. RaidObj.returnUnixTime = returnUnixTime;
  382. RaidObj.toXCoord = toXCoord;
  383. RaidObj.toYCoord = toYCoord;
  384. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  385. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  386. RaidObj['unit'+i+'Count'] = units[i];
  387. }
  388. t.save.push (RaidObj);
  389. for (u in Seed.queue_atkp['city' + cityId]){
  390. if (Seed.queue_atkp['city' + cityId][u]['marchId'] == marchId){
  391. delete Seed.queue_atkp['city' + cityId][u];
  392. if (Object.keys(Seed.queue_atkp['city' + cityId]).length == 0) {
  393. Seed.queue_atkp['city' + cityId] = uWCloneInto([]);
  394. }
  395. break;
  396. }
  397. }
  398. for (u in Seed.knights['city' + cityId]){
  399. if (Seed.knights['city' + cityId][u]['knightId'] == knightId){
  400. Seed.knights['city' + cityId][u]["knightStatus"] = 1;
  401. break;
  402. }
  403. }
  404. GM_setValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, JSON2.stringify(t.save));
  405. unsafeWindow.cityinfo_army();
  406. setTimeout(unsafeWindow.update_seed_ajax, 250);
  407. t.GetRaids(cityId);
  408. }
  409. },
  410. },true);
  411. },
  412. StopCityRaids : function (cityId){
  413. var t = Tabs.Raid;
  414. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  415. params.pf = 0;
  416. params.ctrl = 'BotManager';
  417. params.action = 'stopAll';
  418. params.settings = {};
  419.  
  420. params.settings.cityId = cityId;
  421. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  422. method: "post",
  423. parameters: params,
  424. loading: true,
  425. onSuccess: function(rslt){
  426. if (rslt.ok) {
  427. }
  428. },
  429. },true);
  430. setTimeout(t.GetRaids, (750), cityId);
  431. },
  432. StopAllRaids : function (){
  433. var t = Tabs.Raid;
  434. if (t.stopping == true || t.resuming == true || t.deleting == true) return;
  435. if (t.activecount == 0) return;
  436. t.stopping = true;
  437. for (i=0;i<Seed.cities.length;i++){
  438. setTimeout(t.DoAllStop, (i*1500),i);
  439. }
  440. },
  441. ResumeAllRaids : function (){
  442. var t = Tabs.Raid;
  443. if (t.stopping == true || t.resuming == true || t.deleting == true) return;
  444. if (t.stopcount == 0) return;
  445. t.resuming = true;
  446. for (i=0;i<Seed.cities.length;i++){
  447. setTimeout(t.DoAllResume, (i*1500),i);
  448. }
  449. },
  450. DeleteAllRaids : function (){
  451. var t = Tabs.Raid;
  452. if (t.stopping == true || t.resuming == true || t.deleting == true) return;
  453. if (t.stopcount == 0) return;
  454. t.deleting = true;
  455. count=0;
  456. t.count = t.stopcount;
  457. for (d=0; d< Seed.cities.length;d++) {
  458. var cityId = Seed.cities[d][0];
  459. var city_atkp = Seed.queue_atkp['city'+cityId];
  460. for (var e in city_atkp){
  461. destinationUnixTime = city_atkp[e]['destinationUnixTime'];
  462. MarchId = city_atkp[e]['marchId'];
  463. MarchStatus = city_atkp[e]['marchStatus'];
  464. MarchType = city_atkp[e]['marchType'];
  465. botMarchStatus = city_atkp[e]['botMarchStatus'];
  466. if (MarchType == 9 && botMarchStatus == 3 && MarchStatus == 10) {
  467. count++;
  468. setTimeout(t.DoAllDelete, (count*1250), MarchId,d,count);
  469. }
  470. }
  471. }
  472. },
  473. DoAllStop: function(i) {
  474. var t = Tabs.Raid;
  475. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  476. params.pf = 0;
  477. params.ctrl = 'BotManager';
  478. params.action = 'stopAll';
  479. params.settings = {};
  480. params.settings.cityId = Seed.cities[i][0];
  481. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  482. method: "post",
  483. parameters: params,
  484. loading: true,
  485. onSuccess: function(rslt){
  486. if (rslt.ok) {
  487. t.stopprogress = t.stopprogress + (100/Seed.cities.length);
  488. actionLog('Stopping: '+ Seed.cities[i][1],'RAIDS');
  489. t.updatebotbutton('Stopping: '+ t.stopprogress.toFixed(0) + '%', 'pboldraidtab');
  490. if (t.stopprogress.toFixed(0) == 100) {
  491. t.stopprogress = 0;
  492. setTimeout(function(){t.updatebotbutton('Raids: S ('+ t.activecount + ')', 'pboldraidtab');t.stopping = false;}, (5000));
  493. }
  494. }
  495. else {
  496. if (rslt.msg == "The system is busy, please try again later") setTimeout (t.DoAllStop, (2000),i);
  497. else {
  498. t.stopprogress = t.stopprogress + (100/Seed.cities.length);
  499. actionLog('Stopping: '+ Seed.cities[i][1] + ' - ' + rslt.msg,'RAIDS');
  500. t.updatebotbutton('Stopping: '+ t.stopprogress.toFixed(0) + '%', 'pboldraidtab')
  501. if (t.stopprogress.toFixed(0) == 100) {
  502. t.stopprogress = 0;
  503. setTimeout(function(){t.updatebotbutton('Raids: S ('+ t.activecount + ')', 'pboldraidtab');t.stopping = false;}, (5000));
  504. }
  505. }
  506. }
  507. },
  508. },true);
  509. },
  510.  
  511. DoAllResume: function(i) {
  512. var t = Tabs.Raid;
  513. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  514. params.pf = 0;
  515. params.ctrl = 'BotManager';
  516. params.action = 'resumeAll';
  517. params.settings = {};
  518. params.settings.cityId = Seed.cities[i][0];
  519. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  520. method: "post",
  521. parameters: params,
  522. loading: true,
  523. onSuccess: function(rslt){
  524. if (rslt.ok) {
  525. t.stopprogress = t.stopprogress + (100/Seed.cities.length);
  526. actionLog('Resuming: '+ Seed.cities[i][1],'RAIDS');
  527. t.updatebotbutton('Resuming: '+ t.stopprogress.toFixed(0) + '%', 'pboldraidtab');
  528. if (t.stopprogress.toFixed(0) == 100) {
  529. t.stopprogress = 0;
  530. setTimeout(function(){t.updatebotbutton('Raids: S ('+ t.activecount + ')', 'pboldraidtab');t.resuming = false;}, (5000));
  531. }
  532. }
  533. else {
  534. if (rslt.msg == "The system is busy, please try again later") setTimeout (t.DoAllResume, (2000),i);
  535. else {
  536. t.stopprogress = t.stopprogress + (100/Seed.cities.length);
  537. actionLog('Resuming: '+ Seed.cities[i][1] + ' - ' + rslt.msg,'RAIDS');
  538. t.updatebotbutton('Resuming: '+ t.stopprogress.toFixed(0) + '%', 'pboldraidtab')
  539. if (t.stopprogress.toFixed(0) == 100) {
  540. t.stopprogress = 0;
  541. setTimeout(function(){t.updatebotbutton('Raids: S ('+ t.activecount + ')', 'pboldraidtab');t.resuming = false;}, (5000));
  542. }
  543. }
  544. }
  545. },
  546. },true);
  547. },
  548. DoAllDelete : function (Id,city,count){
  549. var t = Tabs.Raid;
  550. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  551. cityID = 'city'+ Seed.cities[city][0];
  552. for (f in Seed.queue_atkp[cityID]){
  553. if (Seed.queue_atkp[cityID][f]['marchId'] == Id) {
  554. marchId = Seed.queue_atkp[cityID][f]['marchId'];
  555. cityId = Seed.queue_atkp[cityID][f]['cityId'];
  556. knightId = Seed.queue_atkp[cityID][f]['knightId'];
  557. toTileLevel = Seed.queue_atkp[cityID][f]['toTileLevel'];
  558. returnUnixTime = Seed.queue_atkp[cityID][f]['returnUnixTime'];
  559. destinationUnixTime = Seed.queue_atkp[cityID][f]['destinationUnixTime'];
  560. toXCoord = Seed.queue_atkp[cityID][f]['toXCoord'];
  561. toYCoord = Seed.queue_atkp[cityID][f]['toYCoord'];
  562. var units = {};
  563. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  564. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  565. units[i] = Seed.queue_atkp[cityID][f]['unit'+i+'Count'];
  566. }
  567. }
  568. }
  569. params.pf = 0;
  570. params.ctrl = 'BotManager';
  571. params.action = 'deleteMarch';
  572. params.marchId = marchId;
  573. params.settings = {};
  574. params.settings.cityId = cityId;
  575. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  576. method: "post",
  577. parameters: params,
  578. loading: true,
  579. onSuccess: function(rslt){
  580. if (rslt != "") {
  581. var serverID = getServerId();
  582. t.save = GM_getValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, "[]");
  583. if (t.save == undefined) t.save = GM_getValue ('SavedRaids_'+serverID, "[]");
  584. if (t.save != undefined) t.save = JSON2.parse (t.save);
  585. if (t.save == undefined) t.save =new Array();
  586. var RaidObj = {};
  587. RaidObj.marchId = marchId;
  588. RaidObj.cityId = cityId;
  589. RaidObj.knightId = knightId;
  590. RaidObj.toTileLevel = toTileLevel;
  591. RaidObj.returnUnixTime = destinationUnixTime;
  592. RaidObj.returnUnixTime = returnUnixTime;
  593. RaidObj.toXCoord = toXCoord;
  594. RaidObj.toYCoord = toYCoord;
  595. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  596. var u = unsafeWindow.cm.UNIT_TYPES[ui];
  597. RaidObj['unit'+u+'Count'] = units[u];
  598. }
  599. t.save.push (RaidObj);
  600.  
  601. for (u in Seed.queue_atkp['city' + cityId]){
  602. if (Seed.queue_atkp['city' + cityId][u]['marchId'] == marchId){
  603. delete Seed.queue_atkp['city' + cityId][u];
  604. if (Object.keys(Seed.queue_atkp['city' + cityId]).length == 0) {
  605. Seed.queue_atkp['city' + cityId] = uWCloneInto([]);
  606. }
  607. break;
  608. }
  609. }
  610. for (u in Seed.knights['city' + cityId]){
  611. if (Seed.knights['city' + cityId][u]['knightId'] == knightId){
  612. Seed.knights['city' + cityId][u]["knightStatus"] = 1;
  613. break;
  614. }
  615. }
  616. setTimeout (function (){GM_setValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, JSON2.stringify(t.save));}, 0);
  617. unsafeWindow.cityinfo_army();
  618. setTimeout(unsafeWindow.update_seed_ajax, 250);
  619. }
  620. },
  621. },true);
  622. t.stopprogress = count * (100/t.count);
  623. actionLog('Deleting: '+ Seed.cities[city][1],'RAIDS');
  624. t.updatebotbutton('Deleting: '+ t.stopprogress.toFixed(0) + '%', 'pboldraidtab');
  625. if (t.stopprogress.toFixed(0) == 100) {
  626. t.stopprogress = 0;
  627. setTimeout(function(cid){t.GetRaids(cid); t.updatebotbutton('Raids: S ('+ t.activecount + ')', 'pboldraidtab');t.deleting = false; }, 5000, cityId);
  628. }
  629. },
  630. DeleteCityRaids : function (cityId){
  631. var t = Tabs.Raid;
  632. if (t.stopping == true || t.resuming == true || t.deleting == true) return;
  633. count=0;
  634. for (d=0; d< Seed.cities.length;d++) {
  635. if (Seed.cities[d][0]==cityId) {
  636. var cityId = Seed.cities[d][0];
  637. var city_atkp = Seed.queue_atkp['city'+cityId];
  638. for (var e in city_atkp){
  639. destinationUnixTime = city_atkp[e]['destinationUnixTime'];
  640. MarchStatus = city_atkp[e]['marchStatus'];
  641. MarchType = city_atkp[e]['marchType'];
  642. botMarchStatus = city_atkp[e]['botMarchStatus'];
  643. if (MarchType == 9 && botMarchStatus == 3 && MarchStatus == 10) {
  644. count++;
  645. }
  646. }
  647. }
  648. }
  649. t.count = count;
  650. if (t.count == 0) return;
  651. t.deleting = true;
  652. count=0;
  653. for (d=0; d< Seed.cities.length;d++) {
  654. if (Seed.cities[d][0]==cityId) {
  655. var cityId = Seed.cities[d][0];
  656. var city_atkp = Seed.queue_atkp['city'+cityId];
  657. for (var e in city_atkp){
  658. destinationUnixTime = city_atkp[e]['destinationUnixTime'];
  659. MarchId = city_atkp[e]['marchId'];
  660. MarchStatus = city_atkp[e]['marchStatus'];
  661. MarchType = city_atkp[e]['marchType'];
  662. botMarchStatus = city_atkp[e]['botMarchStatus'];
  663. if (MarchType == 9 && botMarchStatus == 3 && MarchStatus == 10) {
  664. count++;
  665. setTimeout(t.DoAllDelete, (count*1250), MarchId,d,count);
  666. }
  667. }
  668. }
  669. }
  670. },
  671. AddRaid : function (Id){
  672. var t = Tabs.Raid;
  673. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  674. update = {};
  675. params.pf = 0;
  676. params.ctrl = 'BotManager';
  677. params.action = 'saveMarch';
  678. params.settings = {};
  679. params.queue = {0:{botMarches:{botMarchStatus:1,botState:1},cityMarches:{}}};
  680. for (y in t.save){
  681. if (t.save[y]['marchId'] == Id){
  682. params.settings.cityId = t.save[y]['cityId'];
  683. params.queue[0].cityMarches.knightId = t.save[y]['knightId']; //parseInt(document.getElementById('AddKnights').value);
  684. params.queue[0].cityMarches.toXCoord = t.save[y]['toXCoord'];
  685. params.queue[0].cityMarches.toYCoord = t.save[y]['toYCoord'];
  686. params.queue[0].cityMarches.unit0Count = 0;
  687. for (var ui in unsafeWindow.cm.UNIT_TYPES){
  688. var i = unsafeWindow.cm.UNIT_TYPES[ui];
  689. params.queue[0]['cityMarches']['unit'+i+'Count'] = t.save[y]['unit'+i+'Count'];
  690. }
  691. }
  692. }
  693. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  694. method: "post",
  695. parameters: params,
  696. loading: true,
  697. onSuccess: function(rslt){
  698. if (rslt.ok) {
  699. t.GetRaids(params.settings.cityId);
  700. unsafeWindow.cityinfo_army();
  701. setTimeout(unsafeWindow.update_seed_ajax, 250);
  702. for (yy=0;yy<t.save.length;yy++){
  703. if (t.save[yy]['marchId'] == Id){
  704. t.save.splice (yy,1);
  705. }
  706. }
  707. var serverID = getServerId();
  708. setTimeout (function (){GM_setValue ('SavedRaids_'+unsafeWindow.tvuid+'_'+serverID, JSON2.stringify(t.save));}, 0);
  709. t.paint();
  710. } else {
  711. alert('Error: '+ rslt.msg);
  712. }
  713. },
  714. },true);
  715. },
  716. getKnights : function(cityId){
  717. var t = Tabs.Raid;
  718. var knt = new Array();
  719. var status ="";
  720. for (k in Seed.knights['city' + cityId]){
  721. if ( Seed.leaders['city' + cityId]["resourcefulnessKnightId"] != Seed.knights['city' + cityId][k]["knightId"] && Seed.leaders['city' + cityId]["politicsKnightId"] != Seed.knights['city' + cityId][k]["knightId"] && Seed.leaders['city' + cityId]["combatKnightId"] != Seed.knights['city' + cityId][k]["knightId"] && Seed.leaders['city' + cityId]["intelligenceKnightId"] != Seed.knights['city' + cityId][k]["knightId"]){
  722. if (Seed.knights['city' + cityId][k]["knightStatus"] == 1 ) status = "Free";
  723. else status = "Marching";
  724. knt.push ({
  725. Name: Seed.knights['city' + cityId][k]["knightName"],
  726. Combat: parseInt(Seed.knights['city' + cityId][k]["combat"]),
  727. ID: Seed.knights['city' + cityId][k]["knightId"],
  728. Status: status,
  729. });
  730. }
  731. }
  732. knt = knt.sort(function sort(a,b) {a = a['Combat'];b = b['Combat'];return a == b ? 0 : (a > b ? -1 : 1);});
  733. document.getElementById('AddKnights').options.length=0;
  734. var o = document.createElement("option");
  735. o.text = '--Choose a Knight--';
  736. o.value = 0;
  737. document.getElementById("AddKnights").options.add(o);
  738. for (k in knt){
  739. if (knt[k]["Name"] !=undefined){
  740. var o = document.createElement("option");
  741. o.text = (knt[k]["Name"] + ' (' + knt[k]["Combat"] +') (' + knt[k]["Status"] +')');
  742. o.value = knt[k]["ID"];
  743. document.getElementById("AddKnights").options.add(o);
  744. }
  745. }
  746. },
  747. clickCitySelect : function (city){
  748. var t = Tabs.Raid;
  749. t.cityId = city['id'];
  750. t.GetRaids(t.cityId);
  751. },
  752. GetRaids : function(cityId){
  753. var t = Tabs.Raid;
  754. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  755. params.pf = 0;
  756. params.ctrl = 'BotManager';
  757. params.action = 'getMarches';
  758. params.settings = {};
  759. params.settings.cityId = cityId;
  760. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  761. method: "post",
  762. parameters: params,
  763. loading: true,
  764. onSuccess: function(rslt){
  765. if (rslt.ok) {
  766. t.rslt = rslt;
  767. t.paint();
  768. unsafeWindow.cityinfo_army();
  769. setTimeout(unsafeWindow.update_seed_ajax, 250);
  770. }
  771. },
  772. },true);
  773. },
  774. resetRaids : function(cityId,cityName){
  775. var t = Tabs.Raid;
  776. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  777. params.pf = 0;
  778. params.ctrl = 'BotManager';
  779. params.action = 'resetRaidTimer';
  780. params.settings = {};
  781. params.settings.cityId = cityId;
  782. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/_dispatch.php" + unsafeWindow.g_ajaxsuffix, {
  783. method: "post",
  784. parameters: params,
  785. loading: true,
  786. onSuccess: function(rslt){
  787. if (rslt.ok) {
  788. unsafeWindow.cityinfo_army();
  789. setTimeout(unsafeWindow.update_seed_ajax, 250);
  790. t.citiesdone += cityName + ' ';
  791. }
  792. },
  793. },true);
  794. },
  795. sendreport: function(){
  796. var t = Tabs.Raid;
  797. if(!Options.RaidOptions.foodreport) return;
  798. var now = new Date().getTime()/1000.0;
  799. now = now.toFixed(0);
  800. if (now < (parseInt(Options.RaidOptions.LastReport)+(Options.RaidOptions.MsgInterval*60*60))) return;
  801. var total = 0;
  802. var message = 'Raid Stats: %0A';
  803. message += '%0A Food Gain (for '+ Options.RaidOptions.MsgInterval +' hour of raiding) %0A';
  804. for (q=1;q<=Seed.cities.length;q++){
  805. var cityID = 'city' + Seed.cities[q-1][0];
  806. var gain = parseInt(Seed.resources[cityID]['rec1'][0] / 3600) - parseIntNan(Options.RaidOptions.Foodstatus[q]);
  807. message+= Seed.cities[q-1][1] + ': Start: ' + addCommas(parseIntNan(Options.RaidOptions.Foodstatus[q])) + ' End :' + addCommas(parseInt(Seed.resources[cityID]['rec1'][0] / 3600)) + ' Gain: ';
  808. message += addCommas(gain) + '%0A';
  809. total += gain;
  810. Options.RaidOptions.Foodstatus[q] = parseIntNan(Seed.resources[cityID]['rec1'][0] / 3600);
  811. }
  812. message += '%0A Total food gain : '+addCommas(total)+'%0A';
  813. var params = unsafeWindow.Object.clone(unsafeWindow.g_ajaxparams);
  814. params.emailTo = Seed.player['name'];
  815. params.subject = "Raid Overview";
  816. params.message = message;
  817. params.requestType = "COMPOSED_MAIL";
  818. new MyAjaxRequest(unsafeWindow.g_ajaxpath + "ajax/getEmail.php" + unsafeWindow.g_ajaxsuffix, {
  819. method: "post",
  820. parameters: params,
  821. onSuccess: function (rslt) {
  822. if (rslt.ok) {
  823. DeleteLastMessage();
  824. } else {
  825. }
  826. },
  827. onFailure: function () {
  828. },
  829. },true);
  830. Options.RaidOptions.LastReport = now;
  831. saveOptions();
  832. },
  833. hide : function (){
  834. },
  835.  
  836. show : function (){
  837. },
  838.  
  839. updatebotbutton : function (text, id) {
  840. var but=document.getElementById(id);
  841. but.innerHTML = '<span style="color: #ff6">'+text+'</span>';
  842. },
  843.  
  844. };