-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMagicMarker.lua
More file actions
1634 lines (1444 loc) · 55.4 KB
/
MagicMarker.lua
File metadata and controls
1634 lines (1444 loc) · 55.4 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
--[[
**********************************************************************
MagicMarker - your best friend for raid marking. See README.txt for
more details.
**********************************************************************
This file is part of MagicMarker, a World of Warcraft Addon
MagicMarker is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MagicMarker is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with mod. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************
]]
local mod = LibStub("AceAddon-3.0"):NewAddon("MagicMarker", "AceConsole-3.0",
"AceEvent-3.0", "AceTimer-3.0",
"LibLogger-1.0")
MagicMarker = mod
local MagicMarker = MagicMarker
local MagicComm = LibStub("MagicComm-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("MagicMarker", false)
mod.MAJOR_VERSION = "MagicMarker-1.0"
mod.MINOR_VERSION = tonumber("@project-date-integer@") or tonumber(date("%Y%m%d%H%M%S"))
-- Upvalue of global functions
local GetBindingKey = GetBindingKey
local GetNumGroupMembers = GetNumGroupMembers
local GetRaidRosterInfo = GetRaidRosterInfo
local GetRaidTargetIndex = GetRaidTargetIndex
local GetRealZoneText = GetRealZoneText
local GetTime = GetTime
local InCombatLockdown = InCombatLockdown
local IsAltKeyDown = IsAltKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsInInstance = IsInInstance
local UnitIsGroupLeader = UnitIsGroupLeader
local IsInRaid = IsInRaid
local UnitIsGroupAssistant = UnitIsGroupAssistant
local IsShiftKeyDown = IsShiftKeyDown
local LibStub = LibStub
local SendChatMessage = SendChatMessage
local SetRaidTarget = SetRaidTarget
local UnitAffectingCombat = UnitAffectingCombat
local UnitCanAttack = UnitCanAttack
local UnitClass = UnitClass
local UnitCreatureType = UnitCreatureType
local UnitExists = UnitExists
local UnitGUID = UnitGUID
local UnitIsDead = UnitIsDead
local UnitIsPlayer = UnitIsPlayer
local UnitLevel = UnitLevel
local UnitName = UnitName
local UnitPlayerControlled = UnitPlayerControlled
local UnitSex = UnitSex
local GetInstanceInfo = GetInstanceInfo
local GetDifficultyInfo = GetDifficultyInfo
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local format = string.format
local ipairs = ipairs
local next = next
local pairs = pairs
local sort = table.sort
local strfind = strfind
local strlen = strlen
local sub = string.sub
local tinsert = tinsert
local tonumber = tonumber
local tostring = tostring
local type = type
-- Number of CC used for each crowd control method
local networkData = { }
-- class makeup of the party/raid
local raidClassList = {}
local raidClassNames = {}
-- Spell ID to CC id mapping (upvalued)
local spellIdToCCID
-- More upvalues
local mobdata
local db
-- New method data
local markedTargets = {} -- [mark] => data
local tankPriorityList = {} -- ordered array of known targets
local ccPriorityList = {} -- ordered array of known ccable targets
local assignedTargets = {} -- guid => data
local externalTargets = {} -- [mark] => data
local templateTargets = {} -- [mark] => data
local playerName
local cleu_parser = CreateFrame("Frame")
cleu_parser.OnEvent = function(frame, event, ...)
mod.HandleCombatEvent(mod,event,...)
end
cleu_parser:SetScript("OnEvent", cleu_parser.OnEvent)
local cleu_subevents = {
["SPELL_AURA_APPLIED"] = true,
["UNIT_DIED"] = true,
["PARTY_KILL"] = true,
}
local function ends_with(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
local function ends_with(str, ending)
return ending == "" or str:sub(-#ending) == ending
end
-- CC Classes, matches CC_LIST in Config.lua. Tank/kite has no classes specified for it
local CC_CLASS = {
false, "MAGE", "WARLOCK", "PRIEST", "DRUID", "HUNTER", false ,
"PRIEST", "WARLOCK", "ROGUE", "WARLOCK", "DRUID",
"DRUID", "PALADIN", "HUNTER", "WARLOCK", "PALADIN", "ROGUE",false,
"SHAMAN", "PALADIN"
}
local defaultConfigDB = {
profile = {
filterdead = false,
autolearncc = true,
acceptCCPrio = false,
acceptMobData = false,
acceptRaidMarks = false,
battleMarking = false,
honorMarks = false,
honorRaidMarks = true,
logLevel = 3,
mobDataBehavior = 1,
resetRaidIcons = true,
modifier = "ALT",
minTankTargets = 1,
noCombatRemark = true,
burnDownIsTank = false
}
}
local function SetNetworkData(cmd, data, misc1, misc2, misc3, misc4)
networkData.cmd = cmd
networkData.data = data
networkData.misc1 = misc1
networkData.misc2 = misc2
networkData.misc3 = misc3
networkData.misc4 = misc4
networkData.dbversion = MagicMarkerDB.version
end
local function SetExternalTarget(id, guid, uid, name, hash)
if id and id > 0 and id < 9 then
externalTargets[id].guid = guid
externalTargets[id].uid = uid
externalTargets[id].name = name
externalTargets[id].mark = guid and id or nil
externalTargets[id].hash = hash
end
end
local function SetTemplateTarget(id, name, network)
if id and id > 0 and id < 9 then
templateTargets[id].guid = name and UnitGUID(name) or nil
templateTargets[id].name = name
templateTargets[id].uid = name
templateTargets[id].mark = name and id or nil
if name then
SetExternalTarget(id)
for oid = 1, 8 do
-- We can only have the same template target once so clean it up
if oid ~= id and templateTargets[oid].name == name then
SetTemplateTarget(oid)
end
end
if not network then
SetNetworkData("MARKV2", name, id, "TMPL")
mod:SendUrgentMessage()
end
end
end
end
local function LowSetTarget(id, uid, val, ccid, guid)
if id and id > 0 and id < 9 then
markedTargets[id].guid = guid
markedTargets[id].uid = uid
markedTargets[id].ccid = ccid
markedTargets[id].value = val
end
end
local function GUIDToUID(guid)
local _, _, _, _, _, npc_id = strsplit("-",guid);
if npc_id == 0 then
return nil
end
return tostring(npc_id)
end
-- Returns [id, difficulty string, isHeroic]
function mod:GetDifficultyInfo()
if GetDifficultyInfo then
local _,instype, diffid, diffname = GetInstanceInfo()
if instype ~= "none" and diffid and diffid > 0 then
local name, _, heroic = GetDifficultyInfo(diffid)
-- Classic Era has GetDifficultyInfo but it returns nothing
if name then
return diffid, name, heroic
end
end
end
return 0, "Normal", false
end
-- Returns [GUID, UID, Name]
function mod:GetUnitID(unit)
local guid, uid
local unitName = UnitName(unit)
guid = UnitGUID(unit)
uid = GUIDToUID(guid)
return guid, uid or mod:SimplifyName(unitName), unitName
end
function mod:IsClassic()
return (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
end
function mod:IsBurningCrusadeClassic()
return (WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC)
end
function mod:IsWrathClassic()
return (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
end
function mod:OnInitialize()
-- Set up the config database
self.db = LibStub("AceDB-3.0"):New("MagicMarkerConfigDB", defaultConfigDB, "Default")
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileDeleted","OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
-- this is the mob database
MagicMarkerDB = MagicMarkerDB or { }
MagicMarkerDB.frameStatusTable = MagicMarkerDB.frameStatusTable or {}
MagicMarkerDB.unitCategoryMap = nil -- Delete old data, no way to convert since it's missing zone info
mobdata = MagicMarkerDB.mobdata or {}
MagicMarkerDB.mobdata = mobdata
db = self.db.profile
-- Buggy FuBar_MM caused these to be stored as strings
db.logLevel = tonumber(db.logLevel)
db.mobDataBehavior = tonumber(db.mobDataBehavior)
db.remarkDelay = nil -- no longer needed
self:UpgradeDatabase()
-- sets ccprio/raid target defaults
self:FixProfileDefaults()
-- This is moved to the profile
if MagicMarkerDB.targetdata then
db.targetdata = MagicMarkerDB.targetdata
MagicMarkerDB.targetdata = nil
end
self:SetLogLevel(db.logLevel)
self.commPrefix = "MagicMarker"
self.commPrefixRT = "MagicMarkerRT"
-- no longer used
MagicMarkerDB.debug = nil
MagicMarkerDB.logLevel = nil
for id = 0,9 do
markedTargets[id] = {}
externalTargets[id] = {}
templateTargets[id] = {}
end
spellIdToCCID = MagicComm.spellIdToCCID
end
function mod:OnEnable()
mod:SetupLDB()
playerName = UnitName("player")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA","ZoneChangedNewArea")
self:ZoneChangedNewArea()
self:GenerateOptions()
self:RegisterChatCommand("mmtmpl", function() mod:Print("This command is deprected. Use |cffdfa9cf/mm tmpl|r or |cffdfa9cf/magic tmpl|r instead.") end, false, true)
MagicComm:RegisterListener(self, "MM")
end
function mod:OnDisable()
MagicComm:UnregisterListener(self, "MM")
self:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
self:UnregisterChatCommand("magic")
self:DisableEvents()
end
function mod:OnMobdataReceive(zone, data, version, sender)
if version ~= MagicMarkerDB.version then
if self.hasTrace then self:trace("[Net] MagicMarkerDB version mismatch (got = %s, have %d).", tostring(version), MagicMarkerDB.version) end
return
end
if db.acceptMobData then
if self.hasDebug then self:debug("[Net] Received mob data for %s from %s.", data.name, sender) end
self:MergeZoneData(zone, data)
end
self:NotifyChange()
end
function mod:OnMobdataPartialReceive(data, version, sender)
if version ~= MagicMarkerDB.version then
if self.hasTrace then self:trace("[Net] MagicMarkerDB version mismatch (got = %s, have %d).", tostring(version), MagicMarkerDB.version) end
return
end
if db.acceptMobData then
if self.hasDebug then self:debug("[Net] Received partial mob database update from %s.", sender) end
for zone, zonedata in pairs(data) do
self:MergeZoneData(zone, zonedata, nil, true)
end
end
self:NotifyChange()
end
function mod:OnTargetReceive(data, version, sender)
if version ~= MagicMarkerDB.version then
if self.hasTrace then self:trace("[Net] MagicMarkerDB version mismatch (got = %s, have %d).", tostring(version), MagicMarkerDB.version) end
return
end
if db.acceptRaidMarks then
if self.hasDebug then self:debug("[Net] Received raid mark configuration from %s.", sender) end
db.targetdata = data
end
self:NotifyChange()
end
function mod:OnCCPrioReceive(data, version, sender)
if version ~= MagicMarkerDB.version then
if self.hasTrace then self:trace("[Net] MagicMarkerDB version mismatch (got = %s, have %d).", tostring(version), MagicMarkerDB.version) end
return
end
if db.acceptCCPrio then
if self.hasDebug then self:debug("[Net] Received crowd control prioritizations %s.", sender) end
db.ccprio = data
end
self:NotifyChange()
end
local function InsertUnitData(unitdata, hash)
for id, data in ipairs(hash) do
if data.guid == unitdata.guid then
hash[id] = unitdata
return
end
end
hash[#hash+1] = unitdata
end
function mod:OnCommUnmarkV2(guid, mark, sender)
local data = assignedTargets[guid]
local changed = mod:SmartMark_RemoveGUID(guid, mark, true)
local name = guid
if self.hasDebug then
name = (data and data.name) or name
if not sender then sender = "Unknown" end
end
if changed then
if self.hasDebug then self:debug("[Net:%s] Removing %s from %s.", sender, self:GetTargetName(mark), name) end
elseif self.hasTrace then
self:trace("[Net:%s] Already removed %s from %s.", sender, self:GetTargetName(mark), name)
end
end
local verRespMsg = "%s: %s revision %s"
function mod:OnVersionResponse(ver, major, minor, sender)
self:Print(format(verRespMsg, sender or "Unknown Sender", major or "Unknown", minor or "Unknown"))
end
function mod:QueryAddonVersions()
SetNetworkData("VCHECK")
self:SendUrgentMessage("GUILD")
self:SendUrgentMessage("RAID")
end
-- Queue data to be sent after modifying the configuration data
local queuedData = {}
local queuedDataTimer
function mod:QueueData_Add(zone, mob, hash)
if not queuedData[zone] then
queuedData[zone] = {}
end
queuedData[zone][mob] = hash
self:QueueData_Schedule()
if self.hasSpam then self:spam("Queued %s in zone %s for partial update.", hash.name, zone) end
end
function mod:QueueData_Schedule()
if queuedDataTimer then
self:CancelTimer(queuedDataTimer, true)
end
queuedDataTimer = self:ScheduleTimer("QueueData_Send", 5)
end
function mod:QueueData_Send()
if InCombatLockdown() then
self:QueueData_Schedule()
return
end
SetNetworkData("MOBDATA_PARTIAL", queuedData)
self:SendBulkMessage("RAID")
for id,data in pairs(queuedData) do
queuedData[id] = nil
end
end
-- This allows importing from the MagicMarker_Data addon
function mod:ImportData(data, version, reallyImport)
if MagicMarkerDB.importedVersion and MagicMarkerDB.importedVersion >= version then
return
end
if reallyImport then
for zone,zoneData in pairs(data) do
if mod.raids[zone] then
zoneData.isRaid = true
elseif zoneData.heroic and ends_with(zone, "Heroic") then
zone = gsub(zone, "Heroic", "")
elseif not zoneData.heroic and not ends_with(zone, "Normal") then
zone = zone .. "Normal"
end
self:MergeZoneData(zone, zoneData, true)
end
MagicMarkerDB.importedVersion = version
else
local popup = _G.StaticPopupDialogs
if type(popup) ~= "table" then popup = {} end
if type(popup["MMImportQuery"]) ~= "table" then
popup["MMImportQuery"] = {
text = L["MagicMarker_Data version newer than the previously imported data. Do you want to import it?"],
button1 = L["Yes"],
button2 = L["No"],
whileDead = 1,
hideOnEscape = 1,
timeout = 0,
OnAccept = function() mod:ImportData(data, version, true) end
}
end
StaticPopup_Show("MMImportQuery")
end
end
function mod:MergeCCMethods(dest, source)
if not source or not source.ccopt or not dest then return end
if not dest.ccopt then
dest.ccopt = source.ccopt
return
end
for id in pairs(source.ccopt) do
dest.ccopt[id] = true
end
end
function mod:MergeZoneData(zone, zoneData, override, partial)
local localData = mobdata[zone]
local localMob, simpleName
if self.hasDebug then self:debug("Merging data for zone %s [%s].", zoneData.name or zone, zone) end
if not partial and (not localData or (db.mobDataBehavior == 3 and not override)) then -- replace
if self.hasTrace then self:trace("Replacing local data with networked data.") end
mobdata[zone] = zoneData
elseif localData then
if zoneData.isRaid then
localData.isRaid = zoneData.isRaid
end
localData = localData.mobs
if zoneData.mobs then
zoneData = zoneData.mobs
end
for mob, data in pairs(zoneData) do
-- Enable me for 2.4 to handle numeric ID keys
simpleName = self:SimplifyName(mob.name)
if simpleName ~= mob then
-- mob is a 2.4 numeric ID
if localData[simpleName] then
localData[mob] = localData[simpleName]
localData[simpleName] = nil
end
else
for lm, ld in pairs(localData) do
simpleName = self:SimplifyName(ld.name)
if simpleName == mob then
-- We found a numeric id locally, use that instead
mob = lm
break
end
end
end
if not localData[mob] or (db.mobDataBehavior == 2 and not override) or
(db.mobDataBehavior == 3 and partial) then
if self.hasTrace then self:trace("Replacing entry for %s from merged data.", data.name) end
local oldData = localData[mob]
localData[mob] = data
self:MergeCCMethods(data, oldData)
else
if self.hasTrace then self:trace("Adding additional crowd control methods for %s from merged data.", data.name) end
self:MergeCCMethods(localData[mob], data)
end
end
end
if mobdata[zone] then
self:AddZoneConfig(zone, mobdata[zone])
end
end
function mod:BroadcastZoneData(zone)
zone = mod:SimplifyName(zone)
if mobdata[zone] then
SetNetworkData("MOBDATA", mobdata[zone], zone)
self:SendBulkMessage()
end
end
function mod:BroadcastAllZones()
for zone, data in pairs(mobdata) do
SetNetworkData("MOBDATA", data, zone)
self:SendBulkMessage()
end
end
function mod:BroadcastRaidTargets()
if self.hasTrace then self:trace("Broadcast raid target data to the raid.") end
SetNetworkData("TARGETS", db.targetdata)
self:SendBulkMessage()
end
function mod:BroadcastCCPriorities()
if self.hasTrace then self:trace("Broadcast cc priority data to the raid.") end
SetNetworkData("CCPRIO", db.ccprio)
self:SendBulkMessage()
end
function mod:HandleCombatEvent()
local timestamp, event, hideCaster, sourceGUID, sourceName, sourceFlags,
sourceRaidFlags, guid, name, destflags, destRaidFlags, spellid, spellname = CombatLogGetCurrentEventInfo()
-- bail out early if we don't care for the subevent
if not cleu_subevents[event] then return end
if event == "UNIT_DIED" or event == "PARTY_KILL" then
local data = assignedTargets[guid]
if data then
if self.hasDebug then self:debug("Releasing %s from dead mob %s.", self:GetTargetName(data.mark), name) end
mod:SmartMark_RemoveGUID(guid, data.mark, false, true)
end
-- Special Thaddius hack; Stalagg and Feugen never dies, so unmark if we detect Thaddius death
if mod.unmarkThaddiusAdds and GUIDToUID(guid) == "15928" then
mod.unmarkThaddiusAdds = nil
for id,mobdata in pairs(tankPriorityList) do
local uid = GUIDToUID(mobdata.guid)
if uid == "15929" or uid == "15930" then
mod:SmartMark_RemoveGUID(mobdata.guid, mobdata.mark, false, true)
end
end
end
return
end
if db.autolearncc and event == "SPELL_AURA_APPLIED" then
local ccid = spellIdToCCID[spellid]
if not ccid then return end
local uid = GUIDToUID(guid)
if not uid then return end
local hash, zone = self:GetUnitHash(uid, true)
if hash then
if not hash.ccopt then
hash.ccopt = {}
end
local addcc = function(newccid)
if not hash.ccopt[newccid] then
hash.ccopt[newccid] = true
self:QueueData_Add(zone, hash)
if self.hasDebug then
self:debug("Learned that %s can be CC'd with %s",
hash.name, spellname)
end
end
end
if type(ccid) == "table" then
for id = 1,#ccid do
addcc(ccid[id])
end
elseif type(ccid) == "number" then
addcc(ccid)
end
self:NotifyChange()
end
end
end
do
local notPvPInstance = { raid = true, party = true }
function mod:ZoneChangedNewArea()
local zone,name = self:GetZoneName()
if zone == nil or zone == "" then
self:ScheduleTimer(self.ZoneChangedNewArea,5,self)
else
local zoneData = mobdata[zone]
local enableLogging
if not zoneData or zoneData.mm == nil then
local inInstance, type = IsInInstance()
enableLogging = inInstance and notPvPInstance[type]
else
enableLogging = zoneData.mm
end
if enableLogging then
self:EnableEvents(zoneData and zoneData.targetMark)
else
self:DisableEvents()
end
end
end
end
function mod:RegisterMMFu(plugin)
if self.hasWarn then
self:warn("Please uninstall FuBar_mod. It does no longer work with this version of Magic Marker. Instead there's a built-in LDB data provider.")
end
end
function mod:EnableEvents(markOnTarget)
if not self.addonEnabled then
self.addonEnabled = true
mod:UpdateLDB()
if self.hasInfo then self:info(L["Magic Marker enabled."]) end
if markOnTarget then
self:RegisterEvent("PLAYER_TARGET_CHANGED", "SmartMark_MarkUnit", "target")
end
self:RegisterEvent("UPDATE_MOUSEOVER_UNIT", "SmartMark_MarkUnit", "mouseover")
self:RegisterEvent("PLAYER_REGEN_ENABLED", "ScheduleGroupScan")
self:RegisterEvent("GROUP_ROSTER_UPDATE", "ScheduleGroupScan")
cleu_parser:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:ScheduleGroupScan()
end
end
function mod:DisableEvents()
if self.addonEnabled then
self.addonEnabled = false
mod:UpdateLDB()
if self.hasInfo then self:info(L["Magic Marker disabled."]) end
self:UnregisterEvent("PLAYER_REGEN_ENABLED") -- rescan group every time we exit combat.
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
self:UnregisterEvent("UPDATE_MOUSEOVER_UNIT")
self:UnregisterEvent("RAID_ROSTER_UPDATE")
self:UnregisterEvent("PARTY_MEMBERS_CHANGED")
cleu_parser:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
end
function mod:ToggleMagicMarker()
if self.addonEnabled then
self:DisableEvents()
else
self:EnableEvents()
end
end
local party_idx = { "party1", "party2", "party3", "party4" }
function mod:MarkRaidTargets()
if self.hasDebug then self:debug("Making all targets of the raid.") end
self:IterateGroup(function (self, unit) self:SmartMark_MarkUnit(unit.."target") end, true)
end
local groupScanTimer
function mod:LogClassInformation(unitName, class)
if not class then _,class = UnitClass(unitName) end
if class then
if self.hasTrace then self:trace(" found %s => %s.", unitName, class) end
raidClassList[class] = (raidClassList[class] or 0) + 1
class = class:upper()
raidClassNames[class] = raidClassNames[class] or {}
raidClassNames[class][#raidClassNames[class] +1] = unitName
elseif self.hasWarn then
self:warn(L["Unable to determine the class for %s."], unitName)
end
end
function mod:ScanGroupMembers()
if raidClassList.FAKE then return end
for id,_ in pairs(raidClassList) do raidClassList[id] = 0 end
for id,_ in pairs(raidClassNames) do
for num, _ in ipairs(raidClassNames[id]) do
raidClassNames[id][num] = nil
end
end
if UnitClass("player") then
if self.hasTrace then self:trace("Rescanning raid/party member classes.") end
self:IterateGroup(self.LogClassInformation)
end
end
function mod:CacheRaidMarkForUnit(unit)
local id = GetRaidTargetIndex(unit)
if id then
MagicMarkerDB.raidMarkCache[unit] = id
if self.hasDebug then self:debug("Cached "..id.." for "..unit); end
end
end
function mod:CacheRaidMarks()
MagicMarkerDB.raidMarkCache = {}
if self.hasDebug then self:debug("Caching raid / party marks.") end
self:IterateGroup(self.CacheRaidMarkForUnit)
end
function mod:MarkRaidFromCache()
if not MagicMarkerDB.raidMarkCache then
return
end
for unit,id in pairs(MagicMarkerDB.raidMarkCache) do
if markedTargets[id].uid and markedTargets[id].uid ~= unit then
mod:SmartMark_RemoveGUID(markedTargets[id].guid, nil, nil, true)
end
SetTemplateTarget(id, unit)
self:SetRaidTarget(unit, id)
end
self:SmartMark_RecalculateMarks()
end
function mod:IterateGroup(callback, useID, ...)
local id, name
if self.hasSpam then self:spam("Iterating group...") end
if IsInRaid() then
local maxgrp, class, groupid, online, dead
local playerName = UnitName("player")
local zoneID, zone = self:GetZoneName()
maxgrp = self.zoneGroupNum[zoneID]
for id = 1,GetNumGroupMembers() do
name, _, groupid, _, _, class, _, online, dead = GetRaidRosterInfo(id)
if name == playerName or (online and (not db.filterdead or not dead) and (not maxgrp or groupid <= maxgrp)) then
callback(self, (useID and "raid"..id) or name, class, ...)
end
end
else
if GetNumGroupMembers() > 0 then
for id = 1,GetNumGroupMembers()-1 do
callback(self, (useID and party_idx[id]) or UnitName(party_idx[id]), nil, ...)
end
end
callback(self, (useID and "player") or UnitName("player"), nil, ...);
end
end
function mod:MarkRaidFromTemplate(template)
if self.hasDebug then self:debug("Marking from template: "..template) end
local usedMarks = {}
if template == "arch" or template == "archimonde" then
self:IterateGroup(mod.MarkTemplates.decursers.func, false, usedMarks)
self:IterateGroup(mod.MarkTemplates.shamans.func, false, usedMarks)
elseif mod.MarkTemplates[template] and mod.MarkTemplates[template].func then
self:IterateGroup(mod.MarkTemplates[template].func, false, usedMarks)
else
if self.hasWarn then self:warn(L["Unknown raid template: %s"], template) end
end
if next(usedMarks) then
for id in pairs(usedMarks) do
if markedTargets[id].uid and markedTargets[id].uid ~= usedMarks[id] then
mod:SmartMark_RemoveGUID(markedTargets[id].guid, nil, nil, true)
end
SetTemplateTarget(id, usedMarks[id])
end
self:SmartMark_RecalculateMarks()
end
end
function mod:ScheduleGroupScan()
if groupScanTimer then self:CancelTimer(groupScanTimer, true) end
groupScanTimer = self:ScheduleTimer("ScanGroupMembers", 5)
end
-- Return whether a target is eligable for marking
local function UnitIsEligable (unit)
local type = UnitCreatureType(unit)
return UnitExists(unit)
and (UnitCanAttack("player", unit) or UnitIsEnemy("player", unit))
and not UnitIsDead(unit)
and type ~= "Critter" and type ~= "Totem"
and not UnitPlayerControlled(unit) and not UnitIsPlayer(unit)
end
-- Return the hash for the unit of NIL if it's not available
function mod:GetUnitHash(uid, currentZone)
if not uid then return end
if currentZone then
local zone = mod:GetZoneName()
local tmpHash = mobdata[zone]
if tmpHash then
return tmpHash.mobs[uid], zone
end
end
for zone, data in pairs(mobdata) do
if data.mobs[uid] then
return data.mobs[uid], zone
end
end
end
local unitValueCache = {}
function mod:UnitValue(uid, hash, modifier)
-- if unitValueCache[unit] then return unitValueCache[unit] end
local unitData = hash or self:GetUnitHash(uid, true)
local value, ccvalue = 0, 0
if not modifier then modifier = 0 end
if unitData then
value = 10-unitData.priority
if value > 0 then
value = value * 2 + 2-unitData.category -- Tank > CC
end
if unitData.ccpriority == 6 then
ccvalue = value
else
ccvalue = 10-unitData.ccpriority
if ccvalue > 0 then
ccvalue = ccvalue * 2 -- Tank > CC
end
end
end
if self.hasTrace then self:trace("Unit Value for %s = [%d, %d]", uid, value, ccvalue) end
-- unitValueCache[unit] = value
return value+modifier, ccvalue+modifier, unitData
end
local function IsModifierPressed()
if GetBindingKey("MAGICMARKSMARTMARK") then
return mod.markKeyDown
elseif db.modifier == "ALT" then
return IsAltKeyDown()
elseif db.modifier == "SHIFT" then
return IsShiftKeyDown()
elseif db.modifier == "CTRL" then
return IsControlKeyDown()
end
end
local function SmartMark_TankSorter(unit1, unit2)
if unit1.value == unit2.value then
return unit1.guid < unit2.guid -- ensure stable sort
else
return (unit1.value or 0) > (unit2.value or 0)
end
end
local function SmartMark_CCSorter(unit1, unit2)
if unit1.ccval == unit2.ccval then
return (unit1.guid or "") < (unit2.guid or "") -- ensure stable sort
else
return ( unit1.ccval or 0) > (unit2.ccval or 0) -- should never happen.. but it does!?
end
end
function mod:OnAssignData(targets, sender)
if not sender then sender = "Unknown" end
if self.hasDebug then self:debug("[Net:%s] Received assignment data.", sender) end
-- for id in pairs(tankPriorityList) do
-- tankPriorityList[id] = nil
-- ccPriorityList[id] = nil
-- end
for guid,data in pairs(targets) do
if not data.hash or not data.ccval then
if self.hasWarn then self:warn("[Net:%s] Assignment data is not compatible. Ignoring.", sender) end
return
end
data.guid = guid
-- Set the right "value" parameter
data.val = nil
data.sender = sender
InsertUnitData(data, tankPriorityList)
if data.hash.ccopt then
InsertUnitData(data, ccPriorityList)
end
end
sort(tankPriorityList, SmartMark_TankSorter)
sort(ccPriorityList, SmartMark_CCSorter)
self:SmartMark_RecalculateMarks(true)
self:UpdateLDBCount()
end
function mod:IsValidMarker()
return UnitIsGroupLeader("player") or UnitIsGroupAssistant("player") or not IsInRaid()
end
-- This is solely for debugging purposes
-- i.e /dump mod.smdata
mod.smdata = {
tank = tankPriorityList,
cc = ccPriorityList,
assigned = assignedTargets,
external = externalTargets,
tmpl = templateTargets,
marked = markedTargets
}
local valueModifier = 0.99
local function SmartMark_FindUnusedMark(list, used)
for _,id in pairs(list) do
if not used[id] then
used[id] = true
return id
end
end
end
-- recalculate mark assignments based on the priority lists
do
local ccUsed = {}
local marksUsed = {}
local categoryMarkCache = {}
local newCcCount = {}
function mod:OnCommResetV2()
if self.hasDebug then
self:debug("[Net] Raid cache clear received.")
end
valueModifier = 0.99
for id in pairs(ccUsed) do ccUsed[id] = nil end
for id in pairs(newCcCount) do newCcCount[id] = nil end
for id in pairs(assignedTargets) do assignedTargets[id] = nil end
for id in pairs(categoryMarkCache) do categoryMarkCache[id] = nil end
for id in pairs(tankPriorityList) do tankPriorityList[id] = nil end
for id in pairs(ccPriorityList) do ccPriorityList[id] = nil end
for id = 1,8 do
LowSetTarget(id)
SetExternalTarget(id)
SetTemplateTarget(id)
marksUsed[id] = nil
end
mod:SetTargetCount(0, 0)
end
function mod:SmartMark_RecalculateMarks(network)
local id, data, ccount
local inCombat = InCombatLockdown()
local canReprioritize = not inCombat or not next(assignedTargets)
-- empty data from the previous run
for id in pairs(categoryMarkCache) do categoryMarkCache[id] = nil end
for id in pairs(markedTargets) do LowSetTarget(id) end
if canReprioritize then
-- reprioritize mid-combat
for id in pairs(ccUsed) do ccUsed[id] = nil end
for id in pairs(newCcCount) do newCcCount[id] = nil end
for id in pairs(marksUsed) do marksUsed[id] = nil end
for id in pairs(assignedTargets) do assignedTargets[id] = nil end
end