-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdobijara_po_ucieczce.js
43 lines (40 loc) · 1.36 KB
/
dobijara_po_ucieczce.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
let enemiesIds;
let dobijac = true;
let ucieczka = false;
window.g.delays.limit = 150;
const _parseInput = window.parseInput;
window.parseInput = (data, ...args) => {
const ret = _parseInput(data, ...args);
if (data.f) {
if (data.f.w) {
enemiesIds = Object.keys(data.f.w).filter(id => parseInt(id, 10) !== window.hero.id);
}
if (data.f.m) {
if (Object.values(data.f.m).some(message => message.includes("Walka przerwana! Użyta mikstura ucieczki!")) && data.f.move === -1 && !data.f.close) {
ucieczka = true;
execute("fight&a=quit");
}
}
if (data.f.close === 1 && dobijac && ucieczka) {
if (enemiesIds.length) {
for (const id of enemiesIds) {
if (window.g.other[id]) {
const { x, y } = window.g.other[id];
if (checkDistance(x, y)) {
execute(`fight&a=attack&id=${id}`);
}
}
}
}
}
}
return ret;
}
const checkDistance = (x, y) => Math.abs(window.hero.x - x) <= 2 && Math.abs(window.hero.y - y) <= 2;
const execute = (url) => {
window._g(url, res => {
if ((!res || res.e !== "ok" || res.w)) {
setTimeout(execute, 50, url);
}
});
}