Autor | Zpráva | ||
---|---|---|---|
IIIIIIIIII Profil |
#1 · Zasláno: 6. 7. 2020, 17:10:24
Ahoj takže k věci mam skript ktery nefunguje a to proto že se přidal lag serveru v nahodnem intervalu viz i.stack.imgur.com/vjBno.png veděl by tam někdo přidat něco co by to sparvne vypočitalo ?
<50span id="serverTime" title="Connection time to server: 105ms">2:40:47</50span> const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); const isNumber = d => '0' <= d && d <= '9'; const getDate = date => { return { h: date.getHours().toString().padStart(2, 0), m: date.getMinutes().toString().padStart(2, 0), s: date.getSeconds().toString().padStart(2, 0), ms: date.getMilliseconds().toString().padStart(3, 0) } } let formData = {} let time = {}; let year = (new Date()).getFullYear(); let month = (new Date()).getMonth(); let day = (new Date()).getDate(); function setParam(name, value) { localStorage.setItem(name, value); } let attacks = document.getElementById('commands_incomings').getElementsByClassName('command-row no_ignored_command'); let x; for(var i = 0; i < attacks.length; i++){ x = attacks[i].insertCell(1); x.setAttribute('style','width:5px'); x.innerHTML= '<span><button id="atk'+i+'" name="sendSnipe"><img class="quickbar_image"' +'data-src="https://dspl.innogamescdn.com/asset/28fc2c0/graphic//buildings/barracks.png" alt=""'+ 'src="https://dspl.innogamescdn.com/asset/28fc2c0/graphic//buildings/barracks.png"></button></span>'; k = 'atk'+i; document.getElementById(k).addEventListener('click', command); } $('button[name=sendSnipe]').click(function(e){ e.preventDefault(); }); function command(ind){ var command_url, time_aux = [], id; $('#serverTime').click(); console.log(ind); id = '#'+ind.path[1].id; if(id == '#') id = '#' + ind.path[0].id; if(id == '#') id = '#' + ind.path[2].id; command_url = $($(id).parent().parent().parent()).find('td:eq(0) .quickedit-content a:eq(0)').attr('href'); console.log(id); console.log(command_url); console.log($(id)); console.log($(id).parent().parent().parent()); console.log($($(id).parent().parent().parent()).find('td:eq(2)')); time_aux = $($(id).parent().parent().parent()).find('td:eq(2)').text().match(/[+-]?\d+(?:\.\d+)?/g); console.log(time_aux); time.hour = parseInt(time_aux[0]); time.minute = parseInt(time_aux[1]); time.second = parseInt(time_aux[2]); time.millisecond = parseInt(time_aux[3]); console.log(time); console.log('jestem tu') $.ajax({ type: 'GET', url: command_url + "&client_time=" + Math.round(Timing.getCurrentServerTime() / 1e3), headers: { "TribalWars-Ajax": 1 }, success: function (data) { console.log('entrou aqui.'); var coord = [], villageToAttackId; coord = $(data).find('span.village_anchor:eq(0) a').text().match(/(\d\d\d)(\d\d\d)*(?!.*(\d\d\d)\|(\d\d\d))/g); villageToAttackId = parseInt($(data).find('span.village_anchor:eq(0)').data('id')); formData.x = coord[0]; formData.y = coord[1]; formData.source_village = game_data.village.id; console.log(formData); firstRequest(villageToAttackId); }, error: function(data){ console.log(data.error); } }); } function firstRequest(villageToAttackId) { $.ajax({ type: "GET", url: "/game.php?village=" + formData.source_village + "&screen=place&ajax=command&target=" + villageToAttackId + "&client_time=" + Math.round(Timing.getCurrentServerTime() / 1e3), data: {}, dataType: "json", headers: { "TribalWars-Ajax": 1 }, success: function (data) { if (!data.error) { data = $(data.response.dialog); formData.spear = $('#unit_input_spear', data).data('all-count'); formData.sword = $('#unit_input_sword', data).data('all-count'); formData.axe = $('#unit_input_axe', data).data('all-count'); formData.archer = $('#unit_input_archer', data).data('all-count'); formData.spy = $('#unit_input_spy', data).data('all-count'); formData.marcher = $('#unit_input_marcher', data).data('all-count'); formData.light = $('#unit_input_light', data).data('all-count'); formData.heavy = $('#unit_input_heavy', data).data('all-count'); formData.ram = $('#unit_input_ram', data).data('all-count'); formData.catapult = $('#unit_input_catapult', data).data('all-count'); formData.snob = $('#unit_input_snob', data).data('all-count'); formData.attack = 'l'; console.dir(formData); secondRequest(); } }, error: function (data) { console.log(data.error); } }); } function secondRequest() { $.ajax({ type: "POST", url: "/game.php?village=" + formData.source_village + "&screen=place&ajax=confirm&h=" + csrf_token + "&client_time=" + Math.round(Timing.getCurrentServerTime() / 1e3), data: formData, dataType: "json", headers: { "TribalWars-Ajax": 1 }, success: function (data) { console.log(data); if (!data.error) { console.log('dupaasf'); var date, s, m, ms, y, sn, duration, data_aux; data_aux = $(data.response.dialog); console.log(data_aux); duration = $('span.relative_time', data_aux).data('duration'); // $('#attack_name', data_aux).val(time.hour.toString().padStart(2, 0) + ':' + time.minute.toString().padStart(2, 0) + ':' + time.second.toString().padStart(2, 0)); formData.data = data_aux.serialize(); let date_attack = (new Date(year, month, day, time.hour, time.minute, time.second)); let date_attack_time = date_attack.getTime() setInterval(function () { date = new Date(Timing.getCurrentServerTime()), s = date.getSeconds(), m = date.getMinutes(), y, sn; x = (s + (m * 60)); sn = (time.minute * 60 + time.second) - x; if (!(sn % 2)) { sn = sn - 6; setInterval(function () { date = new Date(Timing.getCurrentServerTime()), ms = date.getMilliseconds(); y = (time.minute * 60 + time.second) - sn; x = (s + (m * 60)); if (x == y && ms > (time.millisecond + 20) && ms <= (time.millisecond + 70)) { let nametime = new Date(date.getTime() + Math.round((date_attack_time - (new Date).getTime()) / 2)); console.log(nametime); $('#attack_name', data_aux).val(getDate(nametime).h + ':' + getDate(nametime).m + ':' + getDate(nametime).s); formData.data = data_aux.serialize(); thirdRequest(s, m, duration, sn, date); } }, 1); } }, 1000); } }, error: function (data) { console.log(data.error); console.log('dupa'); } }); } function thirdRequest(s, m, duration, sn, date) { setTimeout(function () { console.log('jestem') console.log(s, m, duration, sn, date) $.ajax({ url: "/game.php?village=" + formData.source_village + "&screen=place&ajaxaction=popup_command&h=" + csrf_token + "&client_time=" + Math.round(Timing.getCurrentServerTime() / 1e3), data: formData.data, type: "POST", dataType: "json", headers: { "TribalWars-Ajax": 1 }, success: function () { setParam('id', time.hour + ':' + time.minute + ':' + time.second); setParam('envio', s + (m * 60)); setParam('data', Date.parse(date)); setParam('try', sn); setParam('duration', duration); location.reload(); }, error: function (data) { console.log(data.error); } }); }, 10); } |
||
Davex Profil |
#2 · Zasláno: 6. 7. 2020, 19:57:42
Co se má správně počítat a kde to v tom skriptu je?
|
||
Časová prodleva: 4 dny
|
|||
IIIIIIIIII Profil |
vlastně cely skript je o vypočítaní vzhledem k tomu by stačilo přidat něco co přidava lag co je napsano viz Connection time to server: 105ms to piše při každem odeslaní i všem
v kodu je to viz všade kde je &client_time=" ¨ kromě viz kde je rozptil kde je viz setInterval(function () { date = new Date(Timing.getCurrentServerTime()), ms = date.getMilliseconds(); y = (time.minute * 60 + time.second) - sn; x = (s + (m * 60)); if (x == y && ms > (time.millisecond + 20) && ms <= (time.millisecond + 70)) { let nametime = new Date(date.getTime() + Math.round((date_attack_time - (new Date).getTime()) / 2)); console.log(nametime); $('#attack_name', data_aux).val(getDate(nametime).h + ':' + getDate(nametime).m + ':' + getDate(nametime).s); formData.data = data_aux.serialize(); thirdRequest(s, m, duration, sn, date); coz je rozptil mezi utoky let attacks = document.getElementById('commands_incomings').getElementsByClassName('command-row no_ignored_command'); let x; for(var i = 0; i < attacks.length; i++){ x = attacks[i].insertCell(1); x.setAttribute('style','width:5px'); x.innerHTML= '<span><button id="atk'+i+'" name="sendSnipe"><img class="quickbar_image"' +'data-src="https://dspl.innogamescdn.com/asset/28fc2c0/graphic//buildings/barracks.png" alt=""'+ 'src="https://dspl.innogamescdn.com/asset/28fc2c0/graphic//buildings/barracks.png"></button></span>'; k = 'atk'+i; document.getElementById(k).addEventListener('click', command); v postatě by stačilo aby při posledním počitaní se mohly přidat milisekundy ktere přidam viz napřiklad 300ms aby se přidaly kdy se přejmenuje dany ukot viz function firstRequest(villageToAttackId) { |
||
Kajman Profil |
Nejsem si jistý, co chcete, ale možná stačí cyklicky volat setTimeout místo setInterval a v něm zohlednit poslední nebo typický lag. Něco jako Pravidelné spouštění JavaScript kódu
|
||
IIIIIIIIII Profil |
Kajman:
dobře mohl byste mi to vložit rovnou do skriptu abych to vyzkoušel? sem v tom tragicky :D |
||
IIIIIIIIII Profil |
#6 · Zasláno: 12. 7. 2020, 01:02:44
$('#serverTime').click(100); v postatě nepomohlo :D špatně se to vypočitava
|
||
Časová prodleva: 4 roky
|
0