-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathRaidCore.lua
More file actions
1183 lines (1074 loc) · 37.7 KB
/
RaidCore.lua
File metadata and controls
1183 lines (1074 loc) · 37.7 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
----------------------------------------------------------------------------------------------------
-- Client Lua Script for RaidCore Addon on WildStar Game.
--
-- Copyright (C) 2015 RaidCore
----------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------
-- Description: TODO
----------------------------------------------------------------------------------------------------
require "Apollo"
require "Window"
require "GameLib"
require "ChatSystemLib"
local GeminiAddon = Apollo.GetPackage("Gemini:Addon-1.1").tPackage
local JSON = Apollo.GetPackage("Lib:dkJSON-2.5").tPackage
local RaidCore = GeminiAddon:NewAddon("RaidCore", false, {}, "Gemini:Timer-1.0")
local Log = Apollo.GetPackage("Log-1.0").tPackage
----------------------------------------------------------------------------------------------------
-- Copy of few objects to reduce the cpu load.
-- Because all local objects are faster.
----------------------------------------------------------------------------------------------------
local GetPlayerUnit = GameLib.GetPlayerUnit
local GetGameTime = GameLib.GetGameTime
local GetCurrentZoneMap = GameLib.GetCurrentZoneMap
local next, pcall = next, pcall
----------------------------------------------------------------------------------------------------
-- Constants.
----------------------------------------------------------------------------------------------------
-- Should be 5.23 when replacement tokens will works (see #88 issue).
local RAIDCORE_CURRENT_VERSION = "6.4.1"
-- Should be deleted.
local ADDON_DATE_VERSION = 17020118
-- State Machine.
local MAIN_FSM__SEARCH = 1
local MAIN_FSM__RUNNING = 2
RaidCore.E = {
-- Events.
UNIT_CREATED = "OnUnitCreated",
UNIT_DESTROYED = "OnUnitDestroyed",
ENTERED_COMBAT = "OnEnteredCombat",
BUFF_ADD = "OnBuffAdd",
BUFF_UPDATE = "OnBuffUpdate",
BUFF_REMOVE = "OnBuffRemove",
DEBUFF_ADD = "OnDebuffAdd",
DEBUFF_UPDATE = "OnDebuffUpdate",
DEBUFF_REMOVE = "OnDebuffRemove",
CAST_START = "OnCastStart",
CAST_END = "OnCastEnd",
HEALTH_CHANGED = "OnHealthChanged",
DATACHRON = "OnDatachron",
NPC_SAY = "OnNPCSay",
NPC_YELL = "OnNPCYell",
NPC_WHISPER = "OnNPCWhisper",
COMBAT_LOG_HEAL = "OnCombatLogHeal",
SHOW_SHORTCUT_BAR = "OnShowShortcutBar",
-- Special Keywords.
ALL_UNITS = "**",
NO_BREAK_SPACE = string.char(194, 160),
-- Tracking.
TRACK_ALL = 0xFF,
TRACK_BUFFS = 0x01,
TRACK_CASTS = 0x02,
TRACK_HEALTH = 0x04,
-- Locations.
LOCATION_STATIC_FLOOR = 0,
LOCATION_STATIC_NAME = 1,
LOCATION_LEFT_ASS = 34,
LOCATION_RIGHT_ASS = 35,
LOCATION_STATIC_CHEST = 40,
-- Core Events.
CHANGE_WORLD = "OnChangeWorld",
SUB_ZONE_CHANGE = "OnSubZoneChanged",
RECEIVED_MESSAGE = "OnReceivedMessage",
CHARACTER_CREATED = "OnCharacterCreated",
-- Combat Interface States.
INTERFACE_DISABLE = 1,
INTERFACE_DETECTCOMBAT = 2,
INTERFACE_DETECTALL = 3,
INTERFACE_LIGHTENABLE = 4,
INTERFACE_FULLENABLE = 5,
-- Comparism types.
COMPARE_EQUAL = 1,
COMPARE_FIND = 2,
COMPARE_MATCH = 3,
-- Log.
ERROR = "ERROR",
CURRENT_ZONE_MAP = "CurrentZoneMap",
TRACK_UNIT = "TrackThisUnit",
UNTRACK_UNIT = "UnTrackThisUnit",
JOIN_CHANNEL_TRY = "JoinChannelTry",
JOIN_CHANNEL_STATUS = "JoinChannelStatus",
CHANNEL_COMM_STATUS = "ChannelCommStatus",
SEND_MESSAGE = "SendMessage",
SEND_MESSAGE_RESULT = "SendMessageResult",
SPAWN_LOCATION = "SpawnLocation",
-- Carbine Events.
EVENT_COMBAT_LOG_HEAL = "CombatLogHeal",
EVENT_UNIT_ENTERED_COMBAT = "UnitEnteredCombat",
EVENT_UNIT_CREATED = "UnitCreated",
EVENT_UNIT_DESTROYED = "UnitDestroyed",
EVENT_CHAT_MESSAGE = "ChatMessage",
EVENT_SHOW_ACTION_BAR_SHORTCUT = "ShowActionBarShortcut",
EVENT_BUFF_ADDED = "BuffAdded",
EVENT_BUFF_UPDATED = "BuffUpdated",
EVENT_BUFF_REMOVED = "BuffRemoved",
EVENT_CHANGE_WORLD = "ChangeWorld",
EVENT_SUB_ZONE_CHANGED = "SubZoneChanged",
EVENT_NEXT_FRAME = "NextFrame",
EVENT_FRAME_COUNT = "FrameCount",
EVENT_WINDOWS_MANAGEMENT_READY = "WindowManagementReady",
EVENT_CHARACTER_CREATED = "CharacterCreated",
EVENT_DISPLAY_RAIDCORE_WINDOW= "DisplayRaidCoreMainWindow",
-- Comm events. Using numbers for these instead to save bandwidth would break
-- compatibility with older versions of raidcore.
COMM_VERSION_CHECK_REQUEST = "VersionCheckRequest",
COMM_VERSION_CHECK_REPLY = "VersionCheckReply",
COMM_NEWEST_VERSION = "NewestVersion",
COMM_LAUNCH_PULL = "LaunchPull",
COMM_LAUNCH_BREAK = "LaunchBreak",
COMM_SYNC_SUMMON = "SyncSummon",
COMM_ENCOUNTER_IND = "Encounter_IND",
-- Triggers
TRIGGER_ALL = 1,
TRIGGER_ANY = 2,
}
local EVENT_UNIT_NAME_INDEX = {
[RaidCore.E.UNIT_CREATED] = 3,
[RaidCore.E.UNIT_DESTROYED] = 3,
[RaidCore.E.CAST_START] = 4,
[RaidCore.E.CAST_END] = 5,
[RaidCore.E.HEALTH_CHANGED] = 3,
[RaidCore.E.ENTERED_COMBAT] = 3,
[RaidCore.E.BUFF_ADD] = 5,
[RaidCore.E.BUFF_UPDATE] = 5,
[RaidCore.E.BUFF_REMOVE] = 3,
[RaidCore.E.DEBUFF_ADD] = 5,
[RaidCore.E.DEBUFF_UPDATE] = 5,
[RaidCore.E.DEBUFF_REMOVE] = 3,
[RaidCore.E.NPC_SAY] = 2,
[RaidCore.E.NPC_YELL] = 2,
[RaidCore.E.NPC_WHISPER] = 2,
}
local EVENT_UNIT_SPELL_ID_INDEX = {
[RaidCore.E.CAST_START] = 2,
[RaidCore.E.CAST_END] = 2,
[RaidCore.E.BUFF_ADD] = 2,
[RaidCore.E.BUFF_UPDATE] = 2,
[RaidCore.E.BUFF_REMOVE] = 2,
[RaidCore.E.DEBUFF_ADD] = 2,
[RaidCore.E.DEBUFF_UPDATE] = 2,
[RaidCore.E.DEBUFF_REMOVE] = 2,
[RaidCore.E.NPC_SAY] = 1,
[RaidCore.E.NPC_YELL] = 1,
[RaidCore.E.NPC_WHISPER] = 1,
}
----------------------------------------------------------------------------------------------------
-- Privates variables.
----------------------------------------------------------------------------------------------------
local _tWipeTimer
local _tTrigPerZone = {}
local _tEncountersPerZone = {}
local _tDelayedUnits = {}
local _bIsEncounterInProgress = false
local _tCurrentEncounter = nil
local _eCurrentFSM
local _tMainFSMHandlers
local markCount = 0
local VCReply, VCtimer = {}, nil
----------------------------------------------------------------------------------------------------
-- Privates functions
----------------------------------------------------------------------------------------------------
local function OnEncounterUnitEvents(sMethod, ...)
if EVENT_UNIT_NAME_INDEX[sMethod] == nil then
return
end
local sName = select(EVENT_UNIT_NAME_INDEX[sMethod], ...)
-- Check if any events are bound
local tUnitEvents = _tCurrentEncounter.tUnitEvents
tUnitEvents = tUnitEvents and tUnitEvents[sMethod]
if not tUnitEvents then return end
-- Check for events bound by name
local tHandlers = tUnitEvents[sName] or {}
local nSize = #tHandlers
for i = 1, nSize do
tHandlers[i](_tCurrentEncounter, ...)
end
-- Check for events bound for all units
local tAnyHandlers = tUnitEvents[RaidCore.E.ALL_UNITS] or {}
nSize = #tAnyHandlers
for i = 1, nSize do
tAnyHandlers[i](_tCurrentEncounter, ...)
end
end
local function OnEncounterUnitSpellEvents(sMethod, ...)
if EVENT_UNIT_NAME_INDEX[sMethod] == nil or EVENT_UNIT_SPELL_ID_INDEX[sMethod] == nil then
return
end
local sName = select(EVENT_UNIT_NAME_INDEX[sMethod], ...)
local spellId = select(EVENT_UNIT_SPELL_ID_INDEX[sMethod], ...)
-- Check if any events are bound
local tUnitSpellEvents = _tCurrentEncounter.tUnitSpellEvents
tUnitSpellEvents = tUnitSpellEvents and tUnitSpellEvents[sMethod]
if not tUnitSpellEvents then return end
-- Check for events bound by name
local tUnitHandlers = tUnitSpellEvents[sName]
tUnitHandlers = tUnitHandlers and tUnitHandlers[spellId] or {}
local nSize = #tUnitHandlers
for i = 1, nSize do
tUnitHandlers[i](_tCurrentEncounter, ...)
end
-- Check for events bound for all units
local tAnyHandlers = tUnitSpellEvents[RaidCore.E.ALL_UNITS]
tAnyHandlers = tAnyHandlers and tAnyHandlers[spellId] or {}
nSize = #tAnyHandlers
for i = 1, nSize do
tAnyHandlers[i](_tCurrentEncounter, ...)
end
end
local function OnEncounterDatachronEvents(sMethod, ...)
if sMethod ~= RaidCore.E.DATACHRON then
return
end
local sMessage = ...
local tDatachronEvents = _tCurrentEncounter.tDatachronEvents or {}
local tDatachronEventsEqual = _tCurrentEncounter.tDatachronEventsEqual or {}
tDatachronEventsEqual = tDatachronEventsEqual and tDatachronEventsEqual[sMessage] or {}
local nSize = #tDatachronEventsEqual
for i = 1, nSize do
tDatachronEventsEqual[i](_tCurrentEncounter, sMessage, true)
end
for sSearchMessage, tEvents in next, tDatachronEvents do
nSize = #tEvents
for i = 1, nSize do
local tEvent = tEvents[i]
local compareType = tEvent.compareType
local fHandler = tEvent.fHandler
local result = nil
if compareType == RaidCore.E.COMPARE_FIND then
result = sMessage:find(sSearchMessage)
elseif compareType == RaidCore.E.COMPARE_MATCH then
result = sMessage:match(sSearchMessage)
end
if result ~= nil then
fHandler(_tCurrentEncounter, sMessage, result)
end
end
end
end
local function OnEncounterHookGeneric(sMethod, ...)
local fEncounter = _tCurrentEncounter[sMethod]
if fEncounter then
fEncounter(_tCurrentEncounter, ...)
end
OnEncounterUnitEvents(sMethod, ...)
OnEncounterUnitSpellEvents(sMethod, ...)
OnEncounterDatachronEvents(sMethod, ...)
end
local function RemoveDelayedUnit(nId, sName)
if _tDelayedUnits[sName] then
if _tDelayedUnits[sName][nId] then
_tDelayedUnits[sName][nId] = nil
end
if next(_tDelayedUnits[sName]) == nil then
_tDelayedUnits[sName] = nil
end
end
end
local function AddDelayedUnit(nId, tUnit, sName)
local tMap = GetCurrentZoneMap()
if tMap then
local tTrig = _tTrigPerZone[tMap.continentId]
tTrig = tTrig and tTrig[tMap.parentZoneId]
tTrig = tTrig and tTrig[tMap.id]
tTrig = tTrig and tTrig[sName]
if tTrig then
if not _tDelayedUnits[sName] then
_tDelayedUnits[sName] = {}
end
_tDelayedUnits[sName][nId] = tUnit
end
end
end
local function SearchEncounter()
local tMap = GetCurrentZoneMap()
if tMap then
local tEncounters = _tEncountersPerZone[tMap.continentId]
tEncounters = tEncounters and tEncounters[tMap.parentZoneId]
tEncounters = tEncounters and tEncounters[tMap.id] or {}
local nSize = #tEncounters
for i = 1, nSize do
local tEncounter = tEncounters[i]
if tEncounter:OnTrig(_tDelayedUnits) then
_tCurrentEncounter = tEncounter
break
end
end
end
end
local function CleanDelayedUnits()
for sName, tDelayedList in next, _tDelayedUnits do
for nId, tUnit in next, tDelayedList do
if not tUnit:IsValid() or tUnit:IsDead() then
RemoveDelayedUnit(nId, sName)
end
end
end
end
local function ProcessDelayedUnit()
for nDelayedName, tDelayedList in next, _tDelayedUnits do
for nDelayedId, tUnit in next, tDelayedList do
if tUnit:IsValid() then
local bInCombat = tUnit:IsInCombat()
local s, e = pcall(OnEncounterHookGeneric, RaidCore.E.UNIT_CREATED, nDelayedId, tUnit, nDelayedName)
RaidCore:HandlePcallResult(s, e)
if bInCombat then
s, e = pcall(OnEncounterHookGeneric, RaidCore.E.ENTERED_COMBAT, nDelayedId, tUnit, nDelayedName, bInCombat)
RaidCore:HandlePcallResult(s, e)
end
end
end
end
CleanDelayedUnits()
end
local function InitModuleZones(module, id1, id2, id3)
_tTrigPerZone[id1] = _tTrigPerZone[id1] or {}
_tTrigPerZone[id1][id2] = _tTrigPerZone[id1][id2] or {}
_tTrigPerZone[id1][id2][id3] = _tTrigPerZone[id1][id2][id3] or {}
_tEncountersPerZone[id1] = _tEncountersPerZone[id1] or {}
_tEncountersPerZone[id1][id2] = _tEncountersPerZone[id1][id2] or {}
_tEncountersPerZone[id1][id2][id3] = _tEncountersPerZone[id1][id2][id3] or {}
table.insert(_tEncountersPerZone[id1][id2][id3], module)
for _, Mob in next, module.tTriggerNames do
_tTrigPerZone[id1][id2][id3][Mob] = true
end
end
----------------------------------------------------------------------------------------------------
-- RaidCore Initialization
----------------------------------------------------------------------------------------------------
function RaidCore:Print(sMessage)
ChatSystemLib.PostOnChannel(ChatSystemLib.ChatChannel_Debug, tostring(sMessage), "RaidCore")
end
function RaidCore:OnInitialize()
_tMainFSMHandlers = {
[MAIN_FSM__SEARCH] = {
[RaidCore.E.CHANGE_WORLD] = self.SEARCH_OnCheckMapZone,
[RaidCore.E.SUB_ZONE_CHANGE] = self.SEARCH_OnCheckMapZone,
[RaidCore.E.CHARACTER_CREATED] = self.SEARCH_OnCheckMapZone,
[RaidCore.E.UNIT_CREATED] = self.SEARCH_OnUnitCreated,
[RaidCore.E.ENTERED_COMBAT] = self.SEARCH_OnEnteredCombat,
[RaidCore.E.UNIT_DESTROYED] = self.SEARCH_OnUnitDestroyed,
[RaidCore.E.RECEIVED_MESSAGE] = self.SEARCH_OnReceivedMessage,
},
[MAIN_FSM__RUNNING] = {
[RaidCore.E.ENTERED_COMBAT] = self.RUNNING_OnEnteredCombat,
[RaidCore.E.RECEIVED_MESSAGE] = self.RUNNING_OnReceivedMessage,
[RaidCore.E.UNIT_DESTROYED] = self.RUNNING_OnUnitDestroyed,
},
}
_eCurrentFSM = MAIN_FSM__SEARCH
self.xmlDoc = XmlDoc.CreateFromFile("RaidCore.xml")
self.xmlDoc:RegisterCallback("OnDocLoaded", self)
Apollo.LoadSprites("Textures_GUI.xml")
Apollo.LoadSprites("Textures_Bars.xml")
Apollo.LoadSprites("RaidCore_Draw.xml")
Apollo.LoadTemplates("RaidCore_Templates.xml")
local GeminiLocale = Apollo.GetPackage("Gemini:Locale-1.0").tPackage
self.L = GeminiLocale:GetLocale("RaidCore")
local GeminiDB = Apollo.GetPackage("Gemini:DB-1.0").tPackage
self.db = GeminiDB:New(self, nil, true)
-- Create default settings to provide to GeminiDB.
local tDefaultSettings = {
profile = {
version = RAIDCORE_CURRENT_VERSION,
Encounters = {},
BarsManagers = self:GetBarsDefaultSettings(),
DrawManagers = self:GetDrawDefaultSettings(),
-- Simple and general settings.
bSoundEnabled = true,
bAcceptSummons = true,
bLUAErrorMessage = false,
bLogSpawnLocations = false,
bReadyCheckOnBreakTimeout = true,
sReadyCheckMessage = self.L["Raid Resume"],
bEnableTestEncounters = false,
bDisableSelectiveTracking = false,
}
}
self.tCMD2function = {
["config"] = self.DisplayMainWindow,
["reset"] = self.ResetAll,
["versioncheck"] = self.VersionCheck,
["pull"] = self.LaunchPull,
["break"] = self.LaunchBreak,
["summon"] = self.SyncSummon,
}
for sCommand, fHandler in next, self.tCMD2function do
self.tCMD2function[self.L[sCommand]] = fHandler
end
self.tAction2function = {
[RaidCore.E.COMM_VERSION_CHECK_REQUEST] = self.VersionCheckRequest,
[RaidCore.E.COMM_VERSION_CHECK_REPLY] = self.VersionCheckReply,
[RaidCore.E.COMM_NEWEST_VERSION] = self.NewestVersionRequest,
[RaidCore.E.COMM_LAUNCH_PULL] = self.LaunchPullRequest,
[RaidCore.E.COMM_LAUNCH_BREAK] = self.LaunchBreakRequest,
[RaidCore.E.COMM_SYNC_SUMMON] = self.SyncSummonRequest,
[RaidCore.E.COMM_ENCOUNTER_IND] = self.EncounterInd,
}
-- Final parsing about encounters.
for name, module in self:IterateModules() do
local s, e = pcall(module.PrepareEncounter, module)
if self:HandlePcallResult(s, e) then
for i = 1, #module.continentIdList do
for ii = 1, #module.parentMapIdList do
for iii = 1, #module.mapIdList do
InitModuleZones(
module,
module.continentIdList[i],
module.parentMapIdList[ii],
module.mapIdList[iii]
)
end
end
end
end
-- Fill Default setting with encounters definitions.
tDefaultSettings.profile.Encounters[name] = module.tDefaultSettings or {}
end
-- Initialize GeminiDB with the default table.
self.db:RegisterDefaults(tDefaultSettings)
-- Load every software block.
self:CombatInterface_Init()
-- Do additional initialization.
self.nextFrameSemaphore = 0
self.frameCountSemaphore = 0
self.mark = {}
self.worldmarker = {}
_tWipeTimer = ApolloTimer.Create(0.5, true, "RUNNING_WipeCheck", self)
_tWipeTimer:Stop()
-- Initialize the Zone Detection.
self:SEARCH_OnCheckMapZone()
end
function RaidCore:HandlePcallResult(success, error, output)
if not success then
if output then
error = tostring(error) .. tostring(output)
end
if self.db.profile.bLUAErrorMessage then
self:Print(error)
end
Log:Add(RaidCore.E.ERROR, error)
end
return success
end
----------------------------------------------------------------------------------------------------
-- RaidCore OnDocLoaded
----------------------------------------------------------------------------------------------------
function RaidCore:OnDocLoaded()
-- Send version information to OneVersion Addon.
local fNumber = RAIDCORE_CURRENT_VERSION:gmatch("%d+")
local sSuffix = RAIDCORE_CURRENT_VERSION:gmatch("%a+")()
local nMajor, nMinor = fNumber(), fNumber()
local nSuffix = sSuffix == "alpha" and -2 or sSuffix == "beta" and -1 or 0
Event_FireGenericEvent("OneVersion_ReportAddonInfo", "RaidCore", nMajor, nMinor, 0, nSuffix)
-- Load every software block.
self:BarManagersInit(self.db.profile.BarsManagers)
self:DrawManagersInit(self.db.profile.DrawManagers)
self:GUI_init(RAIDCORE_CURRENT_VERSION)
self:CI_JoinChannelTry()
-- Register handlers for events, slash commands and timer, etc.
Apollo.RegisterSlashCommand("raidc", "OnRaidCoreOn", self)
end
----------------------------------------------------------------------------------------------------
-- RaidCore Channel Communication functions.
----------------------------------------------------------------------------------------------------
function RaidCore:SendMessage(tMessage, tDPlayerId)
assert(type(tMessage) == "table")
tMessage.sender = GetPlayerUnit():GetName()
self:CombatInterface_SendMessage(JSON.encode(tMessage), tDPlayerId)
end
function RaidCore:ProcessMessage(tMessage, nSenderId)
if type(tMessage) ~= "table" or type(tMessage.action) ~= "string" then
-- Silent error.
return
end
local func = self.tAction2function[tMessage.action]
if func then
func(self, tMessage, nSenderId)
end
end
function RaidCore:VersionCheckRequest(tMessage, nSenderId)
local msg = {
action = RaidCore.E.COMM_VERSION_CHECK_REPLY,
version = ADDON_DATE_VERSION,
tag = RAIDCORE_CURRENT_VERSION,
}
self:SendMessage(msg, nSenderId)
end
function RaidCore:VersionCheckReply(tMessage, nSenderId)
if tMessage.sender and tMessage.version and VCtimer then
VCReply[tMessage.sender] = tMessage.version
end
end
function RaidCore:NewestVersionRequest(tMessage, nSenderId)
if tMessage.version and ADDON_DATE_VERSION < tMessage.version then
self:Print("Your RaidCore version is outdated. Please get " .. tMessage.version)
end
end
function RaidCore:LaunchPullRequest(tMessage, nSenderId)
if not self:isRaidManagement(tMessage.sender) then return false end
if tMessage.cooldown then
local tOptions = { bEmphasize = true }
self:AddTimerBar("PULL", "PULL", tMessage.cooldown, nil, tOptions)
self:AddMsg("PULL", ("PULL in %s"):format(tMessage.cooldown), 2, nil, "Green")
end
end
function RaidCore:LaunchBreakRequest(tMessage, nSenderId)
if not self:isRaidManagement(tMessage.sender) then return false end
if tMessage.cooldown and tMessage.cooldown > 0 then
local tOptions = { bEmphasize = true }
self:AddTimerBar("BREAK", "BREAK", tMessage.cooldown, nil, tOptions)
self:AddMsg("BREAK", ("BREAK for %ss"):format(tMessage.cooldown), 5, "Long", "Green")
else
self:RemoveTimerBar("BREAK")
self:RemoveMsg("BREAK")
end
end
function RaidCore:SyncSummonRequest(tMessage, nSenderId)
if not self.db.profile.bAcceptSummons or not self:isRaidManagement(tMessage.sender) then
return false
end
local CSImsg = CSIsLib.GetActiveCSI()
if not CSImsg or not CSImsg.strContext then return end
if CSImsg.strContext == self.L["message.summon.csi"] then
self:Print(self.L["message.summon.request"]:format(tMessage.sender))
if CSIsLib.IsCSIRunning() then
CSIsLib.CSIProcessInteraction(true)
end
end
end
function RaidCore:EncounterInd(tMessage, nSenderId)
if _tCurrentEncounter and _tCurrentEncounter.ReceiveIndMessage then
_tCurrentEncounter:ReceiveIndMessage(tMessage.sender, tMessage.reason, tMessage.data)
end
end
---------------------------------------------------------------------------------------------------
---- Some Functions
-----------------------------------------------------------------------------------------------------
function RaidCore:StartFrameCount()
self.frameCountSemaphore = self.frameCountSemaphore + 1
if self.frameCountSemaphore == 1 then
Apollo.RegisterEventHandler(RaidCore.E.EVENT_FRAME_COUNT, "OnFrameCount", RaidCore)
end
end
function RaidCore:StopFrameCount()
self.frameCountSemaphore = self.frameCountSemaphore - 1
if self.frameCountSemaphore == 0 then
Apollo.RemoveEventHandler(RaidCore.E.EVENT_FRAME_COUNT, RaidCore)
end
end
function RaidCore:OnFrameCount(frames)
end
function RaidCore:StartNextFrame()
self.nextFrameSemaphore = self.nextFrameSemaphore + 1
if self.nextFrameSemaphore == 1 then
Apollo.RegisterEventHandler(RaidCore.E.EVENT_NEXT_FRAME, "OnNextFrame", RaidCore)
end
end
function RaidCore:StopNextFrame()
self.nextFrameSemaphore = self.nextFrameSemaphore - 1
if self.nextFrameSemaphore == 0 then
Apollo.RemoveEventHandler(RaidCore.E.EVENT_NEXT_FRAME, RaidCore)
end
end
function RaidCore:OnNextFrame()
local nCurrentTime = GetGameTime()
self:OnDrawUpdate(nCurrentTime)
self:OnGUINextFrame(nCurrentTime)
end
function RaidCore:isPublicEventObjectiveActive(objectiveString)
local activeEvents = PublicEvent:GetActiveEvents()
if activeEvents == nil then
return false
end
for eventId, event in next, activeEvents do
local objectives = event:GetObjectives()
if objectives ~= nil then
for id, objective in next, objectives do
if objective:GetShortDescription() == objectiveString then
return objective:GetStatus() == 1
end
end
end
end
return false
end
function RaidCore:hasActiveEvent(tblEvents)
for key, value in next, tblEvents do
if self:isPublicEventObjectiveActive(key) then
return true
end
end
return false
end
function RaidCore:PlaySound(sFilename)
assert(type(sFilename) == "string")
if self.db.profile.bSoundEnabled then
Sound.PlayFile("Sounds\\".. sFilename .. ".wav")
end
end
function RaidCore:MarkUnit(unit, location, mark, color)
if unit and not unit:IsDead() then
local nId = unit:GetId()
if not self.mark[nId] then
self.mark[nId] = {}
if not mark then
markCount = markCount + 1
self.mark[nId].number = tostring(markCount)
else
self.mark[nId].number = tostring(mark)
end
local markFrame = Apollo.LoadForm(self.xmlDoc, "MarkFrame", "InWorldHudStratum", self)
markFrame:SetUnit(unit, location)
markFrame:FindChild("Name"):SetText(self.mark[nId].number)
if color then
markFrame:FindChild("Name"):SetTextColor(color)
end
self:MarkerVisibilityHandler(markFrame)
self.mark[nId].frame = markFrame
elseif mark or color then
if mark then
self.mark[nId].number = tostring(mark)
self.mark[nId].frame:FindChild("Name"):SetText(self.mark[nId].number)
end
if color then
self.mark[nId].frame:FindChild("Name"):SetTextColor(color)
end
end
self:SetMark2UnitBar(nId, self.mark[nId].number)
end
end
function RaidCore:MarkerVisibilityHandler(markFrame)
-- If marker was never on screen it might already have been destroyed again
-- so we'll check if it still exists
if not markFrame or not markFrame:IsValid() then return end
if markFrame:IsOnScreen() then
markFrame:Show(true)
else
-- run check again later
self:ScheduleTimer("MarkerVisibilityHandler", 1, markFrame)
end
end
-- Removes all the world markers
function RaidCore:ResetWorldMarkers()
for nId, _ in next, self.worldmarker do
self:DropWorldMarker(nId)
end
end
function RaidCore:CreateWorldMarker(key, sText, tPosition, color)
local markFrame = Apollo.LoadForm(self.xmlDoc, "MarkFrame", "InWorldHudStratum", self)
markFrame:SetWorldLocation(tPosition)
markFrame:FindChild("Name"):SetText(sText)
if color then
markFrame:FindChild("Name"):SetTextColor(color)
end
self:MarkerVisibilityHandler(markFrame)
self.worldmarker[key] = markFrame
end
function RaidCore:UpdateWorldMarker(key, sText, tPosition, color)
if sText then
local wndText = self.worldmarker[key]:FindChild("Name")
if wndText:GetText() ~= sText then
wndText:SetText(sText)
end
end
if tPosition then
self.worldmarker[key]:SetWorldLocation(tPosition)
end
if color then
local wndText = self.worldmarker[key]:FindChild("Name")
wndText:SetTextColor(color)
end
end
function RaidCore:DropWorldMarker(key)
if self.worldmarker[key] then
self.worldmarker[key]:Destroy()
self.worldmarker[key] = nil
end
end
function RaidCore:SetWorldMarker(key, sText, tPosition, sColor)
assert(key)
local sLocalizedTest = self.L[sText]
local tWorldMarker = self.worldmarker[key]
if not tWorldMarker and sText and tPosition then
self:CreateWorldMarker(key, sLocalizedTest, tPosition, sColor)
elseif tWorldMarker and (sText or tPosition) then
self:UpdateWorldMarker(key, sLocalizedTest, tPosition, sColor)
elseif tWorldMarker and not sLocalizedTest and not tPosition then
self:DropWorldMarker(key)
end
end
function RaidCore:OnMarkUpdate()
for k, v in next, self.mark do
if v.unit:GetPosition() then
v.frame:SetWorldLocation(v.unit:GetPosition())
end
end
end
function RaidCore:DropMark(key)
if self.mark[key] then
local markFrame = self.mark[key].frame
markFrame:SetUnit(nil)
markFrame:Destroy()
self.mark[key] = nil
end
end
function RaidCore:ResetMarks()
for nId, _ in next, self.mark do
self:DropMark(nId)
end
markCount = 0
end
function RaidCore:ResetAll()
_tWipeTimer:Stop()
self:BarsRemoveAll()
self:ResetMarks()
self:ResetWorldMarkers()
self:ResetLines()
end
function RaidCore:isRaidManagement(strName)
if not GroupLib.InGroup() then return false end
for nIdx=0, GroupLib.GetMemberCount() do
local tGroupMember = GroupLib.GetGroupMember(nIdx)
if tGroupMember and tGroupMember.strCharacterName == strName then
if tGroupMember.bIsLeader or tGroupMember.bRaidAssistant then
return true
else
return false
end
end
end
return false -- just in case
end
function RaidCore:AutoCleanUnitDestroyed(nId, tUnit, sName)
self:RemoveUnit(nId)
self:DropMark(nId)
end
----------------------------------------------------------------------------------------------------
-- Commands Line:
----------------------------------------------------------------------------------------------------
function RaidCore:OnRaidCoreOn(cmd, args)
local tArgc = {}
for sWord in string.gmatch(args, "[^%s]+") do
table.insert(tArgc, sWord)
end
-- Default command.
local command = "config"
-- Extract the first argument.
if #tArgc >= 1 then
command = string.lower(tArgc[1])
table.remove(tArgc, 1)
end
local func = self.tCMD2function[command]
if func then
func(self, tArgc)
else
self:Print(("Unknown command: %s"):format(command))
local tAllCommands = {}
for k, v in next, self.tCMD2function do
table.insert(tAllCommands, k)
end
local sAllCommands = table.concat(tAllCommands, ", ")
self:Print(("Available commands are: %s"):format(sAllCommands))
end
end
function RaidCore:VersionCheck()
if VCtimer then
self:Print(self.L["VersionCheck already running ..."])
elseif GroupLib.GetMemberCount() == 0 then
self:Print(self.L["Command available only in group."])
else
self:Print(self.L["Checking version on group member."])
VCReply[GetPlayerUnit():GetName()] = ADDON_DATE_VERSION
local msg = {
action = RaidCore.E.COMM_VERSION_CHECK_REQUEST,
}
VCtimer = ApolloTimer.Create(5, false, "VersionCheckResults", self)
self:SendMessage(msg)
end
end
function RaidCore:VersionCheckResults()
local nMaxVersion = ADDON_DATE_VERSION
for _, v in next, VCReply do
if v > nMaxVersion then
nMaxVersion = v
end
end
local tNotInstalled = {}
local tOutdated = {}
local nMemberWithLasted = 0
for i = 1, GroupLib.GetMemberCount() do
local tMember = GroupLib.GetGroupMember(i)
if tMember then
local sPlayerName = tMember.strCharacterName
local sPlayerVersion = VCReply[sPlayerName]
if not sPlayerVersion then
table.insert(tNotInstalled, sPlayerName)
elseif sPlayerVersion < nMaxVersion then
if tOutdated[sPlayerVersion] == nil then
tOutdated[sPlayerVersion] = {}
end
table.insert(tOutdated[sPlayerVersion], sPlayerName)
else
nMemberWithLasted = nMemberWithLasted + 1
end
end
end
if next(tNotInstalled) then
self:Print(self.L["Not installed: %s"]:format(table.concat(tNotInstalled, ", ")))
end
if next(tOutdated) then
self:Print("Outdated RaidCore Version:")
for sPlayerVersion, tList in next, tOutdated do
self:Print((" - '%s': %s"):format(sPlayerVersion, table.concat(tList, ", ")))
end
end
self:Print(self.L["%d members are up to date."]:format(nMemberWithLasted))
-- Send Msg to oudated players.
local msg = {action = RaidCore.E.COMM_NEWEST_VERSION, version = nMaxVersion}
self:SendMessage(msg)
self:ProcessMessage(msg)
VCtimer = nil
end
function RaidCore:LaunchPull(tArgc)
if not self:isRaidManagement(GetPlayerUnit():GetName()) then
self:Print("You must be a raid leader or assistant to use this command!")
return
end
local nTime = #tArgc >= 1 and tonumber(tArgc[1])
nTime = nTime and nTime > 2 and nTime or 10
local msg = {
action = RaidCore.E.COMM_LAUNCH_PULL,
cooldown = nTime,
}
self:SendMessage(msg)
self:ProcessMessage(msg)
end
function RaidCore:LaunchBreak(tArgc)
if not self:isRaidManagement(GetPlayerUnit():GetName()) then
self:Print("You must be a raid leader or assistant to use this command!")
return
end
local nTime = #tArgc >= 1 and tonumber(tArgc[1])
nTime = nTime and nTime > 2 and nTime or 600
local msg = {
action = RaidCore.E.COMM_LAUNCH_BREAK,
cooldown = nTime
}
self:SendMessage(msg)
self:ProcessMessage(msg)
-- Cancel previous timer if started.
if self.LaunchBreakTimerId then
self:CancelTimer(self.LaunchBreakTimerId)
end
-- Start a timer for Ready Check call..
if nTime > 0 and self.db.profile.bReadyCheckOnBreakTimeout then
self.LaunchBreakTimerId = self:ScheduleTimer(function()
self.LaunchBreakTimerId = nil
GroupLib.ReadyCheck(self.db.profile.sReadyCheckMessage or "")
end,
nTime
)
end
end
function RaidCore:SyncSummon()
local myName = GetPlayerUnit():GetName()
if not self:isRaidManagement(myName) then
self:Print("You must be a raid leader or assistant to use this command!")
return false
end
local msg = {
action = RaidCore.E.COMM_SYNC_SUMMON,
}
self:SendMessage(msg)
end
----------------------------------------------------------------------------------------------------
-- Relation between: CombatInterface <-> RaidCore <-> Encounter
----------------------------------------------------------------------------------------------------
function RaidCore:GlobalEventHandler(sMethod, ...)
-- Call the encounter handler if we were in RUNNING.
if _eCurrentFSM == MAIN_FSM__RUNNING then
local s, e = pcall(OnEncounterHookGeneric, sMethod, ...)
self:HandlePcallResult(s, e)
end
-- Call the FSM handler, if needed.
local fFSMHandler = _tMainFSMHandlers[_eCurrentFSM][sMethod]
if fFSMHandler then
fFSMHandler(self, ...)
end
end
function RaidCore:SEARCH_OnUnitCreated(nId, tUnit, sName)
AddDelayedUnit(nId, tUnit, sName)
end