-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcomm.lua
More file actions
1215 lines (1208 loc) · 39.3 KB
/
comm.lua
File metadata and controls
1215 lines (1208 loc) · 39.3 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
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
--[[--
by ALA
CREDIT shagu/pfQuest(MIT LICENSE) @ https://github.com/shagu
--]]--
local __addon, __private = ...;
local MT = __private.MT;
local CT = __private.CT;
local VT = __private.VT;
local DT = __private.DT;
--> upvalue
local GetTime = GetTime;
local next = next;
local tonumber = tonumber;
local tremove, wipe = table.remove, table.wipe;
local strlen, strupper, strsplit, strsub, strmatch, gsub = string.len, string.upper, string.split, string.sub, string.match, string.gsub;
local GetFactionInfoByID = GetFactionInfoByID;
local Ambiguate = Ambiguate;
local RegisterAddonMessagePrefix = RegisterAddonMessagePrefix or C_ChatInfo.RegisterAddonMessagePrefix;
local IsAddonMessagePrefixRegistered = IsAddonMessagePrefixRegistered or C_ChatInfo.IsAddonMessagePrefixRegistered;
local GetRegisteredAddonMessagePrefixes = GetRegisteredAddonMessagePrefixes or C_ChatInfo.GetRegisteredAddonMessagePrefixes;
local SendAddonMessage = SendAddonMessage or C_ChatInfo.SendAddonMessage;
local SendAddonMessageLogged = SendAddonMessageLogged or C_ChatInfo.SendAddonMessageLogged;
local IsInGroup, IsInRaid = IsInGroup, IsInRaid;
local GetNumGroupMembers = GetNumGroupMembers;
local GetRaidRosterInfo = GetRaidRosterInfo;
local UnitName = UnitName;
local UnitClassBase = UnitClassBase;
local UnitExists = UnitExists;
local UnitInBattleground = UnitInBattleground;
local UnitIsConnected = UnitIsConnected;
local ChatFrame_AddMessageEventFilter = ChatFrame_AddMessageEventFilter;
local LE_PARTY_CATEGORY_HOME = LE_PARTY_CATEGORY_HOME;
local _G = _G;
-->
local DataAgent = DT.DB;
local l10n = CT.l10n;
local EventAgent = VT.EventAgent;
local __MAIN_META = VT.MAIN_META;
-->
MT.BuildEnv("comm");
--> COMM
local ADDON_PREFIX = "CDXLT";
local ADDON_PREFIX_V1 = ADDON_PREFIX .. "1";
local ADDON_PREFIX_V2 = ADDON_PREFIX .. "2";
local ADDON_MSG_HEAD_PUSHQUEST_V2 = "Q";
local ADDON_MSG_HEAD_PUSHLINE_V2 = "L";
local ADDON_MSG_HEAD_PULL_V2 = "P";
local ADDON_MSG_HEAD_RESET_V2 = "R";
local ADDON_MSG_HEAD_ONLINE_V2 = "O";
local META = { }; -- [quest_id] = { [flag:whether_nodes_added], [completed], [num_lines], [line(1, 2, 3, ...)] = { shown, objective_type, objective_id, description, finished, is_large_pin, progress, required, }, }
local OBJ_LOOKUP = { };
local GROUP_MEMBERS = { };
local GROUP_MEMBERS_INFO = { };
VT.COMM_META = META;
VT.COMM_OBJ_LOOKUP = OBJ_LOOKUP;
VT.COMM_GROUP_MEMBERS = GROUP_MEMBERS;
VT.COMM_GROUP_MEMBERS_INFO = GROUP_MEMBERS_INFO;
local _Inited = { };
--> function predef
local CommDelUUID, CommAddUUID, CommSubUUID, CommGetUUID, CommResetUUID;
local GetVariedNodeTexture, AddCommonNodes, DelCommonNodes, AddLargeNodes, DelLargeNodes, AddVariedNodes, DelVariedNodes;
local AddSpawn, DelSpawn, AddUnit, DelUnit, AddObject, DelObject, AddRefloot, DelRefloot, AddItem, DelItem, AddEvent, DelEvent;
local AddQuester_VariedTexture, DelQuester_VariedTexture, AddQuestStart, DelQuestStart, AddQuestEnd, DelQuestEnd;
local AddLine, DelLine;
local AddExtra, DelExtra;
local MessageTicker, ScheduleMessage;
local PushReset, PushAddQuest, PushDelQuest, PushAddLine, PushFlushBuffer;
local PushResetSingle, PushAddQuestSingle, PushDelQuestSingle, PushAddLineSingle, PushFlushBufferSingle;
local PushSingle, PullSingle, BroadcastOnline;
local DisableComm, EnableComm;
local UpdateGroupMembers;
-->
local noop = function() end
local is_comm_enabled = false;
--> -- uuid:{ 1type, 2id, 3color3(run-time), 4{ [quest] = { [line] = TEXTURE, }, }, }
--> -- line: 'start', 'end', >=1:line_quest_leader, 'extra'
--> -- uuid 对应单位/对象类型,储存任务-行信息,对应META_COMMON表坐标设置一次即可
local _UUID = { };
function CommDelUUID(name)
_UUID[name] = nil;
end
function CommAddUUID(name, _T, _id, _quest, _line, _val)
local UUID = _UUID[name];
if UUID == nil then
UUID = { event = { }, item = { }, object = { }, quest = { }, unit = { }, };
_UUID[name] = UUID;
end
local uuid = UUID[_T][_id];
if uuid == nil then
uuid = { _T, _id, nil, { }, };
UUID[_T][_id] = uuid;
end
local ref = uuid[4][_quest];
if ref == nil then
ref = { [_line] = _val or 1, };
uuid[4][_quest] = ref;
else
ref[_line] = _val or 1;
end
return uuid;
end
function CommSubUUID(name, _T, _id, _quest, _line, total_del)
local UUID = _UUID[name];
if UUID ~= nil then
local uuid = UUID[_T][_id];
if uuid ~= nil then
local ref = uuid[4][_quest];
if ref ~= nil then
local val = ref[_line];
if val ~= nil then
ref[_line] = nil;
if next(ref) == nil then
uuid[4][_quest] = nil;
end
if next(uuid[4]) == nil then
if not total_del then
ref[_line] = 0;
uuid[4][_quest] = ref;
end
return uuid, true;
else
if not total_del then
ref[_line] = 0;
uuid[4][_quest] = ref;
end
return uuid, false;
end
else
if next(ref) == nil then
uuid[4][_quest] = nil;
end
if next(uuid[4]) == nil then
return uuid, true;
else
return uuid, false;
end
end
else
if next(uuid[4]) == nil then
return uuid, true;
else
return uuid, false;
end
end
end
return uuid;
end
end
function CommGetUUID(name, _T, _id)
local UUID = _UUID[name];
if UUID ~= nil then
return UUID[_T][_id];
end
end
function CommResetUUID()
wipe(_UUID);
end
MT.CommAddUUID = CommAddUUID;
MT.CommSubUUID = CommSubUUID;
MT.CommGetUUID = CommGetUUID;
if VT.__is_dev then
VT.COMM_UUID = _UUID;
end
-->
--> send data to ui
local COMMON_UUID_FLAG = { };
local LARGE_UUID_FLAG = { };
local VARIED_UUID_FLAG = { };
function GetVariedNodeTexture(texture_list)
local TEXTURE = 0;
for quest, list in next, texture_list do
for _, texture in next, list do
if texture > TEXTURE then
TEXTURE = texture;
end
end
end
return TEXTURE ~= 0 and TEXTURE or nil;
end
-- common_objective pin
function AddCommonNodes(name, _T, _id, _quest, _line, coords_table)
local uuid = CommAddUUID(name, _T, _id, _quest, _line, -9998);
if COMMON_UUID_FLAG[uuid] == nil then
if coords_table ~= nil then
MT.MapAddCommonNodes(uuid, coords_table);
end
COMMON_UUID_FLAG[uuid] = true;
end
end
function DelCommonNodes(name, _T, _id, _quest, _line, total_del)
local uuid, del = CommSubUUID(name, _T, _id, _quest, _line, total_del);
if del == false then
del = true;
for _, ref in next, uuid[4] do
for line, val in next, ref do
if val == -9998 then
del = false;
break;
end
end
end
end
if del == true then
MT.MapDelCommonNodes(uuid);
COMMON_UUID_FLAG[uuid] = nil;
end
end
-- large_objective pin
function AddLargeNodes(name, _T, _id, _quest, _line, coords_table)
local uuid = CommAddUUID(name, _T, _id, _quest, _line, -9999);
if LARGE_UUID_FLAG[uuid] == nil then
if coords_table ~= nil then
MT.MapAddLargeNodes(uuid, coords_table);
end
LARGE_UUID_FLAG[uuid] = true;
end
end
function DelLargeNodes(name, _T, _id, _quest, _line, total_del)
local uuid, del = CommSubUUID(name, _T, _id, _quest, _line, total_del);
if del == false then
del = true;
for _, ref in next, uuid[4] do
for line, val in next, ref do
if val == -9999 then
del = false;
break;
end
end
end
end
if del == true then
MT.MapDelLargeNodes(uuid);
LARGE_UUID_FLAG[uuid] = nil;
end
end
-- varied_objective pin
function AddVariedNodes(name, _T, _id, _quest, _line, coords_table, varied_texture)
local uuid = CommAddUUID(name, _T, _id, _quest, _line, varied_texture);
local TEXTURE = GetVariedNodeTexture(uuid[4]);
if uuid[5] ~= TEXTURE then
uuid[5] = TEXTURE;
MT.MapAddVariedNodes(uuid, coords_table, VARIED_UUID_FLAG[uuid]);
VARIED_UUID_FLAG[uuid] = true;
end
end
function DelVariedNodes(name, _T, _id, _quest, _line)
local uuid, del = CommSubUUID(name, _T, _id, _quest, _line, true);
if del == true then
uuid[5] = nil;
if VARIED_UUID_FLAG[uuid] ~= nil then
MT.MapDelVariedNodes(uuid);
VARIED_UUID_FLAG[uuid] = nil;
end
elseif del == false then
local TEXTURE = GetVariedNodeTexture(uuid[4]);
if uuid[5] ~= TEXTURE then
uuid[5] = TEXTURE;
if VARIED_UUID_FLAG[uuid] ~= nil then
MT.MapAddVariedNodes(uuid, nil, true);
end
end
end
end
-->
--> send quest data
function AddSpawn(name, quest, line, spawn, show_coords, showFriend)
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
local large_pin = DataAgent.large_pin:Check(quest, 'unit', unit);
AddUnit(name, quest, line, unit, show_coords, large_pin, showFriend);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
local large_pin = DataAgent.large_pin:Check(quest, 'object', object);
AddObject(name, quest, line, object, show_coords, large_pin);
end
end
if spawn.I ~= nil then
for item, num in next, spawn.I do
local large_pin = DataAgent.large_pin:Check(quest, 'item', item);
AddItem(name, quest, line, item, show_coords, large_pin);
end
end
end
function DelSpawn(name, quest, line, spawn, total_del)
if spawn.U ~= nil then
for unit, _ in next, spawn.U do
local large_pin = DataAgent.large_pin:Check(quest, 'unit', unit);
DelUnit(name, quest, line, unit, total_del, large_pin);
end
end
if spawn.O ~= nil then
for object, _ in next, spawn.O do
local large_pin = DataAgent.large_pin:Check(quest, 'object', object);
DelObject(name, quest, line, object, total_del, large_pin);
end
end
if spawn.I ~= nil then
for item, num in next, spawn.I do
local large_pin = DataAgent.large_pin:Check(quest, 'item', item);
DelItem(name, quest, line, item, total_del, large_pin);
end
end
end
function AddUnit(name, quest, line, uid, show_coords, large_pin, showFriend)
local info = DataAgent.unit[uid];
if info ~= nil then
if showFriend ~= nil then
local isFriend = nil;
if info.fac == nil then
if info.facId ~= nil then
local _, _, standing_rank, _, _, val = GetFactionInfoByID(info.facId);
if val ~= nil and val > 0 then
isFriend = true;
else -- if val <= -3000 then -- 冷淡不会招致主动攻击,敌对开始主动攻击
isFriend = false;
end
else
isFriend = false;
end
else
isFriend = VT.IsUnitFacFriend[info.fac];
end
if not showFriend ~= not isFriend then
return;
end
end
if large_pin then
AddLargeNodes(name, 'unit', uid, quest, line, nil);
else
AddCommonNodes(name, 'unit', uid, quest, line, nil);
end
local spawn = info.spawn;
if spawn ~= nil then
AddSpawn(name, quest, line, spawn, show_coords, showFriend);
end
end
end
function DelUnit(name, quest, line, uid, total_del, large_pin)
local info = DataAgent.unit[uid];
if info ~= nil then
if large_pin then
DelLargeNodes(name, 'unit', uid, quest, line, total_del);
else
DelCommonNodes(name, 'unit', uid, quest, line, total_del);
end
local spawn = info.spawn;
if spawn ~= nil then
DelSpawn(name, quest, line, spawn, total_del);
end
end
end
function AddObject(name, quest, line, oid, show_coords, large_pin)
local info = DataAgent.object[oid];
if info ~= nil then
if large_pin then
AddLargeNodes(name, 'object', oid, quest, line, nil);
else
AddCommonNodes(name, 'object', oid, quest, line, nil);
end
local spawn = info.spawn;
if spawn ~= nil then
AddSpawn(name, quest, line, spawn, show_coords);
end
end
local name = l10n.object[oid];
if name ~= nil then
OBJ_LOOKUP[name] = oid;
end
end
function DelObject(name, quest, line, oid, total_del, large_pin)
local info = DataAgent.object[oid];
if info ~= nil then
if large_pin then
DelLargeNodes(name, 'object', oid, quest, line, total_del);
else
DelCommonNodes(name, 'object', oid, quest, line, total_del);
end
local spawn = info.spawn;
if spawn ~= nil then
DelSpawn(name, quest, line, spawn, total_del);
end
end
end
function AddRefloot(name, quest, line, rid, show_coords, large_pin)
local info = DataAgent.refloot[rid];
if info ~= nil then
if info.U ~= nil then
for uid, _ in next, info.U do
AddUnit(name, quest, line, uid, show_coords, large_pin, nil);
end
end
if info.O ~= nil then
for oid, _ in next, info.O do
AddObject(name, quest, line, oid, show_coords, large_pin);
end
end
end
end
function DelRefloot(name, quest, line, rid, total_del, large_pin)
local info = DataAgent.refloot[rid];
if info ~= nil then
if info.U ~= nil then
for uid, _ in next, info.U do
DelUnit(name, quest, line, uid, total_del, large_pin);
end
end
if info.O ~= nil then
for oid, _ in next, info.O do
DelObject(name, quest, line, oid, total_del, large_pin);
end
end
end
end
function AddItem(name, quest, line, iid, show_coords, large_pin)
if DataAgent.blacklist_item[iid] ~= nil then
return;
end
local info = DataAgent.item[iid];
if info ~= nil then
if info.U ~= nil then
for uid, rate in next, info.U do
if rate >= VT.SETTING.min_rate then
AddUnit(name, quest, line, uid, show_coords, large_pin, nil);
end
end
end
if info.O ~= nil then
for oid, rate in next, info.O do
if rate >= VT.SETTING.min_rate then
AddObject(name, quest, line, oid, show_coords, large_pin);
end
end
end
if info.R ~= nil then
for rid, rate in next, info.R do
if rate >= VT.SETTING.min_rate then
AddRefloot(name, quest, line, rid, show_coords, large_pin);
end
end
end
if info.V ~= nil then
for vid, _ in next, info.V do
AddUnit(name, quest, line, vid, show_coords, large_pin, true);
end
end
if info.I ~= nil then
for iid2, _ in next, info.I do
AddItem(name, quest, line, iid2, show_coords, large_pin);
end
end
end
end
function DelItem(name, quest, line, iid, total_del, large_pin)
if DataAgent.blacklist_item[iid] ~= nil then
return;
end
local info = DataAgent.item[iid];
if info ~= nil then
if info.U ~= nil then
for uid, rate in next, info.U do
DelUnit(name, quest, line, uid, total_del, large_pin);
end
end
if info.O ~= nil then
for oid, rate in next, info.O do
DelObject(name, quest, line, oid, total_del, large_pin);
end
end
if info.R ~= nil then
for rid, _ in next, info.R do
DelRefloot(name, quest, line, rid, total_del, large_pin);
end
end
if info.V ~= nil then
for vid, _ in next, info.V do
DelUnit(name, quest, line, vid, total_del, large_pin);
end
end
if info.I ~= nil then
for iid2, _ in next, info.I do
DelItem(name, quest, line, iid2, total_del, large_pin);
end
end
end
end
function AddEvent(name, quest, line, eid, show_coords, large_pin)
local info = DataAgent.event[eid];
if info ~= nil then
MT.PreloadCoords(info);
if large_pin then
AddLargeNodes(name, 'event', eid, quest, line, nil);
else
AddCommonNodes(name, 'event', eid, quest, line, nil);
end
local spawn = info.spawn;
if spawn ~= nil then
AddSpawn(name, quest, line, spawn, false);
end
end
end
function DelEvent(name, quest, line, eid, total_del, large_pin)
local info = DataAgent.event[eid];
if info ~= nil then
if large_pin then
DelLargeNodes(name, 'event', eid, quest, line, total_del);
else
DelCommonNodes(name, 'event', eid, quest, line, total_del);
end
local spawn = info.spawn;
if spawn ~= nil then
DelSpawn(name, quest, line, spawn, total_del);
end
end
end
--
function AddQuester_VariedTexture(name, quest, info, which, TEXTURE)
if info ~= nil then
local O = info.O;
if O ~= nil then
for index = 1, #O do
local oid = O[index];
local info = DataAgent.object[oid];
if info ~= nil then
AddVariedNodes(name, 'object', oid, quest, which, nil, TEXTURE);
end
local name = l10n.object[oid];
if name ~= nil then
OBJ_LOOKUP[name] = oid;
end
end
end
local U = info.U;
if U ~= nil then
for index = 1, #U do
local uid = U[index];
local info = DataAgent.unit[uid];
if info ~= nil then
AddVariedNodes(name, 'unit', uid, quest, which, nil, TEXTURE);
end
end
end
end
end
function DelQuester_VariedTexture(name, quest, info, which)
if info ~= nil then
local O = info.O;
if O ~= nil then
for index = 1, #O do
DelVariedNodes(name, 'object', O[index], quest, which);
end
end
local U = info.U;
if U ~= nil then
for index = 1, #U do
DelVariedNodes(name, 'unit', U[index], quest, which);
end
end
end
end
function AddQuestStart(name, quest, info, TEXTURE)
AddQuester_VariedTexture(name, quest, info.start, 'start', TEXTURE or MT.GetQuestStartTexture(info));
end
function DelQuestStart(name, quest, info)
DelQuester_VariedTexture(name, quest, info.start, 'start');
end
function AddQuestEnd(name, quest, info, TEXTURE)
AddQuester_VariedTexture(name, quest, info["end"], 'end', TEXTURE);
end
function DelQuestEnd(name, quest, info)
DelQuester_VariedTexture(name, quest, info["end"], 'end');
end
-->
--> line -1 = Quest Giver -2 = Quest Completer 0 = event
function AddLine(name, quest_id, _line, _type, _id, finished)
-- if finished then
-- MT.Debug('AddLine-T_T', name, _type, _id);
-- else
-- MT.Debug('AddLine-T_F', name, _type, _id);
-- end
if _type == 'monster' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', _id);
AddUnit(name, quest_id, _line, _id, not finished, large_pin, nil);
return large_pin;
elseif _type == 'item' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'item', _id);
AddItem(name, quest_id, _line, _id, not finished, large_pin);
return large_pin;
elseif _type == 'object' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'object', _id);
AddObject(name, quest_id, _line, _id, not finished, large_pin);
return large_pin;
elseif _type == 'event' or _type == 'log' then
AddEvent(name, quest_id, _line, _id, not finished, true);
return true;
elseif _type == 'reputation' then
elseif _type == 'player' or _type == 'progressbar' then
else
MT.Debug('comm_objective_type', quest_id, finished, _type);
end
return nil;
end
function DelLine(name, quest_id, _line, _type, _id, total_del)
if _type == 'monster' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', _id);
DelUnit(name, quest_id, _line, _id, total_del, large_pin);
elseif _type == 'item' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'item', _id);
DelItem(name, quest_id, _line, _id, total_del, large_pin);
elseif _type == 'object' then
local large_pin = DataAgent.large_pin:Check(quest_id, 'object', _id);
DelObject(name, quest_id, _line, _id, total_del, large_pin);
elseif _type == 'event' or _type == 'log' then
DelEvent(name, quest_id, _line, _id, total_del, true);
elseif _type == 'reputation' then
elseif _type == 'player' or _type == 'progressbar' then
else
MT.Debug('comm_objective_type', quest_id, _type, _id);
end
end
function AddExtra(name, quest_id, extra, text, completed)
if extra.U ~= nil then
for uid, check in next, extra.U do
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', uid);
if check == completed or check == 'always' then
AddUnit(name, quest_id, 'extra', uid, true, large_pin, true);
else
DelUnit(name, quest_id, 'extra', uid, false, large_pin);
end
end
end
if extra.I ~= nil then
for iid, check in next, extra.I do
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', iid);
if check == completed or check == 'always' then
AddItem(name, quest_id, 'extra', iid, true, large_pin);
else
DelItem(name, quest_id, 'extra', iid, false, large_pin);
end
end
end
if extra.O ~= nil then
for oid, check in next, extra.O do
OBJ_LOOKUP[l10n.object[oid]] = oid;
local large_pin = DataAgent.large_pin:Check(quest_id, 'object', oid);
if check == completed or check == 'always' then
AddObject(name, quest_id, 'extra', oid, true, large_pin);
else
DelObject(name, quest_id, 'extra', oid, false, large_pin);
end
end
end
if extra.E ~= nil then
for eid, check in next, extra.E do
if check == completed or check == 'always' then
AddEvent(name, quest_id, 'extra', eid, true, true);
else
DelEvent(name, quest_id, 'extra', eid, false, true);
end
end
end
end
function DelExtra(name, quest_id, extra)
if extra.U ~= nil then
for uid, check in next, extra.U do
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', uid);
DelUnit(name, quest_id, 'extra', uid, true, large_pin);
end
end
if extra.I ~= nil then
for iid, check in next, extra.I do
local large_pin = DataAgent.large_pin:Check(quest_id, 'unit', iid);
DelItem(name, quest_id, 'extra', iid, true, large_pin);
end
end
if extra.O ~= nil then
for oid, check in next, extra.O do
local large_pin = DataAgent.large_pin:Check(quest_id, 'object', oid);
DelObject(name, quest_id, 'extra', oid, true, large_pin);
end
end
if extra.E ~= nil then
for eid, check in next, extra.E do
DelEvent(name, quest_id, 'extra', eid, true, true);
end
end
end
-->
--> net buffer
local MessageBuffer = { };
local MessageTop = 0;
local SchedulerRunning = false;
local SentTarget = { };
function MessageTicker()
local msg = tremove(MessageBuffer, 1);
MessageTop = MessageTop - 1;
if MessageBuffer[1] ~= nil then
SchedulerRunning = true;
MT.After(0.02, MessageTicker);
else
SchedulerRunning = false;
end
SendAddonMessage(msg[1], msg[2], msg[3], msg[4]);
SentTarget[strupper(Ambiguate(msg[3], 'none'))] = GetTime();
end
function ScheduleMessage(prefix, msg, channel, target)
MessageTop = MessageTop + 1;
MessageBuffer[MessageTop] = { prefix, msg, channel, target, };
if not SchedulerRunning then
SchedulerRunning = true;
MT.After(0.02, MessageTicker);
end
end
--> Message Filter
-- ERR_CHAT_PLAYER_NOT_FOUND_S
local C_String = _G.ERR_CHAT_PLAYER_NOT_FOUND_S;
local C_Pattern = gsub(C_String, "%%s", "(.+)");
local function F_Filter(self, event, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9, arg10, line, arg12, arg13, arg14, ...)
if C_String ~= _G.ERR_CHAT_PLAYER_NOT_FOUND_S then
C_String = _G.ERR_CHAT_PLAYER_NOT_FOUND_S;
C_Pattern = gsub(C_String, "%%s", "(.+)");
end
local name = strmatch(arg1, C_Pattern);
if name ~= nil then
name = strupper(Ambiguate(name, 'none'));
local t = SentTarget[name];
if t ~= nil then
if GetTime() - t < 2.0 then
return true;
else
SentTarget[name] = nil;
end
end
end
return false;
end
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", F_Filter);
-->
MT.ScheduleMessage = ScheduleMessage;
-->
--> comm
--
local _CommBuffer = { };
local _CommBufferLen = { };
--
local function PushMessage(msg)
local len = strlen(msg);
local mem = _CommBuffer["*"];
local mel = _CommBufferLen["*"];
if mem == nil then
_CommBuffer["*"] = msg;
_CommBufferLen["*"] = len;
elseif mel < 249 - len then
_CommBuffer["*"] = mem .. "\001" .. msg;
_CommBufferLen["*"] = mel + 1 + len;
else
for name, val in next, GROUP_MEMBERS do
if val then
ScheduleMessage(ADDON_PREFIX_V2, mem, "WHISPER", name);
end
end
_CommBuffer["*"] = msg;
_CommBufferLen["*"] = len;
end
end
function PushReset()
PushMessage(ADDON_MSG_HEAD_RESET_V2);
end
function PushAddQuest(_quest, _completed, title, num_lines)
PushMessage(ADDON_MSG_HEAD_PUSHQUEST_V2 .. "\001" .. _quest .. "\0011\001" .. _completed .. "\001" .. num_lines .. "\001" .. title);
end
function PushDelQuest(_quest, _completed)
PushMessage(ADDON_MSG_HEAD_PUSHQUEST_V2 .. "\001" .. _quest .. "\001-1\001" .. _completed);
end
function PushAddLine(_quest, _line, _finished, _type, _id, _text)
PushMessage(ADDON_MSG_HEAD_PUSHLINE_V2 .. "\001" .. _quest .. (_finished and "\0011\001" or "\0010\001") .. _line .. "\001" .. _type .. "\001" .. _id .. "\001" .. _text);
end
function PushFlushBuffer()
local mem = _CommBuffer["*"];
if mem ~= nil then
for name, val in next, GROUP_MEMBERS do
if val then
ScheduleMessage(ADDON_PREFIX_V2, mem, "WHISPER", name);
end
end
_CommBuffer["*"] = nil;
_CommBufferLen["*"] = nil;
end
end
--
local function PushMessageSingle(name, msg)
local len = strlen(msg);
local mem = _CommBuffer[name];
local mel = _CommBufferLen[name];
if mem == nil then
_CommBuffer[name] = msg;
_CommBufferLen[name] = len;
elseif mel < 249 - len then
_CommBuffer[name] = mem .. "\001" .. msg;
_CommBufferLen[name] = mel + 1 + len;
else
ScheduleMessage(ADDON_PREFIX_V2, mem, "WHISPER", name);
_CommBuffer[name] = msg;
_CommBufferLen[name] = len;
end
end
function PushResetSingle(name)
PushMessageSingle(name, ADDON_MSG_HEAD_RESET_V2);
end
function PushAddQuestSingle(name, _quest, _completed, title, num_lines)
PushMessageSingle(name, ADDON_MSG_HEAD_PUSHQUEST_V2 .. "\001" .. _quest .. "\0011\001" .. _completed .. "\001" .. num_lines .. "\001" .. title);
end
function PushDelQuestSingle(name, _quest, _completed)
PushMessageSingle(name, ADDON_MSG_HEAD_PUSHQUEST_V2 .. "\001" .. _quest .. "\001-1\001" .. _completed);
end
function PushAddLineSingle(name, _quest, _line, _finished, _type, _id, _text)
PushMessageSingle(name, ADDON_MSG_HEAD_PUSHLINE_V2 .. "\001" .. _quest .. (_finished and "\0011\001" or "\0010\001") .. _line .. "\001" .. _type .. "\001" .. _id .. "\001" .. _text);
end
function PushFlushBufferSingle(name)
local mem = _CommBuffer[name];
if mem ~= nil then
ScheduleMessage(ADDON_PREFIX_V2, mem, "WHISPER", name);
_CommBuffer[name] = nil;
_CommBufferLen[name] = nil;
end
end
--
function PushSingle(name, immediate)
MT.Debug('comm.|cffff0000PushSingle|r', name);
PushResetSingle(name);
for quest, meta in next, __MAIN_META do
PushAddQuestSingle(name, quest, meta.completed, meta.title, meta.num_lines);
for line = 1, #meta do
local meta_line = meta[line];
if meta_line[3] ~= nil then
PushAddLineSingle(name, quest, line, meta_line[5], meta_line[2], meta_line[3], meta_line[4]);
end
end
end
if immediate then
PushFlushBufferSingle(name);
end
end
function PullSingle(name, immediate)
MT.Debug('comm.|cffff0000PullSingle|r', name);
if immediate then
ScheduleMessage(ADDON_PREFIX_V2, ADDON_MSG_HEAD_PULL_V2, "WHISPER", name);
else
PushMessageSingle(name, ADDON_MSG_HEAD_PULL_V2);
end
end
function BroadcastOnline()
MT.Debug('comm.|cffff0000BroadcastOnline|r');
for name, val in next, GROUP_MEMBERS do
ScheduleMessage(ADDON_PREFIX_V2, ADDON_MSG_HEAD_ONLINE_V2, "WHISPER", name);
end
end
-- OnComm
--[==[
_completed -- -1 = failed, 0 = uncompleted, 1 = completed
--]==]
local function OnCommInit(name)
if META[name] ~= nil then
for quest, meta in next, META[name] do
for index = 1, meta.num_lines do
local meta_line = meta[index];
if meta_line ~= nil then
DelLine(name, quest, index, meta_line[2], meta_line[3], true);
end
end
local info = DataAgent.quest[quest];
if info ~= nil then
-- DelQuestStart(name, quest, info);
DelQuestEnd(name, quest, info);
end
end
end
META[name] = { };
end
local function OnCommQuestAdd(name, quest, completed, num_lines, title)
local pmeta = META[name];
local meta = pmeta[quest];
if meta == nil then
pmeta[quest] = { completed = completed, title = title, num_lines = num_lines, };
else
meta.completed = completed;
meta.title = title;
end
local info = DataAgent.quest[quest];
if info ~= nil then
-- AddQuestStart(name, quest, info);
AddQuestEnd(name, quest, info, completed == 1 and CT.IMG_INDEX.IMG_E_COMPLETED or CT.IMG_INDEX.IMG_E_UNCOMPLETED);
if info.extra ~= nil then
AddExtra(name, quest, info.extra, title, completed);
end
end
end
local function OnCommQuestDel(name, quest)
local pmeta = META[name];
local meta = pmeta[quest];
if meta ~= nil then
pmeta[quest] = nil;
for index = 1, meta.num_lines do
local meta_line = meta[index];
if meta_line ~= nil then
DelLine(name, quest, index, meta_line[2], meta_line[3], true);
end
end
local info = DataAgent.quest[quest];
if info ~= nil then
-- DelQuestStart(name, quest, info);
DelQuestEnd(name, quest, info);
if info.extra ~= nil then
DelExtra(name, quest, info.extra);
end
end
end
end
local function OnCommQuestLine(name, quest, line, type, id, text, finished)
local pmeta = META[name];
local meta = pmeta[quest];
if meta ~= nil then
local meta_line = meta[line];
if meta_line == nil then
meta[line] = { nil, type, id, text, finished, };
else
meta_line[2] = type;
meta_line[3] = id;
meta_line[4] = text;
meta_line[5] = finished;
end
if type == 'object' and l10n.object[id] ~= nil then
OBJ_LOOKUP[l10n.object[id]] = id;
end
AddLine(name, quest, line, type, id, finished);
end
end
local function OnCommCodexLiteV1(prefix, msg, channel, sender, target, zoneChannelID, localID, name, instanceID)
MT.Debug('|cff00ff7fOnCommCodexLiteV1|r', msg, name);
local control_code = strsub(msg, 1, 6);
if control_code == "_push_" then
if META[name] ~= nil then
-- local _, _head, _quest, _done, _val, _type, _id, _text = strsplit("^", msg);
local _, _head, _quest, _1, _2, _3, _4, _5 = strsplit("^", msg);
if _head == "QUEST" then
-- _1 : _completed _2 : _act _3 : _num_lines _4 : _title
_quest = tonumber(_quest);
local _act = tonumber(_2); -- 1 = add, -1 = del
if _act == -1 then
OnCommQuestDel(name, _quest);
MT.Debug('|cff00ff7fV1-Q|r|cffff0000Del|r', name, _quest, _1);
elseif _act == 1 then
OnCommQuestAdd(name, _quest, tonumber(_1), tonumber(_3), _4);
MT.Debug('|cff00ff7fV1-Q|r|cff00ff00Add|r', name, _quest, _1, _3, _4);
else
MT.Debug('|cff00ff7fV1|r |cffff0000Invalid act|r', name, _act, msg);
end
elseif _head == "LINE" then
-- _1 : finished _2 : _line _3 : _type _4 : _id _5 : _text
_quest = tonumber(_quest);
local meta = META[name][_quest];
if meta ~= nil then
OnCommQuestLine(name, _quest, tonumber(_2) or _2, _3, tonumber(_4), _5, _1 == "1");
MT.Debug('|cff00ff7fV1-Q|r|cff00ffffLine|r', name, _quest, _2, _3, _4, _1, _5);
end
else
MT.Debug('|cff00ff7fV2|r |cffff0000Invalid head|r', name, _head, msg);
end
end
elseif control_code == "_pull_" then
if _Inited[name] == nil then
ScheduleMessage(ADDON_PREFIX_V1, "_pull_", "WHISPER", name);
end
-- PushSingle(name);
elseif control_code == "_rst__" then
OnCommInit(name);
_Inited[name] = GetTime();
MT.Debug('|cff00ff7fV1-Q|r|cffff7f00Reset|r', name);
elseif control_code == "_conn_" then
MT.Debug('|cff00ff7fV1-Q|r|cff00ff7fOnline|r', name);
end
end
local _NextPushSingle = { };
local function OnCommCodexLiteV2(prefix, msg, channel, sender, target, zoneChannelID, localID, name, instanceID)
local _SEQ = { strsplit("\001", msg) };
local _LEN = #_SEQ;
local _pos = 1;
while _pos <= _LEN do
local _head = _SEQ[_pos];
_pos = _pos + 1;
if _head == ADDON_MSG_HEAD_PUSHQUEST_V2 then
local _act = _SEQ[_pos + 1]; -- 1 = add, -1 = del
-- _1 : _act _2 : _completed _3 : _num_lines _4 : _title
if _act == "1" then