· 4 years ago · Aug 09, 2021, 06:52 PM
1var dropboxToken='voeQxDKEfdAAAAAAAAAAAWmeVbsqR6fFyKdfA2gXF05UhEt-ztkJqkFZY6PkMTzk';
2
3var backgroundColor = "#32313f";
4var borderColor = "#3e6147";
5var headerColor = "#202825";
6var titleColor = "#ffffdf";
7var headerColorPlayers="#323232"
8var headerColorCoords="#4d4d4d"
9var headerColorFirstRow="#666600"
10
11var databaseName="test/"
12
13
14var filename_reports=`${databaseName}Reports.txt`;
15var filename_incomings=`${databaseName}Incomings.txt`;
16var filename_users=`${databaseName}Users.txt`;
17var filename_support=`${databaseName}Support.txt`;
18var filename_commands_attack=`${databaseName}Commands_attack.txt`;
19
20var filename_status_upload=`${databaseName}status.txt`;
21var filename_history_upload=`${databaseName}history_upload.txt`;
22
23var speedWorld=getSpeedConstant().worldSpeed;
24var speedTroupes=getSpeedConstant().unitSpeed;
25
26
27
28
29
30
31var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
32var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
33var swordSpeed=1320*1000/(speedWorld*speedTroupes)//ms
34var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
35
36//formula ((base time/100)/speedWorld) * stable time factor //https://forum.tribalwars.net/index.php?threads/next-lvl-of-barracks-unit-production-speed.54638/
37var axeTime=Math.round( ((1320/100.0)/speedWorld) * 15.58823529 ) *1000//milisec
38var lhTime=Math.round( ((1800/100.0)/speedWorld) * 20.88235294 ) *1000//milisec
39var ramTime=Math.round( ((4800/100.0)/speedWorld) * 27.84313725 ) *1000//milisec
40
41var countApiKey = "taggingScriptTest";
42var countNameSpace="madalinoTribalWarsScripts"
43
44
45//verify acces users
46var response_users= getUsers()
47var tribemates=response_users.split("\n").map(e=>{return e.trim().toLowerCase()})
48console.log(tribemates)
49// if(!tribemates.includes(game_data.player.name.toLowerCase())){
50// UI.ErrorMessage("try later","slow")
51// throw new Error("you do not have acces");
52// // console.log("you do not have acces" )
53// }
54
55
56
57
58var troopsPop = {
59 spear : 1,
60 sword : 1,
61 axe : 1,
62 archer : 1,
63 spy : 2,
64 light : 4,
65 marcher : 5,
66 heavy : 4,
67 ram : 5,
68 catapult : 8,
69 knight : 10,
70 snob : 100
71};
72{/* <img src="https://img.icons8.com/officel/16/000000/long-arrow-right.png"/> */}
73{/* <img src="https://img.icons8.com/officel/16/000000/long-arrow-left.png"/> */}
74
75function hitCountApi(){
76 $.getJSON(`https://api.countapi.xyz/hit/${countNameSpace}/${countApiKey}`, response=>{
77 console.log(`This script has been run ${response.value} times`);
78 });
79}
80hitCountApi()
81
82
83
84html = `
85<div id="div_container" class="ui-widget-content div_remove" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
86 <div style="position:relative;top:10px;left: 560px;display:flex">
87 <div id="minimize_page" style="background-color:white;margin-right:10px"><a href="#"><img src="https://img.icons8.com/material-outlined/16/000000/collapse.png"/></a></div>
88 <div class="close-btn" ><a href="#" onclick="closeWindow()"><b><font color="${titleColor}">X</font></b></a></div>
89 </div>
90
91 <h2><center style="margin:10px;"><u><font color="${titleColor}">Upload data</font></u></center></h2>
92
93 <div id="page_support" style="position:relative;top:-35px;left: 20px" ><a href="#" onclick="viewSupport()"><img src="https://img.icons8.com/officel/30/000000/long-arrow-right.png"/></a></div>
94
95 <div id="div_minimize">
96 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
97 <tr>
98 <td style="text-align:center; width:auto; background-color:${headerColor}">
99 <h2><center style="margin:10px"><u><font color="${titleColor}">reports</font></u></center></h2>
100 </td>
101 <td style="text-align:center; width:auto; background-color:${headerColor}">
102 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReportsManual()" value="Upload manual"></center>
103 <center style="margin:10px"><u><input class="btn" type="button" id="upload_reports" onclick="uploadReports()" value="Upload auto"></center>
104
105 </td>
106 <td style="text-align:center; width:auto; background-color:${headerColor}">
107 <p><center style="margin:10px"><font color="${titleColor}" id="progress_reports">progress</font></center></p>
108 </td>
109 </tr>
110 <tr>
111 <td style="text-align:center; width:auto; background-color:${headerColor}">
112 <h2><center style="margin:10px"><u><font color="${titleColor}">incomings</font></u></center></h2>
113 </td>
114 <td style="text-align:center; width:auto; background-color:${headerColor}">
115 <center style="margin:10px"><u><input class="btn" type="button" id="upload_incomings" onclick="uploadIncomings()" value="Upload"></center>
116 </td>
117 <td style="text-align:center; width:auto; background-color:${headerColor}">
118 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_incomings">progress</font></center></p>
119 </td>
120 </tr>
121 <tr>
122 <td style="text-align:center; width:auto; background-color:${headerColor}">
123 <h2><center style="margin:10px"><u><font color="${titleColor}">Commands</font></u></center></h2>
124 </td>
125 <td style="text-align:center; width:auto; background-color:${headerColor}">
126 <center style="margin:10px"><u><input class="btn" type="button" onclick="uploadSupports()" value="Upload"></center>
127 </td>
128 <td style="text-align:center; width:auto; background-color:${headerColor}">
129 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_support">progress</font></center></p>
130 </td>
131 </tr>
132 <tr>
133 <td style="text-align:center; width:auto; background-color:${headerColor}">
134 <h2><center style="margin:10px"><u><font color="${titleColor}">All info</font></u></center></h2>
135 </td>
136 <td style="text-align:center; width:auto; background-color:${headerColor}">
137 <center style="margin:10px"><u><input class="btn" type="button" onclick="uploadAll()" value="Upload all"></center>
138 </td>
139 <td style="text-align:center; width:auto; background-color:${headerColor}">
140 <p><center style="margin:10px" ><font color="${titleColor}" id="progress_all">progress</font></center></p>
141 </td>
142 </tr>
143 </table>
144 <h2><center style="margin:10px"><u><font color="${titleColor}">Search reports</font></u></center></h2>
145 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
146 <tr>
147 <td style="text-align:center; width:auto; background-color:${headerColor}">
148 <center style="margin:10px"><u><input class="btn" type="button" onclick="loadReports()" value="Load reports"></center>
149 </td>
150 <td style="text-align:center; width:auto; background-color:${headerColor}">
151 <center style="margin:10px"><u><input style="text-align: center;" type="text" id="input_search" onclick="" placeholder="coord" ></center>
152 </td>
153 <td style="text-align:center; width:auto; background-color:${headerColor}">
154 <p><center style="margin:10px"><font color="${titleColor}" id="progress_search">status</font></center></p>
155 </td>
156 </tr>
157 <tr>
158 <td style="text-align:center; width:auto; background-color:${headerColor}">
159 <center style="margin:10px"><u><input class="btn" id="btn_off_coord" type="button" value="off coords"></center>
160 </td>
161 <td style="text-align:center; width:auto; background-color:${headerColor}">
162 <center style="margin:10px"><u><input class="btn" id="btn_def_coord" type="button" value="def coords"></center>
163 </td>
164 <td style="text-align:center; width:auto; background-color:${headerColor}">
165 <center style="margin:10px"><u><input class="btn" id="btn_stack_coord" type="button" value="stacked coords"></center>
166 <center style="margin:10px"><u><input style="text-align: center;" type="text" id="input_stacked" onclick="" placeholder="nr stack" ></center>
167 </td>
168 </tr>
169 </table>
170 <center style="margin:10px"><div id="report_view" style="background-color:#d2c09e"> report view <div><center>
171 </div>
172</div>
173`;
174////////////////////////////////////////add and remove window from page///////////////////////////////////////////
175if(document.getElementById("incomings_table")==null){
176 $("#div_container").remove()
177 $("#contentContainer").eq(0).prepend(html);
178 $("#mobileContent").eq(0).prepend(html);
179
180 if(game_data.device=="desktop"){
181 $("#div_container").css("position","fixed");
182 $("#div_container").draggable();
183 }
184}
185function closeWindow(){
186 $(".div_remove").remove()
187 list_href=[]
188 // window.location.reload();
189}
190
191function getUsers(){
192 var result
193 $.ajax({
194 url: "https://content.dropboxapi.com/2/files/download",
195 method: 'POST',
196 dataType: "text",
197 async: false,
198 headers: { 'Authorization': 'Bearer ' + dropboxToken,
199 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename_users})},
200
201 success: (data) => {
202 result=data
203
204 },error:(err)=>{
205 alert(err)
206 reject(err)
207 }
208 })
209 return result
210}
211
212function addWindow(){
213 $("#contentContainer").eq(0).prepend(html);
214 $("#mobileContent").eq(0).prepend(html);
215
216 if(game_data.device=="desktop"){
217 $("#div_container").css("position","fixed");
218 $("#div_container").draggable();
219 }
220}
221
222var loadReportsOk=false;
223function testLoadReports(){
224 $("#input_search").on("input",function(){
225 if(loadReportsOk==false)
226 UI.ErrorMessage("upload reports first","fast")
227 })
228 $("#btn_off_coord, #btn_def_coord, #btn_stack_coord").on("click",function(){
229 if(loadReportsOk==false)
230 UI.ErrorMessage("upload reports first","fast")
231 })
232
233 $("#input_search").mouseout(function(){
234 if(loadReportsOk==false)
235 $("#input_search").val("");
236 })
237 $("#minimize_page").on("click",()=>{
238 $("#div_minimize").toggle(500)
239 })
240}
241testLoadReports()
242
243
244
245function addCssStyle(){
246 var css =`
247 .shadow20 {
248 text-shadow: 0 0 4px black, 0 0 4px black, 0 0 4px black, 0 0 4px black, 0 0 4px black;
249 }
250
251 `,
252 head = document.head || document.getElementsByTagName('head')[0],
253 style = document.createElement('style');
254
255 head.appendChild(style);
256 style.type = 'text/css';
257 if (style.styleSheet){
258 // This is required for IE8 and below.
259 style.styleSheet.cssText = css;
260 } else {
261 style.appendChild(document.createTextNode(css));
262 }
263}
264addCssStyle()
265
266
267if(document.getElementById("incomings_table")!=null){
268 window.setInterval(function(){
269
270 var rows= $(".row_a,.row_b")
271 console.log("check incomings")
272 for(let i=0;i<rows.length;i++)
273 {
274 let currentHour=rows[i].children[rows[i].children.length-1].innerText.split(":")
275 if(parseInt(currentHour[0])==0 && parseInt(currentHour[1])==0 && parseInt(currentHour[2])<20){
276 rows[i].remove();
277 }
278 // else{
279 // break;
280 // }
281 }
282 },10000)
283}
284
285
286async function uploadAll(){
287 let resultReports= await uploadReports().catch(err=>alert(err))
288 console.log("status uploads",resultReports)
289 let resultIncomings= await uploadIncomings().catch(err=>alert(err))
290 console.log("status incomings",resultIncomings)
291 let resultSupports= await uploadSupports().catch(err=>alert(err))
292 console.log("status commands",resultSupports)
293
294
295}
296
297
298/////////////////////////////////////////////////get all reports info//////////////////////////////////////////////////////////////////
299async function uploadReports(){
300
301
302 document.getElementById("progress_reports").innerText="get links..";
303
304 let [map_history_upload,status]=await Promise.all([readFileDropbox(filename_history_upload),insertlibraryLocalBase() ]).catch(err=>{alert(err)})
305 console.log(status)
306 let current_page=window.location.href;
307
308 try {
309 map_history_upload=new Map( JSON.parse(lzw_decode(map_history_upload)));
310 } catch (error) {
311 console.log("erorr map history upload from dropbox")
312 map_history_upload=new Map()
313 }
314
315 //if database is stored locally
316 if(await localBase.getItem(game_data.world+"history_upload")!=undefined){
317 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"history_upload"))));
318 console.log("map_localBase history upload",map_localBase)
319 map_history_upload=new Map([...map_localBase, ...map_history_upload])
320 }
321
322 console.log("map_history_upload",map_history_upload)
323 //delete if it's too old
324 Array.from(map_history_upload.keys()).forEach(key=>{
325 let currentDate=new Date();
326 let reportDate=new Date(map_history_upload.get(key).date)
327 if(currentDate.getTime()- reportDate.getTime() > 100*24*3600*1000){
328 console.log("remove id: "+map_history_upload.get(key).date)
329 map_history_upload.delete(key)
330 }
331
332 })
333
334
335
336
337
338
339
340
341 var [list_href, mapVillage]=await Promise.all([getLinks(true,map_history_upload),getInfoVIllages() ]).catch(err=>{alert(err)})
342
343
344 console.log("aici baaa")
345 console.log("map_history_upload",map_history_upload)
346
347 $(document).on('click','.autoHideBox',function(){
348 UI.SuccessMessage("stop",2000)
349 list_href=[]
350 })
351
352
353 list_href=list_href.reverse();
354 console.log(list_href)
355 var list_data_reports=[]
356 var nr_reports=0;
357 var nr_reports_total=list_href.length
358 addWindow();
359 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
360 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
361 var current_url
362
363 return new Promise(async(resolve,reject)=>{
364 async function ajaxRequest (urls) {
365 var time= 0
366 if(urls.length>0)
367 current_url=urls.pop().href;
368 else
369 current_url="stop"
370 console.log("inside function "+urls.length)
371 if (urls.length >= 0 && current_url!= "stop") {
372 var start_ajax=new Date()
373 $.ajax({
374 method: 'GET',
375 url: current_url,
376 })
377 .done(function (result) {
378 document.body.innerHTML= result;
379 result=null
380 // addWindow();
381 var startReport=new Date().getTime();
382 let list=getDataReport(tribemates);
383 var stopReport=new Date().getTime();
384 console.log(stopReport-startReport)
385 console.log(list)
386 if(list==null ){
387 console.log("recaptcha, upload again")
388 UI.ErrorMessage("recaptcha, upload again","slow")
389 addWindow();
390 document.getElementById("progress_reports").innerText="recaptcha";
391 list_href=[]
392
393 }
394 else{
395 console.log("reports info "+list.length)
396 for(let j=0;j<list.length;j++){
397 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
398 }
399 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
400 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
401
402 nr_reports++;
403 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
404 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
405 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
406 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
407 map_history_upload.set(idReport,{
408 date:time_report,
409 playerId:game_data.player.id
410 })
411 }
412 else{
413 map_history_upload.set(idReport,{
414 date:currentDate,
415 playerId:game_data.player.id
416 })
417 }
418 }
419 console.log("map_history_upload size "+map_history_upload.size)
420 var stop_ajax=new Date();
421 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
422 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
423 window.setTimeout(function(){
424 ajaxRequest(list_href);
425 },200-dif_time)
426 });
427
428 }
429 else
430 {
431
432
433
434 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
435 console.log("before reading map from dropbox")
436 let [map_dropbox, mapStatus]=await Promise.all([readFileDropbox(filename_reports) ,readFileDropbox(filename_status_upload)]).catch(err=>{alert(err)})
437
438 try {
439 map_dropbox=new Map( JSON.parse(lzw_decode(map_dropbox)));
440 } catch (error) {
441 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
442 map_dropbox=new Map()
443 }
444
445 //if database is stored locally
446 if(await localBase.getItem(game_data.world+"reports")!=undefined){
447 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"reports"))));
448 console.log("map_localBase",map_localBase)
449 map_dropbox=new Map([...map_localBase, ...map_dropbox])
450 }
451
452
453
454 document.body.innerHTML= httpGet(current_page);
455
456 addWindow();
457 let nr_update=0;
458 let nr_write=0;
459 list_data_reports.forEach(function(el){
460 if(map_dropbox.has(el.coord)){//update el[0]=key
461 let obj_dropbox=map_dropbox.get(el.coord)
462
463 if(el.coord==el.reportInfo.coordAttacker ){
464 console.log("update for offensive" && el.reportInfo.typeAttacker!="?")
465 delete el.reportInfo["troopsAtHome_"+el.coord]
466 delete el.reportInfo["time_report_home_"+el.coord]
467
468
469 if(el.reportInfo.typeAttacker=="new_off"){
470 console.log("new_off, don't do anything")
471 }else{
472 console.log("coord exists in dropbox already")
473 let time_prev=new Date(obj_dropbox.time_report);
474 let time_current=new Date(el.reportInfo.time_report);
475 console.log(time_current-time_prev)
476 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
477 console.log("it was def_cat")
478 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})//merge old info with new info
479 nr_update++;
480 }
481 else if(time_current-time_prev>0 ){
482 console.log("update coord: "+el.coord+" in dropbox")
483 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})//merge old info with new info
484 nr_update++;
485 }
486 }
487
488 }
489 if(el.coord==el.reportInfo.coordDefender && el.reportInfo.typeDefender!="?"){
490 console.log("update for defensive")
491 if(el.reportInfo.typeDefender=="new_off" || el.reportInfo.typeDefender=="home_seen"){
492 console.log(`defend type:${el.reportInfo.typeDefender} update troops home`)
493
494 let time_prev=new Date(obj_dropbox.time_report);
495 let time_current=new Date(el.reportInfo.time_report);
496
497 if(time_current-time_prev>=0 ){
498 console.log("update coord: "+el.coord+" in dropbox")
499
500 obj_dropbox["troopsAtHome_"+el.coord]=el.reportInfo["troopsAtHome_"+el.coord]
501 obj_dropbox["time_report_home_"+el.coord]=el.reportInfo["time_report_home_"+el.coord]
502
503 map_dropbox.set(el.coord,obj_dropbox)
504 nr_update++;
505 }
506
507 }else{
508 console.log("coord exists in dropbox already")
509 let time_prev=new Date(obj_dropbox.time_report);
510 let time_current=new Date(el.reportInfo.time_report);
511 console.log(time_current-time_prev)
512 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeDefender=="def" )){//48 hours
513 console.log("it was def_cat")
514 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})
515 nr_update++;
516 }
517 else if(time_current-time_prev>0 ){
518 console.log("update coord: "+el.coord+" in dropbox")
519 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})
520 nr_update++;
521 }
522 }
523 }
524 }
525 else{//write
526 if(el.coord==el.reportInfo.coordAttacker && el.reportInfo.typeAttacker!="?"){
527 delete el.reportInfo["troopsAtHome_"+el.coord]
528 delete el.reportInfo["time_report_home_"+el.coord]
529
530 console.log("write coord in dropbox")
531 map_dropbox.set(el.coord,el.reportInfo)
532 nr_write++;
533 }
534 else if(el.coord==el.reportInfo.coordDefender && el.reportInfo.typeDefender!="?"){
535 console.log("write coord in dropbox")
536 if(el.reportInfo.typeDefender=="home_seen"){
537 el.reportInfo.typeDefender="?"
538 }
539
540 map_dropbox.set(el.coord,el.reportInfo)
541 nr_write++;
542 }
543 }
544 })
545
546
547
548 console.log("map_dropbox before",map_dropbox)
549
550 //clear map if contains data on tribe mates
551 let counterAttacker=0;
552 let counterDefender=0;
553 let counterTypAttacker=0;
554 let counterTypeDefender=0;
555 Array.from(map_dropbox.keys()).forEach(key=>{
556 try {
557 let obj=map_dropbox.get(key)
558 let obj_village=mapVillage.get(key)
559 if(key == obj.coordAttacker){
560 if(tribemates.includes(obj.nameAttacker.toLowerCase()) || obj.nameAttacker.toLowerCase() != obj_village.playerName.toLowerCase() ){
561 map_dropbox.delete(key)
562 console.log(`delete coord ${key} old owner:${obj.nameAttacker.toLowerCase()} != new owner:${obj_village.playerName.toLowerCase()} (off report)`)
563 counterAttacker++
564 }
565 else if(obj.typeAttacker=="?"){
566 map_dropbox.delete(key)
567 counterTypAttacker++
568 }
569 }
570 else if(key == obj.coordDefender){
571 if(tribemates.includes(obj.nameDefender.toLowerCase()) || obj.nameDefender.toLowerCase() != obj_village.playerName.toLowerCase() ){
572 map_dropbox.delete(key)
573 counterDefender++
574 console.log(`delete coord ${key} old owner:${obj.nameDefender.toLowerCase()} != new owner:${obj_village.playerName.toLowerCase()} (def report)`)
575
576 }
577 else if(obj.typeDefender=="?"){
578 map_dropbox.delete(key)
579 counterTypeDefender++
580 }
581 }
582
583 } catch (error) {
584
585 }
586
587
588
589 })
590 console.log("remove counterAttacker",counterAttacker)
591 console.log("remove counterDefender",counterDefender)
592 console.log("remove counterTypAttacker",counterTypAttacker)
593 console.log("remove counterTypeDefender",counterTypeDefender)
594
595
596
597
598
599 console.log("map_dropbox after")
600 console.log(map_dropbox);
601 console.log("list_data_reports")
602 console.log(list_data_reports);
603
604
605 let serverTime=document.getElementById("serverTime").innerText
606 let serverDate=document.getElementById("serverDate").innerText.split("/")
607 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
608 let date_current=serverDate+" "+serverTime
609 console.log(date_current)
610 //update status map
611 let obj_status={
612 name:game_data.player.name,
613 report_date:date_current,
614 }
615
616 if(mapStatus=="[]")
617 mapStatus=new Map()
618 else
619 mapStatus=new Map(JSON.parse(mapStatus))
620
621 if(mapStatus.has(game_data.player.id)){
622 let obj_update=mapStatus.get(game_data.player.id)
623 mapStatus.set(game_data.player.id, {...obj_update, ...obj_status} )
624 }
625 else{
626 mapStatus.set(game_data.player.id,obj_status)
627 }
628
629
630 UI.SuccessMessage("compressing database, wait few seconds",2000)
631
632 var nr_start=new Date().getTime()
633 var length_data=JSON.stringify(Array.from(map_dropbox.entries())).length;
634
635 var data=JSON.stringify(Array.from(map_dropbox.entries()))
636 data=replaceSpecialCaracters(data)
637 data=lzw_encode(data)
638 var length_data_compressed=data.length;
639
640 var nr_stop=new Date().getTime()
641 console.log("after")
642 console.log(map_dropbox)
643 console.log("compressing data: "+(nr_stop-nr_start))
644 console.log("length before: "+length_data+" length after compression: "+length_data_compressed)
645 console.log("compression factor: "+(length_data/length_data_compressed) )
646
647
648 let data_status=JSON.stringify(Array.from(mapStatus.entries()))
649
650
651 await localBase.setItem(game_data.world+"reports",data)
652 let result=await uploadFile(data,filename_reports,dropboxToken).catch(err=>alert(err))
653 let resultStatus=await uploadFile(data_status,filename_status_upload,dropboxToken).catch(err=>alert(err))
654
655
656
657 if(result=="succes"){
658 let data =lzw_encode(JSON.stringify(Array.from(map_history_upload.entries())))
659 await localBase.setItem(game_data.world+"history_upload",data)
660 await uploadFile(data,filename_history_upload,dropboxToken).catch(err=>alert(err))
661
662 document.getElementById("progress_reports").innerText="done";
663 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,2000)
664 resolve("succes")
665
666 }
667 else
668 reject("error")
669
670 }
671 }
672 ajaxRequest(list_href);
673 })
674
675
676}
677
678/////////////////////////////////////////////////get all reports info MANUAL//////////////////////////////////////////////////////////////////
679async function uploadReportsManual(){
680 let types=["off","new_off","def","def_cat",'def_spy',"spy","def??","none"]
681 document.getElementById("progress_reports").innerText="get links..";
682 let current_page=window.location.href;
683
684 let [map_history_upload,status]=await Promise.all([readFileDropbox(filename_history_upload),insertlibraryLocalBase() ]).catch(err=>{alert(err)})
685 console.log(status)
686
687 try {
688 map_history_upload=new Map( JSON.parse(lzw_decode(map_history_upload)));
689 } catch (error) {
690 console.log("erorr map history upload from dropbox")
691 map_history_upload=new Map()
692 }
693
694 //if database is stored locally
695 if(await localBase.getItem(game_data.world+"history_upload")!=undefined){
696 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"history_upload"))));
697 console.log("map_localBase history upload",map_localBase)
698 map_history_upload=new Map([...map_localBase, ...map_history_upload])
699 }
700
701 console.log("map_history_upload",map_history_upload)
702 //delete if it's too old
703 Array.from(map_history_upload.keys()).forEach(key=>{
704 let currentDate=new Date();
705 let reportDate=new Date(map_history_upload.get(key).date)
706 if(currentDate.getTime()- reportDate.getTime() > 100*24*3600*1000){
707 console.log("remove id: "+map_history_upload.get(key).date)
708 map_history_upload.delete(key)
709 }
710
711 })
712
713
714
715
716
717
718
719 var [list_href, mapVillage]=await Promise.all([getLinks(true,map_history_upload),getInfoVIllages() ]).catch(err=>{alert(err)})
720
721
722
723 $(document).on('click','.autoHideBox',function(){
724 UI.SuccessMessage("stop, press again enter",2000)
725 list_href=[]
726 })
727
728 list_href=list_href.reverse();
729 console.log(list_href)
730 var list_data_reports=[]
731 var nr_reports=0;
732 var nr_reports_total=list_href.length
733 addWindow();
734 document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
735 // UI.InfoMessage(nr_reports+"/"+nr_reports_total+" reports")
736 var current_url
737 async function ajaxRequest (urls) {
738 var time= 0
739 if(urls.length>0)
740 current_url=urls.pop().href;
741 else
742 current_url="stop"
743 console.log("inside function "+urls.length)
744 if (urls.length >= 0 && current_url!= "stop") {
745 var start_ajax=new Date()
746 $.ajax({
747 method: 'GET',
748 url: current_url,
749 })
750 .done(function (result) {
751 document.body.innerHTML= result;
752 $(".nopad").prepend("<p style='color:red'>press key enter to go to next report</p>")
753 result=null
754 // addWindow();
755 let list=getDataReport(tribemates);
756 console.log(list)
757 if(list==null ){
758 console.log("recaptcha, upload again")
759 UI.ErrorMessage("recaptcha, upload again","slow")
760 addWindow();
761 document.getElementById("progress_reports").innerText="recaptcha";
762 list_href=[]
763
764 }
765 else{
766 console.log("reports info "+list.length)
767 for(let j=0;j<list.length;j++){
768
769 if(document.getElementById("select_type_attacker")==null && !tribemates.includes(list[j].reportInfo.nameAttacker)){
770 let type=(list[j].reportInfo.typeAttacker!="?")?list[j].reportInfo.typeAttacker:"none"
771
772 console.log(type)
773 let htmlSelect='<select id="select_type_attacker" style="width: 100%">';
774 for(let k=types.length-1;k>=0;k--){
775 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
776 }
777 htmlSelect+='</select>';
778 $("#attack_info_att").append(htmlSelect)
779 document.getElementById("select_type_attacker").value=type
780 }
781 if(document.getElementById("select_type_defender")==null && !tribemates.includes(list[j].reportInfo.nameDefender)){
782 let type=(list[j].reportInfo.typeDefender!="?")?list[j].reportInfo.typeDefender:"none"
783 console.log(type)
784 let htmlSelect='<select id="select_type_defender" style="width: 100%">';
785 for(let k=types.length-1;k>=0;k--){
786 htmlSelect+='<option value="'+types[k]+'">'+types[k]+'</option>'
787 }
788 htmlSelect+='</select>';
789 $("#attack_info_def").append(htmlSelect)
790 document.getElementById("select_type_defender").value=type
791
792 }
793
794 }
795 // document.getElementById("progress_reports").innerText=nr_reports+"/"+nr_reports_total+" reports";
796 UI.SuccessMessage(nr_reports+"/"+nr_reports_total+" reports")
797
798 nr_reports++;
799 let idReport= parseInt(current_url.match(/view=(\d+)/)[1]);
800 let currentDate=new Date().getFullYear()+"-"+(new Date().getMonth()+1)+"-"+new Date().getDate();
801 if(document.getElementsByClassName("unit-item unit-item-axe").length>0){
802 var time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
803 map_history_upload.set(idReport,{
804 date:time_report,
805 playerId:game_data.player.id
806 })
807 }
808 else{
809 map_history_upload.set(idReport,{
810 date:currentDate,
811 playerId:game_data.player.id
812 })
813 }
814 }
815 var stop_ajax=new Date();
816 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
817 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
818
819 window.onkeyup = function(e) {
820 console.log(e.which)
821 if(e.which==13 && current_url!= "stop"){
822 console.log("next")
823 window.onkeyup = function(e){}
824
825 for(let j=0;j<list.length;j++){
826 if(document.getElementById("select_type_attacker")!=null){
827 let type=document.getElementById("select_type_attacker").value
828 if(type!="none"){
829 list[j].reportInfo.typeAttacker=type
830 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
831 }
832 }
833 if(document.getElementById("select_type_defender")!=null){
834 let type=document.getElementById("select_type_defender").value
835 if(type!="none"){
836 list[j].reportInfo.typeDefender=type
837 list_data_reports.push({"coord":list[j].coord,"reportInfo":list[j].reportInfo});
838 }
839 }
840
841 }
842 console.log("new list")
843 console.log(list)
844 console.log("big list")
845 console.log(list_data_reports)
846
847 window.setTimeout(function(){
848 ajaxRequest(list_href);
849 },200-dif_time)
850 }
851 e.preventDefault()
852 }
853 });
854
855 }
856 else
857 {
858 ////////////////////////////////////extract data from dropbox/////////////////////////////////////////
859 console.log("before reading map from dropbox")
860 let [map_dropbox, mapStatus]=await Promise.all([readFileDropbox(filename_reports) ,readFileDropbox(filename_status_upload)]).catch(err=>{alert(err)})
861 try {
862 map_dropbox=new Map( JSON.parse(lzw_decode(map_dropbox)));
863 } catch (error) {
864 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
865 map_dropbox=new Map()
866 }
867
868 //if there database is stored locally
869 if(await localBase.getItem(game_data.world+"reports")!=undefined){
870 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"reports"))));
871 console.log("map_localBase",map_localBase)
872 map_dropbox=new Map([...map_localBase, ...map_dropbox])
873 }
874
875
876
877 document.body.innerHTML= httpGet(current_page);
878 if(typeof(TWMap) !="undefined" ){
879 console.log("init map")
880 TWMap.init();
881 }
882
883
884 addWindow();
885 let nr_update=0;
886 let nr_write=0;
887 list_data_reports.forEach(function(el){
888 if(map_dropbox.has(el.coord)){//update el[0]=key
889 let obj_dropbox=map_dropbox.get(el.coord)
890
891 if(el.coord==el.reportInfo.coordAttacker ){
892 console.log("update for offensive" && el.reportInfo.typeAttacker!="?")
893 delete el.reportInfo["troopsAtHome_"+el.coord]
894 delete el.reportInfo["time_report_home_"+el.coord]
895
896
897 if(el.reportInfo.typeAttacker=="new_off"){
898 console.log("new_off, don't do anything")
899 }else{
900 console.log("coord exists in dropbox already")
901 let time_prev=new Date(obj_dropbox.time_report);
902 let time_current=new Date(el.reportInfo.time_report);
903 console.log(time_current-time_prev)
904 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeAttacker=="def" )){//48 hours
905 console.log("it was def_cat")
906 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})//merge old info with new info
907 nr_update++;
908 }
909 else if(time_current-time_prev>0 ){
910 console.log("update coord: "+el.coord+" in dropbox")
911 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})//merge old info with new info
912 nr_update++;
913 }
914 }
915
916 }
917 if(el.coord==el.reportInfo.coordDefender && el.reportInfo.typeDefender!="?"){
918 console.log("update for defensive")
919 if(el.reportInfo.typeDefender=="new_off" || el.reportInfo.typeDefender=="home_seen"){
920 console.log(`defend type:${el.reportInfo.typeDefender} update troops home`)
921
922 let time_prev=new Date(obj_dropbox.time_report);
923 let time_current=new Date(el.reportInfo.time_report);
924
925 if(time_current-time_prev>=0 ){
926 console.log("update coord: "+el.coord+" in dropbox")
927
928 obj_dropbox["troopsAtHome_"+el.coord]=el.reportInfo["troopsAtHome_"+el.coord]
929 obj_dropbox["time_report_home_"+el.coord]=el.reportInfo["time_report_home_"+el.coord]
930
931 map_dropbox.set(el.coord,obj_dropbox)
932 nr_update++;
933 }
934
935 }else{
936 console.log("coord exists in dropbox already")
937 let time_prev=new Date(obj_dropbox.time_report);
938 let time_current=new Date(el.reportInfo.time_report);
939 console.log(time_current-time_prev)
940 if(time_current-time_prev<48*3600*1000 && (el.reportInfo.typeDefender=="def" )){//48 hours
941 console.log("it was def_cat")
942 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})
943 nr_update++;
944 }
945 else if(time_current-time_prev>0 ){
946 console.log("update coord: "+el.coord+" in dropbox")
947 map_dropbox.set(el.coord,{...obj_dropbox, ...el.reportInfo})
948 nr_update++;
949 }
950 }
951 }
952 }
953 else{//write
954 if(el.coord==el.reportInfo.coordAttacker && el.reportInfo.typeAttacker!="?"){
955 delete el.reportInfo["troopsAtHome_"+el.coord]
956 delete el.reportInfo["time_report_home_"+el.coord]
957
958 console.log("write coord in dropbox")
959 map_dropbox.set(el.coord,el.reportInfo)
960 nr_write++;
961 }
962 else if(el.coord==el.reportInfo.coordDefender && el.reportInfo.typeDefender!="?"){
963 console.log("write coord in dropbox")
964 if(el.reportInfo.typeDefender=="home_seen"){
965 el.reportInfo.typeDefender="?"
966 }
967
968 map_dropbox.set(el.coord,el.reportInfo)
969 nr_write++;
970 }
971 }
972 })
973
974
975 console.log("map_dropbox before",map_dropbox)
976
977
978 //clear map if contains data on tribe mates
979 let counterAttacker=0;
980 let counterDefender=0;
981 let counterTypAttacker=0;
982 let counterTypeDefender=0;
983 Array.from(map_dropbox.keys()).forEach(key=>{
984 try {
985 let obj=map_dropbox.get(key)
986 let obj_village=mapVillage.get(key)
987 if(key == obj.coordAttacker){
988 if(tribemates.includes(obj.nameAttacker.toLowerCase()) || obj.nameAttacker.toLowerCase() != obj_village.playerName.toLowerCase() ){
989 map_dropbox.delete(key)
990 counterAttacker++
991 }
992 else if(obj.typeAttacker=="?"){
993 map_dropbox.delete(key)
994 counterTypAttacker++
995 }
996 }
997 else if(key == obj.coordDefender){
998 if(tribemates.includes(obj.nameDefender.toLowerCase()) || obj.nameDefender.toLowerCase() != obj_village.playerName.toLowerCase() ){
999 map_dropbox.delete(key)
1000 counterDefender++
1001 }
1002 else if(obj.typeDefender=="?"){
1003 map_dropbox.delete(key)
1004 counterTypeDefender++
1005 }
1006 }
1007
1008 } catch (error) {
1009
1010 }
1011 })
1012 console.log("remove counterAttacker",counterAttacker)
1013 console.log("remove counterDefender",counterDefender)
1014 console.log("remove counterTypAttacker",counterTypAttacker)
1015 console.log("remove counterTypeDefender",counterTypeDefender)
1016
1017 console.log("map_dropbox")
1018 console.log(map_dropbox);
1019 console.log("list_data_reports")
1020 console.log(list_data_reports);
1021
1022
1023
1024
1025
1026 let serverTime=document.getElementById("serverTime").innerText
1027 let serverDate=document.getElementById("serverDate").innerText.split("/")
1028 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
1029 let date_current=serverDate+" "+serverTime
1030
1031 //update status map
1032 let obj_status={
1033 name:game_data.player.name,
1034 report_date:date_current,
1035 }
1036
1037 if(mapStatus=="[]")
1038 mapStatus=new Map()
1039 else
1040 mapStatus=new Map(JSON.parse(mapStatus))
1041
1042 if(mapStatus.has(game_data.player.id)){
1043 let obj_update=mapStatus.get(game_data.player.id)
1044 mapStatus.set(game_data.player.id, {...obj_update, ...obj_status} )
1045 }
1046 else{
1047 mapStatus.set(game_data.player.id,obj_status)
1048 }
1049
1050
1051 UI.SuccessMessage("compressing database, wait few seconds",2000)
1052
1053 var nr_start=new Date().getTime()
1054 var length_data=JSON.stringify(Array.from(map_dropbox.entries())).length;
1055
1056 var data=JSON.stringify(Array.from(map_dropbox.entries()))
1057 data=replaceSpecialCaracters(data)
1058 data=lzw_encode(data)
1059 var length_data_compressed=data.length;
1060
1061 var nr_stop=new Date().getTime()
1062 console.log("after")
1063 console.log(map_dropbox)
1064 console.log("compressing data: "+(nr_stop-nr_start))
1065 console.log("length before: "+length_data+" length after compression: "+length_data_compressed)
1066 console.log("compression factor: "+(length_data/length_data_compressed) )
1067
1068 let data_status=JSON.stringify(Array.from(mapStatus.entries()))
1069
1070 await localBase.setItem(game_data.world+"reports",data)
1071 let result=await uploadFile(data,filename_reports,dropboxToken).catch(err=>alert(err))
1072 let resultStatus=await uploadFile(data_status,filename_status_upload,dropboxToken).catch(err=>alert(err))
1073
1074 if(result=="succes"){
1075 console.log("status upload success")
1076 let data =lzw_encode(JSON.stringify(Array.from(map_history_upload.entries())))
1077 await localBase.setItem(game_data.world+"history_upload",data)
1078 await uploadFile(data,filename_history_upload,dropboxToken).catch(err=>alert(err))
1079
1080 document.getElementById("progress_reports").innerText="done";
1081 UI.SuccessMessage("upload reports done\n update: "+nr_update+" \nwrite: "+nr_write,2000)
1082
1083 }
1084 else
1085 console.log("status upload error")
1086
1087
1088
1089
1090
1091
1092
1093 }
1094 }
1095 ajaxRequest(list_href);
1096
1097}
1098///////////////////////////////////////////////////////////////////get all links////////////////////////////////////////////////////////////////
1099function getLinks(all,map_idReports){
1100
1101 // var currentPage=document.body.innerHTML;
1102 return new Promise((resolve,reject)=>{
1103 let list_pages=[]
1104 let current_href=window.location.href;
1105 // if(current_href.includes("screen=report"))// upload only reports from current folder
1106 // all=false;
1107 if(all){// all pages from all folders
1108 let href= game_data.link_base_pure+"report&mode=all&group_id=-1";
1109 document.body.innerHTML=httpGet(href)
1110 }
1111 let page_size=parseInt(document.getElementsByName("page_size")[0].value)
1112 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
1113 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
1114 list_pages.push(item.value)
1115 })
1116 }
1117 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
1118 let length_page=document.getElementsByClassName("paged-nav-item").length
1119 for(let i=0;i<length_page+1;i++){
1120 let current=game_data.link_base_pure+`report&mode=all&from=${i*page_size}`
1121 list_pages.push(current);
1122
1123 }
1124 }
1125 else{
1126 let current_link=game_data.link_base_pure+`report&mode=all&from=0`
1127 list_pages.push(current_link);
1128 }
1129 list_pages=list_pages.reverse();
1130
1131 console.log("list pages")
1132 console.log(list_pages)
1133
1134 let list_href=[];
1135 var indexIncoming=1;
1136 var url_length=list_pages.length
1137 function ajaxRequest (urls) {
1138 let current_url
1139
1140 if(urls.length>0){
1141 current_url=urls.pop()
1142 }
1143 else{
1144 current_url="stop"
1145 }
1146 console.log("length"+urls.length)
1147 // console.log(current_url)
1148 var start_ajax=new Date();
1149 if (urls.length >= 0 && current_url!="stop") {
1150 $.ajax({
1151 url: current_url,
1152 method: 'get',
1153 success: (data) => {
1154 document.body.innerHTML=data
1155 let table_report= document.getElementById("report_list").firstElementChild.children;
1156 let year=document.getElementById("serverDate").innerText.split("/")[2];
1157 for(let i=1;i<table_report.length-1;i++){
1158 let month_day=table_report[i].children[2].innerText;
1159 let date_report=new Date(year+" "+month_day)
1160 let current_date=new Date();
1161 if(Math.abs(current_date-date_report)<100*24*3600*1000){//old
1162
1163 let img_icon=table_report[i].children[1].children[0].children.length;
1164 if(img_icon>0){//wordsTranslate[0]=supports ///// || table_report[i].innerText.includes(wordsTranslate[0])
1165 let obj={
1166 id:table_report[i].getElementsByTagName("a")[0].getAttribute("data-id"),
1167 href:table_report[i].getElementsByTagName("a")[0].href
1168 }
1169 if(!map_idReports.has(parseInt(obj.id)))
1170 list_href.push(obj)
1171 }
1172 }
1173 else{
1174 list_pages=[]
1175 }
1176 }
1177
1178
1179 UI.InfoMessage("page "+indexIncoming+"/"+url_length)
1180 indexIncoming++;
1181 var stop_ajax=new Date();
1182 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
1183 window.setTimeout(function(){
1184 ajaxRequest (list_pages)
1185 },200-dif_time)
1186 }
1187 })
1188
1189 }
1190 else
1191 {
1192 UI.SuccessMessage("done",2000)
1193 resolve(list_href)
1194 }
1195 }
1196 if(list_pages.length>0)
1197 ajaxRequest(list_pages);
1198 else
1199 reject("error??")
1200
1201 })
1202
1203}
1204
1205
1206////////////////////////////////////////////////////////////get data from report////////////////////////////////////////////////////////////////////
1207
1208function getDataReport(tribemates){
1209 var mapObject={};
1210 var listObject=[];
1211
1212 // tribemates=[]
1213 var reportInfo={};
1214 try{
1215 if($("#attack_info_att").length>0){
1216 var attackInfo=$("#attack_info_att");
1217 if(attackInfo.text().includes("deleted") || attackInfo.text().includes("---")){
1218 console.log("error upload")
1219 return 0;
1220 }
1221 var defenseInfo = $("#attack_info_def");
1222 if(defenseInfo.text().includes("deleted") || defenseInfo.text().includes("---")){
1223 console.log("error upload")
1224 return 0;
1225 }
1226
1227 var attackingPlayer = attackInfo.find('a[href*=info_player]');
1228 var defendingPlayer = defenseInfo.find('a[href*=info_player]');
1229 var attackingPlayerId=attackingPlayer.prop('href').match(/id=(\w+)/)[1];
1230 var defendingPlayerId=defendingPlayer.prop('href').match(/id=(\w+)/)[1];
1231 reportInfo.attackingPlayerId=attackingPlayerId;
1232 reportInfo.defendingPlayerId=defendingPlayerId;
1233 }
1234 ///////////////////////////////////////////////////////////////////////////
1235
1236
1237 if(document.getElementsByClassName("unit-item unit-item-axe").length>1)
1238 {
1239 var time_report=document.getElementsByClassName("small grey")[0].parentElement.innerText;
1240 // if(new Date()-new Date(time_report)>14*24*3600*1000)//report too old
1241 // return listObject;
1242 reportInfo.attackingArmy = attackInfo.find('#attack_info_att_units tr:nth-of-type(2) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
1243 reportInfo.attackingArmyLosses = attackInfo.find('#attack_info_att_units tr:nth-of-type(3) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
1244
1245 reportInfo.time_report=time_report
1246 var report=document.getElementsByClassName("vis")[3].innerHTML;
1247 var index=report.indexOf('<div class="no-preview">');
1248 report=report.substring(0,index);
1249 // report=lzw_encode(report);
1250 // reportInfo.report=report;
1251
1252 ///////////////////////////defender date////////////////////
1253 var nameAttacker=document.getElementById("attack_info_att").children[0].children[0].children[1].innerText;
1254 var coordAttacker=document.getElementsByClassName("village_anchor")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1255 var nameDefender=document.getElementById("attack_info_def").children[0].children[0].children[1].innerText;
1256 var coordDefender=document.getElementsByClassName("village_anchor")[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
1257 reportInfo.nameAttacker=nameAttacker;
1258 reportInfo.coordAttacker=coordAttacker;
1259 reportInfo.nameDefender=nameDefender;
1260 reportInfo.coordDefender=coordDefender;
1261
1262 if(reportInfo.attackingArmy[3].type=="archer"){
1263 var spear_atac_total =reportInfo.attackingArmy[0].count
1264 var sword_atac_total =reportInfo.attackingArmy[1].count
1265 var axe_atac_total =reportInfo.attackingArmy[2].count
1266 var archer_atac_total=reportInfo.attackingArmy[3].count
1267 var spy_atac_total =reportInfo.attackingArmy[4].count*2
1268 var light_atac_total =reportInfo.attackingArmy[5].count*4
1269 var heavy_atac_total =reportInfo.attackingArmy[7].count*6
1270 var ram_atac_total =reportInfo.attackingArmy[8].count*5
1271 var cat_atac_total =reportInfo.attackingArmy[9].count*8
1272 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
1273
1274 var spear_atac_pierderi =reportInfo.attackingArmyLosses[0].count
1275 var sword_atac_pierderi =reportInfo.attackingArmyLosses[1].count
1276 var axe_atac_pierderi =reportInfo.attackingArmyLosses[2].count
1277 var archer_atac_pierderi=reportInfo.attackingArmyLosses[3].count
1278 var spy_atac_pierderi =reportInfo.attackingArmyLosses[4].count*2
1279 var light_atac_pierderi =reportInfo.attackingArmyLosses[5].count*4
1280 var heavy_atac_pierderi =reportInfo.attackingArmyLosses[7].count*6
1281 var ram_atac_pierderi =reportInfo.attackingArmyLosses[8].count*5
1282 var cat_atac_pierderi =reportInfo.attackingArmyLosses[9].count*8
1283 }
1284 else{
1285 var spear_atac_total=reportInfo.attackingArmy[0].count
1286 var sword_atac_total=reportInfo.attackingArmy[1].count
1287 var axe_atac_total =reportInfo.attackingArmy[2].count
1288 var spy_atac_total =reportInfo.attackingArmy[3].count*2
1289 var light_atac_total=reportInfo.attackingArmy[4].count*4
1290 var heavy_atac_total=reportInfo.attackingArmy[5].count*6
1291 var ram_atac_total =reportInfo.attackingArmy[6].count*5
1292 var cat_atac_total =reportInfo.attackingArmy[7].count*8
1293 var noble=parseInt(document.getElementsByClassName("unit-item unit-item-snob")[0].innerText)*100;
1294 var archer_atac_total=0;
1295
1296 var spear_atac_pierderi=reportInfo.attackingArmyLosses[0].count
1297 var sword_atac_pierderi=reportInfo.attackingArmyLosses[1].count
1298 var axe_atac_pierderi =reportInfo.attackingArmyLosses[2].count
1299 var spy_atac_pierderi =reportInfo.attackingArmyLosses[3].count*2
1300 var light_atac_pierderi=reportInfo.attackingArmyLosses[4].count*4
1301 var heavy_atac_pierderi=reportInfo.attackingArmyLosses[5].count*6
1302 var ram_atac_pierderi =reportInfo.attackingArmyLosses[6].count*5
1303 var cat_atac_pierderi =reportInfo.attackingArmyLosses[7].count*8
1304
1305 }
1306
1307
1308
1309 var typeAttacker="?";
1310 var nrTroupesAttacker=0;
1311 var nrTroupesAttackerTotal=0;
1312 var time_return=0;
1313
1314
1315 if(axe_atac_total+light_atac_total+ram_atac_total + cat_atac_total >=6000)//&& axe_atac_total>=2500
1316 {
1317 typeAttacker="off";
1318 nrTroupesAttacker=(axe_atac_total-axe_atac_pierderi)+(light_atac_total-light_atac_pierderi) + (ram_atac_total-ram_atac_pierderi);
1319 console.log("ianinte")
1320 if(ram_atac_total>0 && noble==0 && axe_atac_total>=0){
1321 console.log("aici")
1322 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
1323 let time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
1324 time_return=new Date(time_report).getTime()+time_attack;
1325 time_return=new Date(time_return)
1326 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
1327 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
1328
1329 }else if(axe_atac_total>=0 && noble==0 ){
1330 nrTroupesAttackerTotal=axe_atac_total+light_atac_total
1331 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
1332 time_return=new Date(time_report).getTime()+time_attack;
1333 time_return=new Date(time_return)
1334 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
1335 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
1336
1337 }else if(axe_atac_total>=0 && noble>0){
1338 nrTroupesAttackerTotal=axe_atac_total+light_atac_total+ram_atac_total
1339 time_attack=axeSpeed*calcDistance(coordAttacker,coordDefender)
1340 time_return=new Date(time_report).getTime()+time_attack;
1341 time_return=new Date(time_return)
1342 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
1343 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
1344 }
1345 }
1346 else if(spy_atac_total>4000){
1347 typeAttacker="spy";
1348 nrTroupesAttacker=spy_atac_total-spy_atac_pierderi;
1349 }
1350 else if(axe_atac_total+light_atac_total+ram_atac_total >20 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total<15)
1351 {
1352 typeAttacker="new_off";
1353 }
1354 else if(axe_atac_total+light_atac_total+ram_atac_total <15 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total>15){
1355 typeAttacker="def";
1356 }
1357 else if(spy_atac_total>=800 && axe_atac_total+light_atac_total+ram_atac_total<500 && spear_atac_total+sword_atac_total+archer_atac_total+heavy_atac_total<40){
1358 typeAttacker="def_spy";
1359 }
1360 else if(spear_atac_total + sword_atac_total + archer_atac_total > 1000){
1361 typeAttacker="def";
1362 }
1363
1364
1365
1366
1367
1368 if((cat_atac_total>=50*8 && typeAttacker=="def") || (cat_atac_total>=50*8 && axe_atac_total+light_atac_total+ram_atac_total<20)){
1369 typeAttacker="def_cat";
1370 nrTroupesAttacker=cat_atac_total-cat_atac_pierderi;
1371 if(noble==0){
1372 nrTroupesAttackerTotal=heavy_atac_total+cat_atac_total
1373 time_attack=ramSpeed*calcDistance(coordAttacker,coordDefender)
1374 time_return=new Date(time_report).getTime()+time_attack;
1375 time_return=new Date(time_return)
1376 let date=new Date(time_return).toDateString().split(" ").slice(1).join(" ")
1377 time_return=date+" "+new Date(time_return).toTimeString().split(" ")[0]
1378 }
1379 }
1380
1381 reportInfo.time_return=time_return
1382 reportInfo.nrTroupesAttackerTotal=nrTroupesAttackerTotal
1383 reportInfo.typeAttacker=typeAttacker;
1384 reportInfo.nrTroupesAttacker=nrTroupesAttacker;
1385
1386
1387
1388 /////////////////////////////////////////////////defender date/////////////////////
1389 var nrTroupesDefender=0;
1390 var typeDefender="?";
1391 if(document.getElementsByClassName("unit-item unit-item-axe").length>2){
1392
1393 reportInfo.defendingArmy = defenseInfo.find('#attack_info_def_units tr:nth-of-type(2) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
1394 reportInfo.defendingArmyLosses = defenseInfo.find('#attack_info_def_units tr:nth-of-type(3) .unit-item').get().map((el) => { return { type: $(el).prop('class').match(/unit-item-([\w\-]+)/)[1], count: parseInt($(el).text().trim()) } })
1395
1396 let armyAtHome=[]
1397
1398 for(let i=0;i<reportInfo.defendingArmy.length;i++){
1399 armyAtHome.push({
1400 type:reportInfo.defendingArmy[i].type,
1401 count:reportInfo.defendingArmy[i].count-reportInfo.defendingArmyLosses[i].count
1402 })
1403 }
1404 reportInfo["troopsAtHome_"+coordDefender]=armyAtHome
1405 reportInfo["time_report_home_"+coordDefender]=time_report
1406
1407
1408 if(reportInfo.defendingArmy[3].type=="archer"){
1409 var spear_aparare_total =reportInfo.defendingArmy[0].count
1410 var sword_aparare_total =reportInfo.defendingArmy[1].count
1411 var axe_aparare_total =reportInfo.defendingArmy[2].count
1412 var archer_aparare_total=reportInfo.defendingArmy[3].count
1413 var spy_aparare_total =reportInfo.defendingArmy[4].count*2
1414 var light_aparare_total =reportInfo.defendingArmy[5].count*4
1415 var heavy_aparare_total =reportInfo.defendingArmy[7].count*6
1416 var ram_aparare_total =reportInfo.defendingArmy[8].count*5
1417 var cat_aparare_total =reportInfo.defendingArmy[9].count*8
1418
1419 var spear_aparare_pierderi =reportInfo.defendingArmyLosses[0].count
1420 var sword_aparare_pierderi =reportInfo.defendingArmyLosses[1].count
1421 var axe_aparare_pierderi =reportInfo.defendingArmyLosses[2].count
1422 var archer_aparare_pierderi=reportInfo.defendingArmyLosses[3].count
1423 var spy_aparare_pierderi =reportInfo.defendingArmyLosses[4].count*2
1424 var light_aparare_pierderi =reportInfo.defendingArmyLosses[5].count*4
1425 var heavy_aparare_pierderi =reportInfo.defendingArmyLosses[7].count*6
1426 var ram_aparare_pierderi =reportInfo.defendingArmyLosses[8].count*5
1427 var cat_aparare_pierderi =reportInfo.defendingArmyLosses[9].count*8
1428
1429 }
1430 else{
1431 var spear_aaparare_total=reportInfo.defendingArmy[0].count
1432 var sword_aparare_total =reportInfo.defendingArmy[1].count
1433 var axe_aparare_total =reportInfo.defendingArmy[2].count
1434 var spy_aparare_total =reportInfo.defendingArmy[3].count*2
1435 var light_aparare_total =reportInfo.defendingArmy[4].count*4
1436 var heavy_aparare_total =reportInfo.defendingArmy[5].count*6
1437 var ram_aparare_total =reportInfo.defendingArmy[6].count*5
1438 var cat_aparare_total =reportInfo.defendingArmy[7].count*8
1439 var archer_aparare_total=0;
1440
1441 var spear_aaparare_pierderi=reportInfo.defendingArmyLosses[0].count
1442 var sword_aparare_pierderi =reportInfo.defendingArmyLosses[1].count
1443 var axe_aparare_pierderi =reportInfo.defendingArmyLosses[2].count
1444 var spy_aparare_pierderi =reportInfo.defendingArmyLosses[3].count*2
1445 var light_aparare_pierderi =reportInfo.defendingArmyLosses[4].count*4
1446 var heavy_aparare_pierderi =reportInfo.defendingArmyLosses[5].count*6
1447 var ram_aparare_pierderi =reportInfo.defendingArmyLosses[6].count*5
1448 var cat_aparare_pierderi =reportInfo.defendingArmyLosses[7].count*8
1449 var archer_aparare_pierderi=0;
1450
1451 }
1452
1453
1454
1455 nrTroupesDefender=(axe_aparare_total-axe_aparare_pierderi)+(light_aparare_total-light_aparare_pierderi) + (ram_aparare_total-ram_aparare_pierderi);
1456 if(axe_aparare_total+light_aparare_total+ram_aparare_total +cat_aparare_total >=5000 ){//axe_aparare_total>=2500
1457 typeDefender="off";
1458 }
1459 else if(axe_aparare_total+light_aparare_total+ram_aparare_total +cat_aparare_total >=500 ){//axe_aparare_total>=2500
1460 typeDefender="new_off";
1461 }
1462 else{
1463 typeDefender="home_seen";
1464
1465 }
1466
1467
1468 }
1469
1470 if(document.getElementsByClassName("unit-item unit-item-axe").length>4){
1471 let travelingTroopsContainer = $(document).find('#attack_spy_away');
1472 if (travelingTroopsContainer.length)
1473 {
1474 reportInfo.travelingTroops = {};
1475
1476 travelingTroopsContainer.find('.unit-item').each((i, el) => {
1477 let $el = $(el);
1478 let cls = $el.prop('class');
1479 let unitType = cls.match(/unit\-item\-(\w+)/)[1];
1480 reportInfo.travelingTroops[unitType] = parseInt($el.text().trim());
1481 });
1482
1483 var axe_aparare_spy=reportInfo.travelingTroops.axe
1484 var light_aparare_spy=reportInfo.travelingTroops.light*4;
1485 var ram_aparare_spy=reportInfo.travelingTroops.ram*5;
1486 nrTroupesDefender+=axe_aparare_spy+(light_aparare_spy) + (ram_aparare_spy)
1487
1488 if(nrTroupesDefender >= 5000 )
1489 typeDefender="off";
1490
1491 else{
1492 var spear_aparare_spy=reportInfo.travelingTroops.spear
1493 var sword_aparare_spy=reportInfo.travelingTroops.sword
1494 if(document.getElementsByClassName("unit-item unit-item-archer").length>0)
1495 var archer_aparare_spy=reportInfo.travelingTroops.archer
1496 else
1497 var archer_aparare_spy=0
1498
1499 var heavy_aparare_spy=reportInfo.travelingTroops.heavy*6;
1500 var trupe_aparare_total=spear_aparare_total+sword_aparare_total+archer_aparare_total+heavy_aparare_total;
1501 var total_aparare_spy=spear_aparare_spy+sword_aparare_spy+archer_aparare_spy+heavy_aparare_spy;
1502
1503 if(total_aparare_spy>1000){
1504 typeDefender="def";
1505 nrTroupesDefender=total_aparare_spy;
1506 }
1507 else if(axe_aparare_spy+light_aparare_spy <10 && axe_aparare_total+light_aparare_total<100 && trupe_aparare_total>5000 && total_aparare_spy<=1000){
1508 typeDefender="def??";
1509 }
1510 }
1511 }
1512
1513 }
1514 reportInfo.typeDefender=typeDefender;
1515 reportInfo.nrTroupesDefender=nrTroupesDefender;
1516
1517
1518
1519 if(!tribemates.includes(nameAttacker.toLowerCase()) && !reportInfo.typeAttacker.includes("?")){//!reportInfo.typeAttacker.includes("?")
1520 // console.log("attacker")
1521 mapObject.coord=coordAttacker;
1522 mapObject.reportInfo=reportInfo;
1523 listObject.push(mapObject);
1524 mapObject={};
1525 }
1526 if(!tribemates.includes(nameDefender.toLowerCase()) && !reportInfo.typeDefender.includes("?")){
1527 // console.log("defender")
1528 mapObject.coord=coordDefender;
1529 mapObject.reportInfo=reportInfo;
1530 listObject.push(mapObject);
1531 }
1532 }
1533 else if(document.getElementsByClassName("unit-item unit-item-axe").length==1)
1534 {
1535 var typeSupporter="?";
1536 var nrTroupesSupporter=0;
1537 let time_report=document.getElementsByClassName("vis")[3].firstElementChild.children[1].children[1].innerText;
1538 if(new Date()-new Date(time_report)>14*3600*1000)//report too old
1539 return listObject;
1540 var report=document.getElementsByClassName("vis")[3].innerHTML;
1541 // report=lzw_encode(report);
1542 reportInfo.time_report=time_report;
1543 // reportInfo.report=report;
1544
1545 var text=document.getElementsByClassName("vis")[3].innerText.split("\n");
1546 var nameSupporter=text[3].split(":")[1].trim();
1547 var coordSupporter=text[4].split(":")[1].trim().match(/[0-9]{3}\|[0-9]{3}/)[0];
1548 var supporterPlayerId=document.getElementsByClassName("vis")[3].getElementsByTagName("a")[1].href.split("id=")[1]
1549 // var supporterPlayerId=document.getElementsByClassName("village_anchor contexted")[0].getAttribute("data-player")
1550
1551 reportInfo.nameSupporter=nameSupporter;
1552 reportInfo.coordSupporter=coordSupporter;
1553 reportInfo.supporterPlayerId=supporterPlayerId;
1554
1555
1556 var axe_total=parseInt(document.getElementsByClassName("unit-item unit-item-axe")[0].innerText);
1557 var light_total=parseInt(document.getElementsByClassName("unit-item unit-item-light")[0].innerText)*4;
1558 var ram_total=parseInt(document.getElementsByClassName("unit-item unit-item-ram")[0].innerText)*5;
1559
1560 var spear_total=parseInt(document.getElementsByClassName("unit-item unit-item-spear")[0].innerText);
1561 var sword_total=parseInt(document.getElementsByClassName("unit-item unit-item-sword")[0].innerText);
1562 var archer_total=parseInt(document.getElementsByClassName("unit-item unit-item-archer")[0].innerText);
1563 var heavy_total=parseInt(document.getElementsByClassName("unit-item unit-item-heavy")[0].innerText)*6;
1564
1565 var total_atac=axe_total+light_total+ram_total;
1566 var total_aparare=spear_total+sword_total+archer_total+heavy_total;
1567
1568 if(total_atac>total_aparare && total_atac>=200){
1569 typeSupporter="off";
1570 nrTroupesSupporter=total_atac;
1571 }
1572 else if(total_aparare>total_atac && total_aparare>=200){
1573 typeSupporter="def";
1574 nrTroupesSupporter=total_aparare;
1575 }
1576 reportInfo.typeSupporter=typeSupporter;
1577 reportInfo.nrTroupesSupporter=nrTroupesSupporter;
1578
1579 if(!tribemates.includes(nameSupporter) && !reportInfo.typeSupporter.includes("?")){
1580 // console.log("supporter")
1581 mapObject.coord=coordSupporter;
1582 mapObject.reportInfo=reportInfo;
1583 listObject.push(mapObject);
1584 }
1585 }
1586 else if(document.getElementsByClassName("unit-item unit-item-axe").length==0 || document.getElementsByClassName("g-recaptcha").length>0
1587 ||document.getElementsByClassName("unit-item unit-item-axe")==undefined || checkContainsCaptcha(document)==true){//recaptcha
1588 console.log("recapthca")
1589 return null;
1590 }
1591
1592 return listObject;
1593 }
1594 catch(e){
1595 console.log("erorr in upload")
1596 console.log(e)
1597 return 0;
1598 }
1599
1600}
1601
1602function checkContainsCaptcha(docOrHtml) {
1603 var foundCaptcha = false;
1604 if (typeof docOrHtml == 'string') {
1605 foundCaptcha = !!docOrHtml.match(/data\-bot\-protect=/);
1606 } else {
1607 let $doc = $(docOrHtml);
1608 let $body = $doc.find('#ds_body');
1609 foundCaptcha = $body.length && !!$body.data('bot-protect')
1610 }
1611
1612 if (foundCaptcha) console.log('Found captcha!');
1613 return foundCaptcha;
1614}
1615
1616function calcDistance(coord1,coord2){
1617 let x1=parseInt(coord1.split("|")[0])
1618 let y1=parseInt(coord1.split("|")[1])
1619 let x2=parseInt(coord2.split("|")[0])
1620 let y2=parseInt(coord2.split("|")[1])
1621
1622 return Math.sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
1623}
1624
1625////////////////////////////////////////////////data compression////////////////////////////////////////////////////////////////////////////
1626function lzw_encode (s) {
1627 if (!s) return s;
1628 var dict = new Map(); // Use a Map!
1629 var data = (s + "").split("");
1630 var out = [];
1631 var currChar;
1632 var phrase = data[0];
1633 var code = 256;
1634 for (var i = 1; i < data.length; i++) {
1635 currChar = data[i];
1636 if (dict.has(phrase + currChar)) {
1637 phrase += currChar;
1638 } else {
1639 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1640 dict.set(phrase + currChar, code);
1641 code++;
1642 if (code === 0xd800) { code = 0xe000; }
1643 phrase = currChar;
1644 }
1645 }
1646 out.push (phrase.length > 1 ? dict.get(phrase) : phrase.codePointAt(0));
1647 for (var i = 0; i < out.length; i++) {
1648 out[i] = String.fromCodePoint(out[i]);
1649 }
1650 //console.log ("LZW MAP SIZE", dict.size, out.slice (-50), out.length, out.join("").length);
1651 return out.join("");
1652}
1653////////////////////////////////////////////////data decompression////////////////////////////////////////////////////////////////////////////
1654function lzw_decode (s) {
1655 var dict = new Map(); // Use a Map!
1656 var data = Array.from(s + "");
1657 //var data = (s + "").split("");
1658 var currChar = data[0];
1659 var oldPhrase = currChar;
1660 var out = [currChar];
1661 var code = 256;
1662 var phrase;
1663 for (var i = 1; i < data.length; i++) {
1664 var currCode = data[i].codePointAt(0);
1665 if (currCode < 256) {
1666 phrase = data[i];
1667 } else {
1668 phrase = dict.has(currCode) ? dict.get(currCode) : (oldPhrase + currChar);
1669 }
1670 out.push(phrase);
1671 var cp = phrase.codePointAt(0);
1672 currChar = String.fromCodePoint(cp); //phrase.charAt(0);
1673 dict.set(code, oldPhrase + currChar);
1674 code++;
1675 if (code === 0xd800) { code = 0xe000; }
1676 oldPhrase = phrase;
1677 }
1678 return out.join("");
1679}
1680///////////////////////////////////////////////////////get request//////////////////////////////////////////////////////////////////////////
1681function httpGet(theUrl){
1682 var xmlHttp = new XMLHttpRequest();
1683 xmlHttp.open( "GET", theUrl, false ); // false for synchronous request
1684 xmlHttp.send( null );
1685 return xmlHttp.responseText;
1686}
1687
1688
1689///////////////////////////////////////////////////////get speed//////////////////////////////////////////////////////////////////////////
1690
1691
1692///////////////////////////////////////////////////////get all incomings//////////////////////////////////////////////////////////////////////////
1693
1694function getIncomings(){
1695 return new Promise( (resolve,reject)=>{
1696
1697 if(document.getElementsByClassName("info").length>0)
1698 $(".info").remove()
1699 var current_href_incomings=window.location.href;
1700 let incomings_href= game_data.link_base_pure+"overview_villages&mode=incomings&type=all&subtype=attacks&group=0&page=-1";
1701
1702 console.log("currentLink")
1703 console.log(incomings_href)
1704 document.body.innerHTML=httpGet(incomings_href);
1705 let list_href=[];
1706 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
1707 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
1708 list_href.push(el.value);
1709 })
1710 list_href.pop();
1711 }
1712 else if(document.getElementsByClassName("paged-nav-item").length>0){
1713 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
1714 for(let i=0;i<arr.length;i++)
1715 list_href.push(arr[i].getAttribute("href"))
1716 }
1717 else{
1718 list_href.push(incomings_href)
1719
1720 }
1721 if(document.getElementById("incomings_table")==null)
1722 throw new Error("you don't have any incomings");
1723
1724 console.log(list_href)
1725 let incomings_data=new Map();
1726
1727
1728 var indexIncoming=1;
1729 var url_length=list_href.length
1730 var start_ajax=new Date();
1731 function ajaxRequest (urls) {
1732 let current_url
1733 var time=0
1734 if(urls.length>0){
1735 current_url=urls.pop()
1736 }
1737 else{
1738 current_url="stop"
1739 }
1740 console.log("length "+urls.length)
1741 // console.log(current_url)
1742
1743 if (urls.length >= 0 && current_url!="stop") {
1744 $.ajax({
1745 url: current_url,
1746 method: 'get',
1747 success: (data) => {
1748 document.body.innerHTML=data
1749 if(document.getElementById("incomings_table")==null)
1750 alert("turn off the filters");
1751 let table_incomings=document.getElementById("incomings_table").getElementsByTagName("tbody")[0].children
1752 for(let i=1;i<table_incomings.length-1;i++){
1753 if(table_incomings[i].children[0].innerText!="--"){
1754 let coord_def=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1755 let coord_off=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
1756 let length_tr=table_incomings[i].children.length
1757 let time_land=table_incomings[i].children[length_tr-2].innerText
1758
1759 let player_off=table_incomings[i].children[length_tr-4].innerText
1760 let player_def=game_data.player.name
1761
1762 let id_player_def=game_data.player.id
1763 let id_player_off=table_incomings[i].children[length_tr-4].getElementsByTagName("a")[0].href.split("id=")[1]
1764
1765 let id_coord_def=table_incomings[i].children[2].getElementsByTagName("a")[0].href.split("village=")[1].split("&")[0]
1766 let id_coord_off=table_incomings[i].children[2].getElementsByTagName("a")[0].href.split("id=")[1]
1767
1768
1769 let server_date=document.getElementById("serverDate").innerText.split("/")
1770 let date_land=getLandTime(time_land)
1771 let labelName="none"
1772 let type_attack=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[0].src.split("command/")[1]
1773 if(table_incomings[i].children[0].getElementsByTagName("img").length==2){
1774 labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src.split("tiny/")[1]
1775 if(labelName==undefined)
1776 labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src.split("command/")[1]
1777
1778 }
1779
1780
1781
1782 // console.log(date_land)
1783 if(!incomings_data.has(coord_off)){
1784 let list=[{
1785 date_land:date_land,
1786 coord_def:coord_def,
1787 coord_off:coord_off,
1788 player_off:player_off,
1789 player_def:player_def,
1790 labelName:labelName,
1791 type_attack:type_attack,
1792 id_player_def:id_player_def,
1793 id_player_off:id_player_off,
1794 id_coord_def:id_coord_def,
1795 id_coord_off:id_coord_off
1796 }]
1797 incomings_data.set(coord_off,list)
1798
1799 }else{
1800 let list=incomings_data.get(coord_off)
1801 list.push({
1802 date_land:date_land,
1803 coord_def:coord_def,
1804 coord_off:coord_off,
1805 player_off:player_off,
1806 player_def:player_def,
1807 labelName:labelName,
1808 type_attack:type_attack,
1809 id_player_def:id_player_def,
1810 id_player_off:id_player_off,
1811 id_coord_def:id_coord_def,
1812 id_coord_off:id_coord_off
1813 })
1814 incomings_data.set(coord_off,list)
1815 }
1816 }
1817 }
1818
1819 UI.InfoMessage(indexIncoming+"/"+url_length)
1820 indexIncoming++;
1821 var stop_ajax=new Date();
1822 var dif_time=stop_ajax.getTime()-start_ajax.getTime()
1823 window.setTimeout(function(){
1824 ajaxRequest (list_href)
1825 },200)
1826 }
1827 })
1828
1829 }
1830 else
1831 {
1832 UI.SuccessMessage("done",2000)
1833 if(document.getElementById("incomings_table")!=null){
1834 // showButtons();
1835 }
1836
1837 if( document.getElementsByClassName("g-recaptcha").length>0){//recaptcha
1838 console.log("recapthca")
1839 UI.ErrorMessage("recapthca, upload again")
1840 resolve(null);
1841 }
1842
1843 window.setTimeout(function(){
1844 document.body.innerHTML=httpGet(current_href_incomings);
1845 console.log(incomings_data)
1846 resolve(incomings_data)
1847 },1000+Math.random()*500)
1848
1849
1850
1851 }
1852 }
1853 if(list_href.length>0)
1854 ajaxRequest(list_href);
1855 else
1856 reject("error on incomings")
1857 })
1858}
1859///////////////////////////////////////////////////////upload all incomings//////////////////////////////////////////////////////////////////////////
1860
1861async function uploadIncomings(){
1862
1863 var [incomings_data, map_incomings_dropbox,mapStatus,status]=await Promise.all([getIncomings(), readFileDropbox(filename_incomings),readFileDropbox(filename_status_upload),insertlibraryLocalBase()]).catch(err=>{alert(err)})
1864 console.log(status)
1865
1866
1867
1868 return new Promise(async(resolve,reject)=>{
1869
1870 //merge map dropbox with map locabase
1871 try {
1872 map_incomings_dropbox=new Map( JSON.parse(lzw_decode(map_incomings_dropbox)));
1873 } catch (error) {
1874 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
1875 map_incomings_dropbox=new Map()
1876 }
1877
1878 //if there database is stored locally
1879 if(await localBase.getItem(game_data.world+"incomings")!=undefined){
1880 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"incomings"))));
1881 console.log("map_localBase",map_localBase)
1882 map_incomings_dropbox=new Map([...map_localBase, ...map_incomings_dropbox])
1883 }
1884
1885
1886
1887
1888
1889 let keys_dropbox=Array.from(map_incomings_dropbox.keys());
1890
1891 let server_date=document.getElementById("serverDate").innerText.split("/")
1892 let server_time=document.getElementById("serverTime").innerText
1893 let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
1894 /////////////////////////////////eliminate old incomings from dropbox////////////////////////////////////
1895 let start=new Date();
1896 keys_dropbox.forEach(el=>{
1897 let list=map_incomings_dropbox.get(el);
1898 let update=false;
1899 for(let i=0;i<list.length;i++){
1900 let date_incomings=new Date(list[i].date_land)
1901 // console.log(date_incomings<current_date)
1902 if(date_incomings<current_date){
1903 list.splice(i,1);
1904 i--;
1905 update=true;
1906 }
1907 if(list[i]==""){
1908 list.splice(i,1);
1909 update=true;
1910 }
1911
1912
1913 }
1914 if(update==true || list.length==0){
1915 if(list.length==0)
1916 map_incomings_dropbox.delete(el);
1917 else{
1918 map_incomings_dropbox.set(el,list);
1919 }
1920 }
1921 })
1922 console.log(map_incomings_dropbox)
1923 let stop=new Date();
1924 console.log(stop-start)
1925
1926 let keys_incomings=Array.from(incomings_data.keys());
1927 keys_incomings.forEach(el=>{
1928 let list=incomings_data.get(el)
1929 if(map_incomings_dropbox.has(el)){//update
1930 let list_dropbox=map_incomings_dropbox.get(el)
1931 list_dropbox=list_dropbox.concat(list);
1932 var list_concat =[...new Map(list_dropbox.map(item => [item["date_land"], item])).values()]
1933 map_incomings_dropbox.set(el,list_concat);
1934 }
1935 else{//add
1936 map_incomings_dropbox.set(el,list);
1937 }
1938 })
1939
1940
1941 let serverTime=document.getElementById("serverTime").innerText
1942 let serverDate=document.getElementById("serverDate").innerText.split("/")
1943 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
1944 let date_current=serverDate+" "+serverTime
1945
1946 //update status map
1947 let obj_status={
1948 name:game_data.player.name,
1949 incoming_date:date_current,
1950 }
1951 if(mapStatus=="[]")
1952 mapStatus=new Map()
1953 else
1954 mapStatus=new Map(JSON.parse(mapStatus))
1955
1956 if(mapStatus.has(game_data.player.id)){
1957 let obj_update=mapStatus.get(game_data.player.id)
1958 mapStatus.set(game_data.player.id, {...obj_update, ...obj_status} )
1959 }
1960 else{
1961 mapStatus.set(game_data.player.id,obj_status)
1962 }
1963
1964
1965
1966
1967
1968
1969
1970 console.log(map_incomings_dropbox)
1971 UI.SuccessMessage("compressing database, wait few seconds",2000)
1972 var data=JSON.stringify(Array.from(map_incomings_dropbox.entries()))
1973 data=replaceSpecialCaracters(data);
1974 data=lzw_encode(data)
1975
1976 console.log("scris in test2")
1977 // document.body.innerHTML=httpGet(current_href_incomings);
1978 addWindow();
1979 showButtons();
1980 document.getElementById("progress_incomings").innerText=incomings_data.size+" coords";
1981 document.getElementById("progress_all").innerText="done";
1982 UI.SuccessMessage("upload incomings done","slow")
1983
1984 let data_status=JSON.stringify(Array.from(mapStatus.entries()))
1985 let resultStatus=await uploadFile(data_status,filename_status_upload,dropboxToken).catch(err=>alert(err))
1986
1987
1988 await localBase.setItem(game_data.world+"incomings",data)
1989 let result=await uploadFile(data,filename_incomings,dropboxToken)
1990 if(result=="succes")
1991 resolve("succes")
1992 else
1993 reject("error")
1994
1995 })
1996}
1997
1998//////////////////////////////////////////////////////upload all data to dropbox/////////////////////////////////////////////////////////////////
1999
2000function uploadFile(data,filename,dropboxToken){
2001 return new Promise((resolve,reject)=>{
2002 var file = new Blob([data], {type: "plain/text"});
2003 var nr_start1=new Date().getTime();
2004 file.name=filename;
2005
2006 //stop refreshing the page
2007 $(document).bind("keydown", disableF5);
2008 window.onbeforeunload = function (e) {
2009 console.log("is uploading");
2010 return "are you sure?";
2011 };
2012
2013 var xhr = new XMLHttpRequest();
2014 xhr.upload.onprogress = function(evt) {
2015 console.log(evt)
2016 var percentComplete = parseInt(100.0 * evt.loaded / evt.total);
2017 console.log(percentComplete)
2018 UI.SuccessMessage("progress upload: "+percentComplete+"%")
2019 };
2020
2021 xhr.onload = function() {
2022 if (xhr.status === 200) {
2023 var fileInfo = JSON.parse(xhr.response);
2024 // Upload succeeded. Do something here with the file info.
2025 UI.SuccessMessage("upload succes")
2026 var nr_stop1=new Date().getTime();
2027 console.log("time upload: "+(nr_stop1-nr_start1))
2028
2029 //enable refresh page
2030 window.onbeforeunload = function (e) {
2031 console.log("done");
2032 };
2033 $(document).unbind("keydown", disableF5);
2034 if(typeof(TWMap) !="undefined" ){
2035 console.log("init map")
2036 TWMap.init();
2037 }
2038 resolve("succes")
2039
2040 }
2041 else {
2042 var errorMessage = xhr.response || 'Unable to upload file';
2043 // Upload failed. Do something here with the error.
2044 UI.SuccessMessage("upload failed")
2045 reject(errorMessage)
2046 }
2047 };
2048
2049 xhr.open('POST', 'https://content.dropboxapi.com/2/files/upload',false);
2050 xhr.setRequestHeader('Authorization', 'Bearer ' + dropboxToken);
2051 xhr.setRequestHeader('Content-Type', 'application/octet-stream');
2052 xhr.setRequestHeader('Dropbox-API-Arg', JSON.stringify({
2053 path: '/' + file.name,
2054 mode: 'add',
2055 autorename: true,
2056 mode:'overwrite',
2057 mute: false
2058 }));
2059
2060 xhr.send(file)
2061 })
2062}
2063
2064function readFileDropbox(filename){
2065 return new Promise((resolve,reject)=>{
2066 $.ajax({
2067 url: "https://content.dropboxapi.com/2/files/download",
2068 method: 'POST',
2069 dataType: "text",
2070 headers: { 'Authorization': 'Bearer ' + dropboxToken,
2071 'Dropbox-API-Arg': JSON.stringify({path: "/"+filename})},
2072
2073 success: (data) => {
2074 resolve(data)
2075 },error: (err)=>{
2076 console.log(err)
2077 reject(err)
2078 }
2079 })
2080 })
2081}
2082
2083
2084function replaceSpecialCaracters(data){
2085 let result=""
2086 for(let i=0;i<data.length;i++){
2087 if(data[i]=="ț")
2088 result+='t'
2089 else if(data[i]=="Ț")
2090 result+="T"
2091 else if(data[i]=="Ă")
2092 result+="A"
2093 else if(data[i]=="ă")
2094 result+="a"
2095 else if(data[i]=="Â")
2096 result+="A"
2097 else if(data[i]=="Ș")
2098 result+="S"
2099 else if(data[i]=="ș")
2100 result+="s"
2101 else if(data[i]=="Î")
2102 result+="I"
2103 else if(data[i]=="î")
2104 result+="i"
2105 else
2106 result+=data[i]
2107 }
2108 return result
2109
2110
2111
2112
2113}
2114
2115function disableF5(e) { if ((e.which || e.keyCode) == 116 || (e.which || e.keyCode) == 82) e.preventDefault(); };
2116
2117
2118//////////////////////////////////////////////////////buttons in incomings page/////////////////////////////////////////////////////////////////
2119
2120
2121function showButtons(){
2122 if(document.getElementById("incomings_table")!=null){
2123 $("#table_incomings").remove();
2124 var incomingshtml=`
2125
2126 <table id="table_incomings" class="" border="1" style="width: 50%;">
2127 <tbody>
2128 <tr>
2129 <td style="text-align:center; width:auto;">
2130 <center style="margin:10px"><u><input class="btn" type="button" onclick="addWindow()"value="open upload"></center>
2131 </td>
2132
2133 <td style="text-align:center; width:auto;">
2134 <center style="margin:10px"><u><input class="btn" type="button" onclick="moreInfo()" value="more info"></center>
2135 </td>
2136 <td style="text-align:center; width:auto;">
2137 <center style="margin:10px"><u><input class="btn" id="btn_tag" type="button" onclick="tagIncomings()" value="tag"></center>
2138 <center style="margin:10px"><u><input class="btn" id="btn_backtime" type="button" value="back time"></center>
2139 <center style="margin:10px"><u><input class="btn" id="btn_senttime" type="button" value="sent time"></center>
2140 </td>
2141 <td style="text-align:center; width:auto;">
2142 <center style="margin:10px"><input class="btn" type="button" onclick="setIntervalIncomings()" value="get incomings"></center>
2143 <center style="margin:10px"><input class="btn" type="button" id="btn_get_fakes" value="get only fakes"></center>
2144 <center style="margin:10px"><input class="btn" type="button" id="btn_get_def" value="get def vills"></center>
2145
2146 <table>
2147 <tr>
2148 <td>pop fake[%]:</td>
2149 <td><input type="number" id="input_pop_fake" value="10" min="0" max="1000" placeholder="[0-100]%" style="text-align:center"></td>
2150 </tr>
2151 <tr hidden>
2152 <td>nr duplicates:</td>
2153 <td><input type="number" id="input_duplicates" value="50" min="0" max="1000" placeholder="50" style="text-align:center"></td>
2154 </tr>
2155 </table>
2156
2157
2158
2159 </td>
2160 <td style="text-align:center; width:auto;">
2161 <center style="margin:10px"><u><input id="btn_highlight" class="btn" type="button" onclick="toggleHighLight()" value="highlight"></center>
2162 </td>
2163 </tr>
2164 </tbody>
2165 </table>
2166 </div>`
2167 // $(".vis").eq(3).append(incomingshtml)
2168 $(".overview_filters").before(incomingshtml)
2169
2170 var link = document.createElement('link');
2171 link.id = "style_popup";
2172 link.rel = 'stylesheet';
2173 link.type = 'text/css';
2174 link.href = 'https://dl.dropboxusercontent.com/s/ki0zhogjf0705c3/style_popup.css';
2175 link.media = 'all';
2176 document.getElementsByTagName('head')[0].appendChild(link);
2177 }
2178
2179
2180 if(document.getElementById("incomings_table")!=null){
2181
2182 //////////////////////////initialize button back time colours
2183 if(localStorage.getItem(game_data.world+"addBacktime")!=null){
2184 let isHighLight=localStorage.getItem(game_data.world+"addBacktime")
2185 if(isHighLight=="true"){
2186 document.getElementById("btn_backtime").classList.add("btn-confirm-yes")
2187 }
2188 else{
2189 document.getElementById("btn_backtime").classList.add("btn-confirm-no")
2190 }
2191
2192 }
2193 else{
2194 localStorage.setItem(game_data.world+"addBacktime","false")
2195 document.getElementById("btn_backtime").classList.remove("btn-confirm-yes")
2196 document.getElementById("btn_backtime").classList.add("btn-confirm-no")
2197 }
2198
2199
2200 //////////////////////////////add event for button back time
2201 $("#btn_backtime").off("click")
2202 $("#btn_backtime").on("click",()=>{
2203 if(document.getElementById("btn_backtime").classList.contains("btn-confirm-yes")){
2204 localStorage.setItem(game_data.world+"addBacktime","false")
2205 document.getElementById("btn_backtime").classList.remove("btn-confirm-yes")
2206 document.getElementById("btn_backtime").classList.add("btn-confirm-no")
2207 }
2208 else{
2209 localStorage.setItem(game_data.world+"addBacktime","true")
2210 document.getElementById("btn_backtime").classList.remove("btn-confirm-no")
2211 document.getElementById("btn_backtime").classList.add("btn-confirm-yes")
2212 }
2213
2214 })
2215
2216
2217
2218 /////////////////////////////initialize button sent time colours
2219 if(localStorage.getItem(game_data.world+"addSentTime")!=null){
2220 let isHighLight=localStorage.getItem(game_data.world+"addSentTime")
2221 if(isHighLight=="true"){
2222 document.getElementById("btn_senttime").classList.add("btn-confirm-yes")
2223 }
2224 else{
2225 document.getElementById("btn_senttime").classList.add("btn-confirm-no")
2226 }
2227
2228 }
2229 else{
2230 localStorage.setItem(game_data.world+"addSentTime","false")
2231 document.getElementById("btn_senttime").classList.remove("btn-confirm-yes")
2232 document.getElementById("btn_senttime").classList.add("btn-confirm-no")
2233 }
2234 ///////////////////////////////////add event for button sent time
2235 $("#btn_senttime").off("click")
2236 $("#btn_senttime").on("click",()=>{
2237 if(document.getElementById("btn_senttime").classList.contains("btn-confirm-yes")){
2238 localStorage.setItem(game_data.world+"addSentTime","false")
2239 document.getElementById("btn_senttime").classList.remove("btn-confirm-yes")
2240 document.getElementById("btn_senttime").classList.add("btn-confirm-no")
2241 }
2242 else{
2243 localStorage.setItem(game_data.world+"addSentTime","true")
2244 document.getElementById("btn_senttime").classList.remove("btn-confirm-no")
2245 document.getElementById("btn_senttime").classList.add("btn-confirm-yes")
2246 }
2247
2248
2249 })
2250 /////////////////////////////initialize button get def village colours
2251 if(localStorage.getItem(game_data.world+"get_def_vills")!=null){
2252 let isHighLight=localStorage.getItem(game_data.world+"get_def_vills")
2253 if(isHighLight=="true"){
2254 document.getElementById("btn_get_def").classList.add("btn-confirm-yes")
2255 }
2256 else{
2257 document.getElementById("btn_get_def").classList.add("btn-confirm-no")
2258 }
2259
2260 }
2261 else{
2262 localStorage.setItem(game_data.world+"get_def_vills","false")
2263 document.getElementById("btn_get_def").classList.remove("btn-confirm-yes")
2264 document.getElementById("btn_get_def").classList.add("btn-confirm-no")
2265 }
2266 ///////////////////////////////////add event for button get def
2267 $("#btn_get_def").off("click")
2268 $("#btn_get_def").on("click",()=>{
2269 if(document.getElementById("btn_get_def").classList.contains("btn-confirm-yes")){
2270 localStorage.setItem(game_data.world+"get_def_vills","false")
2271 document.getElementById("btn_get_def").classList.remove("btn-confirm-yes")
2272 document.getElementById("btn_get_def").classList.add("btn-confirm-no")
2273 }
2274 else{
2275 localStorage.setItem(game_data.world+"get_def_vills","true")
2276 document.getElementById("btn_get_def").classList.remove("btn-confirm-no")
2277 document.getElementById("btn_get_def").classList.add("btn-confirm-yes")
2278 }
2279
2280 })
2281
2282
2283 //////////////////////////initialize button get only fakes colours
2284 if(localStorage.getItem(game_data.world+"get_only_fakes")!=null){
2285 let isHighLight=localStorage.getItem(game_data.world+"get_only_fakes")
2286 if(isHighLight=="true"){
2287 document.getElementById("btn_get_fakes").classList.add("btn-confirm-yes")
2288 }
2289 else{
2290 document.getElementById("btn_get_fakes").classList.add("btn-confirm-no")
2291 }
2292
2293 }
2294 else{
2295 localStorage.setItem(game_data.world+"get_only_fakes","false")
2296 document.getElementById("btn_get_fakes").classList.remove("btn-confirm-yes")
2297 document.getElementById("btn_get_fakes").classList.add("btn-confirm-no")
2298 }
2299 //////////////////////////////////add event for button get only fakes
2300 $("#btn_get_fakes").off("click")
2301 $("#btn_get_fakes").on("click",()=>{
2302 if(document.getElementById("btn_get_fakes").classList.contains("btn-confirm-yes")){
2303 localStorage.setItem(game_data.world+"get_only_fakes","false")
2304 document.getElementById("btn_get_fakes").classList.remove("btn-confirm-yes")
2305 document.getElementById("btn_get_fakes").classList.add("btn-confirm-no")
2306 }
2307 else{
2308 localStorage.setItem(game_data.world+"get_only_fakes","true")
2309 document.getElementById("btn_get_fakes").classList.remove("btn-confirm-no")
2310 document.getElementById("btn_get_fakes").classList.add("btn-confirm-yes")
2311 }
2312
2313 })
2314
2315 let value=localStorage.getItem(game_data.world+"pop_fake_tagging")
2316 if(value!=null){
2317 document.getElementById("input_pop_fake").value=parseFloat(value)
2318 }
2319 $("#input_pop_fake").on("mouseout",()=>{
2320 localStorage.setItem(game_data.world+"pop_fake_tagging", document.getElementById("input_pop_fake").value)
2321 })
2322
2323
2324 value=localStorage.getItem(game_data.world+"duplicates_fake_tagging")
2325 if(value!=null){
2326 document.getElementById("input_duplicates").value=parseFloat(value)
2327 }
2328 $("#input_duplicates").on("mouseout",()=>{
2329 localStorage.setItem(game_data.world+"duplicates_fake_tagging", document.getElementById("input_duplicates").value)
2330 })
2331
2332
2333
2334 }
2335
2336
2337
2338}
2339showButtons();
2340
2341//////////////////////////////////////////////////////show info in incomings page/////////////////////////////////////////////////////////////////
2342
2343async function moreInfo(){
2344 $("#div_container").remove();
2345 $(".deleteTh").remove();
2346
2347 console.log("inainte")
2348 var [map_reports_dropbox, map_incomings_dropbox,status]=await Promise.all([readFileDropbox(filename_reports), readFileDropbox(filename_incomings),insertlibraryLocalBase()]).catch(err=>{alert(err)})
2349 console.log(status)
2350 /////////merge maps for reports
2351 try {
2352 map_reports_dropbox=new Map( JSON.parse(lzw_decode(map_reports_dropbox)));
2353 } catch (error) {
2354 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
2355 map_reports_dropbox=new Map()
2356 }
2357 //if there database is stored locally
2358 if(await localBase.getItem(game_data.world+"reports")!=undefined){
2359 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"reports"))));
2360 console.log("map_localBase",map_localBase)
2361 map_reports_dropbox=new Map([...map_localBase, ...map_reports_dropbox])
2362 }
2363
2364
2365 /////////merge maps for incomings
2366 try {
2367 map_incomings_dropbox=new Map( JSON.parse(lzw_decode(map_incomings_dropbox)));
2368 } catch (error) {
2369 console.log("erorrrrrrrrrrrrrrrr map incomings from dropbox")
2370 map_incomings_dropbox=new Map()
2371 }
2372 //if there database is stored locally
2373 if(await localBase.getItem(game_data.world+"incomings")!=undefined){
2374 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"incomings"))));
2375 console.log("map_localBase",map_localBase)
2376 map_incomings_dropbox=new Map([...map_localBase, ...map_incomings_dropbox])
2377 }
2378
2379
2380
2381
2382
2383
2384 UI.SuccessMessage("get data",1000)
2385 console.log("get incomings")
2386 $(".tr_delimitator").remove();
2387 console.log(map_incomings_dropbox)
2388 if(document.getElementsByClassName("info").length>0)
2389 $(".info").remove()
2390 else{
2391 let start=new Date();
2392
2393
2394 // let table=document.getElementById("incomings_table").lastElementChild.children
2395 let incomings_table=document.getElementById("incomings_table").cloneNode(true)
2396 let table=incomings_table.lastElementChild.children
2397 let list=[];
2398 let map_nr_atacuri=new Map();
2399 let map_nr_destination=new Map();
2400
2401 //adaugare o noua coloana
2402 let coloana_nr=table[0].insertCell(3);
2403 coloana_nr.outerHTML="<th class='deleteTh'><a href=# id='id_nr'> nr</a></th>";
2404 coloana_nr.className="info"
2405
2406 let coloana_tribe=table[0].insertCell(4);
2407 coloana_tribe.outerHTML="<th class='deleteTh'><a href=# id='id_nr_tr'> nr_tribe</a></th>";
2408 coloana_tribe.className="info"
2409
2410 let coloana_type=table[0].insertCell(5);
2411 coloana_type.outerHTML="<th class='deleteTh'><a href=# id='id_type'> type</a></th>";
2412 coloana_type.className="info"
2413
2414 let coloana_pop=table[0].insertCell(6);
2415 coloana_pop.outerHTML="<th class='deleteTh'><a href=# id='id_pop'>pop</a></th>";
2416 coloana_pop.className="info"
2417
2418 let coloana_time=table[0].insertCell(7);
2419 coloana_time.outerHTML="<th class='deleteTh'><a href=# id='id_time'>time</a></th>";
2420 coloana_time.className="info"
2421
2422 let coloana_report=table[0].insertCell(8);
2423 coloana_report.outerHTML="<th class='deleteTh'><a href=# id='id_report'>report</a></th>";
2424 coloana_report.className="info"
2425
2426 var list_coord_player=[]
2427 for(let i=1;i<table.length-1;i++){
2428 let coord=table[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
2429 let coord_destination=table[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
2430 let player_id=table[i].children[table[i].children.length-4].children[0].href.split("player&id=")[1]
2431 list_coord_player.push({
2432 coord:coord,
2433 player_id:player_id
2434 })
2435 //origin coord
2436 if(map_nr_atacuri.has(coord))
2437 map_nr_atacuri.set(coord,parseInt(map_nr_atacuri.get(coord)) +1);
2438 else
2439 map_nr_atacuri.set(coord,1);
2440 //destination coord
2441 if(map_nr_destination.has(coord_destination))
2442 map_nr_destination.set(coord_destination,parseInt(map_nr_destination.get(coord_destination)) +1);
2443 else
2444 map_nr_destination.set(coord_destination,1);
2445 }
2446 var stop=new Date();
2447 console.log("add info: "+(stop-start))
2448
2449 for(let i=1;i<table.length-1;i++){
2450 var html_nr="?"
2451 var html_nr_tribe="<center>0</center>"
2452 var html_type="?"
2453 var html_pop="?"
2454 var html_time="?"
2455 var html_report="?"
2456
2457 var length_tr=table[i].children.length
2458 let coord=list_coord_player[i-1].coord
2459 let player_id=list_coord_player[i-1].player_id
2460 let coord_destination=table[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
2461 let duplicate_destination=map_nr_destination.get(coord_destination)
2462 table[i].children[1].setAttribute("data-nr",duplicate_destination)
2463
2464
2465 html_nr="<h4>"+map_nr_atacuri.get(coord)+"</h4>";
2466
2467
2468 if(map_incomings_dropbox.has(coord)){
2469 let list_incomings=map_incomings_dropbox.get(coord)
2470 // html_nr_tribe=" <center><h4 style='color:black'>"+list_incomings.length+"</h4></center>";
2471 console.log(list_incomings)
2472 list_incomings.sort((o1,o2)=>{
2473 return (new Date(o1.date_land).getTime()<new Date(o2.date_land).getTime())?1:
2474 (new Date(o1.date_land).getTime()>new Date(o2.date_land).getTime())?-1:0
2475 })
2476 html_nr_tribe=`
2477 <div class="popup" onclick='var popup = document.getElementById("tableInc`+i+`");popup.classList.toggle("show")'><center><h4 style='color:black'>${list_incomings.length}</h4></center>
2478 <table class="popuptext" border="1" style="background-color:#f4e4bc;border-color:#c1a264" id="tableInc`+i+'"'+
2479 createTableIncomings(list_incomings)+
2480 '</table></div>';
2481
2482
2483
2484
2485 }
2486 if(map_reports_dropbox.has(coord) )
2487 {
2488 let idPlayer_dropbox
2489 let type_dropbox
2490 let nr_troupes_dropbox
2491
2492 var obj=map_reports_dropbox.get(coord);
2493 var traveling=false
2494 if(coord == obj.coordAttacker){
2495 idPlayer_dropbox=obj.attackingPlayerId;
2496 type_dropbox=obj.typeAttacker;
2497 nr_troupes_dropbox=obj.nrTroupesAttacker
2498 traveling=true;
2499 }
2500 else if(coord == obj.coordDefender){
2501 idPlayer_dropbox=obj.defendingPlayerId;
2502 type_dropbox=obj.typeDefender;
2503 nr_troupes_dropbox=obj.nrTroupesDefender
2504 traveling=false;
2505 }
2506 else{
2507 idPlayer_dropbox=obj.supporterPlayerId
2508 type_dropbox=obj.typeSupporter;
2509 nr_troupes_dropbox=obj.nrTroupesSupporter
2510 }
2511
2512 if(idPlayer_dropbox == player_id)
2513 {
2514 let date_start=new Date(obj.time_report);
2515 let date_stop=new Date();
2516 let days=("00"+parseInt((date_stop-date_start)/(24*3600*1000))).slice(-3);
2517 let hours=("0"+parseInt((date_stop-date_start)/(3600*1000)%24)).slice(-2);
2518 let minutes=("0"+parseInt(((date_stop-date_start)/(60*1000)%60))).slice(-2);
2519 let seconds=( "0"+parseInt((((date_stop-date_start)/1000)%60))).slice(-2);
2520
2521 //calculate population
2522 let date_landing_report=new Date(obj.time_report)
2523 let distance=parseFloat(table[i].children[length_tr-3].innerText);
2524 let time_attack=0;
2525 let time_land=table[i].children[length_tr-2].innerText
2526 let date_land=new Date(getLandTime(time_land))
2527 let labelName=""
2528 if(table[i].children[0].getElementsByTagName("img")[1]==undefined || table[i].children[0].getElementsByTagName("img")[1]==null )
2529 labelName="ram.png"
2530 else
2531 labelName=table[i].children[0].getElementsByTagName("img")[1].src
2532
2533 if(labelName.includes("snob.png")){
2534 time_attack=nobleSpeed*distance
2535 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
2536 time_attack=ramSpeed*distance
2537 }else if(labelName.includes("sword.png")){
2538 time_attack=swordSpeed*distance
2539 }else if(labelName.includes("axe.png")){
2540 time_attack=axeSpeed *distance
2541 }
2542 if(traveling==false)
2543 time_attack=0;
2544
2545 if(type_dropbox=="off"){
2546 // console.log(date_land.getTime())
2547 // console.log(time_attack)
2548 // console.log(date_landing_report.getTime())
2549 let timeForRecruiting = (date_land.getTime()-time_attack)-date_landing_report.getTime()
2550 nr_troupes_dropbox=calcProductionTroupes(timeForRecruiting,nr_troupes_dropbox)
2551 nr_troupes_dropbox=Math.round(nr_troupes_dropbox*10)/10+"%"
2552 // console.log("final "+nr_troupes_dropbox)
2553 }
2554 else{
2555 nr_troupes_dropbox="?"
2556 }
2557
2558
2559 html_type=" <h4 class='cls_type'>"+type_dropbox+"</h4>"
2560 html_pop=" <h4 class='cls_pop'>"+nr_troupes_dropbox+"</h4>"
2561 if(obj.time_return==0 || obj.time_return==undefined){
2562 html_time=" <h4>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
2563 }
2564 else{
2565 html_time=" <h4 class='possible_fake' date-fake='"+obj.time_return+"'>"+days+":"+hours+":"+minutes+":"+seconds+"</h4>";
2566 }
2567
2568 // createTableIncomings
2569 // console.log(obj)
2570 html_report=`
2571 <div class="popup" onclick='var popup = document.getElementById("table`+i+`");popup.classList.toggle("show")'><h4>show</h4>
2572 <table class="popuptext" style="background-color:#f4e4bc" id="table`+i+'"'+
2573 createReport(obj)+
2574 '</table></div>';
2575 }
2576 }
2577 coloana_nr=table[i].insertCell(3);
2578 coloana_nr.innerHTML=html_nr
2579 coloana_nr.className="info test"
2580
2581 coloana_tribe=table[i].insertCell(4);
2582 coloana_tribe.innerHTML=html_nr_tribe
2583 coloana_tribe.className="info"
2584
2585 coloana_type=table[i].insertCell(5);
2586 coloana_type.innerHTML=html_type
2587 coloana_type.className="info"
2588
2589 coloana_pop=table[i].insertCell(6);
2590 coloana_pop.innerHTML=html_pop
2591 coloana_pop.className="info"
2592
2593 coloana_time=table[i].insertCell(7);
2594 coloana_time.innerHTML=html_time
2595 coloana_time.className="info"
2596
2597 coloana_report=table[i].insertCell(8);
2598 coloana_report.innerHTML=html_report
2599 coloana_report.className="info"
2600 }
2601 console.log(incomings_table)
2602 $("#incomings_table tbody tr").remove()
2603 $("#incomings_table tbody").append(table)
2604 sortIncomings();
2605 highLightIncomings();
2606 counterTime();
2607 var stop=new Date();
2608 console.log("add inf final: "+(stop-start))
2609
2610
2611 $('document').ready(function() {
2612 CommandsOverview.init();
2613 UI.ToolTip('.icon_village_notes');
2614
2615 $('.quickedit').QuickEdit({url: TribalWars.buildURL('POST', 'info_command', {ajaxaction: 'edit_other_comment', id: '__ID__'})});
2616 Command.init();
2617 });
2618
2619
2620 }
2621
2622
2623}
2624
2625//////////////////////////////////////////////////////sort incomings by.. /////////////////////////////////////////////////////////////////
2626
2627function sortIncomings()
2628{
2629 var table=document.getElementById("incomings_table").lastElementChild.children;
2630 var new_table=document.getElementById("incomings_table").lastElementChild;
2631 var last_row=table[table.length-1];
2632 var list=[];
2633 var list_info=[]
2634 for(let i=1;i<table.length-1;i++){
2635 if(table[i].classList.contains("row_a")){
2636 table[i].classList.remove("row_a")
2637 table[i].classList.add("row_b")
2638 }
2639 if(table[i].classList.contains("selected")){
2640 table[i].classList.remove("selected")
2641 }
2642
2643 list.push(table[i]);
2644 }
2645 var length_table=1
2646 if(table.length>2){
2647 length_table=table[1].children.length
2648 }
2649
2650
2651 //sort by nr
2652 document.getElementById("id_nr").addEventListener("click",function()
2653 {
2654 var start=new Date();
2655 $(".tr_delimitator").remove();
2656 list.sort( (a,b)=>{
2657 return (parseInt(a.children[3].innerText)<parseInt(b.children[3].innerText))?1:(parseInt(a.children[3].innerText)>parseInt(b.children[3].innerText))?-1:
2658 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2659 });
2660
2661
2662 //add new table in page
2663 for(let i=0;i<list.length;i++)
2664 {
2665 new_table.appendChild(list[i]);
2666 }
2667 new_table.appendChild(last_row);
2668
2669 for(let i=0;i<list.length;i++)
2670 {
2671 list_info.push({
2672 coord_attacker:list[i].children[2].innerText,
2673 nr:parseInt(list[i].children[3].innerText),
2674 })
2675 }
2676 var pozitie=2;
2677 for(let i=0;i<list.length-1;i++)
2678 {
2679 let nr_atacuri=list_info[i].nr
2680 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
2681 {
2682 var tableRef = document.getElementById("incomings_table").lastElementChild;
2683 var newRow = tableRef.insertRow(pozitie);
2684 newRow.className="tr_delimitator"
2685 for(let i=0; i<1;i++){
2686 let cell = newRow.insertCell();
2687 cell.setAttribute("colspan",length_table)
2688 cell.classList.add("selected")
2689 var delimitator = document.createTextNode('--');
2690 cell.appendChild(delimitator);
2691
2692 }
2693 pozitie++;
2694 }
2695 else if(nr_atacuri==1){
2696 break;
2697 }
2698 pozitie++;
2699 }
2700 list_info=[]
2701 var stop=new Date();
2702 console.log(stop-start)
2703 })
2704
2705 //sort by nr tribe
2706 document.getElementById("id_nr_tr").addEventListener("click",function()
2707 {
2708 var start=new Date();
2709
2710 $(".tr_delimitator").remove();
2711 list.sort( (a,b)=>{
2712 return (parseInt(a.children[4].innerText)<parseInt(b.children[4].innerText))?1:(parseInt(a.children[4].innerText)>parseInt(b.children[4].innerText))?-1:
2713 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2714 });
2715
2716
2717 //add new table in page
2718 for(let i=0;i<list.length;i++)
2719 {
2720 new_table.appendChild(list[i]);
2721 }
2722 new_table.appendChild(last_row);
2723
2724 for(let i=0;i<list.length;i++)
2725 {
2726 list_info.push({
2727 coord_attacker:list[i].children[2].innerText,
2728 nr:parseInt(list[i].children[4].innerText),
2729 })
2730 }
2731 var pozitie=2;
2732 for(let i=0;i<list.length-1;i++)
2733 {
2734 let nr_atacuri=list_info[i].nr
2735 if(nr_atacuri>1 && list_info[i].coord_attacker !=list_info[i+1].coord_attacker)
2736 {
2737 var tableRef = document.getElementById("incomings_table").lastElementChild;
2738 var newRow = tableRef.insertRow(pozitie);
2739 newRow.className="tr_delimitator"
2740 for(let i=0; i<1;i++){
2741 let cell = newRow.insertCell();
2742 cell.setAttribute("colspan",length_table)
2743 cell.classList.add("selected")
2744 var delimitator = document.createTextNode('--');
2745 cell.appendChild(delimitator);
2746
2747 }
2748 pozitie++;
2749 }
2750 else if(nr_atacuri==1){
2751 break;
2752 }
2753 pozitie++;
2754 }
2755 list_info=[]
2756 var stop=new Date();
2757 console.log(stop-start)
2758 })
2759
2760
2761 //sort by type
2762 document.getElementById("id_type").addEventListener("click",function()
2763 {
2764 var start=new Date();
2765 $(".tr_delimitator").remove();
2766 list.sort( (a,b)=>{
2767 return (a.children[5].innerText<b.children[5].innerText)?1:(a.children[5].innerText>b.children[5].innerText)?-1:
2768 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2769 });
2770
2771 //add new table in page
2772 for(let i=0;i<list.length;i++)
2773 {
2774 new_table.appendChild(list[i]);
2775 }
2776 new_table.appendChild(last_row);
2777
2778 var pozitie=2;
2779 for(let i=0;i<list.length-1;i++)
2780 {
2781 let type=list[i].children[5].innerText;
2782 if(type!="?" && list[i].children[5].innerText !=list[i+1].children[5].innerText)
2783 {
2784 var tableRef = document.getElementById("incomings_table").lastElementChild;
2785 var newRow = tableRef.insertRow(pozitie);
2786 newRow.className="tr_delimitator"
2787 for(let i=0; i<1;i++){
2788 let cell = newRow.insertCell();
2789 cell.setAttribute("colspan",length_table)
2790 cell.classList.add("selected")
2791 var delimitator = document.createTextNode('--');
2792 cell.appendChild(delimitator);
2793 }
2794 pozitie++;
2795 }
2796 pozitie++;
2797 }
2798 list_info=[]
2799 var stop=new Date();
2800 console.log(stop-start)
2801 })
2802
2803 //sort by nr pop
2804 document.getElementById("id_pop").addEventListener("click",function()
2805 {
2806 var start=new Date();
2807 console.log("aici baaaa")
2808 console.log($(".tr_delimitator"))
2809 $(".tr_delimitator").remove();
2810 list.sort( (a,b)=>{
2811 if(a.children[6].innerText=="?")
2812 var a_comp=2000000;
2813 else
2814 var a_comp=parseFloat(a.children[6].innerText);
2815
2816 if(b.children[6].innerText=="?")
2817 var b_comp=2000000;
2818 else
2819 var b_comp=parseFloat(b.children[6].innerText);
2820
2821 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
2822 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2823 });
2824
2825 //add new table in page
2826 for(let i=0;i<list.length;i++)
2827 {
2828 new_table.appendChild(list[i]);
2829 }
2830 list_info=[]
2831 new_table.appendChild(last_row);
2832
2833 let pozitie=1
2834 for(let i=0;i<list.length;i++)
2835 {
2836 console.log(i)
2837 if(i%4==0 && i>0){
2838 console.log("inside "+i)
2839 var tableRef = document.getElementById("incomings_table").lastElementChild;
2840 var newRow = tableRef.insertRow(pozitie);
2841 newRow.className="tr_delimitator"
2842 for(let i=0; i<1;i++){
2843 let cell = newRow.insertCell();
2844 cell.setAttribute("colspan",length_table)
2845 cell.classList.add("selected")
2846 var delimitator = document.createTextNode('--');
2847 cell.appendChild(delimitator);
2848 }
2849 pozitie++;
2850
2851 }
2852 pozitie++;
2853 }
2854
2855
2856
2857
2858 var stop=new Date();
2859 console.log(stop-start)
2860 })
2861
2862 //sort by time
2863 document.getElementById("id_time").addEventListener("click",function()
2864 {
2865 var start=new Date();
2866
2867 $(".tr_delimitator").remove();
2868
2869 list.sort( (a,b)=>{
2870 if(a.children[7].innerText=="?")
2871 var a_comp=10000000000;
2872 else{
2873 var v=a.children[7].innerText.split(":");
2874 var a_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
2875 }
2876
2877 if(b.children[7].innerText=="?")
2878 var b_comp=10000000000;
2879 else{
2880 var v=b.children[7].innerText.split(":");
2881 var b_comp=parseInt(v[0])*24*3600+parseInt(v[1])*3600 +parseInt(v[2])*60 +parseInt(v[3]);
2882 }
2883
2884 return (a_comp>b_comp)?1:(a_comp<b_comp)?-1:
2885 (a.children[2].innerText<b.children[2].innerText) ? 1: (a.children[2].innerText>b.children[2].innerText)?-1:0;
2886 });
2887
2888 //add new table in page
2889 for(let i=0;i<list.length;i++)
2890 {
2891 new_table.appendChild(list[i]);
2892 }
2893 list_info=[]
2894 new_table.appendChild(last_row);
2895
2896 let pozitie=1
2897 for(let i=0;i<list.length;i++)
2898 {
2899 console.log(i)
2900 if(i%4==0 && i>0){
2901 console.log("inside "+i)
2902 var tableRef = document.getElementById("incomings_table").lastElementChild;
2903 var newRow = tableRef.insertRow(pozitie);
2904 newRow.className="tr_delimitator"
2905 for(let i=0; i<1;i++){
2906 let cell = newRow.insertCell();
2907 cell.setAttribute("colspan",length_table)
2908 cell.classList.add("selected")
2909 var delimitator = document.createTextNode('--');
2910 cell.appendChild(delimitator);
2911 }
2912 pozitie++;
2913
2914 }
2915 pozitie++;
2916 }
2917
2918
2919 var stop=new Date();
2920 console.log(stop-start)
2921 })
2922
2923 //sort by coord destination
2924 var destination_th=document.getElementById("incomings_table").lastElementChild.children[0].children[1]
2925 destination_th=destination_th.getElementsByTagName("a")[0]
2926 destination_th.outerHTML="<a href='#' id='nr_dest'>"+destination_th.innerHTML+"</a>"
2927
2928 document.getElementById("nr_dest").addEventListener("click",function()
2929 {
2930 console.log("aici")
2931 var start=new Date();
2932 let lengthTr=list[0].children.length
2933 $(".tr_delimitator").remove();
2934 list.sort( (a,b)=>{
2935 return (new Date(getLandTime(a.children[lengthTr-2].innerText)).getTime()>new Date(getLandTime(b.children[lengthTr-2].innerText)).getTime())?1:
2936 (new Date(getLandTime(a.children[lengthTr-2].innerText)).getTime()<new Date(getLandTime(b.children[lengthTr-2].innerText)).getTime())?-1:0
2937 })
2938 list.sort( (a,b)=>{
2939 return (parseInt(a.children[1].getAttribute("data-nr"))<parseInt(b.children[1].getAttribute("data-nr")))?1:
2940 (parseInt(a.children[1].getAttribute("data-nr"))>parseInt(b.children[1].getAttribute("data-nr")))?-1:
2941 (a.children[1].innerText<b.children[1].innerText) ? 1: (a.children[1].innerText>b.children[1].innerText)?-1:0;
2942 });
2943
2944
2945 //add new table in page
2946 for(let i=0;i<list.length;i++)
2947 {
2948 new_table.appendChild(list[i]);
2949 }
2950 new_table.appendChild(last_row);
2951 //
2952 for(let i=0;i<list.length;i++)
2953 {
2954 list_info.push({
2955 coord_deff:list[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0],
2956 nr:parseInt(list[i].children[1].getAttribute("data-nr")),
2957 id_coord:list[i].children[1].children[0].href.split("village=")[1].split("&")[0]
2958 })
2959 }
2960 console.log(list_info)
2961
2962 //add delimiter on the first row
2963 var tableRef = document.getElementById("incomings_table").lastElementChild;
2964 var newRow = tableRef.insertRow(1);
2965 newRow.className="tr_delimitator"
2966 let cell = newRow.insertCell();
2967
2968 cell.setAttribute("colspan",length_table)
2969 cell.classList.add("selected")
2970 var delimitator = document.createElement("button")
2971 delimitator.innerText="load: ("+list_info[0].coord_deff+")"
2972 delimitator.setAttribute("data-id",list_info[0].id_coord)
2973 delimitator.setAttribute("data-nr",list_info[0].nr)
2974 delimitator.style.margin="10px"
2975 delimitator.classList.add("btn","load_troops")
2976 cell.appendChild(delimitator);
2977
2978 //add delimiter after each village destination
2979 var pozitie=3;
2980 for(let i=0;i<list.length-1;i++)
2981 {
2982 if(list_info[i].coord_deff !=list_info[i+1].coord_deff)
2983 {
2984 var tableRef = document.getElementById("incomings_table").lastElementChild;
2985 var newRow = tableRef.insertRow(pozitie);
2986 newRow.className="tr_delimitator"
2987 let cell = newRow.insertCell();
2988
2989 cell.setAttribute("colspan",length_table)
2990 cell.classList.add("selected")
2991 var delimitator = document.createElement("button")
2992 delimitator.innerText="load: ("+list_info[i+1].coord_deff+")"
2993 delimitator.setAttribute("data-id",list_info[i+1].id_coord)
2994 delimitator.setAttribute("data-nr",list_info[i+1].nr)
2995 delimitator.style.margin="10px"
2996 delimitator.classList.add("btn","load_troops")
2997 cell.appendChild(delimitator);
2998
2999
3000 pozitie++;
3001 }
3002 pozitie++;
3003 }
3004 list_info=[]
3005 var stop=new Date();
3006 console.log(stop-start)
3007 eventGetTroops();
3008 })
3009
3010
3011}
3012
3013//////////////////////////////////////////////////////tag incomings /////////////////////////////////////////////////////////////////
3014function tagIncomings(){
3015
3016 if(document.getElementsByClassName("info").length==0){
3017 UI.ErrorMessage("press first the button 'more info'!")
3018 }
3019 else{
3020 $("#btn_tag").attr('disabled', true);
3021 $(".tr_delimitator").remove();
3022 let csrf = window.csrf_token;
3023 var list_incomings_href=[]
3024 var indexIncoming=1;
3025 var table_incomings=document.getElementById("incomings_table").children[1].children
3026
3027 var nobleSpeed=2100*1000/(speedWorld*speedTroupes)//ms
3028 var ramSpeed=1800*1000/(speedWorld*speedTroupes)//ms
3029 var swordSpeed=1260*1000/(speedWorld*speedTroupes)//ms
3030 var axeSpeed=1080*1000/(speedWorld*speedTroupes)//ms
3031 console.log("constant world",speedWorld*speedTroupes)
3032
3033
3034
3035 let list_incomingId=[]
3036 let listTdRename=[]
3037 for(let i=1;i<table_incomings.length-1;i++){
3038 let incomingId=table_incomings[i].children[0].children[2].getAttribute("data-id");
3039 let coordDest=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
3040 let coordOrigin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
3041
3042 let href=window.location.href.split("&")[0]+`&screen=info_command&ajaxaction=edit_other_comment&id=${incomingId}&h=${csrf}`
3043 let current_tag=table_incomings[i].children[0].innerText.trim()
3044 var nameTroupe=table_incomings[i].children[0].innerText.trim().split(/\s+/)[0];
3045 let nr=parseInt(table_incomings[i].children[3].innerText);
3046 let nr_tribe=table_incomings[i].children[4].innerText;
3047 let type=table_incomings[i].children[5].innerText;
3048 let pop= (table_incomings[i].children[6].innerText !="?")?parseInt(table_incomings[i].children[6].innerText):"?"
3049 let time=table_incomings[i].children[7].innerText;
3050 let length_tr=table_incomings[i].children.length
3051 let nameAttacker=table_incomings[i].children[length_tr-4].innerText
3052 ////////////////////////////////get land time///////////////////////////////
3053 let time_land=table_incomings[i].children[length_tr-2].innerText
3054 let date_land=getLandTime(time_land)
3055 let fake=false;
3056
3057 list_incomingId.push(incomingId)
3058
3059 let backtime="none"
3060 let sentTime="none"
3061 if(table_incomings[i].getElementsByClassName("possible_fake").length>0 && table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img").length==2){
3062 let date_home=new Date(table_incomings[i].getElementsByClassName("possible_fake")[0].getAttribute("date-fake"))
3063 let distance=calcDistance(coordOrigin,coordDest);
3064 let labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src
3065 let time_attack=0;
3066 if(labelName.includes("snob.png")){
3067 time_attack=nobleSpeed*distance
3068 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
3069 time_attack=ramSpeed*distance
3070 }else if(labelName.includes("sword.png")){
3071 time_attack=swordSpeed*distance
3072 }else if(labelName.includes("axe.png")){
3073 time_attack=axeSpeed *distance
3074 }
3075
3076 let dateLand=new Date(date_land)
3077
3078 time_attack=Math.round(time_attack/1000)*1000
3079 backtime = parseDate(dateLand.getTime()+time_attack)
3080 sentTime = parseDate(dateLand.getTime()-time_attack)
3081
3082
3083 console.log("time_attack",time_attack)
3084 if(time_attack+date_home.getTime()>dateLand.getTime() ){
3085 fake=true;
3086 console.log("fake from "+coordOrigin)
3087 }
3088 var days=parseInt(time.split(":")[0])*24*3600*1000
3089 var hours=parseInt(time.split(":")[1])*3600*1000
3090 var min=parseInt(time.split(":")[2])*60*1000
3091 var sec=parseInt(time.split(":")[3])*1000
3092 var total_time=days+hours+min+sec-time_attack
3093 if(fake==true){
3094 time=total_time/(24*3600*1000)
3095 time+=":00:00:00"
3096 }
3097 }
3098 else if(table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img").length==2){
3099 let distance=calcDistance(coordOrigin,coordDest);
3100 let labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src
3101 let time_attack=0;
3102
3103 if(labelName.includes("snob.png")){
3104 time_attack=nobleSpeed*distance
3105 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
3106 time_attack=ramSpeed*distance
3107 console.log("distance",distance)
3108 console.log("ramSpeed",ramSpeed)
3109 }else if(labelName.includes("sword.png")){
3110 time_attack=swordSpeed*distance
3111 }else if(labelName.includes("axe.png")){
3112 time_attack=axeSpeed *distance
3113 }
3114 time_attack=Math.round(time_attack/1000)*1000
3115 console.log("time_attack",time_attack)
3116
3117 let dateLand=new Date(date_land)
3118 backtime = parseDate(dateLand.getTime()+time_attack)
3119 sentTime = parseDate(dateLand.getTime()-time_attack)
3120 }
3121
3122
3123 let obj={
3124 incomingId:incomingId,
3125 coordOrigin:coordOrigin,
3126 href:href,
3127 nameTroupe:nameTroupe,
3128 nr:nr,
3129 nr_tribe:nr_tribe,
3130 type:type,
3131 pop:pop,
3132 time:time,
3133 nameAttacker:nameAttacker,
3134 fake:fake,
3135 current_tag:current_tag,
3136 backtime:backtime,
3137 sentTime:sentTime,
3138 }
3139 if( !table_incomings[i].children[0].innerText.toLowerCase().includes('"')){//!table_incomings[i].children[0].innerText.toLowerCase().includes(lang["dcfafcb4323b102c7e204555d313ba0a"].toLowerCase()) &&
3140
3141 list_incomings_href.push(obj)
3142 }
3143
3144
3145 listTdRename.push(table_incomings[i].children[0])
3146
3147 }
3148
3149
3150 console.log(listTdRename)
3151 let table_commands=document.getElementById("incomings_table")
3152 let length_columns=table_commands.getElementsByTagName("tbody")[0].children[0].children.length
3153 let lastRow=table_commands.getElementsByTagName("tbody")[0].children[listTdRename.length+1]
3154 $(table_commands).find(".row_a, .row_b").remove()
3155
3156 for(let i=0;i<listTdRename.length;i++){
3157 $(table_commands).append(`<tr class="nowrap row_ax"><td colspan="${length_columns}"> ${listTdRename[i].innerHTML} </td></tr>`)
3158
3159 }
3160 $(table_commands).append(lastRow)
3161
3162
3163 list_incomings_href=list_incomings_href.reverse();
3164
3165
3166
3167
3168 var url_length=list_incomings_href.length
3169 var start_tagging=new Date()
3170 function ajaxRequest (urls) {
3171 let current_url
3172 let labelInfo=""
3173 let current_tag
3174 let obj=null
3175 if(urls.length>0){
3176 obj=urls.pop()
3177 current_url=obj.href;
3178 labelInfo=obj.nameTroupe;
3179 current_tag=obj.current_tag;
3180 let nr
3181 if(obj.nr_tribe=="?")
3182 nr=parseInt(obj.nr)
3183 else{
3184 nr=Math.max(parseInt(obj.nr), parseInt(obj.nr_tribe) )
3185 }
3186
3187 let backtimeLabel=", [BT]: "+obj.backtime
3188 if(localStorage.getItem(game_data.world+"addBacktime")=="false"){
3189 backtimeLabel=""
3190 }
3191
3192 let sentTimeLabel=", [SENT]: "+obj.sentTime
3193 if(localStorage.getItem(game_data.world+"addSentTime")=="false"){
3194 sentTimeLabel=""
3195 }
3196
3197
3198 if(obj.type!="?"){
3199 obj.time=parseInt(obj.time.split(":")[0]);
3200
3201 if(obj.nr==20000)
3202 labelInfo=labelInfo+" "+obj.nameAttacker+", "+nr+", "+obj.type +backtimeLabel+sentTimeLabel;
3203 else if(obj.type=="new_off")
3204 labelInfo=labelInfo+" "+obj.nameAttacker+", "+nr+", off"+backtimeLabel+sentTimeLabel;
3205 else if(obj.type.includes("def"))
3206 labelInfo=labelInfo+" "+obj.nameAttacker+", "+nr+", "+obj.type+", "+obj.time+"d"+backtimeLabel+sentTimeLabel;
3207 else
3208 labelInfo=labelInfo+" "+obj.nameAttacker+", "+nr+", "+obj.type+", "+obj.pop+"% "+obj.time+"d"+backtimeLabel+sentTimeLabel;
3209
3210
3211
3212
3213 }
3214 else{
3215 labelInfo=labelInfo+" "+obj.nameAttacker+", "+nr+backtimeLabel+sentTimeLabel;
3216 }
3217 if(obj.fake==true){
3218 labelInfo+=' ("fake")';
3219 }
3220 // console.log(labelInfo)
3221 }
3222 else{
3223 current_url="stop"
3224 }
3225 console.log("length "+urls.length)
3226 // console.log(current_url)
3227 var start_ajax=new Date();
3228 if (urls.length >= 0 && current_url!="stop") {
3229
3230 let commandId=current_url.split("id=")[1].split("&")[0]
3231 if(current_tag!=labelInfo)
3232 {
3233
3234 $.ajax({
3235 url: current_url,
3236 method: 'POST',
3237 dataType: "json",
3238 data: { text: labelInfo },
3239 headers: { 'TribalWars-Ajax': 1 },
3240 success: (data) => {
3241 $("span[data-id="+obj.incomingId+"]").find(".quickedit-label").text(labelInfo)
3242 $("span[data-id="+obj.incomingId+"]").parent().css("background-color","#ff8080");
3243 UI.SuccessMessage(indexIncoming+"/"+url_length)
3244 indexIncoming++;
3245 var stop_ajax=new Date();
3246 var dif_time=stop_ajax.getTime()-start_ajax.getTime();
3247 console.log("dif_time "+dif_time+" wait "+(200-dif_time))
3248 window.setTimeout(function(){
3249 ajaxRequest (list_incomings_href)
3250
3251 },200-dif_time)
3252 }
3253 })
3254 }
3255 else{
3256 console.log("id: "+commandId+" already tagged")
3257 ajaxRequest (list_incomings_href)
3258 indexIncoming++;
3259 }
3260
3261
3262
3263 }
3264 else
3265 {
3266 UI.SuccessMessage("done",2000)
3267 var stop_tagging=new Date();
3268 console.log("total time "+stop_tagging.getTime()-start_tagging.getTime())
3269
3270 }
3271 }
3272 ajaxRequest(list_incomings_href);
3273
3274 }
3275
3276
3277}
3278
3279function parseDate(time){
3280 let date=new Date(time)
3281
3282 let year=date.getFullYear();
3283 let month=("00"+(date.getMonth()+1)).slice(-2)
3284 let day=("00"+date.getDate()).slice(-2)
3285 let hours=("00"+date.getHours()).slice(-2)
3286 let minutes=("00"+date.getMinutes()).slice(-2)
3287 let seconds=("00"+date.getSeconds()).slice(-2)
3288 let result=`${month}/${day}/${year} ${hours}:${minutes}:${seconds}`
3289 return result
3290}
3291
3292
3293function getLandTime(time_land){
3294 var date_land=""
3295 let server_date=document.getElementById("serverDate").innerText.split("/")
3296 if(time_land.includes(lang["aea2b0aa9ae1534226518faaefffdaad"].replace(" %s",""))){ //today
3297 // console.log("here")
3298 date_land=server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+time_land.match(/\d+:\d+:\d+:\d+/)[0]
3299 }
3300 else if(time_land.includes(lang["57d28d1b211fddbb7a499ead5bf23079"].replace(" %s",""))){ //tomorrow
3301 var tomorrow_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]);
3302 tomorrow_date.setDate(tomorrow_date.getDate()+1);
3303 date_land= ("0"+(tomorrow_date.getMonth()+1)).slice(-2)+"/"+("0"+tomorrow_date.getDate()).slice(-2)+"/"+tomorrow_date.getFullYear()+" "+time_land.match(/\d+:\d+:\d+:\d+/)[0];
3304 }else if(time_land.includes(lang["0cb274c906d622fa8ce524bcfbb7552d"].split(" ")[0])){ //on
3305 var on=time_land.match(/\d+.\d+/)[0].split(".");
3306 date_land=on[1]+"/"+on[0]+"/"+server_date[2]+" "+time_land.match(/\d+:\d+:\d+:\d+/)[0];
3307 }
3308 return date_land;
3309}
3310
3311
3312
3313
3314
3315function calcProductionTroupes(time,popReport){
3316 var maxPop=popReport;
3317 let nrAxemax=6000,nrLcMax=3000,nrRamMax=400;
3318 let countAxe=0,countLc=0,countRam=0;
3319 let time_temp=time
3320 while(maxPop<20000 && time_temp>0){
3321 if(countAxe<nrAxemax){
3322 countAxe++;
3323 time_temp-=axeTime;
3324 maxPop+=1
3325 }
3326 else break;
3327 }
3328 time_temp=time
3329 while(maxPop<20000 && time_temp>0){
3330 if(countLc<nrLcMax){
3331 countLc++;
3332 time_temp-=lhTime;
3333 maxPop+=4
3334 }
3335 else break;
3336 }
3337 time_temp=time
3338 while(maxPop<20000 && time_temp>0){
3339 if(countRam<nrRamMax){
3340 countRam++;
3341 time_temp-=ramTime;
3342 maxPop+=5
3343 }
3344 else break;
3345 }
3346
3347 // console.log("axe "+countAxe+" lc "+countLc+" ram "+countRam)
3348 // console.log(maxPop)
3349 maxPop=(maxPop/20000)*100
3350 return maxPop
3351}
3352 //////////////////////////////////////////////////////search reports /////////////////////////////////////////////////////////////////
3353 var map_search
3354async function loadReports(){
3355
3356 [map_search, status]=await Promise.all([readFileDropbox(filename_reports),insertlibraryLocalBase()]).catch(err=>{alert(err)})
3357 console.log(status)
3358
3359 /////////merge maps for reports
3360 try {
3361 map_search=new Map( JSON.parse(lzw_decode(map_search)));
3362 } catch (error) {
3363 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
3364 map_search=new Map()
3365 }
3366 //if there database is stored locally
3367 if(await localBase.getItem(game_data.world+"reports")!=undefined){
3368 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"reports"))));
3369 console.log("map_localBase",map_localBase)
3370 map_search=new Map([...map_localBase, ...map_search])
3371 }
3372
3373
3374
3375 UI.SuccessMessage("load reports")
3376 console.log(map_search)
3377 loadReportsOk=true;
3378 $("#input_search").on("input",function(){
3379 let current_value=$("#input_search").val()
3380 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
3381 coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
3382 console.log(coords)
3383 $("#report_view").empty()
3384 let contentHtml=""
3385 let nr_found=0;
3386 for(let i=0;i<coords.length;i++){
3387 if(map_search.has(coords[i])){
3388 let obj=map_search.get(coords[i]);
3389 console.log(coords[i])
3390 contentHtml+= `<div>
3391 <center style="margin:10px"><input class="btn evt-confirm-btn btn-confirm-yes" type="button"onclick="$('#table`+i+`').toggle('slow')" value="`+coords[i]+`"></center>
3392
3393 <table class="table_hide" id="table`+i+'"'+
3394 createReport(obj)+
3395 `</table></div>`;
3396 nr_found++;
3397 }
3398 }
3399 $("#report_view").append(contentHtml)
3400 $(".table_hide").hide();
3401 $("#progress_search").text("found: "+nr_found)
3402 }else{
3403 $("#report_view").empty()
3404 }
3405
3406 })
3407 $("#input_search").mouseout(function(){
3408 let current_value=$("#input_search").val()
3409 if(current_value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
3410 let coords=current_value.match(/[0-9]{3}\|[0-9]{3}/g)
3411 $("#input_search").val(Array.from(coords).join(","))
3412 }
3413 })
3414
3415 $("#btn_off_coord").on("click",function(){
3416 let list_output=[]
3417 Array.from(map_search.keys()).forEach(key=>{
3418 let obj=map_search.get(key)
3419 let troop_at_home=obj["troopsAtHome_"+key]
3420 let pop=0;
3421 let time_report_home=obj["time_report_home_"+key]
3422 console.log("troopsAtHome_"+key)
3423
3424 if(troop_at_home!=undefined){
3425 for(let i=0;i<troop_at_home.length;i++){
3426 if(troop_at_home[i].type=="spear" || troop_at_home[i].type=="sword" || troop_at_home[i].type=="archer" || troop_at_home[i].type=="heavy"){
3427 pop+=troop_at_home[i].count*troopsPop[troop_at_home[i].type]
3428 }
3429 }
3430 }
3431 else{
3432 pop=-1
3433 time_report_home="none"
3434 }
3435
3436 if( tribemates.includes(obj.nameAttacker.toLowerCase())==false && obj.typeAttacker.includes("off") ){
3437 list_output.push({
3438 type:"off",
3439 coord:obj.coordAttacker,
3440 name:obj.nameAttacker,
3441 date:time_report_home,
3442 pop:pop
3443 })
3444 }
3445 else if( tribemates.includes(obj.nameDefender.toLowerCase())==false && obj.typeDefender.includes("off") ){
3446 list_output.push({
3447 type:"off",
3448 coord:obj.coordDefender,
3449 name:obj.nameDefender,
3450 date:time_report_home,
3451 pop:pop
3452 })
3453 }
3454
3455 })
3456 list_output.sort((o1,o2)=>{
3457 return (o1.name>o2.name)?1:(o1.name<o2.name)?-1:(o1.pop>o2.pop)?-1:(o1.pop<o2.pop)?1:0
3458 })
3459 console.log(list_output)
3460 let text_output=""
3461 for(let i=0;i<list_output.length;i++){
3462 text_output+=`${list_output[i].type}, ${list_output[i].coord}, ${list_output[i].name}, ${list_output[i].pop}, ${list_output[i].date}\n`
3463
3464 if(i<list_output.length-1){
3465 if(list_output[i].name!=list_output[i+1].name){
3466 text_output+="\n\n"
3467 }
3468 }
3469
3470 }
3471 console.log(text_output)
3472
3473 let html_result=`
3474 <center><div id="table_results" style="height:700px;width:700px;overflow:auto">
3475 <textarea cols="80" rows="80">${text_output}</textarea>
3476 </div></center>
3477 `
3478
3479 Dialog.show("content",html_result)
3480
3481 })
3482
3483
3484
3485 $("#btn_def_coord").on("click",function(){
3486 let list_output=[]
3487 Array.from(map_search.keys()).forEach(key=>{
3488 let obj=map_search.get(key)
3489 let troop_at_home=obj["troopsAtHome_"+key]
3490 let pop=0;
3491 let time_report_home=obj["time_report_home_"+key]
3492 console.log("troopsAtHome_"+key)
3493
3494 if(troop_at_home!=undefined){
3495 for(let i=0;i<troop_at_home.length;i++){
3496 if(troop_at_home[i].type=="spear" || troop_at_home[i].type=="sword" || troop_at_home[i].type=="archer" || troop_at_home[i].type=="heavy"){
3497 pop+=troop_at_home[i].count*troopsPop[troop_at_home[i].type]
3498 }
3499 }
3500 }
3501 else{
3502 pop=-1
3503 time_report_home="none"
3504 }
3505
3506 if( tribemates.includes(obj.nameAttacker.toLowerCase())==false && obj.typeAttacker.includes("def") ){
3507 list_output.push({
3508 type:"def",
3509 coord:obj.coordAttacker,
3510 name:obj.nameAttacker,
3511 date:time_report_home,
3512 pop:pop
3513 })
3514 }
3515 else if( tribemates.includes(obj.nameDefender.toLowerCase())==false && obj.typeDefender.includes("def") ){
3516 list_output.push({
3517 type:"def",
3518 coord:obj.coordDefender,
3519 name:obj.nameDefender,
3520 date:time_report_home,
3521 pop:pop
3522 })
3523 }
3524
3525 })
3526 list_output.sort((o1,o2)=>{
3527 return (o1.name>o2.name)?1:(o1.name<o2.name)?-1:(o1.pop>o2.pop)?-1:(o1.pop<o2.pop)?1:0
3528 })
3529 console.log(list_output)
3530 let text_output=""
3531 for(let i=0;i<list_output.length;i++){
3532 text_output+=`${list_output[i].type}, ${list_output[i].coord}, ${list_output[i].name}, ${list_output[i].pop}, ${list_output[i].date}\n`
3533
3534 if(i<list_output.length-1){
3535 if(list_output[i].name!=list_output[i+1].name){
3536 text_output+="\n\n"
3537 }
3538 }
3539
3540 }
3541 console.log(text_output)
3542
3543 let html_result=`
3544 <center><div id="table_results" style="height:800px;width:800px;overflow:auto">
3545 <textarea cols="80" rows="80">${text_output}</textarea>
3546 </div></center>
3547 `
3548
3549 Dialog.show("content",html_result)
3550
3551 })
3552
3553
3554 $("#btn_stack_coord").on("click",function(){
3555 let list_output=[]
3556 let thresholdStack=parseInt(document.getElementById("input_stacked").value)
3557 thresholdStack=(Number.isNaN(thresholdStack)==true || thresholdStack<0)?0:thresholdStack
3558 console.log(thresholdStack)
3559
3560 Array.from(map_search.keys()).forEach(key=>{
3561 let obj=map_search.get(key)
3562 let troop_at_home=obj["troopsAtHome_"+key]
3563 let pop=0;
3564 let time_report_home=obj["time_report_home_"+key]
3565 console.log("troopsAtHome_"+key)
3566
3567 if(troop_at_home!=undefined){
3568 for(let i=0;i<troop_at_home.length;i++){
3569 if(troop_at_home[i].type=="spear" || troop_at_home[i].type=="sword" || troop_at_home[i].type=="archer" || troop_at_home[i].type=="heavy"){
3570 pop+=troop_at_home[i].count*troopsPop[troop_at_home[i].type]
3571 }
3572 }
3573 }
3574 else{
3575 pop=-1
3576 time_report_home="none"
3577 }
3578
3579 if( tribemates.includes(obj.nameAttacker.toLowerCase())==false && pop>thresholdStack ){
3580 list_output.push({
3581 type:obj.typeAttacker,
3582 coord:obj.coordAttacker,
3583 name:obj.nameAttacker,
3584 date:time_report_home,
3585 pop:pop
3586 })
3587 }
3588 else if( tribemates.includes(obj.nameDefender.toLowerCase())==false && pop>thresholdStack ){
3589 list_output.push({
3590 type:obj.typeDefender,
3591 coord:obj.coordDefender,
3592 name:obj.nameDefender,
3593 date:time_report_home,
3594 pop:pop
3595 })
3596 }
3597
3598 })
3599 list_output.sort((o1,o2)=>{
3600 return (o1.name>o2.name)?1:(o1.name<o2.name)?-1:(o1.pop>o2.pop)?-1:(o1.pop<o2.pop)?1:0
3601 })
3602 console.log(list_output)
3603 let text_output=""
3604 for(let i=0;i<list_output.length;i++){
3605 text_output+=`${list_output[i].type}, ${list_output[i].coord}, ${list_output[i].name}, ${list_output[i].pop}, ${list_output[i].date}\n`
3606
3607 if(i<list_output.length-1){
3608 if(list_output[i].name!=list_output[i+1].name){
3609 text_output+="\n\n"
3610 }
3611 }
3612
3613 }
3614 console.log(text_output)
3615
3616 let html_result=`
3617 <center><div id="table_results" style="height:800px;width:800px;overflow:auto">
3618 <textarea cols="80" rows="80">${text_output}</textarea>
3619 </div></center>
3620 `
3621
3622 Dialog.show("content",html_result)
3623
3624 })
3625
3626
3627
3628
3629}
3630
3631///////////////////////////////////////////////////////create table for view report//////////////////////////////////////////////////////
3632function createReport(obj){
3633 var tableHTML=``;
3634 if(obj.attackingArmy!=undefined){
3635 tableHTML=`
3636 <tbody>
3637 <tr>
3638 <td>Battle time </td>
3639 <td>`+ obj.time_report +`</td>
3640 </tr>
3641 <tr>
3642 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" class="report_ReportAttack">
3643 <table id="attack_info_att" width=100% style="border: 1px solid #DED3B9">
3644 <tbody>
3645 <tr>
3646 <th style="width:20%">Attacker:</th>
3647 <th >`+obj.nameAttacker+`</th>
3648 </tr>
3649 <tr>
3650 <td >Origin:</td>
3651 <td >`+obj.coordAttacker+`</td>
3652 </tr>
3653 <tr>
3654 <td colspan="2" style="padding:0px">`+
3655 createTableTroupes(obj.attackingArmy,obj.attackingArmyLosses)+
3656 `</td>
3657 </tr>
3658 </tbody>
3659 </table>
3660 </td>
3661 </tr>`
3662 }
3663 if(obj.defendingArmy!=undefined){
3664 tableHTML+= `
3665 <tr>
3666 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;" >
3667 <table id="attack_info_def" width=100% style="border: 1px solid #DED3B9">
3668 <tbody>
3669 <tr>
3670 <th style="width:20%">Defender:</th>
3671 <th >`+obj.nameDefender+`</th>
3672 </tr>
3673 <tr>
3674 <td >Origin:</td>
3675 <td >`+obj.coordDefender+`</td>
3676 </tr>
3677 <tr>
3678 <td colspan="2" style="padding:0px">`+
3679 createTableTroupes(obj.defendingArmy,obj.defendingArmyLosses)+
3680 `</td>
3681 </tr>
3682 </tbody>
3683 </table>
3684 </td>
3685 </tr>
3686 `
3687 }
3688
3689 if(obj.travelingTroops!=undefined){
3690 tableHTML+= `
3691 <tr>
3692 <td colspan="2" valign="top" height="160" style="border: solid 1px ; padding 4px;">
3693 <table id="attack_spy_away" width=100% style="border: 1px solid #DED3B9; width:100%; margin-top:5px;">
3694 <tbody>
3695 <tr>
3696 <th colspan="2">Units outside of village:</th>
3697 </tr>
3698
3699 <tr>
3700 <td colspan="2" >`+
3701 createTableTroupesAway(obj.travelingTroops)+
3702 `</td>
3703 </tr>
3704 </tbody>
3705 </table>
3706 </td>
3707 </tr>
3708 `
3709 }
3710 if(obj.attackingArmy!=undefined){
3711 tableHTML+="</tbody>"
3712 }
3713
3714 return tableHTML
3715}
3716
3717function createTableTroupes(totalArmy,lostArmy){
3718 let tableHTML=`
3719 <table class="vis" >
3720 <tbody>
3721 <tr class="center">
3722 <td width="20"></td>`
3723
3724 let units=game_data.units
3725 for(let i=0;i<totalArmy.length;i++){
3726 if(units[i]!="militia"){
3727 if(totalArmy[i].count==0 )
3728 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png" alt class="faded"</td>`
3729 else
3730 tableHTML+=`<td width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+units[i]+`.png"</td>`
3731 }
3732 }
3733 tableHTML+="</tr>"
3734 tableHTML+=`
3735 <tr>
3736 <td width="20">Quantity:</td>`
3737 for(let i=0;i<totalArmy.length;i++){
3738 if(units[i]!="militia"){
3739 if(totalArmy[i].count==0)
3740 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+totalArmy[i].count+"</td>"
3741 else
3742 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+totalArmy[i].count+"</td>"
3743 }
3744 }
3745 tableHTML+="</tr>"
3746 tableHTML+=`
3747 <tr>
3748 <td width="20">Losses:</td>`
3749 for(let i=0;i<lostArmy.length;i++){
3750 if(units[i]!="militia"){
3751 if(lostArmy[i].count==0)
3752 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+` hidden">`+lostArmy[i].count+"</td>"
3753 else
3754 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+units[i]+`">`+lostArmy[i].count+"</td>"
3755 }
3756 }
3757 tableHTML+="</tr>"
3758
3759
3760
3761
3762 tableHTML+="</tr></tbody></table>"
3763 return tableHTML
3764}
3765
3766
3767function createTableTroupesAway(totalArmy){
3768 let tableHTML=`
3769 <table class="vis">
3770 <tbody>
3771 <tr class="center">`
3772
3773 let units=game_data.units
3774 Object.keys(totalArmy).forEach(key=>{
3775 if(totalArmy[key]==0)
3776 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png" alt class="faded"</th>`
3777 else
3778 tableHTML+=`<th width="35"><img src="https://dsen.innogamescdn.com/asset/3ec301e5/graphic/unit/unit_`+key+`.png"</th>`
3779
3780 })
3781
3782
3783 tableHTML+="</tr>"
3784 tableHTML+=`<tr>`
3785 Object.keys(totalArmy).forEach(key=>{
3786 if(totalArmy[key]==0)
3787 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+` hidden">`+totalArmy[key]+"</td>"
3788 else
3789 tableHTML+=`<td style="text-align:center" class="unit-item unit-item-`+key+`">`+totalArmy[key]+"</td>"
3790
3791 })
3792 tableHTML+="</tr>"
3793
3794 tableHTML+="</tr></tbody></table>"
3795 return tableHTML
3796}
3797
3798function createTableIncomings(list){
3799 let serverTime=document.getElementById("serverTime").innerText
3800 let serverDate=document.getElementById("serverDate").innerText.split("/")
3801 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
3802 let date_current=new Date(serverDate+" "+serverTime).getTime()
3803 let html_incomings=`
3804 <tbody>
3805 <tr>
3806 <th><img src="https://dsen.innogamescdn.com/asset/056b9c0b/graphic/unit/att.png"></<th>
3807 <th >speed</th>
3808 <th colspan="2">destination</th>
3809 <th colspan="2">origin</th>
3810 <th >Arrival time</th>
3811 <th >Arrives in</th>
3812 </tr>`
3813
3814 for(let i=0;i<list.length;i++){
3815 console.log(list[i])
3816 let labelName
3817 console.log(list[i].labelName)
3818 if(list[i].labelName=="none")
3819 labelName="https://dsen.innogamescdn.com/asset/056b9c0b/graphic/delete.png"
3820 else
3821 labelName=`https://dsen.innogamescdn.com/asset/a9e85669/graphic/unit/tiny/${list[i].labelName}`
3822
3823 console.log(list[i].labelName)
3824 let arrived=new Date(list[i].date_land).getTime()
3825 if(arrived>date_current){
3826 html_incomings+=`
3827 <tr>
3828 <td><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/${list[i].type_attack}"> </td>
3829 <td><img src="${labelName}"> </td>
3830 <td><a href="${game_data.link_base_pure}info_village&id=${list[i].id_coord_def}"> (${list[i].coord_def})</a> </td>
3831 <td><a href="${game_data.link_base_pure}info_player&id=${list[i].id_player_def}"> ${list[i].player_def}</a> </td>
3832 <td><a href="${game_data.link_base_pure}info_village&id=${list[i].id_coord_off}">(${list[i].coord_off}) </a> </td>
3833 <td><a href="${game_data.link_base_pure}info_player&id=${list[i].id_player_off}">${list[i].player_off} </a> </td>
3834 <td>${list[i].date_land.split(" ")[0]} <b>${list[i].date_land.split(" ")[1]}</b></td>
3835 <td date-time=${arrived} class="counterTime"></td>
3836 </tr>
3837 `
3838 }
3839 }
3840 html_incomings+="</tbody>"
3841 return html_incomings
3842}
3843
3844function counterTime(){
3845
3846 window.setInterval(()=>{
3847
3848 $(".counterTime").each((index,item)=>{
3849 let serverTime=document.getElementById("serverTime").innerText
3850 let serverDate=document.getElementById("serverDate").innerText.split("/")
3851 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
3852 let date_current=new Date(serverDate+" "+serverTime).getTime()
3853 // console.log(date_current)
3854
3855 let time=parseInt(item.getAttribute("date-time"))
3856 let hours=("0"+parseInt((time-date_current)/(3600*1000))).slice(-3);
3857 let minutes=("0"+parseInt(((time-date_current)/(60*1000)%60))).slice(-2);
3858 let seconds=( "0"+parseInt((((time-date_current)/1000)%60))).slice(-2);
3859 result=hours+":"+minutes+":"+seconds
3860 item.innerText=result
3861 })
3862 },1000)
3863
3864
3865}
3866
3867
3868////////////////////////////////////////////////////////get speed world///////////////////////////////////////////////////
3869
3870
3871function getSpeedConstant() { //Get speed constant (world speed * unit speed) for world
3872 if (localStorage.getItem(game_data.world+"speedWorld") !== null) {
3873 let obj=JSON.parse(localStorage.getItem(game_data.world+"speedWorld"))
3874 console.log("speed world already exist")
3875 return obj
3876 }
3877 else { //Get data from xml and save it in localStorage to avoid excessive XML requests to server
3878 let currentHtml=document.body.innerHTML
3879 document.body.innerHTML = httpGet("/interface.php?func=get_config") //Load world data
3880 let obj={}
3881 let worldSpeed = Number(document.getElementsByTagName("speed")[0].innerHTML)
3882 let unitSpeed = Number(document.getElementsByTagName("unit_speed")[0].innerHTML);
3883 obj.unitSpeed=unitSpeed
3884 obj.worldSpeed=worldSpeed
3885 document.body.innerHTML=currentHtml
3886 localStorage.setItem(game_data.world+"speedWorld",JSON.stringify(obj));
3887 console.log("save speed world")
3888 return obj
3889 }
3890}
3891
3892
3893/////////////////////////////////////////////////////// interface for get all tr from incomings page/////////////////////////////////////////
3894function setIntervalIncomings(){
3895 htmlInc = `
3896 <div id="div_container" class="ui-widget-content div_remove" style="width:600px;background-color:${backgroundColor};cursor:move;z-index:50;">
3897 <div class="close-btn" btn_close="btn_close" onclick="closeWindow()" style="position:absolute;top:10px;right: 10px;"><b><a href=#><font color="${titleColor}">X</font></b></a></div>
3898 <h2><center style="margin:10px"><u><font color="${titleColor}">get all incomings</font></u></center></h2>
3899 <table id="table_upload" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
3900 <tr>
3901 <td style="text-align:center; width:auto; background-color:${headerColor}">
3902 <p><center style="margin:10px"><font color="${titleColor}">between hours </font></center></p>
3903 </td>
3904 <td style="text-align:center; width:auto; background-color:${headerColor}">
3905 <p><center style=""><input type="number" id="id_start" size="5" style="text-align:center" class=" input-nicer show" value="0"><br><br></center></p>
3906 </td>
3907 <td style="text-align:center; width:auto; background-color:${headerColor}">
3908 <p><center style=""><input type="number" id="id_stop" size="5" style="text-align:center" class=" input-nicer show" value="100"><br><br></center></p>
3909 </td>
3910
3911 </tr>
3912 </table>
3913 <center style="margin:10px"><u><input class="btn" type="button" id="btn_village" onclick="getTrIncomings()" value="Start"></center>
3914
3915
3916
3917 </div>
3918 `;
3919 ////////////////////////////////////////add and remove window from page/////////////////////////////////////////////////////////////////
3920 $("#div_container").remove()
3921 $("#contentContainer").eq(0).prepend(htmlInc);
3922 $("#mobileContent").eq(0).prepend(htmlInc);
3923
3924 if(game_data.device=="desktop"){
3925 $("#div_container").css("position","fixed");
3926 $("#div_container").draggable();
3927 }
3928 $('#id_start').on('input',function(e){
3929 let value=this.value;
3930 localStorage.setItem(game_data.world+"startInc",value)
3931 });
3932 $('#id_stop').on('input',function(e){
3933 let value=this.value;
3934 localStorage.setItem(game_data.world+"stopInc",value)
3935 });
3936 if(localStorage.getItem(game_data.world+"startInc")!=null)
3937 $('#id_start').val(localStorage.getItem(game_data.world+"startInc"))
3938 if(localStorage.getItem(game_data.world+"stopInc")!=null)
3939 $('#id_stop').val(localStorage.getItem(game_data.world+"stopInc"))
3940
3941
3942}
3943
3944//////////////////////////////////////////////get a list with all tr ///////////////////////////////////////////////////////////////////
3945async function getTrIncomings(){
3946
3947 let map_reports_dropbox
3948 if(localStorage.getItem(game_data.world+"get_only_fakes")=="true" || localStorage.getItem(game_data.world+"get_def_vills")=="true"){
3949 [map_reports_dropbox,status]=await Promise.all([readFileDropbox(filename_reports),insertlibraryLocalBase()]).catch(err=>{alert(err)})
3950 /////////merge maps for reports
3951 try {
3952 map_reports_dropbox=new Map( JSON.parse(lzw_decode(map_reports_dropbox)));
3953 } catch (error) {
3954 console.log("erorrrrrrrrrrrrrrrr map report from dropbox")
3955 map_reports_dropbox=new Map()
3956 }
3957 //if there database is stored locally
3958 if(await localBase.getItem(game_data.world+"reports")!=undefined){
3959 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"reports"))));
3960 console.log("map_localBase",map_localBase)
3961 map_reports_dropbox=new Map([...map_localBase, ...map_reports_dropbox])
3962 }
3963
3964 }
3965
3966 let limitPopFake=parseInt(document.getElementById("input_pop_fake").value)
3967 limitPopFake=(Number.isNaN(limitPopFake) || limitPopFake<0 )?0:limitPopFake
3968
3969 //get pages for all incoming
3970 let list_pages=[]
3971 let start=parseInt(document.getElementById("id_start").value)
3972 let stop=parseInt(document.getElementById("id_stop").value)
3973
3974 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
3975 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
3976 list_pages.push(item.value)
3977 })
3978 list_pages.pop();
3979 }
3980 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
3981 let nr=0;
3982 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
3983 let current=item.href;
3984 current=current.split("page=")[0]+"page="+nr
3985 nr++;
3986 list_pages.push(current);
3987 })
3988 }
3989 else{
3990 let current_link=window.location.href;
3991 list_pages.push(current_link);
3992 }
3993 list_pages=list_pages.reverse();
3994
3995
3996 // go to every page and get incoming
3997 let rows=[]
3998 function ajaxRequest (urls) {
3999 let current_url
4000 let startAjax=new Date().getTime();
4001 if(urls.length>0){
4002 current_url=urls.pop()
4003 }
4004 else{
4005 current_url="stop"
4006 }
4007 console.log(current_url)
4008 if (urls.length >= 0 && current_url!="stop") {
4009 $.ajax({
4010 url: current_url,
4011 method: 'get',
4012 success: (data) => {
4013 document.body.innerHTML=data
4014 let table_incomings=document.getElementById("incomings_table").children[1].children
4015 for(let i=1;i<table_incomings.length-1;i++){
4016 rows.push(table_incomings[i])
4017 }
4018 let stopAjax=new Date().getTime();
4019 let diff=stopAjax-startAjax
4020 console.log("wait inc: "+(200-diff))
4021 window.setTimeout(function(){
4022 ajaxRequest (list_pages)
4023 },200-diff)
4024 }
4025 })
4026
4027 }
4028 else
4029 {
4030 $(".row_a").remove();
4031 $(".row_b").remove();
4032 let table_incomings=document.getElementById("incomings_table")
4033 let lastRow=table_incomings.children[1].children[1];
4034 table_incomings.children[1].children[1].remove();
4035 let nr_row=0;
4036 for(let i=0;i<rows.length;i++){
4037 let hours=rows[i].children[ rows[i].children.length-1 ].innerText.split(":")[0]
4038 let isFake=false
4039 if(hours>=start && hours< stop){
4040 if(localStorage.getItem(game_data.world+"get_only_fakes")=="true" || localStorage.getItem(game_data.world+"get_def_vills")=="true"){
4041 let length_tr=rows[i].children.length
4042
4043 let coordDest=rows[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
4044 let coordOrigin=rows[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0];
4045 let player_id=rows[i].children[length_tr-4].children[0].href.split("player&id=")[1]//attacker's id
4046 ////////////////////////////////get land time attack///////////////////////////////
4047
4048 //only if destination coord exist in database
4049 if(map_reports_dropbox.has(coordOrigin) )
4050 {
4051 let idPlayer_dropbox
4052 let type_dropbox
4053 let nr_troupes_dropbox
4054
4055 var obj=map_reports_dropbox.get(coordOrigin);
4056 var traveling=false
4057 if(coordOrigin == obj.coordAttacker){
4058 idPlayer_dropbox=obj.attackingPlayerId;
4059 type_dropbox=obj.typeAttacker;
4060 nr_troupes_dropbox=obj.nrTroupesAttacker
4061 traveling=true;
4062 }
4063 else if(coordOrigin == obj.coordDefender){
4064 idPlayer_dropbox=obj.defendingPlayerId;
4065 type_dropbox=obj.typeDefender;
4066 nr_troupes_dropbox=obj.nrTroupesDefender
4067 traveling=false;
4068 }
4069 else{
4070 idPlayer_dropbox=obj.supporterPlayerId
4071 type_dropbox=obj.typeSupporter;
4072 nr_troupes_dropbox=obj.nrTroupesSupporter
4073 }
4074
4075 if(idPlayer_dropbox == player_id && rows[i].children[0].getElementsByTagName("img").length==2)
4076 {
4077
4078
4079 //calculate population
4080 let date_landing_report=new Date(obj.time_report)
4081 let distance=calcDistance(coordOrigin,coordDest);
4082 let time_attack=0;
4083 let time_land=rows[i].children[length_tr-2].innerText
4084 let date_land=new Date(getLandTime(time_land))
4085 let labelName=""
4086 if(rows[i].children[0].getElementsByTagName("img")[1]==undefined || rows[i].children[0].getElementsByTagName("img")[1]==null )
4087 labelName="ram.png"
4088 else
4089 labelName=rows[i].children[0].getElementsByTagName("img")[1].src
4090
4091 if(labelName.includes("snob.png")){
4092 time_attack=nobleSpeed*distance
4093 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
4094 time_attack=ramSpeed*distance
4095 }else if(labelName.includes("sword.png")){
4096 time_attack=swordSpeed*distance
4097 }else if(labelName.includes("axe.png")){
4098 time_attack=axeSpeed *distance
4099 }
4100 if(traveling==false)
4101 time_attack=0;
4102
4103 if(type_dropbox=="off"){// do something with pop
4104 // console.log(date_land.getTime())
4105 // console.log(time_attack)
4106 // console.log(date_landing_report.getTime())
4107 let timeForRecruiting = (date_land.getTime()-time_attack)-date_landing_report.getTime()
4108 nr_troupes_dropbox=calcProductionTroupes(timeForRecruiting,nr_troupes_dropbox)
4109 nr_troupes_dropbox=Math.round(nr_troupes_dropbox*10)/10
4110 // console.log("final "+nr_troupes_dropbox)
4111
4112 if(nr_troupes_dropbox<limitPopFake)
4113 isFake=true
4114 }
4115
4116 if(type_dropbox.includes("def") && localStorage.getItem(game_data.world+"get_def_vills")=="true"){
4117 console.log("hererer")
4118 isFake=true
4119 }
4120
4121
4122
4123
4124 console.log(obj.time_return)
4125
4126 if(obj.time_return!=0 ){//do something if the attack is returning home
4127
4128 let date_home=new Date(obj.time_return)
4129 let distance=calcDistance(coordOrigin,coordDest);
4130 let labelName=rows[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src
4131 let time_attack=0;
4132 if(labelName.includes("snob.png")){
4133 time_attack=nobleSpeed*distance
4134 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
4135 time_attack=ramSpeed*distance
4136 }else if(labelName.includes("sword.png")){
4137 time_attack=swordSpeed*distance
4138 }else if(labelName.includes("axe.png")){
4139 time_attack=axeSpeed *distance
4140 }
4141
4142 let time_land=rows[i].children[length_tr-2].innerText
4143 let dateLand=new Date(getLandTime(time_land))
4144
4145 time_attack=Math.round(time_attack/1000)*1000
4146
4147 console.log("time_attack",time_attack)
4148
4149 if(time_attack+date_home.getTime()>dateLand.getTime() ){
4150 isFake=true;
4151 console.log("fake from "+coordOrigin)
4152 }
4153
4154
4155
4156 }
4157
4158 if(isFake==true && localStorage.getItem(game_data.world+"get_only_fakes")=="true"){
4159 $(table_incomings).append(rows[i])
4160 nr_row++;
4161 }
4162 else if(isFake==true && localStorage.getItem(game_data.world+"get_def_vills")=="true"){
4163 $(table_incomings).append(rows[i])
4164 nr_row++;
4165 }
4166
4167
4168 }
4169 }
4170
4171
4172 }
4173 else{
4174 $(table_incomings).append(rows[i])
4175 nr_row++;
4176 }
4177 }
4178
4179
4180 }
4181 table_incomings.children[1].children[0].children[0].innerText="Command ("+nr_row+")"
4182 $(table_incomings).append(lastRow)
4183
4184 //activate renaming
4185 $('document').ready(function() {
4186 CommandsOverview.init();
4187 UI.ToolTip('.icon_village_notes');
4188
4189 $('.quickedit').QuickEdit({url: TribalWars.buildURL('POST', 'info_command', {ajaxaction: 'edit_other_comment', id: '__ID__'})});
4190 Command.init();
4191 });
4192 UI.SuccessMessage("done")
4193 console.log(rows)
4194 showButtons();
4195
4196 }
4197 }
4198 ajaxRequest(list_pages);
4199
4200}
4201
4202/////////////////////////////////////////////highlight trains->yellow, nobles->red, nukes-> green////////////////////////////////////////
4203function highLightIncomings(){
4204 try {
4205 let table=document.querySelectorAll(".row_a,.row_b")
4206 if(localStorage.getItem(game_data.world+"highlight")=="true"){
4207 let colors = {
4208 yellow: '#ffff66',
4209 red: '#ff8080',
4210 green: '#4dff4d'
4211 };
4212 document.getElementById("btn_highlight").classList.remove("btn-confirm-no")
4213 document.getElementById("btn_highlight").classList.add("btn-confirm-yes")
4214 for(let i=0;i<table.length;i++){
4215 let length_tr=table[i].children.length
4216 table[i].classList.remove("selected")
4217 //highlight nukes if has more than 70% pop
4218
4219 if(document.getElementById("id_type")!=null && table[i].firstElementChild.style.backgroundColor!="rgb(255, 255, 102)"){//is different then yellow
4220 let watchTower=table[i].children[0].getElementsByTagName("img")[0].src.includes("attack_large.png")
4221 let watchTowerSmall=table[i].children[0].getElementsByTagName("img")[0].src.includes("attack_small.png")
4222 let hasNuke=false
4223 if(table[i].getElementsByClassName("cls_type").length>0){
4224 let type=table[i].getElementsByClassName("cls_type")[0].innerText
4225 let pop=parseFloat(table[i].getElementsByClassName("cls_pop")[0].innerText)
4226 if(((type=="off" && pop>70)|| watchTower==true) && watchTowerSmall==false){//must be tested
4227 hasNuke=true;
4228 }
4229 }
4230 if(hasNuke==true || watchTower==true ){
4231 $(table[i]).children().each(function(){
4232 console.log("color")
4233 $(this).css('background-color', colors.green);
4234 });
4235 }
4236 }
4237
4238 //highlight all possible trains
4239 for(let j=i+1;j<table.length;j++){
4240
4241 //normal worlds
4242 let tr1=table[i].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{3}/)[0]
4243 let tr2=table[j].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}\:[0-9]{3}/)[0]
4244 let time1=parseInt(tr1.split(":")[0])*3600*1000+parseInt(tr1.split(":")[1])*60*1000+parseInt(tr1.split(":")[2])*1000+parseInt(tr1.split(":")[3])
4245 let time2=parseInt(tr2.split(":")[0])*3600*1000+parseInt(tr2.split(":")[1])*60*1000+parseInt(tr2.split(":")[2])*1000+parseInt(tr2.split(":")[3])
4246
4247 // let tr1=table[i].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/)[0]
4248 // let tr2=table[j].children[length_tr-2].innerText.match(/[0-9]{2}\:[0-9]{2}\:[0-9]{2}/)[0]
4249 // let time1=parseInt(tr1.split(":")[0])*3600*1000+parseInt(tr1.split(":")[1])*60*1000+parseInt(tr1.split(":")[2])*1000
4250 // let time2=parseInt(tr2.split(":")[0])*3600*1000+parseInt(tr2.split(":")[1])*60*1000+parseInt(tr2.split(":")[2])*1000
4251
4252
4253 if(table[i].children[2].innerHTML==table[j].children[2].innerHTML){//if origin coord is the same
4254 if(Math.abs(time1-time2)==50 || Math.abs(time1-time2)==100 || Math.abs(time1-time2)==150 || Math.abs(time1-time2)==0 ){
4255 console.log(tr1+" === "+tr2)
4256 console.log(time1+" === "+time2)
4257 console.log("diference tr: "+(time2-time1))
4258
4259 $(table[i]).children().each(function(){
4260 console.log("color i")
4261 $(this).css('background-color', colors.yellow);
4262 });
4263 console.log(table[j])
4264 $(table[j]).children().each(function(){
4265 console.log("color j")
4266 $(this).css('background-color', colors.yellow);
4267 });
4268 console.log(table[j])
4269 break;
4270 }
4271 }
4272 if(Math.abs(time1-time2)>200)
4273 break;
4274 }
4275
4276
4277
4278
4279
4280
4281 // highlist if it is tagged as noble
4282 if(table[i].children[0].getElementsByTagName("img").length==2){
4283 let hasNoble=table[i].children[0].getElementsByTagName("img")[1].src.includes("snob.png")
4284 if(hasNoble==true){
4285 $(table[i]).children().each(function(){
4286 $(this).css('background-color', colors.red);
4287 });
4288 }
4289 }
4290
4291 }
4292 }
4293 else{
4294 for(let i=0;i<table.length;i++){
4295 $(table[i]).children().each(function(){
4296 $(this).css('background-color', "");
4297 });
4298 }
4299 document.getElementById("btn_highlight").classList.remove("btn-confirm-yes")
4300 document.getElementById("btn_highlight").classList.add("btn-confirm-no")
4301 }
4302
4303 } catch (error) {
4304
4305 }
4306
4307
4308}
4309if(window.location.href.includes("mode=incomings"))
4310 highLightIncomings();
4311
4312
4313
4314
4315
4316function toggleHighLight(){
4317
4318 if(localStorage.getItem(game_data.world+"highlight")!=null){
4319 let isHighLight=localStorage.getItem(game_data.world+"highlight")
4320 if(isHighLight=="true"){
4321 localStorage.setItem(game_data.world+"highlight","false")
4322 UI.ErrorMessage("highlight off",500)
4323 highLightIncomings();
4324 }
4325 else{
4326 localStorage.setItem(game_data.world+"highlight","true")
4327 UI.SuccessMessage("highlight on",500)
4328 highLightIncomings();
4329 }
4330
4331 }
4332 else{
4333 localStorage.setItem(game_data.world+"highlight","true")
4334 highLightIncomings();
4335 }
4336}
4337
4338/////////////////////////////////////////////get and add troops on incoming page for each village////////////////////////////////////////////
4339function eventGetTroops(){
4340 var units=game_data.units
4341
4342
4343 $(".load_troops").on("click",function(event){
4344 event.preventDefault()
4345 $(".load_troops").attr("disabled", true)
4346 let villageId=this.getAttribute("data-id")
4347 let nr_attacks=this.getAttribute("data-nr")
4348 let link_home_troops=game_data.link_base_pure + `map&ajax=map_info&source=${villageId}&target=${villageId}&`
4349 let link_coming_troops=window.location.href.split("village=")[0]+`village=${villageId}&screen=place&mode=call&target=${villageId}`
4350 let coord=this.innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
4351 let button=this
4352 console.log(link_home_troops)
4353 this.parentElement.classList.remove("selected")
4354
4355
4356
4357 let time_start=new Date().getTime();
4358 $.get(link_home_troops,function(response){
4359 console.log(response)
4360 let obj_troops={}
4361 for(let i=0;i<units.length-1;i++){
4362 obj_troops[units[i]]=parseInt(response.units[units[i]].count.home)+parseInt(response.units[units[i]].count.foreign)
4363 }
4364 let wallLevel,farmLevel,flagName,LoyaltyLevel
4365 wallLevel=response.buildings.wall
4366 farmLevel=response.buildings.farm
4367 LoyaltyLevel=response.mood
4368 console.log(response.flag)
4369 if(response.flag!=undefined)
4370 flagName =response.flag.short_desc
4371 else
4372 flagName="none"
4373 console.log(obj_troops)
4374 console.log("wallLevel: "+wallLevel)
4375 console.log("farmLevel: "+farmLevel)
4376 console.log("flagName: "+flagName)
4377 console.log("LoyaltyLevel: "+LoyaltyLevel)
4378
4379
4380
4381 let htmlDiv=`<div id="div_coming_troops" hidden></div>`
4382 $("#contentContainer").eq(0).prepend(htmlDiv)
4383 console.log(link_coming_troops)
4384
4385 $.get(link_coming_troops,function(data){
4386 document.getElementById("div_coming_troops").innerHTML=data
4387
4388 let obj_troops_coming={snob:0}
4389 let troops_coming=document.getElementById("div_coming_troops").querySelectorAll("#support_sum td")
4390 console.log(troops_coming)
4391 for(let i=0;i<troops_coming.length-1;i++){
4392 let name=troops_coming[i].getAttribute("data-unit")
4393 let value=parseInt(troops_coming[i].innerText)
4394 obj_troops_coming[name]=value
4395 }
4396 document.getElementById("div_coming_troops").remove()
4397
4398
4399
4400
4401 let html=`
4402 <div style="width:600px;background-color:${backgroundColor};cursor:move;width:50%;margin:10px auto">
4403
4404 <table class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor}">
4405 <tr>
4406 <td style="text-align:center; width:auto; background-color:${headerColor}">
4407 <p><center style="margin:10px"><font color="${titleColor}">coord </font></center></p>
4408 </td>
4409 <td style="text-align:center; width:auto; background-color:${headerColor}">
4410 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png"> </font></center></p>
4411 </td>
4412 <td style="text-align:center; width:auto; background-color:${headerColor}">
4413 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/flags/small/3.png"> </font></center></p>
4414 </td>
4415 <td style="text-align:center; width:auto; background-color:${headerColor}">
4416 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/snob.png"> </font></center></p>
4417 </td>
4418 <td style="text-align:center; width:auto; background-color:${headerColor}">
4419 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/wall.png"> </font></center></p>
4420 </td>
4421 <td style="text-align:center; width:auto; background-color:${headerColor}">
4422 <p><center style="margin:10px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/farm.png"> </font></center></p>
4423 </td>
4424 <td style="text-align:center; width:auto; background-color:${headerColor}">
4425 <p><center style="margin:10px"><font color="${titleColor}">troops </font></center></p>
4426 </td>
4427
4428 `;
4429 for(let i=0;i<units.length-1;i++){
4430 html+=`<td class="fm_unit" style="width:30px;text-align:center;width:auto; background-color:${headerColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/unit/unit_${units[i]}.png"></td>`
4431 }
4432 html+=`
4433 <td style="text-align:center; width:auto; background-color:${headerColor}">
4434 <p><center style="margin:10px"><font color="${titleColor}">pop</font></center></p>
4435 </td>`
4436 html+=`</tr>
4437 <tr>`
4438
4439 html+=`
4440 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${coord}</td>
4441 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColor};color:white">${nr_attacks}</td>
4442 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColor};color:white">${flagName}</td>
4443 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${LoyaltyLevel}</td>
4444 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${wallLevel}</td>
4445 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">${farmLevel}</td>
4446 <td style="text-align:center; width:auto; background-color:${headerColor}">
4447 <p><center style="margin:10px"><font color="${titleColor}">home</font></center></p>
4448 </td>
4449 `
4450 //home troops
4451 let total_pop=0;
4452 for(let i=0;i<units.length-1;i++){
4453 let value_troop=obj_troops[units[i]]
4454 let name_troop=units[i]
4455 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
4456 total_pop+=value_troop*troopsPop[name_troop]
4457 }
4458 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop+"</td>"
4459 }
4460 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
4461 html+=`</tr>
4462 <tr>
4463 <td style="text-align:center; width:auto; background-color:${headerColor}">
4464 <p><center style="margin:10px"><font color="${titleColor}">coming</font></center></p>
4465 </td>`
4466 //coming troops
4467 total_pop=0;
4468 for(let i=0;i<units.length-1;i++){
4469 let value_troop_coming=obj_troops_coming[units[i]]
4470 let name_troop=units[i]
4471 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
4472 total_pop+=value_troop_coming*troopsPop[name_troop]
4473 }
4474 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop_coming+"</td>"
4475 }
4476 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
4477
4478 html+=`</tr>
4479 <tr>
4480 <td style="text-align:center; width:auto; background-color:${headerColor}">
4481 <p><center style="margin:10px"><font color="${titleColor}">total </font></center></p>
4482 </td>`
4483 //total troops
4484 total_pop=0;
4485 for(let i=0;i<units.length-1;i++){
4486 let value_troop=obj_troops[units[i]]+obj_troops_coming[units[i]]
4487 let name_troop=units[i]
4488 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
4489 total_pop+=value_troop*troopsPop[name_troop]
4490 }
4491 html+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColor};color:white">`+value_troop+"</td>"
4492 }
4493 html+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColor};color:white">`+total_pop+"</td>"
4494
4495 html+=`</tr></table></div>`
4496
4497 button.outerHTML=html
4498
4499
4500 let time_stop=new Date().getTime()
4501 console.log("load troops: "+(time_stop-time_start))
4502 $(".load_troops").attr("disabled", false)
4503
4504
4505
4506
4507
4508
4509 })
4510
4511
4512 })
4513
4514
4515 })
4516}
4517eventGetTroops();
4518
4519
4520
4521//////////////////////////////////////////////////////get data from /map/player.txt and /mapvillage.txt/////////////////////////////////////
4522
4523async function getInfoVIllages(){
4524
4525 return new Promise(async(resolve,reject)=>{
4526 let filename_innoDB=game_data.world+"infoVillages"
4527 await insertlibraryLocalBase().catch(err=>{alert(err)})
4528 let data = await localBase.getItem(filename_innoDB).catch(err=>{alert(err)})
4529
4530
4531 console.log("get info VIllages")
4532 let mapVillage=new Map();
4533 let obj={};
4534 let server_date=document.getElementById("serverDate").innerText.split("/")
4535 let server_time=document.getElementById("serverTime").innerText
4536 let current_date=new Date(server_date[1]+"/"+server_date[0]+"/"+server_date[2]+" "+server_time);
4537 let url=window.location.href.split("/game.php")[0]
4538 let mapPlayer=new Map();
4539 let mapAlly=new Map();
4540
4541
4542 if(data==undefined){
4543 let dataVillage=httpGet(url+"/map/village.txt").split(/\r?\n/);
4544 let dataPlayer=httpGet(url+"/map/player.txt").split(/\r?\n/);
4545 let dataAlly=httpGet(url+"/map/ally.txt").split(/\r?\n/);
4546
4547 for(let i=0;i<dataAlly.length-1;i++){
4548 // console.log(dataPlayer[i].split(",")[1])
4549 let tribeName=innoReplaceSpecialCaracters(dataAlly[i].split(",")[1])
4550 mapAlly.set(dataAlly[i].split(",")[0],tribeName)
4551 }
4552
4553 for(let i=0;i<dataPlayer.length-1;i++){
4554 // console.log(dataPlayer[i].split(",")[1])
4555 let playerName=innoReplaceSpecialCaracters(dataPlayer[i].split(",")[1])
4556 mapPlayer.set(dataPlayer[i].split(",")[0],{
4557 allyId:dataPlayer[i].split(",")[2],
4558 playerName:playerName,
4559 tribeName:mapAlly.get(dataPlayer[i].split(",")[2])
4560 })
4561 }
4562
4563
4564
4565
4566
4567 for(let i=0;i<dataVillage.length;i++){
4568 if(mapPlayer.get(dataVillage[i].split(",")[4])!=undefined){
4569 mapVillage.set(dataVillage[i].split(",")[2]+"|"+dataVillage[i].split(",")[3],{
4570 villageId:dataVillage[i].split(",")[0],
4571 playerId:dataVillage[i].split(",")[4],
4572 points:dataVillage[i].split(",")[5],
4573 allyId:mapPlayer.get(dataVillage[i].split(",")[4]).allyId,
4574 playerName:mapPlayer.get(dataVillage[i].split(",")[4]).playerName,
4575 tribeName:mapPlayer.get(dataVillage[i].split(",")[4]).tribeName
4576 })
4577 }
4578 }
4579 obj.datetime=current_date
4580 obj.data=Array.from(mapVillage.entries())
4581
4582 let data=JSON.stringify(obj)
4583 data=replaceSpecialCaracters(data)
4584
4585 await localBase.setItem(filename_innoDB,data)
4586
4587 }else{
4588
4589 let ino_db= JSON.parse(data)
4590 let db_date=ino_db.datetime
4591 mapVillage=new Map(ino_db.data)
4592
4593 // console.log("mapVillage",mapVillage)
4594
4595
4596
4597
4598 // console.log(mapVillage)
4599 if(new Date(current_date).getTime()-new Date(db_date)>3600*1000){
4600 console.log("update database inno")
4601
4602 let dataVillage=httpGet(url+"/map/village.txt").split(/\r?\n/);
4603 let dataPlayer=httpGet(url+"/map/player.txt").split(/\r?\n/);
4604 let dataAlly=httpGet(url+"/map/ally.txt").split(/\r?\n/);
4605
4606 for(let i=0;i<dataAlly.length-1;i++){
4607 // console.log(dataPlayer[i].split(",")[1])
4608 let tribeName=innoReplaceSpecialCaracters(dataAlly[i].split(",")[1])
4609 mapAlly.set(dataAlly[i].split(",")[0],tribeName)
4610 }
4611
4612 for(let i=0;i<dataPlayer.length-1;i++){
4613 // console.log(dataPlayer[i].split(",")[1])
4614 let playerName=innoReplaceSpecialCaracters(dataPlayer[i].split(",")[1])
4615 mapPlayer.set(dataPlayer[i].split(",")[0],{
4616 allyId:dataPlayer[i].split(",")[2],
4617 playerName:playerName,
4618 tribeName:mapAlly.get(dataPlayer[i].split(",")[2])
4619 })
4620 }
4621
4622
4623
4624 for(let i=0;i<dataVillage.length;i++){
4625 if(mapPlayer.get(dataVillage[i].split(",")[4])!=undefined){
4626 mapVillage.set(dataVillage[i].split(",")[2]+"|"+dataVillage[i].split(",")[3],{
4627 villageId:dataVillage[i].split(",")[0],
4628 playerId:dataVillage[i].split(",")[4],
4629 points:dataVillage[i].split(",")[5],
4630 allyId:mapPlayer.get(dataVillage[i].split(",")[4]).allyId,
4631 playerName:mapPlayer.get(dataVillage[i].split(",")[4]).playerName,
4632 tribeName:mapPlayer.get(dataVillage[i].split(",")[4]).tribeName
4633 })
4634 }
4635 }
4636 obj.datetime=current_date
4637 obj.data=Array.from(mapVillage.entries())
4638
4639 let data=JSON.stringify(obj)
4640 data=replaceSpecialCaracters(data)
4641 await localBase.setItem(filename_innoDB,data)
4642
4643 console.log("upload new data")
4644
4645 }
4646 else{
4647 console.log("already exist")
4648 }
4649 }
4650 resolve(mapVillage)
4651
4652
4653 })
4654
4655
4656}
4657
4658function innoReplaceSpecialCaracters(text){
4659 text=text.replaceAll("+"," ")
4660 text=text.replaceAll("%21","!")
4661 text=text.replaceAll("%23","#")
4662 text=text.replaceAll("%24","$")
4663 text=text.replaceAll("%25","%")
4664
4665 text=text.replaceAll("%28","(")
4666 text=text.replaceAll("%29",")")
4667 text=text.replaceAll("%2A","*")
4668 text=text.replaceAll("%2B","+")
4669 text=text.replaceAll("%2C",",")
4670 text=text.replaceAll("%2F ","/")
4671
4672
4673 text=text.replaceAll("%3A",":")
4674 text=text.replaceAll("%3D","=")
4675 text=text.replaceAll("%3F","?")
4676
4677 text=text.replaceAll("%40","@")
4678
4679 text=text.replaceAll("%5B","[")
4680 text=text.replaceAll("%5D","]")
4681
4682 text=text.replaceAll("%7C","|")
4683 text=text.replaceAll("%7E","~")
4684
4685 text=text.replaceAll("%C3%84","Ä")
4686 text=text.replaceAll("%C3%85","Å")
4687 text=text.replaceAll("%C3%86","Æ")
4688 text=text.replaceAll("%C3%A2","â")
4689 text=text.replaceAll("%C3%A4","ä")
4690 text=text.replaceAll("%C3%A5","å")
4691 text=text.replaceAll("%C3%A6","æ")
4692 text=text.replaceAll("%C3%B6","ö")
4693 text=text.replaceAll("%C3%B8","ø")
4694 text=text.replaceAll("%C3%BC","ü")
4695
4696 text=text.replaceAll("%C4%83","ă")
4697
4698 text=text.replaceAll("%C8%99","ș")
4699 text=text.replaceAll("%C5%A3","ţ")
4700 text=text.replaceAll("%C8%9B","ț")
4701
4702 return text
4703}
4704
4705function insertlibraryLocalBase(){
4706 return new Promise((resolve,reject)=>{
4707
4708 let start=new Date().getTime()
4709 let script = document.createElement('script');
4710 script.type="text/javascript"
4711 script.src="https://dl.dropboxusercontent.com/s/22qgnhyxnyono68/libraryIndexedDB.js?dl=0"
4712 script.onload = function () {
4713 let stop=new Date().getTime()
4714 console.log(`insert idb library in ${stop-start} ms`)
4715 resolve("insert library")
4716 };
4717 document.getElementsByTagName("head")[0].appendChild(script);
4718 })
4719}
4720
4721
4722
4723///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
4724
4725
4726////////////////////////////////////////////// get supports out going from command/support page ///////////////////////////////////////
4727
4728function getCommandsGoing(){
4729
4730 return new Promise((resolve,reject)=>{
4731 //create link
4732 let linkCommand=game_data.link_base_pure+"overview_villages&mode=commands&type=all"
4733
4734 // console.log(linkCommand)
4735 document.body.innerHTML=httpGet(linkCommand)
4736
4737
4738 //get pages for all incoming
4739 let list_pages=[]
4740 var map_outgoing_support=new Map()
4741 var map_outgoing_attack=new Map()
4742
4743 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
4744 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0]).forEach(function(item){
4745 list_pages.push(item.value)
4746 })
4747 list_pages.pop();
4748 }
4749 else if(document.getElementsByClassName("paged-nav-item").length>0){//all pages from the current folder
4750 let nr=0;
4751 Array.from(document.getElementsByClassName("paged-nav-item")).forEach(function(item){
4752 let current=item.href;
4753 current=current.split("page=")[0]+"page="+nr
4754 nr++;
4755 list_pages.push(current);
4756 })
4757 }
4758 else{
4759 list_pages.push(linkCommand);
4760 }
4761 list_pages=list_pages.reverse();
4762 // console.log(list_pages)
4763
4764
4765 //for each page
4766 function ajaxRequest (urls) {
4767 let current_url
4768 if(urls.length>0){
4769 current_url=urls.pop()
4770 }
4771 else{
4772 current_url="stop"
4773 }
4774 // console.log(current_url)
4775 if (urls.length >= 0 && current_url!="stop") {// go to every page and get all rows
4776 $.ajax({
4777 url: current_url,
4778 method: 'get',
4779 success: (data) => {
4780 document.body.innerHTML=data
4781 if(document.getElementById("commands_table")==null){//commands outgoing none
4782 resolve(map_outgoing_support)
4783 }else{
4784 var table_commands=document.getElementById("commands_table").getElementsByTagName("tbody")[0].children
4785 for(let i=1;i<table_commands.length-1;i++){
4786 if(table_commands[i].children[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)!=null){//destination must contains coord destination
4787
4788 let commandId=table_commands[i].getElementsByClassName("own_command")[0].getAttribute("data-command-id")
4789 let coord_destination=table_commands[i].getElementsByClassName("quickedit-label")[0].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
4790 let coord_origin=table_commands[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
4791 let coord_origin_id=table_commands[i].children[1].getElementsByTagName("a")[0].href.split("id=")[1]
4792 let landing_time=getLandTime(table_commands[i].children[2].innerText)
4793 let troops={}
4794 let player_origin_name=game_data.player.name
4795 let player_origin_id=game_data.player.id
4796 Array.from(table_commands[i].getElementsByClassName("unit-item")).forEach((elem,index)=>{
4797 troops[game_data.units[index]]=parseInt(elem.innerText)
4798 })
4799
4800 //add data for the current command into a map
4801 let type_attack=table_commands[i].getElementsByTagName("img")[0].src.split("command/")[1]
4802 if(type_attack.includes("support")){
4803 delete troops["snob"]
4804 map_outgoing_support.set(commandId,{
4805 coord_destination:coord_destination,
4806 coord_origin:coord_origin,
4807 landing_time:landing_time,
4808 troops:troops,
4809 player_origin_name:player_origin_name,
4810 player_origin_id:player_origin_id,
4811 commandId:commandId,
4812 coord_origin_id:coord_origin_id,
4813 type_attack:type_attack,
4814 labelName:"none"
4815
4816 })
4817 }
4818 else if(type_attack=="attack_small.png" || type_attack=="attack_medium.png" || type_attack=="attack_large.png"){
4819 // console.log("is an attack")
4820 let serverTime=document.getElementById("serverTime").innerText
4821 let serverDate=document.getElementById("serverDate").innerText.split("/")
4822 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
4823 let date_current=new Date(serverDate+" "+serverTime)
4824 date_current.setDate(date_current.getDate()+7)
4825
4826
4827 map_outgoing_attack.set(commandId,{
4828 coord_destination:coord_destination,
4829 coord_origin:coord_origin,
4830 landing_time:landing_time,
4831 troops:troops,
4832 player_origin_name:player_origin_name,
4833 player_origin_id:player_origin_id,
4834 commandId:commandId,
4835 coord_origin_id:coord_origin_id,
4836 type_attack:type_attack,
4837 labelName:"none",
4838 uploadTime:date_current.getTime()
4839
4840 })
4841 }
4842 }
4843 }
4844
4845 UI.SuccessMessage("get page: "+urls.length)
4846 window.setTimeout(function(){
4847 ajaxRequest (list_pages)
4848 },200)
4849
4850 }
4851 }
4852 })
4853
4854 }
4855 else//append all rows into table
4856 {
4857 UI.SuccessMessage("done")
4858 resolve([map_outgoing_support,map_outgoing_attack])
4859 }
4860 }
4861 ajaxRequest(list_pages);
4862 })
4863
4864}
4865
4866////////////////////////////////////////////// get coming supports and attacks from incoming page ///////////////////////////////////////
4867
4868 function getSupportsAndAttacks(){
4869 return new Promise( (resolve,reject)=>{
4870
4871 if(document.getElementsByClassName("info").length>0)
4872 $(".info").remove()
4873 var current_href_incomings=window.location.href;
4874 ////////////////////////////////////////////////unIgnored attacks/supports....................................
4875 let incomings_href=game_data.link_base_pure+"overview_villages&mode=incomings&type=unignored&subtype=all&group=0&page=-1";
4876
4877 // console.log("currentLink")
4878 // console.log(incomings_href)
4879 document.body.innerHTML=httpGet(incomings_href);
4880
4881
4882
4883
4884 if(document.getElementsByClassName("overview_filters_delete").length>0){
4885 reject("turn off filters on incomings page")
4886 }
4887 let list_href=[];
4888 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
4889 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
4890 list_href.push({
4891 href:el.value,
4892 unignored:true
4893 });
4894 })
4895 list_href.pop();
4896 }
4897 else if(document.getElementsByClassName("paged-nav-item").length>0){
4898 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
4899 for(let i=0;i<arr.length;i++)
4900 list_href.push({
4901 href:arr[i].getAttribute("href"),
4902 unignored:true
4903 })
4904 }
4905 else if(document.getElementById("incomings_table")!=null){
4906 list_href.push({
4907 href:incomings_href,
4908 unignored:true
4909 })
4910 }
4911
4912
4913 ///////////////////////////////////////////////////////////ignored attacks/support////////////////////////////////////////
4914 incomings_href=game_data.link_base_pure+"overview_villages&mode=incomings&type=ignored&subtype=all&group=0&page=-1";
4915
4916 console.log("currentLink")
4917 console.log(incomings_href)
4918 document.body.innerHTML=httpGet(incomings_href);
4919
4920
4921 if(document.getElementsByClassName("vis")[1].getElementsByTagName("select").length>0){
4922 Array.from(document.getElementsByClassName("vis")[1].getElementsByTagName("select")[0].options).forEach(el=>{
4923 list_href.push({
4924 href:el.value,
4925 unignored:false
4926 });
4927 })
4928 list_href.pop();
4929 }
4930 else if(document.getElementsByClassName("paged-nav-item").length>0){
4931 let arr=Array.from(document.getElementsByClassName("paged-nav-item"));
4932 for(let i=0;i<arr.length;i++)
4933 list_href.push({
4934 href:arr[i].getAttribute("href"),
4935 unignored:false
4936 })
4937 }
4938 else if(document.getElementById("incomings_table")!=null){
4939 list_href.push({
4940 href:incomings_href,
4941 unignored:false
4942 })
4943 }
4944
4945
4946
4947
4948
4949
4950
4951 console.log(list_href)
4952
4953
4954 var indexIncoming=1;
4955 var url_length=list_href.length
4956 var map_outgoing_support=new Map()
4957
4958 var list_incomingId=[]
4959 var map_exist_support=localStorage.getItem(game_data.world+"map_exist_support")
4960 if(map_exist_support!=undefined)
4961 map_exist_support=new Map(JSON.parse(map_exist_support))
4962 else
4963 map_exist_support=new Map()
4964
4965
4966 function ajaxRequest (urls) {
4967 let current_url,unignored
4968 var time=0
4969 if(urls.length>0){
4970 let obj=urls.pop();
4971 current_url=obj.href
4972 unignored=obj.unignored
4973 }
4974 else{
4975 current_url="stop"
4976 }
4977 console.log("length "+urls.length)
4978 // console.log(current_url)
4979
4980 if (urls.length >= 0 && current_url!="stop") {
4981 var start_ajax=new Date();
4982 $.ajax({
4983 url: current_url,
4984 method: 'get',
4985 success: (data) => {
4986 document.body.innerHTML=data
4987 if(document.getElementById("incomings_table")==null)
4988 alert("turn off the filters");
4989 let table_incomings=document.getElementById("incomings_table").getElementsByTagName("tbody")[0].children
4990 for(let i=1;i<table_incomings.length-1;i++){
4991
4992 if(table_incomings[i].children[0].innerText!="--"){
4993 let commandId=table_incomings[i].getElementsByClassName("quickedit")[0].getAttribute("data-id")
4994
4995 // console.log(commandId)
4996 list_incomingId.push(commandId)
4997 let coord_destination=table_incomings[i].children[1].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
4998 let coord_origin=table_incomings[i].children[2].innerText.match(/[0-9]{3}\|[0-9]{3}/)[0]
4999 let coord_origin_id=table_incomings[i].children[2].getElementsByTagName("a")[0].href.split("id=")[1]
5000 let length_tr=table_incomings[i].children.length
5001 let landing_time=getLandTime(table_incomings[i].children[length_tr-2].innerText)
5002 let troops={}
5003 let player_origin_name=table_incomings[i].children[length_tr-4].innerText
5004 let player_origin_id=table_incomings[i].children[length_tr-4].getElementsByTagName("a")[0].href.split("id=")[1]
5005
5006
5007 let labelName="none"
5008 let type_attack=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[0].src.split("command/")[1]
5009 if(table_incomings[i].children[0].getElementsByTagName("img").length==2){
5010 labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src.split("tiny/")[1]
5011 if(labelName==undefined)
5012 labelName=table_incomings[i].getElementsByClassName("quickedit")[0].getElementsByTagName("img")[1].src.split("command/")[1]
5013
5014 }
5015
5016
5017 //check if an attack was ignored or unignored
5018 if(map_exist_support.has(commandId)){
5019 if(map_exist_support.get(commandId)!=unignored)
5020 map_exist_support.delete(commandId)
5021 }
5022
5023
5024 // console.log(coord_destination)
5025 //add new command id to localstorage and save data to map_going_support
5026 if(!map_exist_support.has(commandId)){
5027
5028
5029 if(!map_outgoing_support.has(coord_destination)){
5030 map_outgoing_support.set(coord_destination,[{
5031 coord_destination:coord_destination,
5032 coord_origin:coord_origin,
5033 landing_time:landing_time,
5034 troops:troops,
5035 player_origin_name:player_origin_name,
5036 player_origin_id:player_origin_id,
5037 type_attack:type_attack,
5038 commandId:commandId,
5039 labelName:labelName,
5040 coord_origin_id:coord_origin_id,
5041 unignored:unignored
5042 }])
5043 // console.log("list support doesn't exist")
5044 }
5045 else{
5046 let list_support=map_outgoing_support.get(coord_destination)
5047 list_support.push({
5048 coord_destination:coord_destination,
5049 coord_origin:coord_origin,
5050 landing_time:landing_time,
5051 troops:troops,
5052 player_origin_name:player_origin_name,
5053 player_origin_id:player_origin_id,
5054 type_attack:type_attack,
5055 commandId:commandId,
5056 labelName:labelName,
5057 coord_origin_id:coord_origin_id,
5058 unignored:unignored
5059 })
5060 map_outgoing_support.set(coord_destination,list_support)
5061 // console.log("list support updated")
5062
5063 }
5064 map_exist_support.set(commandId,{
5065 unignored:unignored,
5066 playerId:game_data.player.id
5067 })
5068 }
5069
5070
5071 }
5072 }
5073
5074 UI.SuccessMessage(indexIncoming+"/"+url_length)
5075 indexIncoming++;
5076 var stop_ajax=new Date();
5077 var dif_time=stop_ajax.getTime()-start_ajax.getTime()
5078 console.log("wait: "+dif_time)
5079 window.setTimeout(function(){
5080 ajaxRequest (list_href)
5081 },200-dif_time)
5082 }
5083 })
5084
5085 }
5086 else
5087 {
5088 UI.SuccessMessage("done",2000)
5089 if(document.getElementById("incomings_table")!=null){
5090 // showButtons();
5091 }
5092
5093 if( document.getElementsByClassName("g-recaptcha").length>0){//recaptcha
5094 console.log("recapthca")
5095 UI.ErrorMessage("recapthca, upload again")
5096 resolve("recapthca, upload again");
5097 throw new Error("recapthca, upload again");
5098 }
5099
5100 window.setTimeout(function(){
5101 document.body.innerHTML=httpGet(current_href_incomings);
5102
5103
5104 Array.from(map_exist_support.keys()).forEach((key)=>{
5105 if(!list_incomingId.includes(key)){
5106 map_exist_support.delete(key)
5107 console.log("delete id: "+key)
5108 }
5109 })
5110
5111 resolve({
5112 map_outgoing_support:map_outgoing_support,
5113 map_exist_support:map_exist_support
5114 })
5115 },200)
5116
5117
5118
5119 }
5120 }
5121 if(list_href.length>0)
5122 ajaxRequest(list_href);
5123 else
5124 reject("error on incomings")
5125 })
5126}
5127
5128/////////////////////////////////////////////main function for getting all supports and attacks//////////////////////////////////////////
5129
5130async function uploadSupports(){
5131 var [mapVillage, data_support,data_attack,mapStatus]=await Promise.all([getInfoVIllages(), readFileDropbox(filename_support),readFileDropbox(filename_commands_attack),readFileDropbox(filename_status_upload)]).catch(err=>{alert(err)})
5132 var result_commands=await getCommandsGoing().catch(err=>{alert(err);throw err})
5133
5134 var map_going=result_commands[0]
5135 var map_going_attacks=result_commands[1]
5136 console.log("map_going_attacks",map_going_attacks)
5137
5138
5139 //extract data from dropbox, update and then upload
5140 let map_support_dropbox,map_troops_home_dropbox
5141 if(data_support=="[]"){
5142 map_support_dropbox=new Map()
5143 map_troops_home_dropbox=new Map()
5144 }else{
5145
5146 try {
5147 map_support_dropbox=new Map(JSON.parse(lzw_decode(data_support))[0])
5148 map_troops_home_dropbox =new Map(JSON.parse(lzw_decode(data_support))[1])
5149 } catch (error) {
5150 console.log("erorrrrrrrrrrrrrrrr map support from dropbox")
5151 map_support_dropbox=new Map()
5152 map_troops_home_dropbox=new Map()
5153 }
5154 }
5155
5156 //if database is stored locally
5157 if(await localBase.getItem(game_data.world+"map_support_dropbox")!=undefined){
5158 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"map_support_dropbox"))));
5159 console.log("map_localBase_support",map_localBase)
5160 map_support_dropbox=new Map([...map_localBase, ...map_support_dropbox])
5161 }
5162 if(await localBase.getItem(game_data.world+"map_troops_home_dropbox")!=undefined){
5163 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"map_troops_home_dropbox"))));
5164 console.log("map_localBase_support_home",map_localBase)
5165 map_troops_home_dropbox=new Map([...map_localBase, ...map_troops_home_dropbox])
5166 }
5167
5168 let map_support_uploaded=new Map()
5169 Array.from(map_support_dropbox.keys()).forEach(key=>{
5170 let list_coming=map_support_dropbox.get(key)
5171 for(let i=0;i<list_coming.length;i++){
5172 if(list_coming[i].type_attack.includes("support")){
5173 map_support_uploaded.set(list_coming[i].commandId,"true")
5174 }
5175 }
5176 })
5177 console.log("map_support_uploaded",map_support_uploaded)
5178
5179
5180
5181 var resultSupport=await getSupportsAndAttacks().catch(err=>{alert(err);throw err})
5182
5183 var map_coming=resultSupport.map_outgoing_support
5184 var map_troops_home=new Map()
5185 console.log("map_cominghere",map_coming)
5186 console.log("map_support_dropbox",map_support_dropbox)
5187
5188 //for each support coming get all troops
5189 var keys=Array.from(map_coming.keys())
5190 let start_get_troops=new Date().getTime()
5191 const run = async () => {
5192 console.log("Starting...");
5193 for (let i = 0; i < keys.length; i++) {
5194 let list_support=map_coming.get(keys[i])
5195 for(let j=0;j<list_support.length;j++){
5196 if(list_support[j].type_attack.includes("support") && !map_support_uploaded.has(list_support[j].commandId)){
5197 let troops= await ajaxTroopsComing(list_support[j].commandId)
5198 // console.log(troops)
5199 list_support[j].troops=troops
5200 UI.SuccessMessage("info coord coming: "+(keys.length-i)+" , get troops coming "+(list_support.length-j))
5201 }
5202 else{//type_attack=="attack"
5203 try {//in case a barb is taken and tw database is not yet updated will throw an error
5204 let villageId=mapVillage.get(list_support[j].coord_destination).villageId
5205 if(!map_troops_home.has(list_support[j].coord_destination)){
5206 let obj = await ajaxTroopsStationed(villageId)
5207 // console.log("troops home")
5208 console.log(obj)
5209
5210 let serverTime=document.getElementById("serverTime").innerText
5211 let serverDate=document.getElementById("serverDate").innerText.split("/")
5212 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
5213 let date_current=new Date(serverDate+" "+serverTime)
5214 date_current.setDate(date_current.getDate()+7)
5215
5216 obj.uploadTime=date_current.getTime()
5217 map_troops_home.set(list_support[j].coord_destination,obj)
5218 UI.SuccessMessage("info coord home: "+(keys.length-i)+" , get troops home "+(list_support.length-j))
5219
5220 }
5221 } catch (error) {
5222 console.log(error)
5223 }
5224
5225 }
5226 }
5227 map_coming.set(keys[i],list_support)
5228
5229
5230 }
5231 console.log("Done!");
5232 };
5233 await run();
5234 var stop_get_troops=new Date().getTime()
5235 console.log("time get troops "+(stop_get_troops-start_get_troops))
5236
5237 console.log("support outgoing")
5238 console.log(map_going)
5239 console.log("support coming")
5240 console.log(map_coming)
5241 console.log("troops home")
5242 console.log(map_troops_home)
5243
5244 //merge map_going and map_coming
5245 if(map_going !=undefined){// no commands going
5246 Array.from(map_going.keys()).forEach(key=>{
5247 let obj_going=map_going.get(key)
5248 if(map_coming.has(obj_going.coord_destination)){
5249 // console.log("map coming update coord")
5250 let list_coming=map_coming.get(obj_going.coord_destination)
5251 let commandIdNotExist=true
5252 for(let i=0;i<list_coming.length;i++){
5253 if(key==list_coming[i].commandId){
5254 commandIdNotExist=false;
5255 break;
5256 }
5257 }
5258 if(commandIdNotExist==true){
5259 list_coming.push(obj_going)
5260 map_coming.set(obj_going.coord_destination,list_coming)
5261 // console.log("command Id doesnt Exist")
5262 }
5263 }else{
5264 map_coming.set(obj_going.coord_destination,[obj_going])
5265 // console.log("map coming add coord")
5266
5267 }
5268
5269 })
5270 console.log("support coming after merge")
5271 console.log(map_coming)
5272
5273 }
5274
5275
5276
5277 let map_attack_dropbox
5278 /////////////////////////////////get and prelucrate map commands attacks//////////////
5279 if(data_attack=="[]"){
5280 map_attack_dropbox=new Map()
5281 }else{
5282 try {
5283 map_attack_dropbox=new Map(JSON.parse(lzw_decode(data_attack)))
5284 } catch (error) {
5285 console.log("erorrrrrrrrrrrrrrrr map attack from dropbox")
5286 map_attack_dropbox=new Map()
5287 }
5288 }
5289 if(await localBase.getItem(game_data.world+"map_attack_dropbox")!=undefined){
5290 let map_localBase=new Map( JSON.parse(lzw_decode(await localBase.getItem(game_data.world+"map_attack_dropbox"))));
5291 console.log("map_localBase_attacks",map_localBase)
5292 map_attack_dropbox=new Map([...map_localBase, ...map_attack_dropbox])
5293 }
5294
5295
5296 console.log("map_going_attacks",map_going_attacks)
5297
5298 if(map_going_attacks !=undefined){// no commands going
5299 Array.from(map_going_attacks.keys()).forEach(key=>{
5300 try {
5301 let obj=map_going_attacks.get(key)
5302 obj.coord_destination_id=mapVillage.get(obj.coord_destination).villageId
5303 obj.player_destination_name=mapVillage.get(obj.coord_destination).playerName
5304 obj.player_destination_id=mapVillage.get(obj.coord_destination).playerId
5305 map_attack_dropbox.set(key,obj)
5306 } catch (error) {
5307 console.log("command attack to barb")
5308 console.log(error)
5309 }
5310 })
5311 }
5312
5313
5314
5315
5316
5317
5318
5319
5320 return new Promise(async(resolve,reject)=>{
5321
5322 console.log("map_dropbox_coming")
5323 console.log(map_support_dropbox)
5324 console.log("map_dropbox_home")
5325 console.log(map_troops_home_dropbox)
5326
5327
5328 let serverTime=document.getElementById("serverTime").innerText
5329 let serverDate=document.getElementById("serverDate").innerText.split("/")
5330 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
5331 let date_current=new Date(serverDate+" "+serverTime).getTime()
5332 let date_current_commands=serverDate+" "+serverTime
5333
5334
5335
5336 map_troops_home_dropbox=new Map([...map_troops_home_dropbox, ...map_troops_home])
5337 console.log("map_troops_home_dropbox merge")
5338 console.log(map_troops_home_dropbox)
5339 //delete from map troops home if it's older than a week
5340 Array.from(map_troops_home_dropbox.keys()).forEach(key=>{
5341 if(date_current>map_troops_home_dropbox.get(key).uploadTime){
5342 map_troops_home_dropbox.delete(key)
5343 }
5344 })
5345
5346
5347 // update map from dropbox with the new data
5348 Array.from(map_coming.keys()).forEach(key=>{
5349 let list_coming=map_coming.get(key)
5350 if(map_support_dropbox.has(key)){
5351 let list_dropbox=map_support_dropbox.get(key)
5352 list_dropbox=list_dropbox.concat(list_coming)
5353 var list_concat =[...new Map(list_dropbox.map(item => [item["commandId"], item])).values()]
5354 // console.log("list concat")
5355 list_concat.sort((o1,o2)=>{
5356 return (new Date(o1.landing_time).getTime()>new Date(o2.landing_time).getTime())?1:
5357 (new Date(o1.landing_time).getTime()<new Date(o2.landing_time).getTime())?-1:0
5358 })
5359 // console.log(list_concat)
5360 if(list_concat.length==0){
5361 map_support_dropbox.delete(key)
5362 console.log("list is empty, removed")
5363 }
5364 else
5365 map_support_dropbox.set(key,list_concat)
5366 }
5367 else{
5368 console.log("list coming")
5369 list_coming.sort((o1,o2)=>{
5370 return (new Date(o1.landing_time).getTime()>new Date(o2.landing_time).getTime())?1:
5371 (new Date(o1.landing_time).getTime()<new Date(o2.landing_time).getTime())?-1:0
5372 })
5373 // console.log(list_coming)
5374 map_support_dropbox.set(key,list_coming)
5375 }
5376 })
5377
5378
5379 //if a command arrived delete from map
5380 Array.from(map_support_dropbox.keys()).forEach(key=>{
5381 let list_support=map_support_dropbox.get(key)
5382 // console.log(list_support)
5383 if(list_support.length==0){
5384 map_support_dropbox.delete(key)
5385 console.log("delete coord from map support dropbox")
5386 }
5387 else{
5388 for(let i=0;i<list_support.length;i++){
5389 let date_land=new Date(list_support[i].landing_time).getTime()
5390 if(date_current>date_land){
5391 list_support.splice(i,1)
5392 i--;
5393 }
5394 }
5395 map_support_dropbox.set(key,list_support)
5396 }
5397
5398 })
5399
5400 //delete map commands attacks if it's older than 1 week
5401 Array.from(map_attack_dropbox.keys()).forEach(key=>{
5402 let obj=map_attack_dropbox.get(key)
5403 let date_upload=new Date(obj.uploadTime).getTime()
5404
5405 if(date_current > date_upload)
5406 map_attack_dropbox.delete(key)
5407 })
5408
5409
5410 //update status map
5411 let obj_status={
5412 name:game_data.player.name,
5413 command_date:date_current_commands,
5414 }
5415
5416
5417 if(mapStatus=="[]")
5418 mapStatus=new Map()
5419 else
5420 mapStatus=new Map(JSON.parse(mapStatus))
5421
5422 if(mapStatus.has(game_data.player.id)){
5423 let obj_update=mapStatus.get(game_data.player.id)
5424 mapStatus.set(game_data.player.id, {...obj_update, ...obj_status} )
5425 }
5426 else{
5427 mapStatus.set(game_data.player.id,obj_status)
5428 }
5429
5430
5431
5432 UI.SuccessMessage("compressing database, wait few seconds",2000)
5433 let data_list=[Array.from(map_support_dropbox.entries()),Array.from(map_troops_home_dropbox.entries())]
5434 data_list=JSON.stringify(data_list)
5435 data_list=replaceSpecialCaracters(data_list)
5436 data_list=lzw_encode(data_list)
5437 console.log("upload supports")
5438
5439 console.log("map_attack_dropbox",map_attack_dropbox)
5440 let data_commands_attacks=lzw_encode(JSON.stringify(Array.from(map_attack_dropbox.entries())))
5441 let data_status=JSON.stringify(Array.from(mapStatus.entries()))
5442
5443 addWindow();
5444 showButtons();
5445
5446 //save locally
5447 let data_support=lzw_encode(replaceSpecialCaracters(JSON.stringify(Array.from(map_support_dropbox.entries()))))
5448 await localBase.setItem(game_data.world+"map_support_dropbox",data_support)
5449 let data_support_home=lzw_encode(replaceSpecialCaracters(JSON.stringify(Array.from(map_troops_home_dropbox.entries()))))
5450 await localBase.setItem(game_data.world+"map_troops_home_dropbox",data_support_home)
5451
5452 await localBase.setItem(game_data.world+"map_attack_dropbox",data_commands_attacks)
5453
5454
5455 let result_support=await uploadFile(data_list,filename_support,dropboxToken).catch(err=>alert(err))
5456 let result_attacks=await uploadFile(data_commands_attacks,filename_commands_attack,dropboxToken).catch(err=>alert(err))
5457 let result_Status=await uploadFile(data_status,filename_status_upload,dropboxToken).catch(err=>alert(err))
5458
5459 if(result_support=="succes"){
5460 document.getElementById("progress_support").innerText=map_coming.size+" coords"
5461 document.getElementById("progress_all").innerText="done";
5462 var data=JSON.stringify(Array.from(resultSupport.map_exist_support.entries()))
5463 localStorage.setItem(game_data.world+"map_exist_support",data)
5464 UI.SuccessMessage("upload commands done","slow")
5465 resolve("succes")
5466 }
5467 else{
5468 reject("error")
5469 }
5470 })
5471
5472}
5473
5474/////////////////////////////////////////////get troops coming from each village on incomings page//////////////////////////////////////////
5475
5476
5477function ajaxTroopsComing(commandId){
5478 return new Promise((resolve,reject)=>{
5479 let units=game_data.units.slice()
5480 if(units.includes("militia")){
5481 units.pop()
5482 }
5483
5484 let startAjax=new Date().getTime()
5485 $.ajax({
5486 url: game_data.link_base_pure+`info_command&ajax=details&id=${commandId}`,
5487 method: 'get',
5488 success: (data) => {
5489 let troops={}
5490 if(data.units!=undefined){
5491 troops=data.units
5492 Object.keys(troops).forEach(key=>{
5493 troops[key]=parseInt(troops[key].count)
5494 })
5495 }
5496 else{
5497 Object.keys(units).forEach(key=>{
5498 troops[units[key]]=0
5499 })
5500 }
5501 let stopAjax=new Date().getTime()
5502 let difAjax=stopAjax-startAjax
5503 console.log("wait ",difAjax)
5504 window.setTimeout(()=>{
5505 resolve(troops)
5506 },200-difAjax)
5507
5508 },error:(data)=>{
5509 reject(data)
5510 }
5511
5512 })
5513 })
5514}
5515
5516/////////////////////////////////////////////get troops at home from each village on incomings page//////////////////////////////////////////
5517
5518function ajaxTroopsStationed(villageId){
5519 return new Promise((resolve,reject)=>{
5520
5521 let startAjax=new Date().getTime()
5522 $.ajax({
5523 url:game_data.link_base_pure + `map&ajax=map_info&source=${villageId}&target=${villageId}&`,
5524 method: 'get',
5525 success: (response) => {
5526 // console.log(response)
5527 let units=game_data.units
5528 let obj_troops={}
5529 let obj_result={}
5530 for(let i=0;i<units.length-1;i++){
5531 obj_troops[units[i]]=parseInt(response.units[units[i]].count.home)+parseInt(response.units[units[i]].count.foreign)
5532 }
5533 let wallLevel,farmLevel,flagName,LoyaltyLevel
5534 wallLevel=response.buildings.wall
5535 farmLevel=response.buildings.farm
5536 LoyaltyLevel=response.mood
5537 // console.log(response.flag)
5538 if(response.flag!=undefined)
5539 flagName =response.flag.short_desc
5540 else
5541 flagName="none"
5542 // console.log(obj_troops)
5543 // console.log("wallLevel: "+wallLevel)
5544 // console.log("farmLevel: "+farmLevel)
5545 // console.log("flagName: "+flagName)
5546 // console.log("LoyaltyLevel: "+LoyaltyLevel)
5547
5548 obj_result.obj_troops=obj_troops
5549 obj_result.wallLevel=wallLevel
5550 obj_result.farmLevel=farmLevel
5551 obj_result.flagName=flagName
5552 obj_result.LoyaltyLevel=LoyaltyLevel
5553
5554
5555 let stopAjax=new Date().getTime()
5556 let difAjax=stopAjax-startAjax
5557 console.log("wait ",difAjax)
5558 window.setTimeout(()=>{
5559 resolve(obj_result)
5560 },200-difAjax)
5561
5562 },error:(data)=>{
5563 reject(data)
5564 }
5565
5566 })
5567
5568 })
5569}
5570
5571
5572
5573
5574//////////////////////////////////////////////main table + all the logic for creating main table///////////////////////////////////////////////
5575var mapAttacksVillageId=new Map()
5576
5577async function viewSupport(){
5578 if(document.getElementById("div_container")!=null)
5579 document.getElementById("div_container").remove();
5580 ///////////////////////////////////////////////////////////////////main table//////////////////////////////////////////////////////////
5581 let html_info=`
5582 <div id="div_container_view" class="ui-widget-content div_remove" style="width:900px;height:auto;background-color:${backgroundColor};cursor:move;z-index:50;">
5583
5584 <div style="position:relative;top:10px;left: 800px;display:flex;align-items: center;justify-content: center;background-color:${backgroundColor};width:100px;height:30px">
5585 <div id="minimize_page" style="background-color:white;margin-right:10px"><a href="#"><img src="https://img.icons8.com/material-outlined/16/000000/collapse.png"/></a></div>
5586 <div class="close-btn" ><a href="#" onclick="closeWindow()"><b><font color="${titleColor}">X</font></b></a></div>
5587 </div>
5588
5589 <h2 class="div_minimize" ><center style="margin:10px;"><u><font color="${titleColor}">Upload data</font></u></center></h2>
5590
5591 <div class="div_minimize" style="position:relative;top:-35px;left: 20px" ><a href="#" onclick="viewSupport()" id="page_main" ><img src="https://img.icons8.com/officel/30/000000/long-arrow-left.png"/></a></div>
5592
5593
5594 <div class="div_minimize">
5595 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" onclick="createTableSettings()" style="margin:10px" value="Settings">
5596 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_rank_attacker" style="margin:10px" value="Rank attackers">
5597 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_rank_defender" style="margin:10px" value="Rank defenders">
5598 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_upload_time" style="margin:10px" value="Upload time">
5599 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_get_coords" style="margin:10px" value="get coords">
5600 <input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_op_spotter" style="margin:10px" value="OP spotter">
5601 <div id="div_settings" style="margin:10px" hidden> </div>
5602 <div id="div_rank" style="margin:10px" hidden> </div>
5603 <div id="div_rank_attacker" style="margin:10px" hidden> </div>
5604 <div id="div_rank_defender" style="margin:10px" hidden> </div>
5605 <div id="div_upload_time" style="margin:10px" hidden> </div>
5606 <div id="div_get_coords" style="margin:10px" hidden> </div>
5607
5608 <div style="display:flex;justify-content: center;width:100%">
5609 <div style="width: 45%;margin:15px">
5610 <table id="table_search" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};">
5611 <tr>
5612 <td style="text-align:center; width:auto; background-color:${headerColor}">
5613 <center style="margin:5px"><font color="${titleColor}"><p>search by coord</p></font></center>
5614 </td>
5615 <td style="text-align:center; width:auto; background-color:${headerColor}">
5616 <center style="margin:5px"> <input id="input_search" type="text" style="margin:10px" placeholder="coord"></center>
5617 </td>
5618 </tr>
5619 </table>
5620 </div>
5621 <div style="width: 45%;margin:15px" >
5622 <table id="table_select_info" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};" hidden>
5623 <tr>
5624 <td style="text-align:center; width:auto; background-color:${headerColor};text-align:left">
5625 <input style="margin:5px" type="radio" id="radio_offensive" name="type_info" value="offensive_info">
5626 <label for="radio_offensive" style="color:${titleColor};text-align:left;margin:5px">offensive info</label><br>
5627 <input style="margin:5px" type="radio" id="radio_defensive" name="type_info" value="defensive_info" >
5628 <label for="radio_defensive" style="color:${titleColor};text-align:left;margin:5px">defensive info</label><br>
5629
5630 </td>
5631 <td style="text-align:center; width:auto; background-color:${headerColor}">
5632 <select id="select_player">
5633 </select>
5634 </td>
5635 <td style="text-align:center; width:auto; background-color:${headerColor}">
5636 <center><input class="btn evt-confirm-btn btn-confirm-yes" type="button" id="btn_show_info" style="margin:10px" value="show"></center>
5637 </td>
5638 </tr>
5639
5640 </table>
5641 </div>
5642 </div>
5643
5644 <br>
5645
5646 <table id="table_view" class="" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;">
5647 <thead>
5648 <tr>
5649 <td style="text-align:center; width:auto; background-color:${headerColor}" colspan="2">
5650 <center style="margin:1px"><font color="${titleColor}">total</font></center>
5651 </td>
5652 <td style="text-align:center; width:auto; background-color:${headerColor}">
5653 <center style="margin:1px;font-size:16px"><font color="${titleColor}"><a href="#"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png" id="sort_by_attacks"></a><p id="header_attacks">(0)</p></font></center>
5654 </td>
5655 <td style="text-align:center; width:auto; background-color:${headerColor}">
5656 <center style="margin:1px;font-size:16px"><font color="${titleColor}"><a href="#"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/support.png" id="sort_by_supports"></a><p id="header_supports">(0)</p></font></center>
5657 </td>
5658 <td style="text-align:center; width:auto; background-color:${headerColor}">
5659 <center style="margin:1px;font-size:16px"><font color="${titleColor}"><a href="#"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/snob.png" id="sort_by_nobles"></a><p id="header_nobles">(0)</p></font></center>
5660 </td>
5661 <td style="text-align:center; width:auto; background-color:${headerColor}">
5662 <center style="margin:1px;font-size:16px"><font color="${titleColor}"><a href="#"><img src="https://img.icons8.com/office/20/000000/sniper-rifle.png" id="sort_by_snipes"></a><p id="header_snipes">(0/0)</p></font></center>
5663 </td>
5664 <td style="text-align:center; width:auto; background-color:${headerColor}">
5665 <center style="margin:1px;font-size:16px"><font color="${titleColor}"><a href="#"><img src="https://img.icons8.com/ultraviolet/20/000000/horror.png" id="sort_by_recaps"></a><p id="header_recaps">(0/0)</p></font></center>
5666 </td>
5667 </tr>
5668 </thead>
5669 </table>
5670 </div>
5671 </div>
5672
5673 `;
5674
5675 $("#div_container_view").remove()
5676 $("#contentContainer").eq(0).prepend(html_info);
5677 $("#mobileContent").eq(0).prepend(html_info);
5678
5679
5680 ////////////////////////////////////// //delete/////////////////////////////////////////////////////////////////////
5681 // $("#table_search").hide()
5682 // $("#table_view").hide()
5683
5684 // $(".btn-confirm-yes").eq(0).hide()
5685 // $(".btn-confirm-yes").eq(1).hide()
5686 // $(".btn-confirm-yes").eq(2).hide()
5687
5688
5689
5690
5691
5692
5693 if(game_data.device=="desktop"){
5694 $("#div_container_view").css("position","fixed");
5695 $("#div_container_view").draggable();
5696 }
5697 document.getElementById("page_main").addEventListener("click",()=>{
5698 $("#div_container_view").remove()
5699 $("#contentContainer").eq(0).prepend(html);
5700 $("#mobileContent").eq(0).prepend(html);
5701
5702 if(game_data.device=="desktop"){
5703 $("#div_container").css("position","fixed");
5704 $("#div_container").draggable();
5705 }
5706
5707 })
5708 document.getElementById("minimize_page").addEventListener("click",()=>{
5709 console.log("aici")
5710 // $("#div_minimize").toggle(500)
5711
5712 if($('.div_minimize:visible').length){
5713 $('.div_minimize').hide();
5714 $("#div_container_view").css({
5715 'width' : '0px',
5716
5717 })
5718 }
5719 else{
5720 $('.div_minimize').show();
5721 $("#div_container_view").css({
5722 'width' : '900px',
5723 })
5724 }
5725
5726 })
5727 if(typeof(TWMap)!="undefined"){
5728 $("#table_select_info").show()
5729 }
5730
5731
5732
5733
5734
5735 let [mapVillage, map_reports,map_incomings,data_support,map_attacks,map_status,map_history_upload,status_chart]=await Promise.all([getInfoVIllages(), readFileDropbox(filename_reports),readFileDropbox(filename_incomings),
5736 readFileDropbox(filename_support),readFileDropbox(filename_commands_attack),readFileDropbox(filename_status_upload),readFileDropbox(filename_history_upload),insertChartLibrary()]).catch(err=>{alert(err)})
5737 map_reports=new Map(JSON.parse(lzw_decode(map_reports)))
5738 map_incomings=new Map(JSON.parse(lzw_decode(map_incomings)))
5739 map_attacks=new Map(JSON.parse(lzw_decode(map_attacks)))
5740 map_status=new Map(JSON.parse(lzw_decode(map_status)))
5741 map_history_upload=new Map(JSON.parse(lzw_decode(map_history_upload)))
5742
5743
5744 let map_coming=new Map(JSON.parse(lzw_decode(data_support))[0])
5745 let map_home=new Map(JSON.parse(lzw_decode(data_support))[1])
5746 let map_playerId=new Map()
5747 console.log("mapVillage",mapVillage)
5748 console.log("map_coming",map_coming)
5749 console.log("map_home",map_home)
5750 console.log("map_reports",map_reports)
5751 console.log("map_incomings",map_incomings)
5752 console.log("map_attacks",map_attacks)
5753
5754
5755
5756 let serverTime=document.getElementById("serverTime").innerText
5757 let serverDate=document.getElementById("serverDate").innerText.split("/")
5758 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
5759 let date_current=new Date(serverDate+" "+serverTime).getTime()
5760 createTableSettings()
5761 $("#div_settings").hide()
5762
5763 let pop_snipe=parseInt(document.getElementById("settings_pop").value)
5764 if(Number.isNaN(pop_snipe))
5765 pop_snipe=1000
5766
5767
5768 //filters
5769 let list_filters=[]
5770 $('#div_settings input[type=checkbox]:checked').each(function (index,elem) {
5771
5772 list_filters.push(elem.value)
5773 console.log(elem.value)
5774
5775 });
5776 // console.log("list_filters",list_filters)
5777
5778 Array.from(map_coming.keys()).forEach(key=>{
5779 try {
5780 let obj_output={}
5781 let playerId=mapVillage.get(key).playerId
5782 // console.log(playerId)
5783 let villageId=mapVillage.get(key).villageId
5784 let playerName=mapVillage.get(key).playerName
5785
5786 let list_coming=map_coming.get(key)
5787 let hasAttacks=false
5788 let nr_attacks=0,nr_supports=0,nr_nobles=0;
5789 let snipe=false,sniped=false,recap=false,recaped=false;
5790
5791 if(tribemates.includes(playerName.toLowerCase()) || 0==0){// hard coded////////////////////////////////////////////////////////////
5792 // console.log("list_coming",list_coming)
5793 //filter incomings
5794 for(let i=0;i<list_coming.length;i++){
5795 let landing_time=new Date(list_coming[i].landing_time).getTime()
5796 let deleteIncoming=false
5797 //remove if there is an ignored attack/support
5798 if(list_filters.includes("hide_ignored") && list_coming[i].unignored==false){
5799 deleteIncoming=true
5800 console.log("delete ignored attack")
5801 }
5802 //remove if there is a support
5803 if(list_filters.includes("hide_supports") && list_coming[i].type_attack.includes("support")){
5804
5805 let landing_time_current=new Date(list_coming[i].landing_time).getTime()
5806 for(let j=i+1;j<list_coming.length-1;j++){
5807 let landing_time_next=new Date(list_coming[j].landing_time).getTime()//that means there a support which lands with no more than 600 ms before an attack
5808 if(landing_time_next-landing_time_current>600){
5809 deleteIncoming=true
5810 console.log("delete support")
5811 break
5812 }
5813 else
5814 break;
5815 }
5816
5817 if(i==list_coming.length-1){//if last incoming is a support then delete
5818 deleteIncoming=true
5819 console.log("delete support")
5820 }
5821
5822
5823
5824 }
5825 // remove if there is an attack/support further than x hours away
5826 if(list_filters.includes("hide_further_attacks")){
5827 let hours=parseInt(document.getElementById("settings_further").value)*3600*1000
5828 if(Number.isNaN(hours))
5829 hours=100*3600*1000
5830 if((landing_time-date_current)>hours){
5831 deleteIncoming=true
5832 console.log("delete further attacks")
5833 }
5834 }
5835 // remove if there is an attack/support closer than x hours away
5836 if(list_filters.includes("hide_closer_attacks")){
5837 let hours=parseInt(document.getElementById("settings_closer").value)*3600*1000
5838 if(Number.isNaN(hours))
5839 hours=10*3600*1000
5840 if((landing_time-date_current)<hours){
5841 deleteIncoming=true
5842 console.log("delete closer attacks")
5843 }
5844 }
5845
5846 //remove if an attack/def was sent and uploaded to dropbox but then the attacker withdraw his command
5847 if(playerId==game_data.player.id){
5848 let map_exist_command=new Map(JSON.parse(localStorage.getItem(game_data.world+"map_exist_support")))
5849 let keys_commandId=Array.from(map_exist_command.keys())
5850 if(!keys_commandId.includes(list_coming[i].commandId)){// it means there is a command and in localstorage it is not
5851 deleteIncoming=true
5852 console.log("delete withdrawn command")
5853
5854 }
5855 }
5856
5857
5858 //check if is a small/medium/big attack or a support
5859 let coord_origin=list_coming[i].coord_origin
5860 let playerId_origin=list_coming[i].player_origin_id
5861 if(map_reports.has(coord_origin) && list_coming[i].type_attack.includes("attack") )
5862 {
5863 let idPlayer_dropbox
5864 let type_dropbox
5865 let nr_troupes_dropbox
5866
5867 let obj_report=map_reports.get(coord_origin);
5868 var traveling=false
5869 if(coord_origin == obj_report.coordAttacker){
5870 idPlayer_dropbox=obj_report.attackingPlayerId;
5871 type_dropbox=obj_report.typeAttacker;
5872 nr_troupes_dropbox=obj_report.nrTroupesAttacker
5873 traveling=true;
5874 }
5875 else if(coord_origin == obj_report.coordDefender){
5876 idPlayer_dropbox=obj_report.defendingPlayerId;
5877 type_dropbox=obj_report.typeDefender;
5878 nr_troupes_dropbox=obj_report.nrTroupesDefender
5879 traveling=false;
5880 }
5881 else{
5882 idPlayer_dropbox=obj_report.supporterPlayerId
5883 type_dropbox=obj_report.typeSupporter;
5884 nr_troupes_dropbox=obj_report.nrTroupesSupporter
5885 }
5886
5887 if(idPlayer_dropbox == playerId_origin)
5888 {
5889
5890 //calculate population
5891 let date_landing_report=new Date(obj_report.time_report)
5892 let distance=calcDistance(coord_origin,list_coming[i].coord_destination)
5893 let time_attack=0;
5894
5895 let date_land=new Date(landing_time)
5896 // console.log(date_land)
5897 let labelName=list_coming[i].labelName
5898
5899
5900 if(labelName.includes("snob.png")){
5901 time_attack=nobleSpeed*distance
5902 }else if(labelName.includes("ram.png") || labelName.includes("catapult.png")){
5903 time_attack=ramSpeed*distance
5904 }else if(labelName.includes("sword.png")){
5905 time_attack=swordSpeed*distance
5906 }else if(labelName.includes("axe.png")){
5907 time_attack=axeSpeed *distance
5908 }
5909 if(traveling==false)
5910 time_attack=0;
5911
5912 let newTypeAttack=list_coming[i].type_attack
5913 if(type_dropbox=="off"){
5914 let timeForRecruiting = (date_land.getTime()-time_attack)-date_landing_report.getTime()
5915 let pop_small_attack=(parseInt(document.getElementById("settings_small_attack").value)/20000)*100
5916 let pop_medium_attack=(parseInt(document.getElementById("settings_medium_attack").value)/20000)*100
5917
5918 if(pop_medium_attack<pop_small_attack)
5919 alert("pop for medium attacks must be higher than pop for small attacks")
5920 if(Number.isNaN(pop_small_attack))
5921 pop_small_attack=(5000/20000)*100
5922 if(Number.isNaN(pop_medium_attack))
5923 pop_small_attack=(10000/20000)*100
5924
5925 // console.log("time for recruiting",timeForRecruiting)
5926 // console.log("nr_troupes_dropbox",nr_troupes_dropbox)
5927 nr_troupes_dropbox=calcProductionTroupes(timeForRecruiting,nr_troupes_dropbox)
5928 // console.log("nr_troupes_dropbox",nr_troupes_dropbox)
5929 // console.log(list_coming[i])
5930 if(nr_troupes_dropbox <= pop_small_attack)
5931 newTypeAttack="attack_small.png"
5932 else if(nr_troupes_dropbox >pop_small_attack && nr_troupes_dropbox <= pop_medium_attack )
5933 newTypeAttack="attack_medium.png"
5934 else
5935 newTypeAttack="attack_large.png"
5936
5937 }
5938 else if(type_dropbox.includes("def")){
5939 newTypeAttack="def"
5940 }
5941 list_coming[i].type_attack=newTypeAttack
5942 }
5943 }
5944
5945
5946
5947 //delete if filters is on
5948 if(deleteIncoming==true){
5949 list_coming.splice(i,1);
5950 i--;
5951 }
5952
5953 }
5954
5955
5956 //counting attacks,supports, nobles, snipes, recaps
5957
5958 for(let i=0;i<list_coming.length;i++){
5959 let landing_time=new Date(list_coming[i].landing_time).getTime()
5960
5961 if(landing_time>date_current){
5962 if(list_coming[i].type_attack.includes("attack") || list_coming[i].type_attack.includes("def")){
5963
5964 nr_attacks++
5965 hasAttacks=true
5966 }
5967 else{
5968 nr_supports++
5969 }
5970 if(list_coming[i].labelName.includes("snob")){
5971 nr_nobles++
5972
5973 //check for train and if exist check for snipe
5974 for(let j=i+1;j<list_coming.length;j++){
5975 let landing_time_next=new Date(list_coming[j].landing_time).getTime()
5976 if(landing_time_next-landing_time==50 ||landing_time_next-landing_time==100 || landing_time_next-landing_time==150)
5977 {
5978 if(list_coming[i].coord_origin==list_coming[j].coord_origin )//there is a train
5979 {
5980 let pop=0;
5981 let list_snipe_support=[]
5982 for(let k=j-1;k>=0;k--){
5983
5984 if(list_coming[k].type_attack.includes("support")){//there is a snipe(support before second noble),check every support from left
5985 let troops=list_coming[k].troops
5986 Object.keys(troops).forEach(key=>{
5987 pop+=troops[key]*troopsPop[key]
5988 })
5989 list_snipe_support.push(k)
5990 }
5991 else{
5992 break
5993 }
5994 }
5995 if(pop>pop_snipe){
5996 sniped=true
5997 //this support is used for sniping and will be colored later
5998 for(let k=0;k<list_snipe_support.length;k++){
5999 list_coming[list_snipe_support[k]].hasSupportSnipe=true
6000 }
6001 }
6002 snipe=true
6003 }
6004 }
6005 }
6006 //check if needs to be recaped
6007 if(snipe==false && nr_nobles>=4){
6008 recap=true
6009 }
6010 //check if it recaped buy someone from your tribe
6011 if(snipe==false && nr_nobles>=4 && tribemates.includes(list_coming[i].player_origin_name)){
6012 recaped=true
6013 }
6014 }
6015 }
6016 }
6017
6018
6019
6020 if(hasAttacks==true){
6021 obj_output.homeInfo=map_home.get(key)
6022 }
6023 let nr_snipe=(snipe==true)?1:0
6024 let nr_sniped=(sniped==true)?1:0
6025 let nr_recap=(recap==true)?1:0
6026 let nr_recaped=(recaped==true)?1:0
6027
6028 obj_output.coord_destination_id=villageId
6029 obj_output.list_coming=list_coming
6030
6031 obj_output.nr_attacks=nr_attacks
6032 obj_output.nr_supports=nr_supports
6033 obj_output.nr_nobles=nr_nobles
6034
6035 obj_output.nr_snipe=nr_snipe
6036 obj_output.nr_sniped=nr_sniped
6037 obj_output.nr_recap=nr_recap
6038 obj_output.nr_recaped=nr_recaped
6039
6040 // console.log("status snipe/recap")
6041 // console.log(key)
6042 // console.log(nr_snipe,nr_sniped,nr_recap,nr_recaped)
6043
6044 if(!map_playerId.has(playerId) && (nr_attacks>0 || nr_supports>0)){
6045
6046 map_playerId.set(playerId,{
6047 nr_attacks_total:nr_attacks,
6048 nr_supports_total:nr_supports,
6049 nr_nobles_total:nr_nobles,
6050 list_coords:[obj_output],
6051 player_destination_name:playerName,
6052 player_destination_id:playerId,
6053 nr_snipe_total:nr_snipe,
6054 nr_sniped_total:nr_sniped,
6055 nr_recap_total:nr_recap,
6056 nr_recaped_total:nr_recaped
6057 })
6058 }
6059 else{
6060 let obj_update=map_playerId.get(playerId)
6061 let list=obj_update.list_coords
6062 list.push(obj_output)
6063
6064 obj_update.list_coords=list
6065 obj_update.nr_attacks_total+=nr_attacks
6066 obj_update.nr_supports_total+=nr_supports
6067 obj_update.nr_nobles_total+=nr_nobles
6068 obj_update.nr_snipe_total+=nr_snipe,
6069 obj_update.nr_sniped_total+=nr_sniped,
6070 obj_update.nr_recap_total+=nr_recap,
6071 obj_update.nr_recaped_total+=nr_recaped
6072
6073 map_playerId.set(playerId,obj_update)
6074
6075 }
6076
6077 }
6078 } catch (error) {
6079 console.log(error)
6080 }
6081
6082
6083
6084 })
6085 console.log(map_playerId)
6086
6087
6088
6089
6090 //sort table players by attacks
6091 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
6092 return (o1[1].nr_attacks_total>o2[1].nr_attacks_total)?-1:(o1[1].nr_attacks_total<o2[1].nr_attacks_total)?1:0;
6093 }))
6094 //sort tables for each coord by attacks
6095 Array.from(map_playerId.keys()).forEach(key=>{
6096 let obj=map_playerId.get(key)
6097 obj.list_coords.sort((o1,o2)=>{
6098 return (o1.nr_attacks>o2.nr_attacks)?-1:(o1.nr_attacks<o2.nr_attacks)?1:0
6099 })
6100 map_playerId.set(key,obj)
6101 })
6102
6103
6104 console.log(map_playerId)
6105
6106
6107
6108 /////////////////////////////////////////////////////////////////////////////////players table//////////////////////////////////////////////////////////
6109 createTablePlayers(map_playerId,mapVillage)
6110 sortInfoIncomings(map_playerId,mapVillage)
6111
6112
6113 //add event for search input
6114 $("#input_search").on("input",(event)=>{
6115 let text_input=event.target
6116 if(text_input.value!=undefined){
6117 if(text_input.value.match(/[0-9]{3}\|[0-9]{3}/)!=null){
6118 let coord=text_input.value.match(/[0-9]{3}\|[0-9]{3}/)[0]
6119 text_input.value=coord
6120 console.log(coord)
6121 let playerId=mapVillage.get(coord).playerId
6122 let villageId=mapVillage.get(coord).villageId
6123
6124 if($(`.table_player img[coord-id=${villageId}]`).is(":visible")==false)
6125 $(`#table_view img[player-id=${playerId}]`).click();
6126
6127 if($(`.table_coord img[coord-id=${villageId}]`).is(":visible")==false)
6128 $(`.table_player img[coord-id=${villageId}]`).click();
6129
6130
6131 }
6132 }
6133 })
6134
6135
6136
6137 ///////////////////////////////////////////////////////////on map page///////////////////////////////////////////////////////////////////////////////////
6138
6139 let fangs_cat=parseInt(document.getElementById("settings_fang_cat").value)
6140 let pop_small_attack=parseInt(document.getElementById("settings_small_attack").value)
6141 let pop_medium_attack=parseInt(document.getElementById("settings_medium_attack").value)
6142 pop_small_attack=(!Number.isNaN(pop_medium_attack))?pop_medium_attack:5000
6143 pop_medium_attack=(!Number.isNaN(pop_medium_attack))?pop_medium_attack:10000
6144 fangs_cat=(!Number.isNaN(fangs_cat))?fangs_cat:100
6145
6146 //create a map with commands attacks, every coord has number of fangs,nukes,nobles
6147 //this part is for offensive info
6148
6149
6150 let mapVillageByIdFinal=new Map()
6151 let mapAttacksPlayersIdFinal=new Map()
6152
6153 Array.from(map_reports.keys()).forEach(key=>{
6154
6155 try {//if a village become a barb
6156 let obj_report=map_reports.get(key)
6157
6158 let villageId=mapVillage.get(key).villageId
6159 let player_destination_name=mapVillage.get(key).playerName
6160 let player_destination_id=mapVillage.get(key).playerId
6161 let time_report=obj_report.time_report
6162
6163 //get troops at home
6164 let troopsAtHome=null,time_report_home=null
6165 if(obj_report["troopsAtHome_"+key]!=undefined){
6166 troopsAtHome=obj_report["troopsAtHome_"+key]
6167 time_report_home=obj_report["time_report_home_"+key]
6168
6169 }
6170
6171
6172 //get troops away
6173 let troopsAway=[]
6174 let type_village=null
6175 if(key==obj_report.coordAttacker){
6176 for(let i=0;i<obj_report.attackingArmy.length;i++){
6177 troopsAway.push({
6178 type:obj_report.attackingArmy[i].type,
6179 count:obj_report.attackingArmy[i].count - obj_report.attackingArmyLosses[i].count
6180 })
6181 }
6182 //type_village
6183 if(obj_report.typeAttacker.includes("off")){
6184 type_village="light"
6185 }
6186 else if(obj_report.typeAttacker=="spy"){
6187 type_village="spy"
6188 }
6189 else if(obj_report.typeAttacker.includes("def")){
6190 type_village="sword"
6191 }
6192
6193 }
6194 else if(key==obj_report.coordDefender){
6195 if(obj_report.travelingTroops != undefined){/////???????????????????//////
6196 Object.keys(obj_report.travelingTroops).forEach(key=>{
6197 troopsAway.push({
6198 type:key,
6199 count:obj_report.travelingTroops[key]
6200 })
6201 })
6202
6203 }
6204
6205 //type_village
6206 if(obj_report.typeDefender.includes("off")){
6207 type_village="light"
6208 }
6209 else if(obj_report.typeDefender=="spy"){
6210 type_village="spy"
6211 }
6212 else if(obj_report.typeDefender.includes("def")){
6213 type_village="sword"
6214 }
6215 }
6216
6217
6218 mapVillageByIdFinal.set(villageId,{
6219 nr_fangs:0,
6220 nr_nobles:0,
6221 nr_nukes:0,
6222 player_destination_id:player_destination_id,
6223 player_destination_name:player_destination_name,
6224 time_report:time_report,
6225 time_report_home:time_report_home,
6226 troopsAtHome:troopsAtHome,
6227 troopsAway:troopsAway,
6228 type_village:type_village,
6229 villageId:villageId,
6230 })
6231
6232 mapAttacksPlayersIdFinal.set(player_destination_id,player_destination_name)
6233 } catch (error) {
6234
6235 console.log(error)
6236 }
6237
6238
6239 })
6240
6241 let map_ranking_attacker=new Map()
6242 let map_ranking_defender=new Map()
6243 // let mapAttacksVillageId=new Map()
6244 let mapAttacksPlayersId=new Map()
6245 Array.from(map_attacks.keys()).forEach(key=>{//go through each command attack
6246 let obj=map_attacks.get(key)
6247 let date_landing=new Date(obj.landing_time).getTime()
6248 let type_attack=obj.type_attack
6249
6250 let coord=obj.coord_destination
6251 let villageId=obj.coord_destination_id
6252
6253 let player_destination_id=obj.player_destination_id
6254 let player_destination_name=obj.player_destination_name
6255
6256 let player_origin_name=obj.player_origin_name
6257 let player_origin_id=obj.player_origin_id
6258
6259 let troops = obj.troops
6260 let fang=0,nuke=0,noble=0,fake=0
6261
6262
6263 let troopsAtHome=null,time_report_home=null
6264 let troopsAway=null, time_report=null
6265 let type_village=null
6266 if(map_reports.has(coord)){
6267 let obj_report=map_reports.get(coord)
6268 // console.log("obj_report",obj_report)
6269
6270
6271 //troops at home
6272 if(obj_report["troopsAtHome_"+coord]!=undefined){
6273 troopsAtHome=obj_report["troopsAtHome_"+coord]
6274 time_report_home=obj_report["time_report_home_"+coord]
6275 }
6276
6277
6278 //troops away
6279 time_report=obj_report.time_report
6280 if(coord==obj_report.coordAttacker){//get troops attack
6281 troopsAway=[]
6282 for(let i=0;i<obj_report.attackingArmy.length;i++){
6283 troopsAway.push({
6284 type:obj_report.attackingArmy[i].type,
6285 count:obj_report.attackingArmy[i].count - obj_report.attackingArmyLosses[i].count
6286 })
6287 }
6288 //type_village
6289 if(obj_report.typeAttacker.includes("off")){
6290 type_village="light"
6291 }
6292 else if(obj_report.typeAttacker=="spy"){
6293 type_village="spy"
6294 }
6295 else if(obj_report.typeAttacker.includes("def")){
6296 type_village="sword"
6297 }
6298
6299 }else if(coord==obj_report.coordDefender){//get troops away if it's defensive
6300 troopsAway=[]
6301 if(obj_report.travelingTroops != undefined){
6302 Object.keys(obj_report.travelingTroops).forEach(key=>{
6303 troopsAway.push({
6304 type:key,
6305 count:obj_report.travelingTroops[key]
6306 })
6307 })
6308 }
6309 //type_village
6310 if(obj_report.typeDefender.includes("off")){
6311 type_village="light"
6312 }
6313 else if(obj_report.typeDefender=="spy"){
6314 type_village="spy"
6315 }
6316 else if(obj_report.typeDefender.includes("def")){
6317 type_village="sword"
6318 }
6319
6320 }
6321
6322 }
6323
6324
6325 //check for fang
6326 if(troops.axe + troops.light*4 < pop_small_attack && troops.catapult >= fangs_cat )
6327 fang=1
6328
6329 //check for nuke
6330 if(troops.axe + troops.light*4 + troops.ram*5 + troops.catapult*8 > pop_medium_attack)
6331 nuke=1
6332
6333 //check for noble
6334 if(troops.snob>0)
6335 noble=1
6336
6337 //check for fake
6338 let popFake=0
6339 Object.keys(troops).forEach(key=>{
6340 popFake+= troops[key] * troopsPop[key]
6341 })
6342 if(popFake<200)
6343 fake=1
6344
6345
6346
6347
6348 ////map for show info on the map
6349 if(!tribemates.includes(player_destination_name) || 0==0){ //hard coded/////////////////////////////////////////////////////////////
6350
6351 if(date_landing>date_current){
6352 if(mapAttacksVillageId.has(villageId)){
6353 let obj_update=mapAttacksVillageId.get(villageId)
6354 obj_update.nr_nukes+=nuke
6355 obj_update.nr_nobles+=noble
6356 obj_update.nr_fangs+=fang
6357 mapAttacksVillageId.set(villageId,obj_update)
6358
6359 }
6360 else{
6361 mapAttacksVillageId.set(villageId,{
6362 villageId:villageId,
6363 player_destination_name:player_destination_name,
6364 player_destination_id:player_destination_id,
6365 troopsAtHome:troopsAtHome,
6366 time_report_home:time_report_home,
6367 troopsAway:troopsAway,
6368 time_report:time_report,
6369 type_village:type_village,
6370 nr_nukes:nuke,
6371 nr_nobles:noble,
6372 nr_fangs:fang,
6373 })
6374 }
6375 //map for selecting player
6376 if(type_attack.includes("attack"))
6377 mapAttacksPlayersId.set(player_destination_id,player_destination_name)
6378 }
6379
6380
6381 //map for show ranking attackers with fangs/nukes/fakes
6382 if(map_ranking_attacker.has(player_origin_id)){
6383 let obj_update=map_ranking_attacker.get(player_origin_id)
6384 obj_update.nr_nukes+=nuke
6385 obj_update.nr_nobles+=noble
6386 obj_update.nr_fangs+=fang
6387 obj_update.nr_fakes+=fake
6388 map_ranking_attacker.set(player_origin_id,obj_update)
6389 }
6390 else{
6391 map_ranking_attacker.set(player_origin_id,{
6392 player_origin_name:player_origin_name,
6393 nr_nukes:nuke,
6394 nr_nobles:noble,
6395 nr_fangs:fang,
6396 nr_fakes:fake
6397 })
6398 }
6399
6400 //map for show ranking defenders with fangs/nukes/fakes
6401 if(map_ranking_defender.has(player_destination_id)){
6402 let obj_update=map_ranking_defender.get(player_destination_id)
6403 obj_update.nr_nukes+=nuke
6404 obj_update.nr_nobles+=noble
6405 obj_update.nr_fangs+=fang
6406 obj_update.nr_fakes+=fake
6407 map_ranking_defender.set(player_destination_id,obj_update)
6408 }
6409 else{
6410 map_ranking_defender.set(player_destination_id,{
6411 player_origin_name:player_destination_name,
6412 nr_nukes:nuke,
6413 nr_nobles:noble,
6414 nr_fangs:fang,
6415 nr_fakes:fake
6416 })
6417 }
6418
6419
6420
6421 }
6422
6423
6424
6425 })
6426
6427
6428
6429
6430 console.log("mapVillageByIdFinal",mapVillageByIdFinal)
6431 console.log("mapAttacksVillageId",mapAttacksVillageId)
6432
6433 mapAttacksVillageId= new Map([...mapVillageByIdFinal, ...mapAttacksVillageId])
6434 console.log("mapAttacksVillageIdMerged",mapAttacksVillageId)
6435
6436 mapAttacksPlayersId= new Map([...mapAttacksPlayersIdFinal, ...mapAttacksPlayersId])
6437 console.log("mapAttacksPlayersIdMerged",mapAttacksPlayersId)
6438
6439
6440
6441
6442 console.log("map_ranking_attacker",map_ranking_attacker)
6443
6444
6445 //this part is for defensive info
6446 let mapVillageById=new Map()
6447 Array.from(map_playerId.keys()).forEach(key=>{
6448 let list_coords=map_playerId.get(key).list_coords
6449 for(let i=0;i<list_coords.length;i++){
6450 let list_coming=list_coords[i].list_coming
6451 let obj_result={}
6452 let pop=0
6453 let wallLevel=20
6454 //calc pop for support coming
6455 for(let j=0;j<list_coming.length;j++){
6456 if(list_coming[j].type_attack.includes("support")){
6457
6458 pop+=list_coming[j].troops["spear"]*troopsPop["spear"]
6459 pop+=list_coming[j].troops["sword"]*troopsPop["sword"]
6460 pop+=list_coming[j].troops["heavy"]*troopsPop["heavy"]
6461 if(game_data.units.includes("archer"))
6462 pop+=list_coming[j].troops["archer"]*troopsPop["archer"]
6463 }
6464 else if(list_coming[j].type_attack.includes("attack_small.png")){
6465 // list_coords[i].nr_attacks = list_coords[i].nr_attacks-1 //hard coded///////////////
6466 }
6467 }
6468 //calc pop for troops home
6469
6470 if(list_coords[i].homeInfo!=undefined){
6471 let troops_home=list_coords[i].homeInfo.obj_troops
6472 wallLevel=list_coords[i].homeInfo.wallLevel
6473
6474 pop+=troops_home["spear"]*troopsPop["spear"]
6475 pop+=troops_home["sword"]*troopsPop["sword"]
6476 pop+=troops_home["heavy"]*troopsPop["heavy"]
6477 if(game_data.units.includes("archer"))
6478 pop+=troops_home["archer"]*troopsPop["archer"]
6479
6480 }
6481 pop=parseInt(pop/1000)
6482
6483 obj_result.villageId=list_coords[i].coord_destination_id
6484 obj_result.playerId=key
6485
6486 obj_result.nr_attacks=list_coords[i].nr_attacks
6487 obj_result.nr_nobles=list_coords[i].nr_nobles
6488
6489 obj_result.nr_snipe=list_coords[i].nr_snipe
6490 obj_result.nr_sniped=list_coords[i].nr_sniped
6491
6492 obj_result.nr_recap=list_coords[i].nr_recap
6493 obj_result.nr_recaped=list_coords[i].nr_recaped
6494
6495 obj_result.pop=pop
6496 obj_result.wallLevel=wallLevel
6497
6498 mapVillageById.set(list_coords[i].coord_destination_id,obj_result)
6499 }
6500 })
6501
6502
6503 //event for radio button
6504 $("input[name='type_info']").on("click",()=>{
6505 console.log("load radio")
6506 let radio_select=$("input[name='type_info']:checked").val()
6507 //clear options and add 'all' option
6508 $("#select_player").find("option").remove()
6509 $('#select_player').append($('<option>', {
6510 value: "all",
6511 text: "all"
6512 }));
6513
6514 if(radio_select=="defensive_info"){
6515 Array.from(map_playerId.keys()).forEach(key=>{
6516 $('#select_player').append($('<option>', {
6517 value: key,
6518 text: map_playerId.get(key).player_destination_name
6519 }));
6520 })
6521 }
6522 else if(radio_select=="offensive_info"){//offensive info
6523 Array.from(mapAttacksPlayersId.keys()).forEach(key=>{
6524 $('#select_player').append($('<option>', {
6525 value: key,
6526 text: mapAttacksPlayersId.get(key)
6527 }));
6528 })
6529 }
6530
6531 })
6532 $("input[name='type_info']:checked").click()
6533
6534
6535
6536 //btn show info on the map
6537 document.getElementById("btn_show_info").addEventListener("click",()=>{
6538
6539 let radio_select=$("input[name='type_info']:checked").val()
6540
6541 //filter information
6542
6543 if(radio_select=="offensive_info" ){
6544 console.log("mapAttacksVillageId",mapAttacksVillageId)
6545 let drawInfo=true
6546 let originalSpawnSector = TWMap.mapHandler.spawnSector;
6547
6548 TWMap.mapHandler.spawnSector = function (data, sector) {
6549 originalSpawnSector.call(TWMap.mapHandler, data, sector);
6550 let value_option=document.getElementById("select_player").value
6551 console.log(`call`,value_option)
6552 let radio_select_inside=$("input[name='type_info']:checked").val()
6553
6554 if(drawInfo==true && radio_select_inside=="offensive_info"){
6555 drawInfo=false
6556 window.setTimeout(() => {
6557
6558 let visibleSectors=TWMap.map._visibleSectors
6559 Object.keys(visibleSectors).forEach(key=>{
6560 let elements=visibleSectors[key]._elements
6561 Object.keys(elements).forEach(key=>{
6562 let villageId=elements[key].id.match(/\d+/)
6563 // console.log(villageId)
6564 if(villageId!=null){
6565 if(mapAttacksVillageId.has(villageId[0])){
6566
6567 if(value_option=="all"){
6568 let obj=mapAttacksVillageId.get(villageId[0])
6569 createMapInfoOffensiveSmall(obj)
6570 console.log("draw offensive for every player")
6571 }
6572 else{
6573 let obj=mapAttacksVillageId.get(villageId[0])
6574 if(obj.player_destination_id==value_option){
6575 createMapInfoOffensiveSmall(obj)
6576 console.log("draw offensive only for 1 player")
6577
6578 }
6579 }
6580 }
6581 }
6582 })
6583 })
6584 drawInfo=true
6585 }, 200);
6586 }
6587 };
6588
6589 showPopupInfo(mapAttacksVillageId)
6590
6591 }
6592 else if(radio_select=="defensive_info"){
6593
6594 console.log("mapVillageById",mapVillageById)
6595 let drawInfo=true
6596 let originalSpawnSector = TWMap.mapHandler.spawnSector;
6597
6598 TWMap.mapHandler.spawnSector = function (data, sector) {
6599 originalSpawnSector.call(TWMap.mapHandler, data, sector);
6600 let value_option=document.getElementById("select_player").value
6601 console.log(`call`,value_option)
6602 let radio_select_inside=$("input[name='type_info']:checked").val()
6603
6604 if(drawInfo==true && radio_select_inside=="defensive_info"){
6605 drawInfo=false
6606 window.setTimeout(() => {
6607
6608 let visibleSectors=TWMap.map._visibleSectors
6609 Object.keys(visibleSectors).forEach(key=>{
6610 let elements=visibleSectors[key]._elements
6611 Object.keys(elements).forEach(key=>{
6612 let villageId=elements[key].id.match(/\d+/)
6613 // console.log(villageId)
6614 if(villageId!=null){
6615 if(mapVillageById.has(villageId[0])){
6616
6617 if(value_option=="all"){
6618 let obj=mapVillageById.get(villageId[0])
6619 createMapInfoDefensiveSmall(obj)
6620 console.log("draw defensive for every player")
6621 }
6622 else{
6623 let obj=mapVillageById.get(villageId[0])
6624 if(obj.playerId==value_option){
6625 createMapInfoDefensiveSmall(obj)
6626 console.log("draw defensive only for 1 player")
6627
6628 }
6629 }
6630 }
6631 }
6632 })
6633 })
6634
6635 drawInfo=true
6636 }, 200);
6637 }
6638 };
6639 }
6640
6641 })
6642
6643 //add number of reports for each player
6644 console.log("map_status",map_status)
6645 console.log("map_history_upload",map_history_upload)
6646 let map_counter_reports=new Map()
6647 Array.from(map_history_upload.keys()).forEach(key=>{
6648 let obj=map_history_upload.get(key)
6649 if(map_counter_reports.has(obj.playerId)){
6650 let currentValue=map_counter_reports.get(obj.playerId)+1
6651 map_counter_reports.set(obj.playerId,currentValue)
6652 }
6653 else{
6654 map_counter_reports.set(obj.playerId,1)
6655 }
6656 })
6657 console.log("map_counter_reports",map_counter_reports)
6658
6659 //update nr reports on for each player
6660 Array.from(map_status.keys()).forEach(key=>{
6661 let obj=map_status.get(key)
6662 let nrReports=map_counter_reports.get(key)
6663 if(nrReports==undefined)
6664 nrReports=0
6665
6666 obj.name=obj.name+` (${nrReports})`
6667 })
6668
6669
6670 //op spotter
6671 let map_nr_incs_hour=new Map()
6672 Array.from(map_incomings.keys()).forEach(key=>{
6673 let list_incomings=map_incomings.get(key)
6674 for(let i=0;i<list_incomings.length;i++){
6675 let date=list_incomings[i].date_land
6676
6677 if(date!=""){
6678 let newDate= date.substring(0,5)+", "+date.split(" ")[1].split(":")[0]+"h"
6679
6680 if(map_nr_incs_hour.has(newDate)){
6681 map_nr_incs_hour.set(newDate, map_nr_incs_hour.get(newDate)+1)
6682 }
6683 else{
6684 map_nr_incs_hour.set(newDate,1)
6685 }
6686 }
6687 else{
6688 console.log("error")
6689 console.log(list_incomings[i])
6690 }
6691 }
6692 })
6693
6694 console.log("map_nr_incs_hour",map_nr_incs_hour)
6695 let list_spotter=Array.from(map_nr_incs_hour.entries())
6696
6697
6698
6699
6700
6701 //sort by fakes map ranking
6702 map_ranking_attacker = new Map([...map_ranking_attacker.entries()].sort((o1,o2)=>{
6703 return (o1[1].nr_fakes>o2[1].nr_fakes)?-1:(o1[1].nr_fakes<o2[1].nr_fakes)?1:0
6704 }))
6705 map_ranking_defender = new Map([...map_ranking_defender.entries()].sort((o1,o2)=>{
6706 return (o1[1].nr_fakes>o2[1].nr_fakes)?-1:(o1[1].nr_fakes<o2[1].nr_fakes)?1:0
6707 }))
6708 map_status = new Map([...map_status.entries()].sort((o1,o2)=>{
6709 return (new Date(o1[1].report_date).getTime()>new Date(o2[1].report_date).getTime())?-1:(new Date(o1[1].report_date).getTime()<new Date(o2[1].report_date).getTime())?1:0
6710 }))
6711
6712 //create tabels and add event btn for each tabel
6713 createTableRankingAttackers(map_ranking_attacker)
6714 createTableRankingDefenders(map_ranking_defender)
6715 createTableUploadTime(map_status)
6716 createTableGetCoords(mapVillage)
6717
6718 document.getElementById("btn_rank_attacker").addEventListener("click",()=>{
6719 createTableRankingAttackers(map_ranking_attacker)
6720 })
6721 document.getElementById("btn_rank_defender").addEventListener("click",()=>{
6722 createTableRankingDefenders(map_ranking_defender)
6723 })
6724 document.getElementById("btn_upload_time").addEventListener("click",()=>{
6725 createTableUploadTime(map_status)
6726 })
6727 document.getElementById("btn_get_coords").addEventListener("click",()=>{
6728 createTableGetCoords(mapVillage)
6729 })
6730 document.getElementById("btn_op_spotter").addEventListener("click",()=>{
6731 let html_spotter=`<div id="div_op_spotter" style="height:500px;width:800px;overflow:auto" > </div>`
6732 Dialog.show("content",html_spotter)
6733
6734 createChart(list_spotter,"div_op_spotter")
6735 })
6736
6737
6738 ////delete
6739 // $("#table_view").hide()
6740 // let table = $("#div_upload_time tr")
6741 // for(let i=0;i<table.length;i++){
6742 // $(table[i]).find("td").last().hide()
6743 // }
6744
6745
6746
6747
6748}
6749
6750
6751function createMapInfoDefensiveSmall(obj){
6752
6753 try {
6754 if(document.getElementById(`info_extra${obj.villageId}`)==null && obj.nr_attacks>0){
6755 let greenColor="#026440"//green
6756 let redColor="#E80000"//red
6757 let blueLightColor ="#157de5";//blueLightColor
6758 let purpleColor="#a06a34"
6759 let villageImg=document.getElementById(`map_village_${obj.villageId}`)
6760
6761 let parent=document.getElementById(`map_village_${obj.villageId}`).parentElement
6762 let leftImg=villageImg.style.left
6763 let topImg=villageImg.style.top
6764
6765 let colorBorder="background-color:rgba(20, 20, 20, 0.34)"//no border
6766
6767 if(obj.nr_snipe==1)
6768 colorBorder=`background-color:rgba(255, 10, 10, 0.14);outline:rgba(255, 51, 0, 0.7) solid 1px`// red border
6769
6770 if(obj.nr_recap==1)
6771 colorBorder=`background-color:rgba(0, 10, 255, 0.14);outline:rgba(0, 10, 255, 0.7) solid 1px`// blue border
6772
6773 if(obj.nr_sniped==1 || obj.nr_recaped==1)
6774 colorBorder=`background-color:rgba(155, 252, 10, 0.14);outline:rgba(51, 255, 0, 0.7) solid 1px`// green border
6775
6776
6777
6778 while(document.getElementById(`map_icons_${obj.villageId}`)!=null){
6779 document.getElementById(`map_icons_${obj.villageId}`).remove()
6780 }
6781 if(document.getElementById(`map_cmdicons_${obj.villageId}_0`)!=null)
6782 document.getElementById(`map_cmdicons_${obj.villageId}_0`).remove()
6783 if(document.getElementById(`map_cmdicons_${obj.villageId}_1`)!=null)
6784 document.getElementById(`map_cmdicons_${obj.villageId}_1`).remove()
6785
6786 let html_info=`
6787 <img style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-left:7px;" src="https://dsen.innogamescdn.com/asset/c2dee33a/graphic//map/incoming_attack.png">
6788 <center><font color="${greenColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-left:18px; font-size: 12px">${obj.nr_attacks}</font></center>
6789 <center><font color="${blueLightColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:35px;height:15px;z-index:4;margin-top:22px;font-size: 12px">${obj.pop}k</font></center>
6790 <div id="info_extra${obj.villageId}" style="position:absolute;left:${leftImg};top:${topImg};width:51px;height:36px;z-index:3; ${colorBorder}">
6791 </div>
6792 `
6793 if(obj.nr_nobles>0){
6794 html_info+=`
6795 <center><font color="${redColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-left:34px; font-size: 12px">${obj.nr_nobles}</font></center>`
6796 }
6797 if(obj.wallLevel<20){
6798 html_info+=`
6799 <center><font color="${purpleColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-top:22px;margin-left:34px;font-size: 12px;">${obj.wallLevel}</font></center>`
6800 }
6801 $(html_info).appendTo(parent);
6802 }
6803
6804 } catch (error) {
6805
6806 }
6807}
6808
6809function createMapInfoOffensiveSmall(obj){
6810
6811 try {
6812 if(document.getElementById(`info_extra${obj.villageId}`) == null ){
6813 let greenColor="#026440"//green
6814 let redColor="#E80000"//red
6815 let blueLightColor ="#157de5";//blueLightColor
6816 let brownColor="#a06a34"
6817 let villageImg=document.getElementById(`map_village_${obj.villageId}`)
6818
6819 let parent=document.getElementById(`map_village_${obj.villageId}`).parentElement
6820 let leftImg=villageImg.style.left
6821 let topImg=villageImg.style.top
6822
6823 let greenBorder=`background-color:rgba(155, 252, 10, 0.14);outline:rgba(51, 255, 0, 0.7) solid 1px`//green
6824 let redBorder=`background-color:rgba(255, 10, 10, 0.14);outline:rgba(255, 51, 0, 0.7) solid 1px`//red
6825 let blueBorder=`background-color:rgba(0, 10, 255, 0.14);outline:rgba(0, 10, 255, 0.7) solid 1px`// blue border
6826 let colorBorder="background-color:rgba(20, 20, 20, 0.34)"//no border
6827
6828 var noBorder=`background-color:rgba(40, 40, 40, 0.34)`
6829
6830 while(document.getElementById(`map_icons_${obj.villageId}`)!=null){
6831 document.getElementById(`map_icons_${obj.villageId}`).remove()
6832 }
6833 if(document.getElementById(`map_cmdicons_${obj.villageId}_0`)!=null)
6834 document.getElementById(`map_cmdicons_${obj.villageId}_0`).remove()
6835 if(document.getElementById(`map_cmdicons_${obj.villageId}_1`)!=null)
6836 document.getElementById(`map_cmdicons_${obj.villageId}_1`).remove()
6837
6838 let colorTypeAttack=""
6839 if(obj.type_village!=null){
6840 if(obj.type_village=="sword")
6841 colorTypeAttack="background-color:rgb(0,255,255)"
6842 else if(obj.type_village=="light")
6843 colorTypeAttack="background-color:rgb(255, 132, 5)"
6844 else if(obj.type_village=="spy")
6845 colorTypeAttack="background-color:rgb(255,255,255)"
6846
6847
6848 }
6849
6850 let stacks_home=0
6851 let has_noble=false
6852 if(obj.troopsAtHome!=null && obj.troopsAtHome!=undefined){
6853 for(let i=0;i<obj.troopsAtHome.length;i++){
6854 let type=obj.troopsAtHome[i].type
6855 let count=obj.troopsAtHome[i].count
6856 if(type=="spear" || type=="sword" || type=="archer" || type=="heavy" ){
6857 stacks_home+=troopsPop[type] * count
6858 }
6859 if(type =="snob" && count > 0){
6860 has_noble=true
6861 }
6862 }
6863 stacks_home=parseInt(Math.round(stacks_home/1000))
6864 }
6865 else{
6866 stacks_home=-1
6867 }
6868
6869 if(has_noble==false && obj.troopsAway!=null && obj.troopsAway!=undefined){
6870 if(obj.troopsAway.length>0){
6871 let nobleInfo=obj.troopsAway.slice(-1)[0]
6872 if(nobleInfo.type=="snob" && nobleInfo.count>0){
6873 has_noble=true
6874 }
6875 }
6876 }
6877
6878
6879 let html_info
6880 //info for small img village on the map
6881
6882
6883 if(obj.nr_nukes>0 || obj.nr_nobles>0 || obj.nr_fangs >0 ){
6884 if(obj.type_village!=null){
6885 let border= (has_noble==true)?"background-color:rgb(255,255,0)":colorTypeAttack
6886 let borderMain=(obj.type_village=="light")?blueBorder:redBorder
6887 html_info=`
6888 <div id="info_extra${obj.villageId}" style="position:absolute;left:${leftImg};top:${topImg};width:51px;height:36px;z-index:3; ${borderMain}"></div>`
6889
6890 html_info+=`<img style="position:absolute;left:${leftImg};top:${topImg};width:16px;height:16px;z-index:4;margin-left:35px;${border}" src="https://dsen.innogamescdn.com/asset/c2dee33a/graphic/unit/unit_${obj.type_village}.png">`
6891
6892 if(stacks_home>=0){
6893 html_info+=`<center><font color="${"#FFFFF1"}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:16px;height:16px;z-index:4;margin-left:8px;font-size: 10px;">${stacks_home}k</font></center>`
6894
6895 }
6896 }else{
6897 html_info=`
6898 <div id="info_extra${obj.villageId}" style="position:absolute;left:${leftImg};top:${topImg};width:51px;height:36px;z-index:3; ${noBorder}"></div>`
6899 }
6900 if(obj.nr_fangs>0){
6901 html_info+=`
6902 <center><font color="${brownColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-top:22px;margin-left:0px;font-size: 12px;background-color:black;">${obj.nr_fangs}</font></center>`
6903 }
6904 if(obj.nr_nukes>0){
6905 html_info+=`
6906 <center><font color="${greenColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-top:22px;margin-left:17px;font-size: 12px;background-color:black;">${obj.nr_nukes}</font></center>`
6907 }
6908 if(obj.nr_nobles>0){
6909 html_info+=`
6910 <center><font color="${redColor}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:14px;height:14px;z-index:4;margin-top:22px;margin-left:34px;font-size: 12px;background-color:black;">${obj.nr_nobles}</font></center>`
6911 }
6912
6913
6914
6915 }
6916 else{
6917
6918
6919
6920 if(obj.type_village!=null){
6921 let border= (has_noble==true)?"background-color:rgb(255,255,0)":colorTypeAttack
6922 let borderMain=(obj.type_village=="light")?blueBorder:redBorder
6923 html_info=`
6924 <div id="info_extra${obj.villageId}" style="position:absolute;left:${leftImg};top:${topImg};width:51px;height:36px;z-index:3; ${borderMain}"></div>`
6925
6926 html_info+=`<img style="position:absolute;left:${leftImg};top:${topImg};width:16px;height:16px;z-index:4;margin-left:35px;${border}" src="https://dsen.innogamescdn.com/asset/c2dee33a/graphic/unit/unit_${obj.type_village}.png">`
6927
6928 if(stacks_home>=0){
6929 html_info+=`<center><font color="${"#FFFFF1"}" class="shadow20" style="position:absolute;left:${leftImg};top:${topImg};width:16px;height:16px;z-index:4;margin-left:8px;font-size: 10px;">${stacks_home}k</font></center>`
6930
6931 }
6932
6933 }
6934 }
6935 $(html_info).appendTo(parent);
6936
6937
6938 //info for the popup window for each village
6939 }
6940
6941 } catch (error) {
6942 console.log(error)
6943 }
6944}
6945
6946function showPopupInfo(mapAttacksVillageId){
6947 let originalDisplayForVillage = TWMap.popup.displayForVillage;
6948
6949 TWMap.popup.displayForVillage = function (e, a, t) {
6950 console.log('intercepted displayForVillage');
6951 originalDisplayForVillage.call(TWMap.popup, e, a, t);
6952 let villageInfo = e;
6953 console.log(villageInfo)
6954
6955 let obj=mapAttacksVillageId.get(villageInfo.id)
6956
6957
6958
6959 let units=game_data.units
6960 //first row
6961 let militia=0
6962 let drawPopup=false
6963 if(units.includes("militia"))
6964 militia=1
6965
6966 let html_popup=`
6967 <table class="vis popup_info_extra" border="1" style="width: 100%;border-collapse: collapse">
6968 <tr>
6969 <td style="text-align:center; width:auto;background-color:#c1a264" >
6970 <center style="margin:0px;"></center>
6971 </td>
6972 <td style="text-align:center; width:auto;background-color:#c1a264" >
6973 <center style="margin:0px;"><b>seen</b></center>
6974 </td>`
6975
6976
6977 for(let i=0;i<units.length-militia;i++){
6978 html_popup+=`
6979 <td style="text-align:center; width:auto;background-color:#c1a264" >
6980 <center style="margin-top:0px;"><img src="https://dsen.innogamescdn.com/asset/c2dee33a/graphic/unit/unit_${units[i]}.png"></center>
6981 </td>`
6982 }
6983 html_popup+="</tr>"
6984
6985
6986 if(obj!=undefined){
6987 if(obj.troopsAtHome!=null ){
6988 drawPopup=true
6989 html_popup+=`
6990 <tr>
6991 <td style="text-align:center; width:auto;" >
6992 <center style="margin:0px;"><b>at home</b></center>
6993 </td>
6994 <td style="text-align:center; width:auto;" >
6995 <center style="margin:0px;"><b>${obj.time_report_home}</b></center>
6996 </td>
6997 `
6998
6999 for(let i=0;i<obj.troopsAtHome.length-militia;i++){
7000 html_popup+=`
7001 <td style="text-align:center; width:auto;" >
7002 <center style="margin:0px;">${obj.troopsAtHome[i].count}</center>
7003 </td>`
7004 }
7005 html_popup+=`</tr>`
7006 }
7007 }
7008
7009 if(obj!=undefined){
7010 if(obj.troopsAway!=null){
7011 drawPopup=true
7012 html_popup+=`
7013 <tr>
7014 <td style="text-align:center; width:auto;" >
7015 <center style="margin:0px;"><b>away</b></center>
7016 </td>
7017 <td style="text-align:center; width:auto;" >
7018 <center style="margin:0px;"><b>${obj.time_report}</b></center>
7019 </td>`
7020
7021 for(let i=0;i<obj.troopsAway.length;i++){
7022 html_popup+=`
7023 <td style="text-align:center; width:auto;" >
7024 <center style="margin:0px;">${obj.troopsAway[i].count}</center>
7025 </td>`
7026 }
7027 html_popup+=`</tr>`
7028 }
7029 }
7030
7031 html_popup+=`</table>`
7032
7033 if(drawPopup==true){
7034 console.log(document.getElementById("map_popup"))
7035 $(".popup_info_extra").remove()
7036 $('#info_content').prepend(`<tr><td colspan="3">${html_popup}</td></tr>`)
7037
7038 }
7039
7040
7041 }
7042
7043
7044}
7045
7046
7047 ////////////////////////////////////////////////////////////////// create table for players/////////////////////////////////////////////////////
7048
7049function createTablePlayers(map_playerId,mapVillage){
7050 let html_tr_player="<tbody id='tbody_player'>"
7051 let counterPlayer=0;
7052 let nr_attacks_total=0,nr_supports_total=0,nr_nobles_total=0;
7053 let nr_snipe_total=0,nr_sniped_total=0,nr_recap_total=0,nr_recaped_total=0;
7054 Array.from(map_playerId.keys()).forEach(key=>{
7055 let obj=map_playerId.get(key)
7056 counterPlayer++;
7057 nr_attacks_total +=obj.nr_attacks_total
7058 nr_supports_total+=obj.nr_supports_total
7059 nr_nobles_total +=obj.nr_nobles_total
7060 nr_snipe_total +=obj.nr_snipe_total
7061 nr_sniped_total +=obj.nr_sniped_total
7062 nr_recap_total +=obj.nr_recap_total
7063 nr_recaped_total +=obj.nr_recaped_total
7064
7065 html_tr_player+=
7066 `<tr>
7067
7068 <td style="text-align:center; width:40px; background-color:${headerColor}">
7069 <a href="#" ><center style="margin:5px"><font color="${titleColor}"><img player-id="${key}" number-tr="${counterPlayer}"class="infoPlayer" src="https://img.icons8.com/clouds/30/000000/more.png"/></font></center></a>
7070 </td>
7071 <td style="text-align:center; width:auto; background-color:${headerColor}">
7072 <a href="${game_data.link_base_pure}info_player&id=${key}"><center style="margin:5px"><font color="${titleColor}">${obj.player_destination_name}</font></center></a>
7073 </td>
7074 <td style="text-align:center; width:auto; background-color:${headerColor}">
7075 <center style="margin:5px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png">(${obj.nr_attacks_total})</font></center>
7076 </td>
7077 <td style="text-align:center; width:auto; background-color:${headerColor}">
7078 <center style="margin:5px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/support.png">(${obj.nr_supports_total})</font></center>
7079 </td>
7080 <td style="text-align:center; width:auto; background-color:${headerColor}">
7081 <center style="margin:5px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/snob.png">(${obj.nr_nobles_total})</font></center>
7082 </td>
7083 <td style="text-align:center; width:auto; background-color:${headerColor}">
7084 <center style="margin:5px;font-size:16px"><font color="${titleColor}"><img src="https://img.icons8.com/office/20/000000/sniper-rifle.png"/>(${obj.nr_sniped_total}/${obj.nr_snipe_total})</font></center>
7085 </td>
7086 <td style="text-align:center; width:auto; background-color:${headerColor}">
7087 <center style="margin:5px;font-size:16px"><font color="${titleColor}"><img src="https://img.icons8.com/ultraviolet/20/000000/horror.png"/>(${obj.nr_recaped_total}/${obj.nr_recap_total})</font></center>
7088 </td>
7089
7090 </tr>
7091 `
7092
7093 })
7094 html_tr_player+="</tbody>"
7095 if(document.getElementById("tbody_player")!=null)
7096 document.getElementById("tbody_player").remove()
7097 document.getElementById("table_view").innerHTML+=html_tr_player
7098 $("#table_view").hide()
7099 $("#table_view").toggle(500)
7100
7101 document.getElementById("header_attacks").innerText=`(${nr_attacks_total})`
7102 document.getElementById("header_supports").innerText=`(${nr_supports_total})`
7103 document.getElementById("header_nobles").innerText=`(${nr_nobles_total})`
7104 document.getElementById("header_snipes").innerText=`(${nr_sniped_total}/${nr_snipe_total})`
7105 document.getElementById("header_recaps").innerText=`(${nr_recaped_total}/${nr_recap_total})`
7106
7107 $(".infoPlayer").on("click",(event)=>{
7108 let playerId=event.target.getAttribute("player-id")
7109 let numberTr=event.target.getAttribute("number-tr")
7110 // console.log(event.target)
7111 let list_coords=map_playerId.get(playerId).list_coords
7112
7113 /////////// ///////////////////////////////////////////////////////////////////coords table//////////////////////////////////////////////////////////
7114 // red: '#ff8080',
7115 // green: '#4dff4d'
7116 let html_table_player=`
7117 <tr >
7118 <td >
7119 <div style="height:700px;overflow:auto;" id="div_incomingsInfo">
7120 <table class="table_player" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;">
7121 `
7122 let counterVillage=0;
7123 console.log("list_coord",list_coords)
7124 for(let i=0;i<list_coords.length;i++){
7125 let obj=list_coords[i]
7126 if(list_coords[i].nr_attacks>0 || list_coords[i].nr_supports>0){//show attacks and supports, i might delete supports
7127 counterVillage++
7128
7129 let headColorSnipe=(obj.nr_sniped==1)?"#4dff4d":(obj.nr_snipe==1)?"#ff8080":headerColor
7130 let headColorRecap=(obj.nr_recaped==1)?"#4dff4d":(obj.nr_recap==1)?"#ff8080":headerColor
7131
7132 html_table_player+=`
7133 <tr>
7134 <td style="text-align:center; width:40px; background-color:${headerColorPlayers}">
7135 <a href="#" style="margin:0px" ><center ><font color="${titleColor}"><img coord-id="${obj.coord_destination_id}" number-tr-coord="${counterVillage}" class="infoCoord" src="https://img.icons8.com/bubbles/20/000000/more.png"/></font></center></a>
7136 </td>
7137 <td style="text-align:center; width:auto; background-color:${headerColorPlayers}">
7138 <a href="${game_data.link_base_pure}info_village&id=${obj.coord_destination_id}" style="margin:0px"><center><font color="${titleColor}">${obj.list_coming[0].coord_destination}</font></center></a>
7139 </td>
7140 <td style="text-align:center; width:auto; background-color:${headerColorPlayers}">
7141 <center style="margin:0px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png">(${obj.nr_attacks})</font></center>
7142 </td>
7143 <td style="text-align:center; width:auto; background-color:${headerColorPlayers}">
7144 <center style="margin:2px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/support.png">(${obj.nr_supports})</font></center>
7145 </td>
7146 <td style="text-align:center; width:auto; background-color:${headerColorPlayers}">
7147 <center style="margin:2px;font-size:16px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/snob.png">(${obj.nr_nobles})</font></center>
7148 </td>
7149 <td style="text-align:center; width:auto; background-color:${headColorSnipe}">
7150 <center style="margin:2px;font-size:16px"><font color="${titleColor}"><img src="https://img.icons8.com/office/20/000000/sniper-rifle.png"/></font></center>
7151 </td>
7152 <td style="text-align:center; width:auto; background-color:${headColorRecap}">
7153 <center style="margin:2px;font-size:16px"><font color="${titleColor}"><img src="https://img.icons8.com/ultraviolet/20/000000/horror.png"/></font></center>
7154 </td>
7155 </tr>
7156 `
7157 }
7158 }
7159
7160
7161
7162 html_table_player+=`
7163 </div>
7164 </table>
7165 <td>
7166 </tr>
7167 `
7168 let delay=500
7169 // console.log(document.getElementById(`table_player${numberTr}`))
7170 if(document.getElementById(`table_player${numberTr}`)!=null){
7171 $(".tr_table_coord").hide(delay)
7172 window.setTimeout(()=>{
7173 $(".tr_table_coord").remove()
7174 },delay+10)
7175
7176 }
7177 else{
7178
7179 $(".tr_table_coord").remove()
7180 // console.log(html_table_player)
7181 var table_support = document.getElementById("table_view").getElementsByTagName("tbody")[0]
7182 var newRow = table_support.insertRow(numberTr);
7183 newRow.className="tr_table_coord"
7184 newRow.id=`table_player${numberTr}`
7185
7186 let cell = newRow.insertCell();
7187 cell.setAttribute("colspan",7)
7188 var div = document.createElement("div")
7189 div.innerHTML=html_table_player
7190 $(cell).append(div)
7191 $(cell).hide()
7192 $(cell).show(delay)
7193
7194 createEventCoord(map_playerId,mapVillage,playerId)
7195
7196 }
7197 })
7198 sortInfoIncomings(map_playerId,mapVillage)
7199
7200}
7201
7202////////////////////////////////////////////////////////////////// create table with troops and info for each coord////////////////////////////////
7203
7204function createTableCoordTroops(obj,admin){
7205 let units=game_data.units
7206 let troopsSupportComing={}
7207 for(let i=0;i<units.length-1;i++){
7208 troopsSupportComing[units[i]]=0
7209 }
7210 // console.log(troopsSupportComing)
7211 for(let i=0;i<obj.list_coming.length;i++){
7212 if(obj.list_coming[i].type_attack.includes("support")){
7213 Object.keys(troopsSupportComing).forEach(key=>{
7214 troopsSupportComing[key]+=obj.list_coming[i].troops[key]
7215 })
7216 }
7217
7218 }
7219 troopsSupportComing.snob=0;
7220
7221 if(obj.homeInfo==undefined){
7222 obj.homeInfo={
7223 flagName:"none",
7224 LoyaltyLevel:"none",
7225 wallLevel:"none",
7226 farmLevel:"none",
7227 }
7228 }
7229
7230
7231
7232 let html_table_coord=""
7233 ///////////////////////////////////////////////////////////////////info coord table//////////////////////////////////////////////////////////
7234 if(admin==true){
7235 html_table_coord+=`
7236 <tbody>
7237 <tr>
7238
7239 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7240 <center style="margin:5px"><font color="${titleColor}">coord </font></center>
7241 </td>
7242 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7243 <center style="margin:5px;padding;"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/unit/att.png"> </font></center>
7244 </td>
7245 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7246 <center style="margin:5px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/4ba99e83/graphic/flags/small/3.png"> </font></center>
7247 </td>
7248 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7249 <center style="margin:5px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/snob.png"> </font></center>
7250 </td>
7251 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7252 <center style="margin:5x"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/wall.png"> </font></center>
7253 </td>
7254 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7255 <center style="margin:5px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/buildings/farm.png"> </font></center>
7256 </td>
7257 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7258 <center style="margin:5px"><font color="${titleColor}">troops </font></center></p>
7259 </td>
7260
7261 `;
7262 /////////////////////////////////////////////////////////////////////////////Add info village//////////////////////////////////////////////////
7263
7264 for(let i=0;i<units.length-1;i++){
7265 html_table_coord+=`<td class="fm_unit" style="width:30px;text-align:center;width:auto; background-color:${headerColorFirstRow}"><img src="https://dsen.innogamescdn.com/asset/1d2499b/graphic/unit/unit_${units[i]}.png"></td>`
7266 }
7267 html_table_coord+=`
7268 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7269 <center style="margin:1px"><font color="${titleColor}">pop</font></center>
7270 </td>`
7271 html_table_coord+=`</tr>
7272 <tr>`
7273
7274 html_table_coord+=`
7275 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.list_coming[0].coord_destination}</td>
7276 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.nr_attacks}</td>
7277 <td rowspan="3" class="" style="width:70px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.homeInfo.flagName}</td>
7278 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.homeInfo.LoyaltyLevel}</td>
7279 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.homeInfo.wallLevel}</td>
7280 <td rowspan="3" class="" style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">${obj.homeInfo.farmLevel}</td>
7281 <td style="text-align:center; width:auto; background-color:${headerColorCoords}">
7282 <center style="margin:1px"><font color="${titleColor}">home</font></center>
7283 </td>
7284 `
7285 /////////////////////////////////////////////////////////////////////////////////////////home troops//////////////////////////////////////////////////
7286 let total_pop=0;
7287 for(let i=0;i<units.length-1;i++){
7288 let value_troop=(obj.homeInfo.obj_troops!=undefined)?obj.homeInfo.obj_troops[units[i]]:0
7289 let name_troop=units[i]
7290 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
7291 total_pop+=value_troop*troopsPop[name_troop]
7292 }
7293 html_table_coord+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+value_troop+"</td>"
7294 }
7295 html_table_coord+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+total_pop+"</td>"
7296 html_table_coord+=`</tr>
7297 <tr>
7298 <td style="text-align:center; width:auto; background-color:${headerColorCoords}">
7299 <center style="margin:1px"><font color="${titleColor}">coming</font></center>
7300 </td>`
7301
7302 ////////////////////////////////////////////////////////////////////////////////////////coming troops//////////////////////////////////////////////////
7303 total_pop=0;
7304 for(let i=0;i<units.length-1;i++){
7305 let value_troop_coming=troopsSupportComing[units[i]]
7306 let name_troop=units[i]
7307 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
7308 total_pop+=value_troop_coming*troopsPop[name_troop]
7309 }
7310 html_table_coord+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+value_troop_coming+"</td>"
7311 }
7312 html_table_coord+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+total_pop+"</td>"
7313
7314 html_table_coord+=`</tr>
7315 <tr>
7316 <td style="text-align:center; width:auto; background-color:${headerColorCoords}">
7317 <center style="margin:1px"><font color="${titleColor}">total </font></center>
7318 </td>`
7319 ////////////////////////////////////////////////////////////////////////////////////////total troops//////////////////////////////////////////////////
7320 total_pop=0;
7321 for(let i=0;i<units.length-1;i++){
7322 let value_home=(obj.homeInfo.obj_troops!=undefined)?obj.homeInfo.obj_troops[units[i]]:0
7323 let value_troop=troopsSupportComing[units[i]]+value_home
7324 let name_troop=units[i]
7325 if(name_troop!="spy" && name_troop!="light" && name_troop!="marcher" && name_troop!="ram"&& name_troop!="catapult" && name_troop!="axe"){
7326 total_pop+=value_troop*troopsPop[name_troop]
7327 }
7328 html_table_coord+=`<td style="width:30px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+value_troop+"</td>"
7329 }
7330 html_table_coord+=`<td style="width:60px;height:30px;text-align:center; background-color:${headerColorCoords};color:white">`+total_pop+"</td>"
7331 html_table_coord+="</tr></tbody>"
7332 return html_table_coord
7333 }
7334}
7335
7336//////////////////////////////////////////add click event for coord and when it's pressed show table with troops and incomings////////////////////
7337
7338function createEventCoord(map_playerId,mapVillage,playerId){
7339 $(".infoCoord").on("click",(event)=>{
7340
7341 // console.log(this.parentElement)
7342 // console.log($(this).parent())
7343
7344 // console.log("event infoCoord")
7345 let coordId=event.target.getAttribute("coord-id")
7346 let numberTrCoord=event.target.getAttribute("number-tr-coord")
7347 let obj={}
7348 let list_coords=map_playerId.get(playerId).list_coords
7349 // console.log(playerId)
7350 // console.log(list_coords)
7351 for(let i=0;i<list_coords.length;i++){
7352 if(coordId==list_coords[i].coord_destination_id){
7353 obj=list_coords[i]
7354 break;
7355 }
7356 }
7357 console.log("obj",obj)
7358 console.log("mapVillage",mapVillage)
7359
7360 // console.log(obj)
7361 // console.log(coordId)
7362 // console.log(numberTrCoord)
7363 // console.log(event.target)
7364
7365 console.log("objbaaa",obj)
7366 let admin=true
7367 let html_table_coord=`<tr><td >`
7368 if(obj.hasOwnProperty("homeInfo")==true){
7369 html_table_coord=`<table class="table_coord" border="1" coord-id="${coordId}" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;"> `
7370 html_table_coord+=createTableCoordTroops(obj,admin)
7371 html_table_coord+="</table>"
7372 }
7373
7374 html_table_coord+=`
7375 <div style="height:400px;overflow:auto;" id="div_incomingsInfo">
7376 <table class="table_coord" border="1" style="width: 100%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;"></div> `
7377 html_table_coord+=createTableCoordIncomings(obj.list_coming,mapVillage)
7378
7379
7380
7381 html_table_coord+=`</table><td></tr>`
7382
7383
7384
7385
7386 let delay=500
7387 // console.log(document.getElementById(`table_coord${numberTrCoord}`))
7388 if(document.getElementById(`table_coord${numberTrCoord}`)!=null){
7389 $(".tr_table_coord_info").hide(delay)
7390 // $("#div_incomingsInfo").hide(delay)
7391 window.setTimeout(()=>{
7392 $(".tr_table_coord_info").remove()
7393 // $("#div_incomingsInfo").remove()
7394 },delay+10)
7395
7396 }
7397 else{
7398
7399 $(".tr_table_coord_info").remove()
7400 // console.log(html_table_player)
7401 var table_coord = document.getElementsByClassName("table_player")[0].getElementsByTagName("tbody")[0]
7402 var newRow = table_coord.insertRow(numberTrCoord);
7403 newRow.className="tr_table_coord_info"
7404 newRow.id=`table_coord${numberTrCoord}`
7405
7406 let cell = newRow.insertCell();
7407 cell.setAttribute("colspan",7)
7408 var div = document.createElement("div")
7409 div.innerHTML=html_table_coord
7410 $(cell).append(div)
7411 $(cell).hide()
7412 $(cell).show(delay)
7413 counterTime()
7414 }
7415
7416
7417 })
7418}
7419
7420////////////////////////////////////////////////////////////////// create table for incomings////////////////////////////////////////////////////////
7421
7422function createTableCoordIncomings(list,mapVillage){
7423 let serverTime=document.getElementById("serverTime").innerText
7424 let serverDate=document.getElementById("serverDate").innerText.split("/")
7425 serverDate=serverDate[1]+"/"+serverDate[0]+"/"+serverDate[2]
7426 let date_current=new Date(serverDate+" "+serverTime).getTime()
7427 // console.log("create table coord")
7428 console.log("createTableCoordIncomings")
7429 // console.log(list)
7430 // console.log(mapVillage)
7431 let html_incomings=`
7432 <tbody >
7433 <tr>
7434 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7435 <center style="margin:5px"><font color="${titleColor}"><img src="https://dsen.innogamescdn.com/asset/056b9c0b/graphic/unit/att.png"> </font></center>
7436 </td>
7437 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7438 <center style="margin:0px"><font color="${titleColor}">speed/pop </font></center>
7439 </td>
7440 <td colspan="2" style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7441 <center style="margin:0px"><font color="${titleColor}">destination </font></center>
7442 </td>
7443 <td colspan="2" style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7444 <center style="margin:0px"><font color="${titleColor}">origin </font></center>
7445 </td>
7446 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7447 <center style="margin:0px"><font color="${titleColor}">Arrival time </font></center>
7448 </td>
7449 <td style="text-align:center; width:auto; background-color:${headerColorFirstRow}">
7450 <center style="margin:0px"><font color="${titleColor}">Arrives in </font></center>
7451 </td>
7452
7453
7454 </tr>`
7455
7456 for(let i=0;i<list.length;i++){
7457 // console.log("aici baa")
7458 // console.log(list[i])
7459 let labelName
7460 let villageId=mapVillage.get(list[i].coord_destination).villageId
7461 let playerId=mapVillage.get(list[i].coord_destination).playerId
7462 let playerName=mapVillage.get(list[i].coord_destination).playerName
7463 let headerNoble=headerColorCoords
7464 let titleColorNoble=titleColor
7465 let type_attack=list[i].type_attack
7466 console.log(type_attack)
7467 if(list[i].labelName=="none")
7468 labelName=`<img src="https://dsen.innogamescdn.com/asset/056b9c0b/graphic/delete.png">`
7469 else
7470 labelName=`<img src="https://dsen.innogamescdn.com/asset/a9e85669/graphic/unit/tiny/${list[i].labelName}">`
7471
7472 if(type_attack.includes("support")){
7473 let troops=list[i].troops
7474 let pop=0
7475 Object.keys(troops).forEach(key=>{
7476 pop+=troops[key]*troopsPop[key]
7477 })
7478 labelName=pop
7479 if(list[i].hasSupportSnipe==true){
7480 headerNoble="#034a2f"
7481 }
7482 type_attack=`https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/${type_attack}`
7483
7484
7485 }else{
7486 //colore nobles
7487 if(labelName.includes("snob")){
7488 headerNoble="#3f0000"//red
7489 titleColorNoble="#4dff4d"//green
7490 }
7491 if(labelName.includes("snob") ){//&& tribemates.includes(list[i].player_origin_name) //hard coded/////////////
7492 headerNoble="#720000"//lighter red
7493 titleColorNoble="#4dff4d"//green
7494 }
7495
7496 //modify type_attack, small,medium,large
7497 if(type_attack=="def"){
7498 type_attack=`https://img.icons8.com/fluent/16/000000/d.png`
7499 }
7500 else{
7501 type_attack=`https://dsen.innogamescdn.com/asset/a9e85669/graphic/command/${type_attack}`
7502 }
7503
7504
7505 }
7506
7507 // console.log(list[i].labelName)
7508 let arrived=new Date(list[i].landing_time).getTime()
7509 if(arrived>date_current){
7510 let date=list[i].landing_time.split(" ")[0]
7511 let time=list[i].landing_time.split(" ")[1].split(":")
7512 let milisec=time.pop()
7513 time=time.join(":")
7514
7515 html_incomings+=`
7516 <tr style="white-space:nowrap;" >
7517 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7518 <center style="margin:0px;padding:0px"><font color="${titleColor}"><img src="${type_attack}"> </font></center>
7519 </td>
7520 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7521 <center style="margin:0px;padding:0px"><font color="${titleColor}">${labelName}</font></center>
7522 </td>
7523 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7524 <a href="${game_data.link_base_pure}info_village&id=${villageId}"style="margin:0px;padding:0px"><center><font color="${titleColor}">${list[i].coord_destination}</font></center></a>
7525 </td>
7526 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7527 <a href="${game_data.link_base_pure}info_player&id=${playerId}"style="margin:0px;padding:0px"><center><font color="${titleColor}">${playerName}</font></center></a>
7528 </td>
7529 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7530 <a href="${game_data.link_base_pure}info_village&id=${list[i].coord_origin_id}"style="margin:0px;padding:0px"><center><font color="${titleColor}">${list[i].coord_origin}</font></center></a>
7531 </td>
7532 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7533 <a href="${game_data.link_base_pure}info_player&id=${list[i].player_origin_id}" style="margin:0px;padding:0px"><center><font color="${titleColor}">${list[i].player_origin_name}</font></center></a>
7534 </td>
7535 <td style="text-align:center; width:auto; background-color:${headerNoble}">
7536 <center style="margin:0px;padding:0px"><font color="${titleColor}">${date} <b>${time} <font color="${titleColorNoble}"> ${milisec}</font></b> </font></center>
7537 </td>
7538 <td style="text-align:center; width:auto; background-color:${headerNoble}" >
7539 <center style="margin:0px;padding:0px"><font color="${titleColor}" date-time=${arrived} class="counterTime"></font></center>
7540 </td>
7541
7542 </tr>
7543 `
7544 }
7545 }
7546 html_incomings+="</tbody>"
7547 // console.log(html_incomings)
7548 return html_incomings
7549}
7550
7551
7552/////////////////////////////////////////////////////////////////create table for settings//////////////////////////////////////////////////////
7553function createTableSettings(){
7554 let html_table=`
7555 <center>
7556 <table id="table_settings" border="1" style="width: 40%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;">
7557 <tr>
7558 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7559 <input type="checkbox" value="hide_ignored">
7560 </td>
7561 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7562 <font style="margin:5px" color="${titleColor}">hide ignored attacks/support</font>
7563 </td>
7564 </tr>
7565 <tr>
7566 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7567 <input type="checkbox" value="hide_supports">
7568 </td>
7569 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7570 <font style="margin:5px" color="${titleColor}">hide supports</font>
7571 </td>
7572 </tr>
7573 <tr>
7574 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7575 <input type="checkbox" value="hide_further_attacks">
7576 </td>
7577 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7578 <font style="margin:5px" color="${titleColor}">hide attacks further than(hours) </font>
7579 </td>
7580 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7581 <input type="number" style="text-align:center;" id="settings_further" min="0" max="200" placeholder="100">
7582 </td>
7583 </tr>
7584 <tr>
7585 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7586 <input type="checkbox" value="hide_closer_attacks">
7587 </td>
7588 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7589 <font style="margin:5px" color="${titleColor}">hide attacks closer than(hours) </font>
7590 </td>
7591 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7592 <input type="number" style="text-align:center;" id="settings_closer" min="0" max="200" placeholder="20">
7593 </td>
7594 </tr>
7595 <tr>
7596 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7597 <font style="margin:5px" color="${titleColor}">snipe has(pop) </font>
7598 </td>
7599 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7600 <input type="number" style="text-align:center;" id="settings_pop" min="0" max="20000" value="1000" placeholder="1000">
7601 </td>
7602 </tr>
7603 <tr>
7604 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7605 <font style="margin:5px" color="${titleColor}">small attack has less than(pop) </font>
7606 </td>
7607 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7608 <input type="number" style="text-align:center;" id="settings_small_attack" min="0" max="20000" value="5000" placeholder="5000">
7609 </td>
7610 </tr>
7611 <tr>
7612 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7613 <font style="margin:5px" color="${titleColor}">medium attack has less than(pop) </font>
7614 </td>
7615 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7616 <input type="number" style="text-align:center;" id="settings_medium_attack" min="0" max="20000" value="10000" placeholder="10000">
7617 </td>
7618 </tr>
7619 <tr>
7620 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
7621 <font style="margin:5px" color="${titleColor}">fangs has(catapults) </font>
7622 </td>
7623 <td style="text-align:center; width:auto; background-color:${headerColor}" >
7624 <input type="number" style="text-align:center;" id="settings_fang_cat" min="0" max="20000" value="100" placeholder="100">
7625 </td>
7626 </tr>
7627
7628
7629
7630 </table>
7631
7632 </div></center>
7633 `
7634
7635 if(document.getElementById("table_settings")==null)
7636 document.getElementById("div_settings").innerHTML=html_table
7637 else{
7638 $("#div_rank_attacker").hide()
7639 $("#div_rank_defender").hide()
7640 $("#div_upload_time").hide()
7641 $("#div_get_coords").hide(500)
7642 $("#div_settings").toggle(500)
7643 }
7644
7645
7646 //initialize settings only if it's visible
7647
7648 if(localStorage.getItem(game_data.world+"save_settings")!=null ){
7649 let list_checkbox=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[0]
7650
7651 $('#div_settings input[type=checkbox]').each(function (index,elem) {
7652 this.checked=list_checkbox[index]
7653 // console.log(elem.value)
7654 });
7655
7656 let list_input=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[1]
7657 $('#div_settings input[type=number]').each(function (index,elem) {
7658 // var checked = this.checked
7659 this.value=list_input[index]
7660 });
7661
7662 let value_radio=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[2]
7663 $(`input[name='type_info'][value='${value_radio}'`).attr("checked",true)
7664
7665 }
7666
7667
7668
7669 //save settings
7670 $("#div_settings input[type=checkbox],#div_settings input[type=number], input[name='type_info']").on("mouseup input",()=>{
7671 console.log("save")
7672 let list_checkbox=[]
7673 let list_input=[]
7674 //save checkbox
7675 $('#div_settings input[type=checkbox]').each(function () {
7676 var checked = this.checked
7677 list_checkbox.push(checked)
7678 });
7679 //save inputs
7680 $('#div_settings input[type=number] ').each(function () {
7681 // var checked = this.checked
7682 var value=this.value
7683 // console.log(value)
7684 list_input.push(value)
7685 });
7686 //save radio button
7687 let value_radio=$("input[name='type_info']:checked").val()
7688
7689
7690
7691 let list_final=[list_checkbox,list_input,value_radio]
7692 localStorage.setItem(game_data.world+"save_settings",JSON.stringify(list_final))
7693
7694 })
7695
7696
7697 $("#btn_apply").on("click",()=>{
7698 $("#div_container_view").remove();
7699 viewSupport()
7700 })
7701 $("#btn_clear_memory").on("click",()=>{
7702 localStorage.removeItem(game_data.world+"map_exist_support")
7703 UI.SuccessMessage("local storage is cleared",1000)
7704 })
7705
7706}
7707
7708/////////////////////////////////////////////////////////////////create table ranking atackers//////////////////////////////////////////////////////
7709
7710function createTableRankingAttackers(map_ranking){
7711
7712
7713 let html=`
7714 <center>
7715 <div>
7716 <table id="table_rank" border="1" style="width: 60%;background-color:${backgroundColor};border-color:${borderColor}">
7717 <tr>
7718 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7719 <center style="margin:10px" ><font color="${titleColor}">nr</font></center>
7720 </td>
7721 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7722 <center style="margin:10px" ><font color="${titleColor}">player name</font></center>
7723 </td>
7724 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7725 <center style="margin:10px" ><a href="#" id="sort_fakes_att"><font color="${titleColor}">fakes</font><a/></center>
7726 </td>
7727 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7728 <center style="margin:10px" ><a href="#" id="sort_nukes_att"><font color="${titleColor}">nukes</font><a/></center>
7729 </td>
7730 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7731 <center style="margin:10px" ><a href="#" id="sort_fangs_att"><font color="${titleColor}">fangs</font><a/></center>
7732 </td>
7733 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7734 <center style="margin:10px" ><a href="#" id="sort_nobles_att"><font color="${titleColor}">nobles</font><a/></center>
7735 </td>
7736 </tr>`
7737
7738 Array.from(map_ranking.keys()).forEach((key,index)=>{
7739 let obj_attacks=map_ranking.get(key)
7740 html+=`
7741 <tr>
7742 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7743 <center><font style="margin:0px" color="${titleColor}">${index+1}</font></center>
7744 </td>
7745 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7746 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.player_origin_name}</font></center>
7747 </td>
7748 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7749 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_fakes}</font></center>
7750 </td>
7751 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7752 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_nukes}</font></center>
7753 </td>
7754 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7755 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_fangs}</font></center>
7756 </td>
7757 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7758 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_nobles}</font></center>
7759 </td>
7760 </tr>
7761
7762 `
7763 })
7764 html+=`
7765 </table></div></center>`
7766 if(document.getElementById("div_rank_attacker").children.length==0 ){
7767 document.getElementById("div_rank_attacker").innerHTML=html
7768 console.log("initialize rank attacker")
7769 }
7770 else{
7771 $("#div_settings").hide()
7772 $("#div_rank_defender").hide()
7773 $("#div_upload_time").hide()
7774 $("#div_get_coords").hide(500)
7775 $("#div_rank_attacker").toggle(500)
7776 }
7777
7778
7779
7780 $("#sort_fakes_att").off("click")
7781 $("#sort_nukes_att").off("click")
7782 $("#sort_fangs_att").off("click")
7783 $("#sort_nobles_att").off("click")
7784
7785 //sort by nr fakes
7786 $("#sort_fakes_att").on("click",()=>{
7787 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7788 return (o1[1].nr_fakes>o2[1].nr_fakes)?-1:(o1[1].nr_fakes<o2[1].nr_fakes)?1:0
7789 }))
7790 document.getElementById("div_rank_attacker").innerHTML=""
7791 createTableRankingAttackers(map_ranking)
7792 })
7793 //sort by nr nukes
7794 $("#sort_nukes_att").on("click",()=>{
7795 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7796 return (o1[1].nr_nukes>o2[1].nr_nukes)?-1:(o1[1].nr_nukes<o2[1].nr_nukes)?1:0
7797 }))
7798 console.log("sort by nukes")
7799 document.getElementById("div_rank_attacker").innerHTML=""
7800 createTableRankingAttackers(map_ranking)
7801 })
7802 //sort by nr fangs
7803 $("#sort_fangs_att").on("click",()=>{
7804 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7805 return (o1[1].nr_fangs>o2[1].nr_fangs)?-1:(o1[1].nr_fangs<o2[1].nr_fangs)?1:0
7806 }))
7807 console.log("sort by fangs")
7808 document.getElementById("div_rank_attacker").innerHTML=""
7809 createTableRankingAttackers(map_ranking)
7810 })
7811 //sort by nr nobles
7812 $("#sort_nobles_att").on("click",()=>{
7813 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7814 return (o1[1].nr_nobles>o2[1].nr_nobles)?-1:(o1[1].nr_nobles<o2[1].nr_nobles)?1:0
7815 }))
7816 console.log("sort by nobles")
7817 document.getElementById("div_rank_attacker").innerHTML=""
7818 createTableRankingAttackers(map_ranking)
7819 })
7820
7821
7822}
7823
7824
7825/////////////////////////////////////////////////////////////////create table ranking defenders//////////////////////////////////////////////////////
7826
7827function createTableRankingDefenders(map_ranking){
7828
7829
7830 let html=`
7831 <center>
7832 <div>
7833 <table id="table_rank" border="1" style="width: 60%;background-color:${backgroundColor};border-color:${borderColor}">
7834 <tr>
7835 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7836 <center style="margin:10px" ><font color="${titleColor}">nr</font></center>
7837 </td>
7838 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7839 <center style="margin:10px" ><font color="${titleColor}">player name</font></center>
7840 </td>
7841 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7842 <center style="margin:10px" ><a href="#" id="sort_fakes_def"><font color="${titleColor}">fakes</font><a/></center>
7843 </td>
7844 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7845 <center style="margin:10px" ><a href="#" id="sort_nukes_def"><font color="${titleColor}">nukes</font><a/></center>
7846 </td>
7847 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7848 <center style="margin:10px" ><a href="#" id="sort_fangs_def"><font color="${titleColor}">fangs</font><a/></center>
7849 </td>
7850 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7851 <center style="margin:10px" ><a href="#" id="sort_nobles_def"><font color="${titleColor}">nobles</font><a/></center>
7852 </td>
7853 </tr>`
7854
7855 Array.from(map_ranking.keys()).forEach((key,index)=>{
7856 let obj_attacks=map_ranking.get(key)
7857 html+=`
7858 <tr>
7859 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7860 <center><font style="margin:0px" color="${titleColor}">${index+1}</font></center>
7861 </td>
7862 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7863 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.player_origin_name}</font></center>
7864 </td>
7865 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7866 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_fakes}</font></center>
7867 </td>
7868 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7869 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_nukes}</font></center>
7870 </td>
7871 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7872 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_fangs}</font></center>
7873 </td>
7874 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7875 <center><font style="margin:0px" color="${titleColor}">${obj_attacks.nr_nobles}</font></center>
7876 </td>
7877 </tr>
7878
7879 `
7880 })
7881 html+=`
7882 </table></div></center>`
7883 if(document.getElementById("div_rank_defender").children.length==0 ){
7884 document.getElementById("div_rank_defender").innerHTML=html
7885 console.log("initialize rank defender")
7886 }
7887 else{
7888 $("#div_settings").hide()
7889 $("#div_rank_attacker").hide()
7890 $("#div_upload_time").hide()
7891 $("#div_get_coords").hide(500)
7892 $("#div_rank_defender").toggle(500)
7893 }
7894
7895
7896
7897 $("#sort_fakes_def").off("click")
7898 $("#sort_nukes_def").off("click")
7899 $("#sort_fangs_def").off("click")
7900 $("#sort_nobles_def").off("click")
7901
7902 //sort by nr fakes
7903 $("#sort_fakes_def").on("click",()=>{
7904 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7905 return (o1[1].nr_fakes>o2[1].nr_fakes)?-1:(o1[1].nr_fakes<o2[1].nr_fakes)?1:0
7906 }))
7907 document.getElementById("div_rank_defender").innerHTML=""
7908 createTableRankingDefenders(map_ranking)
7909 })
7910 //sort by nr nukes
7911 $("#sort_nukes_def").on("click",()=>{
7912 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7913 return (o1[1].nr_nukes>o2[1].nr_nukes)?-1:(o1[1].nr_nukes<o2[1].nr_nukes)?1:0
7914 }))
7915 console.log("sort by nukes")
7916 document.getElementById("div_rank_defender").innerHTML=""
7917 createTableRankingDefenders(map_ranking)
7918 })
7919 //sort by nr fangs
7920 $("#sort_fangs_def").on("click",()=>{
7921 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7922 return (o1[1].nr_fangs>o2[1].nr_fangs)?-1:(o1[1].nr_fangs<o2[1].nr_fangs)?1:0
7923 }))
7924 console.log("sort by fangs")
7925 document.getElementById("div_rank_defender").innerHTML=""
7926 createTableRankingDefenders(map_ranking)
7927 })
7928 //sort by nr nobles
7929 $("#sort_nobles_def").on("click",()=>{
7930 map_ranking = new Map([...map_ranking.entries()].sort((o1,o2)=>{
7931 return (o1[1].nr_nobles>o2[1].nr_nobles)?-1:(o1[1].nr_nobles<o2[1].nr_nobles)?1:0
7932 }))
7933 console.log("sort by nobles")
7934 document.getElementById("div_rank_defender").innerHTML=""
7935 createTableRankingDefenders(map_ranking)
7936 })
7937
7938
7939}
7940
7941
7942/////////////////////////////////////////////////////////////////create table upload time//////////////////////////////////////////////////////
7943
7944function createTableUploadTime(map_upload_time){
7945
7946
7947 let html=`
7948 <center>
7949 <div>
7950 <table id="table_rank" border="1" style="width: 80%;background-color:${backgroundColor};border-color:${borderColor}">
7951 <tr>
7952 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7953 <center style="margin:10px" ><font color="${titleColor}">nr</font></center>
7954 </td>
7955 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7956 <center style="margin:10px" ><font color="${titleColor}">player name</font></center>
7957 </td>
7958 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7959 <center style="margin:10px" ><a href="#" id="sort_reports"><font color="${titleColor}">reports</font><a/></center>
7960 </td>
7961 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7962 <center style="margin:10px" ><a href="#" id="sort_incomings"><font color="${titleColor}">incomings</font><a/></center>
7963 </td>
7964 <td style="text-align:left; width:auto; background-color:${headerColor}" hidden>
7965 <center style="margin:10px" ><a href="#" id="sort_commands"><font color="${titleColor}">commands</font><a/></center>
7966 </td>
7967
7968 </tr>`
7969
7970 Array.from(map_upload_time.keys()).forEach((key,index)=>{
7971 let obj_upload=map_upload_time.get(key)
7972 html+=`
7973 <tr>
7974 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7975 <center><font style="margin:0px" color="${titleColor}">${index+1}</font></center>
7976 </td>
7977 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7978 <center><font style="margin:0px" color="${titleColor}">${obj_upload.name}</font></center>
7979 </td>
7980 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7981 <center><font style="margin:0px" color="${titleColor}">${parseDate(obj_upload.report_date)}</font></center>
7982 </td>
7983 <td style="text-align:left; width:auto; background-color:${headerColor}" >
7984 <center><font style="margin:0px" color="${titleColor}">${parseDate(obj_upload.incoming_date)}</font></center>
7985 </td>
7986 <td style="text-align:left; width:auto; background-color:${headerColor}" hidden >
7987 <center><font style="margin:0px" color="${titleColor}">${parseDate(obj_upload.command_date)}</font></center>
7988 </td>
7989 </tr>
7990
7991 `
7992 })
7993 html+=`
7994 </table></div></center>`
7995 if(document.getElementById("div_upload_time").children.length==0 ){
7996 document.getElementById("div_upload_time").innerHTML=html
7997 console.log("initialize table upload time")
7998 }
7999 else{
8000 $("#div_settings").hide()
8001 $("#div_rank_defender").hide()
8002 $("#div_rank_attacker").hide()
8003 $("#div_get_coords").hide(500)
8004 $("#div_upload_time").toggle(500)
8005 console.log("rank attacker")
8006 }
8007
8008
8009 $("#sort_reports").off("click")
8010 $("#sort_incomings").off("click")
8011 $("#sort_commands").off("click")
8012
8013 //sort by nr date upload reports
8014 $("#sort_reports").on("click",()=>{
8015 map_upload_time = new Map([...map_upload_time.entries()].sort((o1,o2)=>{
8016 return (new Date(o1[1].report_date).getTime() > new Date(o2[1].report_date).getTime())?-1:
8017 (new Date(o1[1].report_date).getTime() < new Date(o2[1].report_date).getTime())?1:0
8018 }))
8019 console.log("sort by report")
8020 document.getElementById("div_upload_time").innerHTML=""
8021 createTableUploadTime(map_upload_time)
8022 })
8023 //sort by nr date upload incomings
8024 $("#sort_incomings").on("click",()=>{
8025 map_upload_time = new Map([...map_upload_time.entries()].sort((o1,o2)=>{
8026 return (new Date(o1[1].incoming_date).getTime() > new Date(o2[1].incoming_date).getTime())?-1:
8027 (new Date(o1[1].incoming_date).getTime() < new Date(o2[1].incoming_date).getTime())?1:0
8028 }))
8029 console.log("sort by incomings")
8030 document.getElementById("div_upload_time").innerHTML=""
8031 createTableUploadTime(map_upload_time)
8032 })
8033 //sort by nr date upload commands
8034 $("#sort_commands").on("click",()=>{
8035 map_upload_time = new Map([...map_upload_time.entries()].sort((o1,o2)=>{
8036 return (new Date(o1[1].command_date).getTime() > new Date(o2[1].command_date).getTime())?-1:
8037 (new Date(o1[1].command_date).getTime() < new Date(o2[1].command_date).getTime())?1:0
8038 }))
8039 console.log("sort by commands")
8040 document.getElementById("div_upload_time").innerHTML=""
8041 createTableUploadTime(map_upload_time)
8042 })
8043
8044
8045
8046}
8047
8048function parseDate(time){
8049 let date=new Date(time)
8050
8051 let year=date.getFullYear();
8052 let month=("00"+(date.getMonth()+1)).slice(-2)
8053 let day=("00"+date.getDate()).slice(-2)
8054 let hours=("00"+date.getHours()).slice(-2)
8055 let minutes=("00"+date.getMinutes()).slice(-2)
8056 let seconds=("00"+date.getSeconds()).slice(-2)
8057 let result=`${month}/${day}/${year} ${hours}:${minutes}:${seconds}`
8058 return result
8059}
8060
8061////////////////////////////////////////////////sort by attacks,supports,nobles,snipes,recaps////////////////////////////////////////////////////////
8062
8063function sortInfoIncomings(map_playerId,mapVillage){
8064 //////////////////////////////////////////////////////////////sort by attacks///////////////////////////////////////////
8065 document.getElementById("sort_by_attacks").addEventListener("click",()=>{
8066 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
8067 return (o1[1].nr_attacks_total>o2[1].nr_attacks_total)?-1:(o1[1].nr_attacks_total<o2[1].nr_attacks_total)?1:0;
8068 }))
8069 Array.from(map_playerId.keys()).forEach(key=>{
8070 let obj=map_playerId.get(key)
8071 obj.list_coords.sort((o1,o2)=>{
8072 return (o1.nr_attacks>o2.nr_attacks)?-1:(o1.nr_attacks<o2.nr_attacks)?1:0
8073 })
8074 map_playerId.set(key,obj)
8075 })
8076 document.getElementById("tbody_player").remove()
8077 createTablePlayers(map_playerId,mapVillage)
8078 })
8079 //////////////////////////////////////////////////////////////sort by supports///////////////////////////////////////////
8080
8081 document.getElementById("sort_by_supports").addEventListener("click",()=>{
8082 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
8083 return (o1[1].nr_supports_total>o2[1].nr_supports_total)?-1:(o1[1].nr_supports_total<o2[1].nr_supports_total)?1:0;
8084 }))
8085 Array.from(map_playerId.keys()).forEach(key=>{
8086 let obj=map_playerId.get(key)
8087 obj.list_coords.sort((o1,o2)=>{
8088 return (o1.nr_supports>o2.nr_supports)?-1:(o1.nr_supports<o2.nr_supports)?1:0
8089 })
8090 map_playerId.set(key,obj)
8091 })
8092 document.getElementById("tbody_player").remove()
8093 createTablePlayers(map_playerId,mapVillage)
8094
8095 })
8096 //////////////////////////////////////////////////////////////sort by nobles///////////////////////////////////////////
8097 document.getElementById("sort_by_nobles").addEventListener("click",()=>{
8098 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
8099 return (o1[1].nr_nobles_total>o2[1].nr_nobles_total)?-1:(o1[1].nr_nobles_total<o2[1].nr_nobles_total)?1:0;
8100 }))
8101 Array.from(map_playerId.keys()).forEach(key=>{
8102 let obj=map_playerId.get(key)
8103 obj.list_coords.sort((o1,o2)=>{
8104 return (o1.nr_nobles>o2.nr_nobles)?-1:(o1.nr_nobles<o2.nr_nobles)?1:0
8105 })
8106 map_playerId.set(key,obj)
8107 })
8108 document.getElementById("tbody_player").remove()
8109 createTablePlayers(map_playerId,mapVillage)
8110 })
8111 //////////////////////////////////////////////////////////////sort by snipes///////////////////////////////////////////
8112
8113 document.getElementById("sort_by_snipes").addEventListener("click",()=>{
8114 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
8115 return (o1[1].nr_snipe_total>o2[1].nr_snipe_total)?-1:(o1[1].nr_snipe_total<o2[1].nr_snipe_total)?1:0;
8116 }))
8117 Array.from(map_playerId.keys()).forEach(key=>{
8118 let obj=map_playerId.get(key)
8119 obj.list_coords.sort((o1,o2)=>{
8120 return (o1.nr_snipe>o2.nr_snipe)?-1:(o1.nr_snipe<o2.nr_snipe)?1:(o1.nr_sniped>o2.nr_sniped)?-1:(o1.nr_sniped<o2.nr_sniped)?1:0;
8121 })
8122 map_playerId.set(key,obj)
8123 })
8124 document.getElementById("tbody_player").remove()
8125 createTablePlayers(map_playerId,mapVillage)
8126 })
8127 //////////////////////////////////////////////////////////////sort by recaps///////////////////////////////////////////
8128 document.getElementById("sort_by_recaps").addEventListener("click",()=>{
8129 map_playerId= new Map([...map_playerId.entries()].sort((o1,o2) =>{
8130 return (o1[1].nr_recap_total>o2[1].nr_recap_total)?-1:(o1[1].nr_recap_total<o2[1].nr_recap_total)?1:0;
8131 }))
8132 Array.from(map_playerId.keys()).forEach(key=>{
8133 let obj=map_playerId.get(key)
8134 obj.list_coords.sort((o1,o2)=>{
8135 return (o1.nr_recap>o2.nr_recap)?-1:(o1.nr_recap<o2.nr_recap)?1:(o1.nr_recaped>o2.nr_recaped)?-1:(o1.nr_recaped<o2.nr_recaped)?1:0
8136 })
8137 map_playerId.set(key,obj)
8138 })
8139 document.getElementById("tbody_player").remove()
8140 createTablePlayers(map_playerId,mapVillage)
8141 })
8142
8143}
8144
8145
8146
8147/////////////////////////////////////////////////////////////////create table for settings//////////////////////////////////////////////////////
8148function createTableGetCoords(mapVillage){
8149 let html_table=`
8150 <center>
8151 <table id="table_get_coords" border="1" style="width: 70%;background-color:${backgroundColor};border-color:${borderColor};border-spacing:2px;border-collapse:separate;">
8152 <tr>
8153 <td style="text-align:left; width:auto; background-color:${headerColor}" >
8154 <center><font style="margin:5px" color="${titleColor}">Players:</font></center>
8155 </td>
8156 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8157 <input type="text" style="text-align:left;width:98%;font-size:18px" id="input_players" placeholder="name player1, name player2, name player3">
8158 </td>
8159 </tr>
8160 <tr>
8161 <td style="text-align:left; width:auto; background-color:${headerColor}" >
8162 <center><font style="margin:5px" color="${titleColor}">Tribes:</font></center>
8163 </td>
8164 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8165 <input type="text" style="text-align:left;width:98%;font-size:18px" id="input_tribes" placeholder="name tribe1, name tribe2, name tribe3">
8166 </td>
8167 </tr>
8168 <tr>
8169 <td style="text-align:left; width:auto; background-color:${headerColor}" >
8170 <center><font style="margin:5px" color="${titleColor}">Continents:</font></center>
8171 </td>
8172 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8173 <input type="text" style="text-align:left;width:98%;font-size:18px" id="input_continents" placeholder="54,55,65">
8174 </td>
8175 </tr>
8176 <tr>
8177 <td style="text-align:left; width:auto; background-color:${headerColor}" ">
8178 <center><font style="margin:5px" color="${titleColor}">Min coord:</font></center>
8179 </td>
8180 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8181 <div style="display:flex">
8182 <div> <input type="number" style="text-align:center;font-size:18px" id="input_x_min" min="0" max="1000" placeholder="X"></div>
8183 <div> <input type="number" style="text-align:center;font-size:18px" id="input_y_min" min="0" max="1000" placeholder="Y"></div>
8184 </div>
8185 </td>
8186 </tr>
8187 <tr>
8188 <td style="text-align:left; width:auto; background-color:${headerColor}" >
8189 <center><font style="margin:5px" color="${titleColor}">Max coord:</font></center>
8190 </td>
8191 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8192 <div style="display:flex">
8193 <div> <input type="number" style="text-align:center;font-size:18px" id="input_x_max" min="0" max="1000" placeholder="X"></div>
8194 <div> <input type="number" style="text-align:center;font-size:18px" id="input_y_max" min="0" max="1000" placeholder="Y"></div>
8195 </div>
8196 </td>
8197 </tr>
8198 <tr>
8199 <td style="text-align:left; width:auto; background-color:${headerColor}" >
8200 <center><font style="margin:5px" color="${titleColor}">Dist from center:</font></center>
8201 </td>
8202 <td style="text-align:center; width:auto; background-color:${headerColor}" >
8203 <div style="display:flex">
8204 <div> <input type="number" style="text-align:center;font-size:18px" id="input_radius" min="0" max="1000" placeholder="R"></div>
8205 <div> <font style="margin:5px" color="${titleColor}">fields from:</font></div>
8206 <div> <input type="number" style="text-align:center;font-size:18px" id="input_center_x" min="0" max="1000" placeholder="X"></div>
8207 <div> <input type="number" style="text-align:center;font-size:18px" id="input_center_y" min="0" max="1000" placeholder="Y"></div>
8208 </div>
8209 </td>
8210 </tr>
8211 <tr>
8212 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
8213 <center style="margin:10px"><input class="btn" type="button" id="btn_extract_coord" value="extract_coords"></center>
8214 </td>
8215 </tr>
8216 <tr>
8217 <td style="text-align:left; width:auto; background-color:${headerColor}" colspan="2">
8218 <font id="nr_coords" style="margin:10px;margin-left:100px;font-size:15px" color="${titleColor}">nr coords:(0)</font>
8219 <center style="margin:10px"><textarea id="input_get_coords" cols="60" rows="20" ></textarea><center>
8220 </td>
8221 </tr>
8222
8223 </table>
8224
8225 </div></center>
8226 `
8227
8228 if(document.getElementById("table_get_coords")==null)
8229 document.getElementById("div_get_coords").innerHTML=html_table
8230 else{
8231 $("#div_rank_attacker").hide()
8232 $("#div_rank_defender").hide()
8233 $("#div_upload_time").hide()
8234 $("#div_settings").hide(500)
8235 $("#div_get_coords").toggle(500)
8236 }
8237
8238
8239 // //initialize settings only if it's visible
8240
8241 if(localStorage.getItem(game_data.world+"save_settings")!=null ){
8242 let list_checkbox=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[0]
8243
8244 $('#div_settings input[type=checkbox], #div_get_coords input[type=checkbox]').each(function (index,elem) {
8245 this.checked=list_checkbox[index]
8246 // console.log(elem.value)
8247 });
8248
8249 let list_input=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[1]
8250 $('#div_settings input[type=number], #div_get_coords input[type=text],#div_get_coords input[type=number]').each(function (index,elem) {
8251 // var checked = this.checked
8252 if(list_input[index]!=undefined)
8253 this.value=list_input[index]
8254 });
8255
8256 let value_radio=JSON.parse(localStorage.getItem(game_data.world+"save_settings"))[2]
8257 $(`input[name='type_info'][value='${value_radio}'`).attr("checked",true)
8258
8259 }
8260
8261
8262
8263 //save settings
8264 $("#div_settings input[type=checkbox],#div_settings input[type=number], input[name='type_info'], #div_get_coords input[type=checkbox], #div_get_coords input[type=text], #div_get_coords input[type=number]").on("mouseup input",()=>{
8265 console.log("save")
8266 let list_checkbox=[]
8267 let list_input=[]
8268 //save checkbox
8269 $('#div_settings input[type=checkbox], #div_get_coords input[type=checkbox]').each(function () {
8270 var checked = this.checked
8271 list_checkbox.push(checked)
8272 });
8273 //save inputs
8274 $('#div_settings input[type=number], #div_get_coords input[type=text], #div_get_coords input[type=number]').each(function () {
8275 // var checked = this.checked
8276 var value=this.value
8277 // console.log(value)
8278 list_input.push(value)
8279 });
8280 //save radio button
8281 let value_radio=$("input[name='type_info']:checked").val()
8282
8283
8284
8285 let list_final=[list_checkbox,list_input,value_radio]
8286 localStorage.setItem(game_data.world+"save_settings",JSON.stringify(list_final))
8287
8288 })
8289
8290
8291 $("#btn_extract_coord").off("click")
8292 $("#btn_extract_coord").on("click",()=>{
8293 //create the logic for extracting coords
8294 let playersName= Array.from(document.getElementById("input_players").value.toLowerCase().split(",")).filter(item => item);
8295 let tribesName= Array.from(document.getElementById("input_tribes").value.toLowerCase().split(",")).filter(item => item)
8296 let continents= Array.from(document.getElementById("input_continents").value.split(",")).filter(item => item)
8297 let xMin= parseInt(document.getElementById("input_x_min").value)
8298 let yMin= parseInt(document.getElementById("input_y_min").value)
8299 let xMax= parseInt(document.getElementById("input_x_max").value)
8300 let yMax= parseInt(document.getElementById("input_y_max").value)
8301
8302 let radius= parseInt(document.getElementById("input_radius").value)
8303 let xCenter= parseInt(document.getElementById("input_center_x").value)
8304 let yCenter= parseInt(document.getElementById("input_center_y").value)
8305
8306
8307 console.log(mapVillage)
8308
8309 let result_coords=[]
8310
8311
8312 Array.from(mapVillage.keys()).forEach(coord=>{
8313 try {
8314 let obj=mapVillage.get(coord)
8315 let isValid=true
8316
8317
8318
8319 // console.log(obj)
8320 //check for players names
8321 if(playersName.length>0){
8322 let found=false
8323 for(let j=0;j<playersName.length;j++){
8324 if(playersName[j].trim() == obj.playerName.toLowerCase()){//let coord get through next filter
8325 found=true
8326 break;
8327 }
8328 }
8329 if(found==false)
8330 isValid=false
8331 }
8332
8333 //check for tribes names
8334 if(tribesName.length>0){
8335 let found=false
8336 for(let j=0;j<tribesName.length;j++){
8337 if(tribesName[j].trim() == obj.tribeName.toLowerCase()){//let coord get through next filter
8338 found=true
8339 break;
8340 }
8341 }
8342 if(found==false)
8343 isValid=false
8344 }
8345
8346 //check for continents
8347 if(continents.length>0){
8348 let found=false
8349 for(let j=0;j<continents.length;j++){
8350 if(continents[j].trim() == getContinent(coord)){//let coord get through next filter
8351 found=true
8352 break;
8353 }
8354 }
8355 if(found==false)
8356 isValid=false
8357 }
8358
8359
8360 let[x,y]=coord.split("|")
8361 //for x min
8362 if(Number.isNaN(xMin)==false && isValid==true){
8363 isValid = (x >= xMin)?true:false
8364 }
8365 //for y min
8366 if(Number.isNaN(yMin)==false && isValid==true){
8367 isValid = (y >= yMin)?true:false
8368 }
8369 //for x max
8370 if(Number.isNaN(xMax)==false && isValid==true){
8371 isValid = (x <= xMax)?true:false
8372 }
8373 //for y max
8374 if(Number.isNaN(yMax)==false && isValid==true){
8375 isValid = (y <= yMax)?true:false
8376 }
8377
8378
8379 if(Number.isNaN(radius)==false && Number.isNaN(xCenter)==false && Number.isNaN(yCenter)==false && isValid==true){
8380 isValid=(calcDistance( xCenter+"|"+yCenter, coord)<radius)?true:false
8381 }
8382
8383
8384
8385 if(isValid==true){
8386 result_coords.push(coord)
8387 }
8388
8389 } catch (error) {}
8390
8391 })
8392 console.log(result_coords)
8393 document.getElementById("input_get_coords").value=result_coords.join(" ")
8394 document.getElementById("nr_coords").innerHTML=`nr coords:(${result_coords.length})`
8395
8396 })
8397
8398
8399
8400
8401 // console.log(mapVillage)
8402}
8403
8404function getContinent(coord){
8405 let [x,y]=Array.from(coord.split("|")).map(e=>parseInt(e))
8406 for(let i=0;i<1000;i+=100){//x axes
8407 for(let j=0;j<1000;j+=100){//y axes
8408 if(i>=x && x<i+100 && j>=y && y<j+100){
8409 let nr_continent= parseInt(y/100)+""+parseInt(x/100)
8410 return nr_continent
8411 }
8412 }
8413 }
8414}
8415
8416
8417
8418function insertChartLibrary(){
8419 return new Promise((resolve,reject)=>{
8420
8421
8422 let start=new Date().getTime()
8423 let script = document.createElement('script');
8424 script.type="text/javascript"
8425 script.src="https://cdn.anychart.com/releases/8.9.0/js/anychart-base.min.js"
8426 script.onload = function () {
8427 let stop=new Date().getTime()
8428 console.log(`insert chart library in ${stop-start} ms`)
8429 resolve("done")
8430 };
8431 document.head.appendChild(script);
8432 })
8433}
8434
8435
8436function createChart(list_points,name_container){
8437 // create a chart
8438 let chart = anychart.area();
8439
8440 // create a line series and set the data
8441 let series = chart.column(list_points);
8442
8443
8444
8445 // set the container id
8446 chart.container(name_container);
8447 chart.tooltip().format("incs: {%value}");
8448
8449 chart.xAxis().labels().rotation(-45);
8450 chart.yAxis().labels().format(function() {
8451 let value = this.value;
8452 // limit the number of symbols to 3
8453 value = value+" incs";
8454 return value
8455 })
8456
8457
8458 // initiate drawing the chart
8459 chart.draw();
8460 document.getElementsByClassName("anychart-credits")[0].remove()
8461
8462
8463}