-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathindex.js
801 lines (750 loc) · 23.1 KB
/
index.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
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
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
const ACTION_DELAY_THROW_ROD = [6023, 6798], // [Min, Max] in ms, 1000 ms = 1 sec
ACTION_DELAY_FISH_START = [1345, 2656], // [Min, Max] - the pressing of F button to reel and start the minigame
ACTION_DELAY_FISH_CATCH = [5564, 15453], // [Min, Max] - time to win the fishing minigame and get a fish as prize
DELAY_BASED_ON_FISH_TIER= true; // tier 4 would get caught 4 sec longer, BAF (tier 11) would get caught 11 sec longer etc
const path = require('path'),
fs = require('fs');
const BAIT_RECIPES = [
{name: "Bait II", itemId: 206001, recipeId: 204100, wormId: 206006},
{name: "Bait III", itemId: 206002, recipeId: 204101, wormId: 206007},
{name: "Bait IV", itemId: 206003, recipeId: 204102, wormId: 206008},
{name: "Bait V", itemId: 206004, recipeId: 204103, wormId: 206009}
];
module.exports = function LetMeFish(mod) {
const command = mod.command,
hasNego = mod.manager.isLoaded('auto-nego'),
notifier = mod.manager.isLoaded('notifier') ? ( mod.require ? mod.require.notifier : require('tera-notifier')(mod) ) : false,
dismantle_contract_type = (mod.majorPatchVersion >= 85 ? 90 : 89);
let enabled = false,
scanning = false,
too_much_fishes = false,
triedDismantling = false,
myGameId = 0n,
statFished = 0,
statFishedTiers = {},
hooks = [],
dismantleFish = true,
dismantleFishGold = false,
thefishes = [],
curTier = 0,
rodId = 0,
baitId = 0,
craftId = 0,
leftArea = 0,
putinfishes = 0,
awaiting_dismantling = 0,
playerLoc = null,
vContractId = null,
invenItems = [],
statStarted = null,
gSettings = {},
settingsFileName,
pendingDeals = [],
negoWaiting = false;
function notificationAFK(msg, timeout)
{
command.message(msg);
console.log(msg);
if(notifier !== false)
{
notifier.notifyafk({
title: 'Fishing',
message: msg,
wait: false,
sound: 'Notification.IM',
},timeout);
}
}
function saveSettings(obj)
{
if (Object.keys(obj).length)
{
try
{
fs.writeFileSync(path.join(__dirname, settingsFileName), JSON.stringify(obj, null, "\t"));
}
catch (err)
{
command.message("Error saving settings " + err);
return false;
}
}
}
function loadSettings()
{
try
{
return JSON.parse(fs.readFileSync(path.join(__dirname, settingsFileName), "utf8"));
}
catch (err)
{
//console.log("Error loading settings " + err);
return {};
}
}
if(!fs.existsSync(path.join(__dirname, './saves')))
{
fs.mkdirSync(path.join(__dirname, './saves'));
}
command.add(['fish', '!fish'], {
$none() {
enabled = !enabled;
command.message(`Let me Fish is now: ${enabled ? "enabled" : "disabled"}.`);
if(enabled)
{
start();
scanning = true;
let stepN = 1;
if(!craftId)
{
command.message(stepN + ") Click craft on a bait recipe you want to auto-craft");
stepN++;
}
command.message(stepN + ") Throw your rod - and it will auto-start");
}
else
{
Stop();
}
},
$default() {
command.message('Error (typo?) in command! see README for the list of valid commands')
},
dismantle() {
dismantleFish = !dismantleFish;
command.message(`Common Fish dismantling is now: ${dismantleFish ? "enabled" : "disabled"}.`);
},
gold() {
dismantleFishGold = !dismantleFishGold;
command.message(`Gold Fish dismantling is now: ${dismantleFishGold ? "enabled" : "disabled"}.`);
},
reset() {
dismantleFish = true;
dismantleFishGold = false;
craftId = 0;
baitId = 0;
command.message("Craft recipe reseted");
command.message("Bait type for reuse reseted");
command.message("Types of fishes to auto-dismantle reseted");
},
list() {
command.message("Recipe for auto-craft: " + (craftId ? craftId : "none"));
command.message("Bait for reusing after craft: " + (baitId ? baitId : "none"));
command.message("Fish auto-dismantling for common fish: " + dismantleFish + ", for goldfish: " + dismantleFishGold);
},
save() {
command.message("Settings saved and would be carried over to next session on this character");
gSettings.dismantleFish = dismantleFish;
gSettings.dismantleFishGold = dismantleFishGold;
gSettings.craftId = craftId;
saveSettings(gSettings);
},
load() {
command.message("reLoaded settings file");
gSettings = loadSettings();
dismantleFish = gSettings.dismantleFish;
dismantleFishGold = gSettings.dismantleFishGold;
craftId = gSettings.craftId;
let found = BAIT_RECIPES.find(obj => obj.recipeId === craftId);
if(found)
{
baitId = found.itemId;
}
else
{
command.message("Your config file is corrupted, bait recipe id is wrong");
}
}
});
function addZero(i)
{
if (i < 10) {
i = "0" + i;
}
return i;
}
function rng([min, max])
{
return min + Math.floor(Math.random() * (max - min + 1));
}
function Stop()
{
enabled = false
vContractId = null;
too_much_fishes = false;
triedDismantling = false;
putinfishes = 0;
unload();
mod.clearAllTimeouts();
if(!scanning)
{
let d = new Date();
let t = d.getTime();
let timeElapsedMSec = t-statStarted;
d = new Date(1970, 0, 1); // Epoch
d.setMilliseconds(timeElapsedMSec);
let h = addZero(d.getHours());
let m = addZero(d.getMinutes());
let s = addZero(d.getSeconds());
command.message('Fished out: ' + statFished + ' fishes. Time elapsed: ' + (h + ":" + m + ":" + s) + ". Per fish: " + Math.round((timeElapsedMSec / statFished) / 1000) + " sec");
command.message('Fishes: ');
for(let i in statFishedTiers)
{
command.message('Tier ' + i + ': ' + statFishedTiers[i]);
}
statFished = 0;
statFishedTiers = {};
}
else
{
command.message('You decided not to fish?');
}
}
function reel_the_fish()
{
mod.toServer("C_START_FISHING_MINIGAME", mod.majorPatchVersion>=88?2:1, {counter:1, unk:15,});
}
function catch_the_fish()
{
statFished++;
mod.toServer("C_END_FISHING_MINIGAME", mod.majorPatchVersion>=88?2:1, {counter:1, unk:24, success:true});
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_THROW_ROD)+500);
}
function check_if_fishing()
{
command.message("Why are we not fishing?... Maybe no bait used?");
console.log("Why are we not fishing?... Maybe no bait used?");
mod.setTimeout(use_bait_item, 500);
}
function throw_the_rod()
{
if(pendingDeals.length)
{
command.message("Lets address suggested deals and give it some time...");
//console.log("nego start wait");
for(let i = 0; i < pendingDeals.length; i++)
{
mod.toClient('S_TRADE_BROKER_DEAL_SUGGESTED', 1, pendingDeals[i]);
pendingDeals.splice(i--, 1);
}
negoWaiting = true;
mod.setTimeout(throw_the_rod, (rng(ACTION_DELAY_THROW_ROD)*6));
}
else if(baitId && !invenItems.filter((item) => item.id === baitId).length)
{
command.message("No bait found in inventory, lets craft some!");
mod.setTimeout(craft_bait_start, rng(ACTION_DELAY_FISH_START)/4);
}
else if(rodId)
{
negoWaiting = false;
mod.toServer('C_USE_ITEM', 3, {
gameId: myGameId,
id: rodId,
dbid: 0n, // dbid is sent only when used from inventory, but not from quickslot
target: 0n,
amount: 1,
dest: 0,
loc: playerLoc.loc,
w: playerLoc.w,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: true
});
mod.clearAllTimeouts();
mod.setTimeout(check_if_fishing, rng(ACTION_DELAY_FISH_START)+180000); // 180 sec cuz after dismantling it might take 2+ minutes for a fish to bite
}
else
{
notificationAFK("You didn't use your rod item when you was told to, did you? Now let-me-fish can't rethrow it for you...");
Stop();
}
}
function use_bait_item()
{
if(baitId)
{
triedDismantling = false;
mod.toServer('C_USE_ITEM', 3, {
gameId: myGameId,
id: baitId,
dbid: 0n, // dbid is sent only when used from inventory, but not from quickslot
target: 0n,
amount: 1,
dest: 0,
loc: playerLoc.loc,
w: playerLoc.w,
unk1: 0,
unk2: 0,
unk3: 0,
unk4: true
});
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_FISH_START));
}
else
{
notificationAFK("How can you fish without a bait?... hmmm...");
Stop();
}
}
function cleanup_by_dismantle()
{
if(enabled)
{
if(dismantleFish || dismantleFishGold)
{
thefishes.length = 0;
if(dismantleFish)
{
thefishes = invenItems.filter((item) => item.id >= 206400 && item.id <= 206456);
}
if(dismantleFishGold)
{
thefishes = thefishes.concat(invenItems.filter((item) => item.id >= 206500 && item.id <= 206514));
}
if(thefishes.length > 20)
{
command.message("Found total fishes: " + thefishes.length);
awaiting_dismantling = thefishes.length;
too_much_fishes = true;
while(thefishes.length > 20)
{
thefishes.pop();
}
}
else
{
too_much_fishes = false;
}
if(thefishes.length)
{
command.message("Gonna dismantle this much fishes now: " + thefishes.length);
if(!vContractId)
{
mod.toServer('C_REQUEST_CONTRACT', 1, {type: dismantle_contract_type});
}
mod.setTimeout(dismantle_put_in_one_fish, (rng(ACTION_DELAY_FISH_START)+15000)); // timeout
}
else if(awaiting_dismantling <= 0)
{
notificationAFK("No fishes-to-dismantle found in your inventory, can't free up space, stopping");
Stop();
}
else // what the fuck is this shit
{
command.message("There is still " + awaiting_dismantling + " fishes awaiting dismantling but we couldn't find them in the inventory, lets ignore them for now and continue fishing");
console.log("There is still " + awaiting_dismantling + " fishes awaiting dismantling but we couldn't find them in the inventory, lets ignore them for now and continue fishing");
console.log("Please send inventory snapshot below to issues for further investigation (don't forget to hide your gameID at top there)");
console.log("inventory: (reported empty of fish)");
console.log(invenItems);
console.log("fish array (reported empty): ");
console.log(thefishes);
awaiting_dismantling = 0;
mod.setTimeout(dismantle_start2, rng(ACTION_DELAY_FISH_START)); // cancel contract & throw the ro
}
}
else
{
notificationAFK("You disabled auto-dismantle, didn't you? Now let-me-fish can't free up inventory space for you... Stopping");
Stop();
}
}
}
function dismantle_put_in_one_fish()
{
if(vContractId)
{
const thefish = thefishes.pop();
if(thefish)
{
command.message("Fish goes into dismantler: id " + thefish.id + ", " + thefish.dbid);
putinfishes++;
mod.toServer('C_RQ_ADD_ITEM_TO_DECOMPOSITION_CONTRACT', 1, {
contractId: vContractId,
dbid: thefish.dbid,
id: thefish.id,
count: 1
});
}
if(thefishes.length)
{
mod.setTimeout(dismantle_put_in_one_fish, (rng(ACTION_DELAY_FISH_START)/4));
}
else
{
mod.setTimeout(dismantle_start0, (rng(ACTION_DELAY_FISH_START)/2));
}
}
else
{
command.message("Hmmm... we didn't get a contract for dismantlying for some reason (lag?)... lets try again");
mod.setTimeout(cleanup_by_dismantle, (rng(ACTION_DELAY_FISH_START)+1500));
}
}
function dismantle_start0()
{
mod.toServer('C_RQ_START_SOCIAL_ON_PROGRESS_DECOMPOSITION', 1, { contract: vContractId });
mod.setTimeout(dismantle_start, 1925);
}
function dismantle_start()
{
awaiting_dismantling =- putinfishes;
putinfishes = 0;
mod.toServer('C_RQ_COMMIT_DECOMPOSITION_CONTRACT', 1, {contract: vContractId});
if(too_much_fishes)
{
mod.setTimeout(cleanup_by_dismantle, rng(ACTION_DELAY_FISH_START)+5500); // timeout backup function
}
else
{
mod.setTimeout(dismantle_start2, rng(ACTION_DELAY_FISH_START));
}
}
function dismantle_start2()
{
if(vContractId)
{
mod.toServer('C_CANCEL_CONTRACT', 1, {
type: dismantle_contract_type,
id: vContractId
});
vContractId = null;
}
if(enabled)
{
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_THROW_ROD)+1000); // lets resume fishing
}
}
function craft_bait_start(chain)
{
if(craftId)
{
let filets = invenItems.find((item) => item.id === 204052);
let needed = (chain ? 2 : 1) * (15 + ((craftId - 204100) * 5)); // inven gets updated AFTER you send another C_START_PRODUCE
if(filets && filets.amount >= needed ) // need one more to trigger "can't craft more bait"
{
mod.toServer('C_START_PRODUCE', 1, {recipe:craftId, unk: 0});
baitId = BAIT_RECIPES.find(obj => obj.recipeId === craftId).itemId;
}
else if(!triedDismantling)
{
triedDismantling = true;
mod.setTimeout(cleanup_by_dismantle, rng(ACTION_DELAY_THROW_ROD));
command.message("You don't have enough fish parts to craft a bait... dismantling fishes to get some");
}
else if(chain || invenItems.filter((item) => item.id === baitId).length) // managed to craft few
{
command.message("Crafted few bait items, then ran out of fish parts, but lets fish again anyway with what we have now!");
mod.setTimeout(use_bait_item, rng(ACTION_DELAY_FISH_START));
}
else
{
notificationAFK("You don't have enough fish parts to craft a bait and no fish to dismantle for fish parts... stopping");
Stop();
}
}
else
{
notificationAFK("You didn't provide a sample craft recipe, did you? Now let-me-fish can't craft more bait for you...");
Stop();
}
}
mod.hook('C_PLAYER_LOCATION', 5, event => {
playerLoc = event;
});
mod.hook('S_LOGIN', mod.majorPatchVersion >= 86 ? 14 : 13, event => {
myGameId = event.gameId;
invenItems = [];
rodId = null;
vContractId = null;
putinfishes = 0;
settingsFileName = `./saves/${event.name}-${event.serverId}.json`;
let lSettings = loadSettings();
if(!Object.keys(lSettings).length)
{
baitId = 0;
craftId = 0;
dismantleFish = true;
dismantleFishGold = false;
}
else
{
dismantleFish = lSettings.dismantleFish || true;
dismantleFishGold = lSettings.dismantleFishGold || false;
craftId = lSettings.craftId || 0;
let found = BAIT_RECIPES.find(obj => obj.recipeId === craftId);
if(found)
{
baitId = found.itemId;
}
else
{
notificationAFK("Your config file is corrupted, bait recipe id is wrong");
}
/*notificationAFK("LOADED SETTINGS: ");
notificationAFK(dismantleFish);
notificationAFK(craftId);
notificationAFK(baitId);*/
}
});
function start()
{
if(hooks.length) return;
Hook('S_START_FISHING_MINIGAME', 1, event => {
if (!enabled || scanning) return;
//let eventgameId = BigInt(data.readUInt32LE(8)) | BigInt(data.readUInt32LE(12)) << 32n;
if(myGameId === event.gameId)
{
let fishTier = event.level; //data.readUInt8(16);
if(DELAY_BASED_ON_FISH_TIER)
{
curTier = fishTier;
}
statFishedTiers[fishTier] = statFishedTiers[fishTier] ? statFishedTiers[fishTier]+1 : 1;
command.message("Started fishing minigame, Tier " + fishTier);
mod.setTimeout(catch_the_fish, (rng(ACTION_DELAY_FISH_CATCH)+(curTier*1000)));
return false; // lets hide that minigame
}
});
Hook('S_FISHING_BITE', 1, event => {
if (!enabled) return;
//let eventgameId = BigInt(data.readUInt32LE(8)) | BigInt(data.readUInt32LE(12)) << 32n;
if(myGameId === event.gameId)
{
mod.clearAllTimeouts(); // clear check f
mod.setTimeout(reel_the_fish, rng(ACTION_DELAY_FISH_START));
leftArea = 0;
if(scanning)
{
scanning = false;
rodId = event.rodId;
let d = new Date();
statStarted = d.getTime();
command.message("Rod set to: " + rodId);
if(!craftId)
{
command.message("You didn't provide a bait recipe for auto-craft, let-me-fish will stop once it runs out of bait...");
}
if(!dismantleFish)
{
command.message("You turned OFF fish auto-dismantling for common fish, let-me-fish will stop once inventory runs out of space...");
}
command.message("Auto-fishing is started now");
}
//command.message("Fish got your bait ");
return false; // lets hide and enjoy peace of mind with no temptation to smash "F" button
}
});
Hook('S_LOAD_TOPO', 3, event => {
if(enabled)
{
Stop();
notificationAFK("You was teleported while fishing, stopping");
}
});
if(mod.majorPatchVersion >= 85)
{
var invenItemsBuffer = [];
var invenFirst = true;
Hook('S_ITEMLIST', mod.majorPatchVersion >= 87 ? 3 : 2, event => {
if(!enabled) return;
if(event.container !== 14)
{
invenItemsBuffer = event.first ? event.items : invenItemsBuffer.concat(event.items);
if(!event.more)
{
if(invenFirst)
{
invenFirst = false;
invenItems = invenItemsBuffer;
}
else
{
invenItems = invenItems.concat(invenItemsBuffer);
}
}
}
if(!event.more) {command.message("You have: " + invenItemsBuffer.length + " items in container #" + event.container + ", pocket #" + event.pocket);}
if(event.lastInBatch && !event.more)
{
invenFirst = true;
command.message("You have: " + invenItems.length + " items TOTAL in inventory");
if(too_much_fishes && putinfishes === 0)
{
mod.clearAllTimeouts();
mod.setTimeout(function() { command.message("Inventory fully updated, starting dismantling of the next batch of fish"); }, ACTION_DELAY_FISH_START[0]/3);
mod.setTimeout(cleanup_by_dismantle, rng(ACTION_DELAY_FISH_START)/3);
}
}
});
}
else
{
Hook('S_INVEN', 18, event => {
if(!enabled) return;
invenItems = event.first ? event.items : invenItems.concat(event.items);
if(too_much_fishes && putinfishes === 0 && !event.more)
{
mod.clearAllTimeouts();
mod.setTimeout(function() { command.message("Inventory fully updated, starting dismantling of the next batch of fish"); }, ACTION_DELAY_FISH_START[0]/3);
mod.setTimeout(cleanup_by_dismantle, rng(ACTION_DELAY_FISH_START)/3);
}
});
}
Hook('S_REQUEST_CONTRACT', 1, event =>{
if(!enabled || scanning || event.type != dismantle_contract_type || event.senderId !== myGameId) return;
vContractId = event.id;
command.message("Got the contract id for dismantling: " + event.id);
mod.clearAllTimeouts();
mod.setTimeout(dismantle_put_in_one_fish, (rng(ACTION_DELAY_FISH_START)/2));
});
Hook('S_CANCEL_CONTRACT', 1, event =>{
if(!enabled || scanning || event.type != dismantle_contract_type || event.id != vContractId || event.senderId !== myGameId) return;
vContractId = null;
command.message("Contract for dismantling cancelled (not by let-me-fish), retrying fishing sequence...");
mod.clearAllTimeouts();
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_THROW_ROD));
});
Hook('C_START_PRODUCE', 1, event =>{
if(!scanning) return;
craftId = event.recipe;
let found = BAIT_RECIPES.find(obj => obj.recipeId === event.recipe);
if(found)
{
baitId = found.itemId;
command.message("Now this recipe would get crafted when out of bait: " + event.recipe + ", and this bait would be activated after: " + baitId);
}
else
{
command.message("What the hell did you just craft instead of a bait?! Go craft some bait!");
}
});
Hook('S_END_PRODUCE', 1, event =>{
if(!enabled || scanning) return;
if(event.success)
{
craft_bait_start(true); // no need to wait, client doesn't (when you click "craft all")
}
});
Hook('S_TRADE_BROKER_DEAL_SUGGESTED', 1, event => {
if(enabled && !scanning && hasNego && !negoWaiting && event.offeredPrice === event.sellerPrice) // lets take a break and trade shall we?
{
for(let i = 0; i < pendingDeals.length; i++)
{
let deal = pendingDeals[i];
if(deal.playerId == event.playerId && deal.listing == event.listing) pendingDeals.splice(i--, 1);
}
pendingDeals.push(event);
command.message("Nego deal was suggested, gonna address it after current fish...")
return false;
}
});
Hook('S_SYSTEM_MESSAGE', 1, event => {
if(!enabled || scanning) return;
const msg = mod.parseSystemMessage(event.message);
//command.message(msg.id);
if(msg.id === 'SMT_CANNOT_FISHING_NON_BAIT') // out of bait
{
command.message("Out of bait, lets craft some!");
mod.clearAllTimeouts();
mod.setTimeout(craft_bait_start, rng(ACTION_DELAY_FISH_START));
}
else if(msg.id === 'SMT_ITEM_CANT_POSSESS_MORE') // craft limit
{
if(!vContractId)
{
mod.clearAllTimeouts();
let itemId = Number(msg.tokens.ItemName.substr(6));
if(itemId >= 206006 && itemId <= 206009)
{
command.message("Crafted worms to the fullest, lets fish using those now!");
baitId = itemId;
}
else
{
command.message("Crafted to the fullest, lets fish again!");
}
mod.setTimeout(use_bait_item, rng(ACTION_DELAY_FISH_START));
}
else // 10k filet // 3 error sysmsgs at once for that lol
{
notificationAFK("You have reached the 10k dismantled fish parts limit, stopping");
mod.clearAllTimeouts();
if(putinfishes)
{
too_much_fishes = false;
enabled = false;
dismantle_start0();
setTimeout(Stop, (rng(ACTION_DELAY_FISH_START)+4000));
}
else
{
Stop();
}
}
}
else if(msg.id === 'SMT_CANNOT_FISHING_FULL_INVEN') // full inven
{
command.message("Inventory full, lets dismantle fish!");
mod.clearAllTimeouts();
mod.setTimeout(cleanup_by_dismantle, rng(ACTION_DELAY_FISH_START)+1500);
}
else if(msg.id === 'SMT_CANNOT_FISHING_NON_AREA' && !negoWaiting) // server trolling us?
{
command.message("Fishing area changed (you left it?), well that happens... lets try again?");
console.log("Fishing area changed (you left it?), well that happens... Retrying...");
mod.clearAllTimeouts();
leftArea++;
if(leftArea < 7)
{
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_THROW_ROD));
}
else
{
Stop();
notificationAFK("Fishing area changed for good it seems, can't fish anymore, - choose better place next time, stopping");
}
}
else if(msg.id === 'SMT_FISHING_RESULT_CANCLE') // hmmm?
{
command.message("Fishing cancelled... lets try again?");
//notificationAFK("Fishing cancelled... due to lag? Retrying...");
mod.clearAllTimeouts();
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_FISH_START));
}
else if(msg.id === 'SMT_YOU_ARE_BUSY' && !vContractId) // anti-anit-bot
{
command.message("Evil people trying to disturb your fishing... lets try again?");
console.log("Evil people trying to disturb your fishing... Retrying...");
mod.clearAllTimeouts();
mod.setTimeout(throw_the_rod, rng(ACTION_DELAY_THROW_ROD)+3000);
}
else if(negoWaiting && !pendingDeals.length && msg.id === 'SMT_MEDIATE_SUCCESS_SELL') // all out of deals and still waiting?
{
command.message('All negotiations finished... resuming fishing shortly')
mod.clearAllTimeouts();
mod.setTimeout(throw_the_rod, (rng(ACTION_DELAY_THROW_ROD)+5500));
}
else if(msg.id === 'SMT_CANNOT_USE_ITEM_WHILE_CONTRACT') // we want to throw the rod but still trading?
{
negoWaiting = true;
command.message('Negotiations are taking long time to finish... lets wait a bit more')
mod.clearAllTimeouts();
mod.setTimeout(throw_the_rod, (rng(ACTION_DELAY_THROW_ROD)+3000));
}
});
}
function unload()
{
if(hooks.length)
{
for(let h of hooks) mod.unhook(h);
hooks = [];
}
}
function Hook()
{
hooks.push(mod.hook(...arguments));
}
}