forked from hzqst/CGAssistantJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcgaapi.js
5684 lines (4915 loc) · 133 KB
/
cgaapi.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
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
var cga = require('bindings')('node_cga');
var moment = require('moment');
var PF = require('pathfinding');
var request = require('request');
var fs = require('fs');
global.is_array_contain = function(arr, val)
{
for (var i = 0; i < arr.length; i++)
{
if (arr[i] == val)
{
return true;
}
}
return false;
}
module.exports = function(callback){
var port = null;
if(process.argv.length >= 3 && parseInt(process.argv[2]) > 0)
port = parseInt(process.argv[2]);
else if(process.env.CGA_GAME_PORT && parseInt(process.env.CGA_GAME_PORT) > 0)
port = parseInt(process.env.CGA_GAME_PORT);
if(typeof port != 'number')
throw new Error('获取游戏本地服务端口失败!');
cga.AsyncConnect(port, function(err){
if(err){
throw new Error('无法连接到本地服务端口,可能未附加到游戏或者游戏已经闪退!');
}
callback();
});
cga.TRADE_STUFFS_ITEM = 1;
cga.TRADE_STUFFS_PET = 2;
cga.TRADE_STUFFS_PETSKILL = 3;
cga.TRADE_STUFFS_GOLD = 4;
cga.TRADE_STUFFS_TRANSLATION = {
1 : '物品',
2 : '宠物',
3 : '宠物技能',
4 : '金币',
};
cga.REQUEST_TYPE_PK = 1;
cga.REQUEST_TYPE_JOINTEAM = 3;
cga.REQUEST_TYPE_EXCAHNGECARD = 4;
cga.REQUEST_TYPE_TRADE = 5;
cga.REQUEST_TYPE_KICKTEAM = 11;
cga.REQUEST_TYPE_LEAVETEAM = 12;
cga.REQUEST_TYPE_TRADE_CONFIRM = 13;
cga.REQUEST_TYPE_TRADE_REFUSE = 14;
cga.REQUEST_TYPE_REBIRTH_ON = 16;
cga.REQUEST_TYPE_REBIRTH_OFF = 17;
cga.ENABLE_FLAG_PK = 0;
cga.ENABLE_FLAG_TEAMCHAT = 1;
cga.ENABLE_FLAG_JOINTEAM = 2;
cga.ENABLE_FLAG_CARD = 3;
cga.ENABLE_FLAG_TRADE = 4;
cga.ENABLE_FLAG_FAMILY = 5;
cga.ENABLE_FLAG_SHOWPETS = 6;
cga.ENABLE_FLAG_AVATAR_PUBLIC = 100;
cga.ENABLE_FLAG_BATTLE_POSITION = 101;
cga.TRADE_STATE_CANCEL = 0;
cga.TRADE_STATE_READY = 1;
cga.TRADE_STATE_CONFIRM = 2;
cga.TRADE_STATE_SUCCEED = 3;
cga.TRADE_STATE_TRANSLATION = {
0 : '取消交易',
1 : '准备交易',
2 : '确认交易',
3 : '交易成功',
};
cga.FL_BATTLE_ACTION_ISPLAYER = 1;
cga.FL_BATTLE_ACTION_ISDOUBLE = 2;
cga.FL_BATTLE_ACTION_ISSKILLPERFORMED = 4;
cga.FL_BATTLE_ACTION_END = 8;
cga.FL_BATTLE_ACTION_BEGIN = 16;
cga.FL_SKILL_SELECT_TARGET = 0x1;
cga.FL_SKILL_SELECT_DEAD = 0x2;
cga.FL_SKILL_TO_PET = 0x4;
cga.FL_SKILL_TO_SELF = 0x8;
cga.FL_SKILL_TO_TEAMMATE = 0x10;
cga.FL_SKILL_TO_ENEMY = 0x20;
cga.FL_SKILL_SINGLE = 0x40;
cga.FL_SKILL_MULTI = 0x80;
cga.FL_SKILL_ALL = 0x100;
cga.FL_SKILL_BOOM = 0x200;
cga.FL_SKILL_FRONT_ONLY = 0x400;
cga.MOVE_GOLD_TOBANK = 1;
cga.MOVE_GOLD_FROMBANK = 2;
cga.MOVE_GOLD_DROP = 3
cga.PET_STATE_READY = 1;
cga.PET_STATE_BATTLE = 2;
cga.PET_STATE_REST = 3;
cga.PET_STATE_WALK = 16;
cga.UI_DIALOG_TRADE = 1;
cga.UI_DIALOG_BATTLE_SKILL = 2;
//延迟x毫秒
cga.delay = (millis) => new Promise((resolve, reject) => {
setTimeout(() => {
resolve();
}, millis);
});
cga.promisify = (fn, args) => new Promise((resolve, reject) => {
args.push((err, reason) => {
console.log(err);
setTimeout(() => {
if (err) reject(err);
else resolve();
}, 0);
});
fn.apply(null, args);
});
cga.moveThinkFnArray = [];
cga.moveThink = (arg)=>{
for(var i = 0; i < cga.moveThinkFnArray.length; ++i){
if(cga.moveThinkFnArray[i](arg) == false){
return false;
}
}
return true;
}
cga.isMoveThinking = false;
cga.registerMoveThink = (fn)=>{
cga.moveThinkFnArray.push(fn);
}
cga.isTeamLeaderEx = ()=>{
return (cga.isTeamLeader == true || cga.getTeamPlayers().length <= 1);
}
cga.getMapInfo = () => {
const info = cga.GetMapXY();
info.indexes = cga.GetMapIndex();
info.name = cga.GetMapName();
return info;
};
cga.getOrientation = (x, y) => {
const p = cga.GetMapXY();
const xy = Math.max(-1, Math.min(1, x - p.x)).toString() + Math.max(-1, Math.min(1, y - p.y)).toString();
switch (xy) {
case '10':
return 0;
case '11':
return 1;
case '01':
return 2;
case '-11':
return 3;
case '-10':
return 4;
case '-1-1':
return 5;
case '0-1':
return 6;
case '1-1':
return 7;
default:
}
return -1;
}
cga.getOrientationPosition = (orientation, offset)=>{
const current = cga.GetMapXY();
switch (orientation) {
case 0:
return [current.x + offset, current.y];
case 1:
return [current.x + offset, current.y + offset];
case 2:
return [current.x, current.y + offset];
case 3:
return [current.x - offset, current.y + offset];
case 4:
return [current.x - offset, current.y];
case 5:
return [current.x - offset, current.y - offset];
case 6:
return [current.x, current.y - offset];
case 7:
return [current.x + offset, current.y - offset];
default:
return new Error('无效参数');
}
}
cga.turnDir = cga.turnOrientation = (orientation, offset = 2) => {
var pos = cga.getOrientationPosition(orientation, offset);
cga.TurnTo(pos[0], pos[1]);
}
/* 异步登出回城
由于2022年1月18日的一次更新之后登出回城有可能失败,故所有脚本中的登出回城操作均推荐更改为异步操作
*/
cga.logBack = (cb)=>{
cga.waitSysMsgTimeout((err, msg)=>{
if(err){
throw new Error('异步登出无反应,可能网络不稳定或者已经掉线!');
}
if(msg == '注销回到传送点。')
{
//保存登出回城的地点到配置文件
var config = cga.loadPlayerConfig();
if(!config)
config = {};
config.settledCity = cga.GetMapName();
cga.savePlayerConfig(config, cb);
return false;
}
var regex = msg.match(/一分钟内'回到城内登入点'最多使用5次,请过(\d+)秒钟后再用!/);
if(regex && regex.length >= 2){
console.log('一分钟登出次数已达上限!等待 '+parseInt(regex[1])+' 秒后重试...');
var wait = parseInt(regex[1]) * 1000;
setTimeout(cga.logBack, wait + 1000, cb);
return false;
}
return true;
}, 5000);
cga.LogBack();
}
//转向(x,y)坐标,默认往前一格避免捡起面前的物品
cga.turnTo = (x, y)=>{
cga.turnOrientation(cga.getOrientation(x, y));
}
//判断是否在战斗状态
cga.isInBattle = function(){
return (cga.GetWorldStatus() == 10) ? true : false;
}
//判断是否在正常状态(非切图非战斗状态)
cga.isInNormalState = function(){
return (cga.GetWorldStatus() == 9 && cga.GetGameStatus() == 3) ? true : false;
}
//将字符串转义为windows下合法的文件名
cga.FileNameEscape = (str)=>{
return str.replace(/[\\/:\*\?"<>|]/g, (c)=>{return {"\\":'%5C','/':'%2F',':':'%3A','*':'%2A','?':'%3F','"':'%22','<':'%3C','>':'%3E','|':'%7C'}[c];});
}
//FileNameEscape的反向操作,反转义
cga.FileNameUnescape = (str)=>{
return str.replace(/%(5C|2F|3A|2A|3F|22|3C|3E|7C)/g, (c)=>{ return {'%5C':'\\','%2F':'/','%3A':':','%2A':'*','%3F':'?','%22':'"','%3C':'<','%3E':'>','%7C':'|'}[c];});
}
//获取制造某种物品所需要的材料信息,返回材料信息object或null
cga.getItemCraftInfo = function(filter){
var result = null;
cga.GetSkillsInfo().forEach((sk)=>{
if(sk.type == 1)
{
var craftInfo = cga.GetCraftsInfo(sk.index).find((craft)=>{
if(typeof filter == 'string')
{
if(filter.charAt(0) == '#')
return craft.itemid == parseInt(filter.substring(1));
else
return craft.name == filter;
}
else if(typeof filter == 'number')
{
return craft.itemid == filter;
}
else if(typeof filter == 'function')
{
return filter(craft);
}
return false;
});
if(craftInfo != undefined){
result = {craft : craftInfo, skill : sk};
return false;
}
}
});
return result;
}
/*鉴定、装饰物品,参数:
cga.manipulateItemEx({
itempos : 操作的物品位置,
immediate : 是否立即完成(高速鉴定),
}, cb回调)
*/
cga.manipulateItemEx = function(options, cb){
var skill = cga.findPlayerSkill(options.skill);
if(!skill){
cb(new Error('你没有'+skillname+'的技能'));
return;
}
cga.SetImmediateDoneWork(options.immediate ? true : false);
cga.StartWork(skill.index, 0);
if(!cga.AssessItem(skill.index, options.itempos)){
cb(new Error('无法操作该物品'));
return;
}
var beginTime = (new Date()).getTime();
var handler = (err, results)=>{
if(results){
cb(null, results);
return;
}
var craftStatus = cga.GetCraftStatus();
var curTime = (new Date()).getTime();
if(err){
if(craftStatus == 0 || craftStatus == 2){
cga.manipulateItemEx(options, cb);
return;
}
//强制重试
var isImmediate = cga.GetImmediateDoneWorkState();
if(isImmediate != 2 && curTime > beginTime + 1000 * 120)
{
cga.manipulateItemEx(options, cb);
return;
}
else if(isImmediate == 2 && curTime > beginTime + 1000 * 5)
{
cga.manipulateItemEx(options, cb);
return;
}
cga.AsyncWaitWorkingResult(handler, 1000);
}
}
cga.AsyncWaitWorkingResult(handler, 1000);
return;
}
//制造物品,参数:物品名,添加的宝石的名字(或物品位置)
//该API已经弃用,请用cga.craftItemEx
cga.craftNamedItem = function(craftItemName, extraItemName){
throw new Error('该API已经弃用,请用cga.craftItemEx')
}
/*制造物品,参数:
cga.craftItemEx({
craftitem : 制造的物品名,
extraitem(可选) : 添加宝石
immediate : 是否立即完成(高速制造),
}, cb回调)
*/
cga.craftItemEx = function(options, cb){
var err = null;
var info = cga.getItemCraftInfo(options.craftitem);
if(info === null)
err = new Error('你没有制造 '+options.craftitem+' 的技能');
if(err){
cb(err);
return;
}
var inventory = cga.getInventoryItems();
var itemArray = [];
info.craft.materials.forEach((mat)=>{
var findRequired = inventory.find((inv)=>{
return (inv.itemid == mat.itemid && inv.count >= mat.count);
});
if(findRequired != undefined){
itemArray.push(findRequired.pos);
} else {
err = new Error('制造' +options.craftitem+'所需物品' +mat.name+'不足!');
return false;
}
});
if(err){
cb(err);
return;
}
if(typeof options.extraitem == 'string'){
var findRequired = inventory.find((inv)=>{
return (inv.name == options.extraitem);
});
if(findRequired != undefined){
itemArray[5] = findRequired.pos;
} else {
err = new Error('制造' +options.extraitem+'所需宝石' +options.extraitem+'不足!');
}
}
if(err){
cb(err);
return;
}
for(var i = 0; i < 6; ++i)
{
if(typeof itemArray[i] != 'number')
itemArray[i] = -1;
}
cga.SetImmediateDoneWork(options.immediate ? true : false);
cga.StartWork(info.skill.index, info.craft.index);
cga.CraftItem(info.skill.index, info.craft.index, 0, itemArray);
var beginTime = (new Date()).getTime();
var handler = (err, results)=>{
if(results){
cb(null, results);
return;
}
var craftStatus = cga.GetCraftStatus();
var curTime = (new Date()).getTime();
if(err){
if(craftStatus == 0 || craftStatus == 2){
cga.craftItemEx(options, cb);
return;
}
//强制重试
var isImmediate = cga.GetImmediateDoneWorkState();
if(isImmediate != 2 && curTime > beginTime + 1000 * 120)
{
cga.craftItemEx(options, cb);
return;
}
else if(isImmediate == 2 && curTime > beginTime + 1000 * 5)
{
cga.craftItemEx(options, cb);
return;
}
cga.AsyncWaitWorkingResult(handler, 1000);
}
}
cga.AsyncWaitWorkingResult(handler, 1000);
}
//获取物品栏里的物品,返回数组
cga.getInventoryItems = function(){
return cga.GetItemsInfo().filter((item)=>{
return item.pos >= 8 && item.pos < 100;
});
}
//获取装备栏里的物品,返回数组
cga.getEquipItems = function(){
return cga.GetItemsInfo().filter((item)=>{
return item.pos >= 0 && item.pos < 8;
});
}
//获取装备耐久,返回数组[当前耐久,最大耐久]
cga.getEquipEndurance = (item)=>{
if(item.attr){
var regex = item.attr.match(/\$4耐久 (\d+)\/(\d+)/);
if(regex && regex.length >= 3){
return [parseInt(regex[1]), parseInt(regex[2])];
}
}
return null;
}
cga.travel = {};
cga.travel.falan = {};
cga.travel.falan.isSettled = ()=>{
var config = cga.loadPlayerConfig();
if(config)
return config.settledCity == '法兰城' ? true : false;
return false;
}
cga.travel.falan.xy2name = (x, y, mapname)=>{
if(x == 242 && y == 100 && mapname == '法兰城')
return 'E1';
if(x == 141 && y == 148 && mapname == '法兰城')
return 'S1';
if(x == 63 && y == 79 && mapname == '法兰城')
return 'W1';
if(x == 233 && y == 78 && mapname == '法兰城')
return 'E2';
if(x == 162 && y == 130 && mapname == '法兰城')
return 'S2';
if(x == 72 && y == 123 && mapname == '法兰城')
return 'W2';
if(x == 46 && y == 16 && mapname == '市场三楼 - 修理专区')
return 'M3';
if(x == 46 && y == 16 && mapname == '市场一楼 - 宠物交易区')
return 'M1';
if(x == 151 && y == 122 && mapname == '法兰城')
return 'B1';
if(x == 155 && y == 122 && mapname == '法兰城')
return 'B2';
return null;
}
cga.travel.falan.isvalid = function(stone){
switch(stone.toUpperCase()){
case 'E': return true;
case 'S': return true;
case 'W': return true;
case 'E1': return true;
case 'S1': return true;
case 'W1': return true;
case 'E2': return true;
case 'S2': return true;
case 'W2': return true;
case 'M1': return true;//市场
case 'M3': return true;
case 'B1': return true;//桥头
case 'B2': return true;
case 'C': return true;//里谢里雅堡
}
return false;
}
cga.travel.falan.toStoneInternal = function(stone, cb){
var curXY = cga.GetMapXY();
var curMap = cga.GetMapName();
const desiredMap = ['法兰城','里谢里雅堡','艾尔莎岛','市场一楼 - 宠物交易区','市场三楼 - 修理专区'];
if(curMap == '法兰城'){
if(stone == 'C'){
cga.travel.falan.toCastle(cb);
return;
}
if(stone == 'B1'){
cga.walkList([
[151, 122]
], cb);
return;
}
if(stone == 'B2'){
cga.walkList([
[155, 122]
], cb);
return;
}
var curStone = cga.travel.falan.xy2name(curXY.x, curXY.y, curMap);
if(curStone) {
var turn = false;
if(stone == 'M1' || stone == 'M3') {
if(curStone == stone){
cb(null);
return;
}
turn = true;
}
else if(stone.length >= 2 && curStone.charAt(1) == stone.charAt(1)) {
if(curStone.charAt(0) == 'S' && stone.charAt(0) == 'B'){
cga.walkList([
stone == 'B1' ? [151, 122] : [155, 122]
], cb);
return;
}
if(curStone == stone){
cb(null);
return;
}
turn = true;
} else if(stone.length < 2){
if(curStone.charAt(0) == stone.charAt(0)){
cb(null);
return;
}
turn = true;
}
if(turn){
switch(curStone){
case 'E2':cga.turnDir(6);break;
case 'S2':cga.turnDir(0);break;
case 'W2':cga.turnDir(0);break;
case 'E1':cga.turnDir(0);break;
case 'S1':cga.turnDir(6);break;
case 'W1':cga.turnDir(6);break;
}
cga.AsyncWaitMovement({map:desiredMap, delay:1000, timeout:5000}, (err, reason)=>{
if(err){
cb(err, reason);
return;
}
cga.travel.falan.toStoneInternal(stone, cb);
});
return;
}
}
}
if(curMap.indexOf('市场') >= 0 && curXY.x == 46 && curXY.y == 16){
if(stone == 'M1' && curMap == '市场一楼 - 宠物交易区'){
cb(null);
return;
}
if(stone == 'M3' && curMap == '市场三楼 - 修理专区'){
cb(null);
return;
}
cga.turnDir(6);
cga.AsyncWaitMovement({map:desiredMap, delay:1000, timeout:5000}, (err, reason)=>{
if(err){
cb(err, reason);
return;
}
cga.travel.falan.toStoneInternal(stone, cb);
});
return;
}
if(curMap == '艾尔莎岛'){
cga.walkList([
[140, 105],
], ()=>{
cga.turnDir(7);
cga.AsyncWaitNPCDialog(()=>{
cga.ClickNPCDialog(4, -1);
cga.AsyncWaitMovement({map:desiredMap, delay:1000, timeout:5000}, (err, reason)=>{
if(err){
cb(err, reason);
return;
}
cga.travel.falan.toStoneInternal(stone, cb);
});
});
})
return;
}
if(curMap == '里谢里雅堡'){
if(stone == 'C'){
cb(null);
return;
}
var walks = null;
const walkOutOfCastle_1 = [
[41, 98, '法兰城'],
[141, 148]
];
const walkOutOfCastle_2 = [
[40, 98, '法兰城'],
[162, 130]
];
const walkOutOfCastle_3 = [
[41, 98, '法兰城'],
];
if(stone == 'M1')
walks = walkOutOfCastle_2;
else if(stone == 'M3')
walks = walkOutOfCastle_1;
else if(stone.length >= 2 && stone.charAt(0) == 'B')
walks = walkOutOfCastle_3;
else if(stone.length == 1)
walks = walkOutOfCastle_2;
else if(stone.length >= 2 && stone.charAt(1) == '1')
walks = walkOutOfCastle_1;
else
walks = walkOutOfCastle_2;
cga.walkList(walks, (err, reason)=>{
if(err){
cb(err, reason);
return;
}
cga.travel.falan.toStoneInternal(stone, cb);
});
return;
}
cga.logBack(()=>{
cga.AsyncWaitMovement({map:desiredMap, delay:1000, timeout:5000}, (err, reason)=>{
if(err){
cb(err, reason);
return;
}
cga.travel.falan.toStoneInternal(stone, cb);
});
});
}
//参数1:传送石名称,有效参数:E1 S1 W1 E2 S2 W2 M1(道具-市场1楼) M3(道具-市场3楼)
//参数2:回调函数function(result), result 为true或false
cga.travel.falan.toStone = function(stone, cb){
if(!cga.travel.falan.isvalid(stone)){
cb(new Error('无效的目的地名称'));
return;
}
cga.travel.falan.toStoneInternal(stone, cb, true);
}
//前往到法兰城东医院
//参数1:回调函数function(result), result 为true或false
cga.travel.falan.toEastHospital = (cb)=>{
cga.travel.falan.toStone('E', ()=>{
cga.walkList([
[221, 83, '医院']
], cb);
});
}
//前往到法兰城西医院
//参数1:回调函数function(result), result 为true或false
cga.travel.falan.toWestHospital = (cb)=>{
cga.travel.falan.toStone('W', (r)=>{
cga.walkList([
[82, 83, '医院'],
], cb);
});
}
//前往到法兰城银行
cga.travel.falan.toBank = (cb)=>{
if(cga.GetMapIndex().index3 == 1121){
cb(null);
return;
}
cga.travel.falan.toStone('E', (r)=>{
cga.walkList([
[238, 111, '银行'],
], cb);
});
}
//从法兰城到里谢里雅堡,启动地点:登出到法兰城即可
cga.travel.falan.toCastle = (cb)=>{
if(cga.GetMapName() == '里谢里雅堡'){
cb(null);
return;
}
if(cga.GetMapName() == '法兰城'){
var curXY = cga.GetMapXY();
var westPath = cga.calculatePath(curXY.x, curXY.y, 141, 88, '里谢里雅堡', null, null, []);
westPath = PF.Util.expandPath(westPath);
var southPath = cga.calculatePath(curXY.x, curXY.y, 153, 100, '里谢里雅堡', null, null, []);
southPath = PF.Util.expandPath(southPath);
var eastPath = cga.calculatePath(curXY.x, curXY.y, 165, 88, '里谢里雅堡', null, null, []);
eastPath = PF.Util.expandPath(eastPath);
var northPath = cga.calculatePath(curXY.x, curXY.y, 153, 70, '里谢里雅堡', null, null, []);
northPath = PF.Util.expandPath(northPath);
var path = westPath;
var target = [141, 88, '里谢里雅堡'];
if(path.length > southPath.length)
{
path = southPath;
target = [153, 100, '里谢里雅堡'];
}
if(path.length > eastPath.length)
{
path = eastPath;
target = [165, 88, '里谢里雅堡'];
}
if(path.length > northPath.length)
{
path = northPath;
target = [153, 70, '里谢里雅堡'];
}
cga.walkList([target], cb);
} else {
cga.travel.falan.toStone('S', ()=>{
cga.travel.falan.toCastle(cb);
});
}
}
cga.travel.falan.toCastleHospital = function(cb){
if(cga.GetMapName() == '里谢里雅堡'){
var pos = cga.GetMapXY();
if(pos.x == 34 && pos.y == 89)
{
cga.TurnTo(36, 87);
cb(true);
return;
}
else
{
cga.walkList([
[34, 89]
], (r)=>{
cga.TurnTo(36, 87);
cb(true);
});
}
return;
}
cga.travel.falan.toStone('C', (r)=>{
cga.walkList([
[34, 89]
], (r)=>{
cga.TurnTo(36, 87);
cb(true);
});
});
}
//前往里堡打卡处并打卡
cga.travel.falan.toCastleClock = (cb)=>{
cga.travel.falan.toStone('C', (r)=>{
cga.walkList([
[58, 83]
], (r)=>{
cga.TurnTo(58, 84);
cga.AsyncWaitNPCDialog((err, dlg)=>{
if(dlg.options == 12){
cga.ClickNPCDialog(4, -1);
cga.AsyncWaitNPCDialog(()=>{
cb(null);
});
} else {
cb(new Error('没有卡时,无法打卡'));
}
});
});
});
}
cga.travel.camp = {};
cga.travel.camp.getRegion = (mapname, mapXY)=>{
if(mapname == '肯吉罗岛')
{
if(mapXY.x <= 316 && mapXY.y >= 325)
{
return '矮人城镇域';
}
if(mapXY.x >= 355 && mapXY.x <= 516 && mapXY.y <= 181)
{
return '沼泽洞穴出口域';
}
if(mapXY.x < 355 && mapXY.y <= 212)
{
return '沼泽洞穴出口域';
}
return '圣骑士营地域';
}
return null;
}
//前往圣骑士营地,noWarp为true时只进到曙光骑士团营地
cga.travel.falan.toCamp = (cb, noWarp)=>{
var warp = ()=>{
var teamplayers = cga.getTeamPlayers();
var isTeamLeader = (teamplayers.length > 0 && teamplayers[0].is_me) == true ? true : false;
if(isTeamLeader){
setTimeout(()=>{
cga.DoRequest(cga.REQUEST_TYPE_LEAVETEAM);
setTimeout(warp, 1500);
}, 1500);
return;
}
cga.TurnTo(7, 21);
cga.AsyncWaitMovement({map:'圣骑士营地', delay:1000, timeout:5000}, cb);
}
var castle_2_camp = ()=>{
var shouldWarp = (cga.getItemCount('承认之戒', true) > 0 && noWarp !== true) ? true : false;
var list = shouldWarp ? [
[55,47, '辛希亚探索指挥部'],
[7,4, '辛希亚探索指挥部', 91, 6],
[95, 9, 27101],
[8, 21],
] : [
];
if(cga.GetMapName() == '里谢里雅堡'){
list.unshift([513, 282, '曙光骑士团营地']);
list.unshift([153, 241, '芙蕾雅']);
list.unshift([41, 98, '法兰城']);
} else if(cga.GetMapName() == '法兰城'){
list.unshift([513, 282, '曙光骑士团营地']);
list.unshift([153, 241, '芙蕾雅']);
} else if(cga.GetMapName() == '芙蕾雅'){
list.unshift([513, 282, '曙光骑士团营地']);
}
cga.walkList(list, (shouldWarp) ? warp : cb);
}
var mapname = cga.GetMapName();
if(mapname == '圣骑士营地'){
cb(null);
return;
}
var mapindex = cga.GetMapIndex().index3;
if(mapindex == 44692){
cga.walkList([
[0, 20, '圣骑士营地'],
], cb);
return;
}
if(mapindex == 44693){
cga.walkList([
[30, 37, '圣骑士营地'],
], cb);
return;
}
if(mapindex == 44698){
cga.walkList([
[3, 23, '圣骑士营地'],
], cb);
return;
}
if(mapindex == 44699){
cga.walkList([
[0, 14, '圣骑士营地'],
], cb);
return;
}
if(mapname == '辛希亚探索指挥部' && cga.GetMapIndex().index3 == 27101){
cga.walkList([[8, 21]], warp);
return;
}
if(mapname == '法兰城' || mapname == '里谢里雅堡' || mapname == '芙蕾雅' || mapname == '曙光骑士团营地'){
castle_2_camp(null);
}else{
cga.travel.falan.toStone('C', castle_2_camp);
}
}
//前往流行商店
cga.travel.falan.toFashionStore = cga.travel.falan.toFabricStore = (cb)=>{
if(cga.GetMapName()=='流行商店'){
cb(null);
return;
}
if(cga.GetMapName() == '法兰城'){
cga.travel.falan.toStone('S1', ()=>{
cga.walkList([