-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
351 lines (286 loc) · 11 KB
/
main.js
File metadata and controls
351 lines (286 loc) · 11 KB
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
loadCode("Data.js")
.then(p => loadCode("General.js"))
.then(p => loadCode("Towns.js"))
.then(p => loadCode("Upgrading.js"))
.then(p => loadCode("Events.js"))
.then(p => loadCode("PhoenixChase.js"))
.then(p => loadCode("UI.js"))
.then(p => loadCode("Future.js"))
.then(p => loadCode("Cleave.js"))
.then(function() {
flog("Code loaded.")
game_log("Finished code loading!");
var attack_mode = true;
var move_to_engage = true;
function prepareAttack()
{
}
function performAttack()
{
//
}
function targetChoice(args)
{
let current_target = get_targeted_monster();
let targeting_me = [];
let in_range = [];
let other = [];
for (id in parent.entities) {
let current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
if (args.type && current.mtype != args.type) continue;
if (args.min_xp && current.xp < args.min_xp) continue;
if (args.max_att && current.attack > args.max_att) continue;
if (args.min_att && current.attack < args.min_att) continue;
if (args.target && current.target != args.target) continue;
if (args.no_target && current.target && current.target != character.name) continue;
if (args.exclusive_target && current.target && current.target === character.name) continue;
if (args.path_check && !can_move_to(current)) continue;
if (current == current_target) continue; // Treated specially below.
if (current.target && current.target === character.name)
targeting_me.push(current);
else if (is_in_range(current, args.skill))
in_range.push(current);
else
other.push(current);
}
// Always include current target if valid and in range.
let targets = [];
if (current_target && !current_target.rip && is_in_range(current_target))
targets.push(current_target)
// Next add anything else targeting me - it has to die!
targets = targets.concat(targeting_me);
// Add other targets in range - but only if we don't have to focus on a specific enemy.
if (!targets.find(t => t.mtype === "phoenix"))
targets = targets.concat(in_range)
// Keep only the first n.
targets = targets.slice(0, args.max_targets || 1);
// Got anything? Return it.
if (targets.length > 0)
return targets;
// Otherwise, pick the nearest monster (which is necessarily outside our range), or
// phoenix if it is in range.
for (id in parent.entities) {
let current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
if (current.mtype == "phoenix")
return [current];
}
return [getNearestMonster(args)];
}
function targetsInCleaveRange()
{
let count = 0;
for (id in parent.entities) {
let current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
//if (is_in_range(current, "cleave")) // unreliable atm
if (simple_distance(character, current) < G.skills.cleave.range)
count++;
}
return count;
}
if (false && character.name === "MKRa")
setInterval(function () {
var targeting_me = [];
for (id in parent.entities) {
var current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
if (current.target && current.target === character.name) targeting_me.push(current);
}
var targetMeStr = "(" + targeting_me.length + ")";
for (t of targeting_me)
targetMeStr += ", " + t.id;
flog("Targeting me = " + targetMeStr + "; my attack = " + character.attack + "; my mana = " + character.mp + "; last ping = " + parent.pings[parent.pings.length - 1]);
}, 20);
function monstersTargetingMe() {
var targeting_me = [];
for (id in parent.entities) {
var current = parent.entities[id];
if (current.type != "monster" || !current.visible || current.dead) continue;
if (current.target && current.target === character.name) targeting_me.push(current);
}
return targeting_me;
}
let lastMove = new Date();
// move that doesn't cause dclimit (outside of packet loss scenarios)
function safe_move(x, y)
{
if (new Date() - lastMove > 70 /*ms*/) {
move(x, y);
lastMove = new Date();
}
}
function approach(target, upTo) {
const MAX_DIST = 80;
let dx = (get_x(target) - get_x(character)) * c("move_ratio", 0.2);
let dy = (get_y(target) - get_y(character)) * c("move_ratio", 0.2);
// Only move if it's a nontrivial amount.
if ((abs(dx) > upTo) || (abs(dy) > upTo))
safe_move(get_x(character) + min(dx, MAX_DIST), get_y(character) + min(dy, MAX_DIST));
}
// Does a move towards the target, but only for up to the specified amount of time.
function move_max_ms(target, ms)
{
let fullDist = simple_distance(character, target);
let speed = character.speed;
let fullTime = fullDist / character.speed * 1000;
if (fullTime < ms)
safe_move(get_x(target), get_y(target));
else
{
let ratio = ms / fullTime;
let x = get_x(character) + ratio * (get_x(target) - get_x(character));
let y = get_y(character) + ratio * (get_y(target) - get_y(character));
safe_move(x, y);
}
}
let enable3Shot = true;
if (character.name == "MKRa")
add_bottom_button("enable3Shot_toggle", "3SHOT", function() {enable3Shot = !enable3Shot; set_button_color("enable3Shot_toggle", enable3Shot ? "#21B221" : "#B21221"); });
let enable5Shot = false;
if (character.name == "MKRa")
add_bottom_button("enable5Shot_toggle", "5SHOT", function() { enable5Shot = !enable5Shot; set_button_color("enable5Shot_toggle", enable5Shot ? "#21B221" : "#B21221"); });
setInterval(function () {
use_hp_or_mp_fixed();
loot();
if (!attack_mode || character.rip) return;
if (is_moving(character) || isTransportingFixed(character)) return;
if (in_town(character)) return;
let targets = targetChoice({ min_xp: 1, max_att: 230, min_att: 10, max_targets: c("max_targets", 1) });
if (targets.length == 0)
{
set_message("No monsters");
return;
}
let primary_target = targets[0];
if (!primary_target)
return;
// Dirty fix for soloing phoenix:
// Random straggler monsters need to be killed or they might overwhelm the regen.
let targeting_me = monstersTargetingMe();
if (targeting_me.length > 0)
primary_target = targeting_me[Math.floor(Math.random() * targeting_me.length)];
let current_target = get_targeted_monster();
if (current_target != primary_target)
change_target(primary_target);
if (couldCleave() && cleaveTargetPos && cleaveTargetCount >= 5)
{
if (simple_distance(cleaveTargetPos, character) > 1)
{
move_max_ms(cleaveTargetPos, 200);
return;
}
else if (character.mp >= G.skills.cleave.mp && /*targetsInCleaveRange()*/ cleaveTargetCount >= 5)
{
use_skill("cleave");
parent.d_text("HIT " + cleaveTargetCount, character, {y: -30, color: 0x3E00F3, size: 24});
cleaveTargetPos = null;
cleaveTargetCount = 0;
}
else if (ms_until(parent.next_skill["use_mp"]) < 1000 / character.frequency && primary_target.mtype != "phoenix")
return; // Don't attack, next mana potion is coming.
}
else if (!is_in_range(primary_target))
{
approach(primary_target, 1);
return;
}
if (can_attack(primary_target))
{
set_message("Attacking")
if (character.name == "MKRa" && enable5Shot && character.mp >= 420 && targets.length > 4)
use_skill("5shot", targets);
else if (character.name == "MKRa" && enable3Shot && character.mp >= 300 && targets.length > 2)
use_skill("3shot", targets);
//else if (character.name == "MKWa" && character.slots.mainhand.name == "bataxe" && character.mp >= 720 && targetsInCleaveRange() >= 4)
// use_skill("cleave");
else
attack(primary_target);
}
}, 1000 / 16 + 5);
// Energize
setInterval(function () {
if (character.name !== "MauranKilom")
return;
if (parent.next_skill["energize"] > new Date())
return;
let MKRa = parent.entities["MKRa"];
if (!MKRa)
return;
if (parent.distance(character, MKRa) > 310)
return;
//if (MKRa.max_mp - MKRa.mp < 300)
if (MKRa.mp > 700)
use_skill("energize", MKRa);
}, 205);
// Hunter's Mark
setInterval(function () {
if (character.name !== "MKRa")
return;
if (parent.next_skill["huntersmark"] > new Date())
return;
let target = get_targeted_monster();
if (!target)
return;
if (target.max_hp < 50000)
return;
if (parent.distance(character, target) > 310)
return;
if (character.mp > 240)
use_skill("huntersmark");
}, 1005);
let chestSightings = [];
setInterval(function() {
for (let c in parent.chests) {
chestSightings[c] = chestSightings[c] ? chestSightings[c] + 1 : 1;
if (chestSightings[c] == 10)
chest_log(c);
}
}, 1000);
function openLoggedChests(str)
{
// Chest identifiers are currently exactly 30 alphanumeric chars long.
let chestsToOpen = str.replace(/.*([A-z0-9]{30})/g, "$1").split("\n");
let chestIndex = 0;
let interval = setInterval(function(){
if (character.esize < 8)
return;
let id = chestsToOpen[chestIndex];
game_log("Opening " + id);
parent.socket.emit("open_chest", {
id: id
});
// This leaves an off-by-one error, but the "undefined" printout is actually useful.
if (chestIndex >= chestsToOpen.length)
clearInterval(interval);
chestIndex += 1;
}, 500);
}
parent.openLoggedChests = openLoggedChests;
setInterval(cleaveLogic, 200);
/*
map_key("H", "snippet", "for (let index in character.items) if (character.items[index]) { send_item('MKMe', index, 1000000); break; }");
map_key("G", "snippet", "send_gold('MKMe', 1000000);");
map_key("M", "snippet", 'use("magiport", "MKRa"); setTimeout(() => use("magiport", "MKWa"), 200); setTimeout(() => use("magiport", "MKWa"), 400);');
//Modified source code of: draw_circle
function draw_circle_on_char(radius,size,color)
{
if(!game.graphics) return;
if(!color) color=0x00F33E;
if(!size) size=0.3;
e=new PIXI.Graphics();
e.lineStyle(size, color);
e.drawCircle(0,0,radius);
parent.drawings.push(e);
character.addChild(e);
return e;
}
let eCleave = null;
setInterval(function () {
if (!eCleave) {
eCleave = draw_circle_on_char(G.skills.cleave.range);
}
}, 10);
*/
}).catch(e => game_log("Error while loading: " + e));