This repository was archived by the owner on Feb 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLordKator_TrinityMagic.lua
More file actions
executable file
·915 lines (749 loc) · 31 KB
/
Copy pathLordKator_TrinityMagic.lua
File metadata and controls
executable file
·915 lines (749 loc) · 31 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
--[[
--
-- LordKator_TrinityMagic - Lord Kator's Trinity Core Magic
--
-- Author: Lord Kator <kator@karlbunch.com>
--
-- Created: Fri Nov 25 10:29:09 EST 2016
]]
-- TODO:
-- Support ctrl, shift, alt click being different commands
-- Default commands by unit: player, party, target(not player/party), npc
--
SLASH_LORDKATOR_TRINITYMAGIC1 = "/lktm"
SLASH_LORDKATOR_TRINITYMAGIC2 = "/magic"
SLASH_LORDKATOR_TRINITYMAGIC_ONALL1 = "/onall"
SLASH_LORDKATOR_TRINITYMAGIC_GIVEME1 = "/giveme"
BINDING_HEADER_LKTMHEADER = "Lord Kator's Trinity Magic"
BINDING_NAME_LKTMBINDING1 = "Open Chat with DOT"
local kPrefDefaultCommand = 'ctrl-command1'
local kPrefDefaultCommandHistory = 'ctrl-command1-history'
local kPrefTaxiHistory = "taxiHistory"
local kPrefSavedNPClist = "savedNPClist"
local kPrefUserWaypoints = "userWaypoints"
local kPrefSessionTargetDPS = "targetDPS"
LKTM = {
version = "0.0.4",
debugLevel = 8,
globalDefaults = {
[kPrefDefaultCommand] = "should use " .. SLASH_LORDKATOR_TRINITYMAGIC1 .. ' [setcmd|prompt] first!',
[kPrefDefaultCommandHistory] = {},
},
characterDefaults = {
[kPrefTaxiHistory] = {},
[kPrefSavedNPClist] = {},
[kPrefUserWaypoints] = {},
},
sessionDefaults = {
targetDPS = 0,
},
eventHandlers = {
["PLAYER_ENTERING_WORLD"] = function()
LKTM:SetupPostClicks()
end,
["PARTY_MEMBERS_CHANGED"] = function()
LKTM:SetupPostClicks()
end,
["VARIABLES_LOADED"] = function()
LKTM:ConvertPreferences()
-- Hook Carbonite Map so Goto takes you directly to the location
LKTM.carbonite_STAC = Nx.Map.STAC
if LKTM.carbonite_STAC then
Nx.Map.STAC = function(self)
local wx,wy=self:FPTWP(self.CFX,self.CFY)
local zx,zy=self:GZP(self.MaI,wx,wy)
local zoneId = LKTM_Data:findAreaId(self.COTF)
if zoneId then
pcall(function() NxMap1:Hide() end)
LKTM:CommandOnUnit("player", format(".go zonexy %.4f %.4f %s\n", zx, zy, zoneId))
else
LKTM:Message(0, "Sorry can't map [" .. self.COTF .. "] to a zoneId")
end
end
local menuText = "Goto"
local ok, _ = pcall(function()
Nx.Map.Map1[1].Men.Ite1[1].Tex = "Teleport..." -- Change "Goto" -> "Teleport..."
table.remove(Nx.Map.Map1[1].Men.Ite1, 2) -- Delete "Clear Goto" entry
end)
if ok then
menuText = "Teleport..."
end
LKTM:Message(0, "Hooked Carbonite map menu, right click the map and select " .. menuText)
end
end,
["COMBAT_LOG_EVENT_UNFILTERED"] = function(frame, event, ...)
local _,_ = frame, event
-- SPELL: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
-- SPELL: local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellId, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
-- RANGE: local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellId, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
-- SWING: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-- SWING: local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
-- ENVIR: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
-- ENVIR: local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, environmentalType, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
--
if select(3, ...) ~= UnitGUID("player") then
return
end
local eventtype = select(2, ...)
if string.sub(eventtype, -7) ~= "_DAMAGE" then
return
end
--[[
if true then
local timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellId, spellName, spellSchool, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
local environmentalType = ""
if eventtype == "SWING_DAMAGE" then
timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
elseif eventtype == "ENVIRONMENTAL_DAMAGE" then
timestamp, eventtype, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, environmentalType, amount, overkill, school, resisted, blocked, absorbed, critical, glancing, crushing = ...
end
print("timestamp:", timestamp, "eventtype:", eventtype, "srcGUID:", srcGUID, "srcName:", srcName, "srcFlags:", srcFlags, "dstGUID:", dstGUID, "dstName:", dstName, "dstFlags:", dstFlags, "environmentalType:", environmentalType, "spellId:", spellId, "spellName:", spellName, "spellSchool:", spellSchool, "amount:", amount, "overkill:", overkill, "school:", school, "resisted:", resisted, "blocked:", blocked, "absorbed:", absorbed, "critical:", critical, "glancing:", glancing, "crushing:", crushing)
end
]]
local timestamp, amount, overkill = select(1, ...), select(12, ...), select(13, ...)
if eventtype == "SWING_DAMAGE" then
amount, overkill = select(9, ...), select(10, ...)
elseif eventtype == "ENVIRONMENTAL_DAMAGE" then
amount, overkill = select(10, ...), select(11, ...)
end
if LKTM.combat_start == nil then
LKTM.combat_start = timestamp
LKTM.combat_total_damage = 0
LKTM.combat_dps = 0
LKTM.dpsBoostTotal = 0.0
LKTM.dpsBoostLastTime = 0
LKTM.dpsBoostLastAmount = 0
LKTM:Message(0, "Combat start, DPS Target = " .. LKTM:GetTargetDPS())
end
LKTM.combat_total_damage = LKTM.combat_total_damage + (amount - overkill)
local combat_seconds = timestamp - LKTM.combat_start
if combat_seconds > 0 then
LKTM.combat_dps = LKTM.combat_total_damage / combat_seconds
if (timestamp - LKTM.dpsBoostLastTime) >= 1.0 and amount ~= LKTM.dpsBoostLastAmount then
local dpsTarget = LKTM:GetTargetDPS()
local dpsBoostAmount = math.floor((combat_seconds * dpsTarget) - LKTM.combat_total_damage)
if dpsBoostAmount > 50 and not UnitIsFriend("player", "target") and UnitChannelInfo("player") == nil then
local cmd = '.damage ' .. dpsBoostAmount
LKTM:CommandOnUnit("target", cmd, true)
LKTM:Message(0, "DPS Boost>> ++" .. dpsBoostAmount .. " hp, target: " .. dpsTarget .. " current: " .. math.floor(LKTM.combat_dps * 10.0)/10.0)
LKTM.dpsBoostLastTime = timestamp
LKTM.dpsBoostLastAmount = dpsBoostAmount
LKTM.dpsBoostTotal = LKTM.dpsBoostTotal + LKTM.dpsBoostLastAmount
end
end
end
--[[
LKTM:Message(0,
amount .. " dmg, (" .. overkill .. " ok) DPS: " ..
math.floor(LKTM.combat_dps * 10.0)/10.0 .. " totalDamage: " ..
LKTM.combat_total_damage .. " (" ..
LKTM.dpsBoostTotal .. " boost) " ..
math.floor(combat_seconds) .. " second(s)"
)
]]
end,
["PLAYER_REGEN_ENABLED"] = function()
LKTM:Message(0, "Combat end: " .. (LKTM.dpsBoostTotal or 0) .. " hit points added, DPS:" .. math.floor((LKTM.combat_dps or 0) * 10.0) / 10.0)
LKTM.dpsBoostAmount = nil
LKTM.combat_start = nil
end,
},
slashCommands = {
["help"] = {
usage = "- List available sub-commands to " .. SLASH_LORDKATOR_TRINITYMAGIC1 .. " or " .. SLASH_LORDKATOR_TRINITYMAGIC2 .. " chat commands",
cmd = function()
LKTM:Message(0, "HELP: Available " .. SLASH_LORDKATOR_TRINITYMAGIC1 .. " or " .. SLASH_LORDKATOR_TRINITYMAGIC2 .. " commands:")
local cmds = { }
for cmd, _ in pairs(LKTM.slashCommands) do
table.insert(cmds, cmd)
end
table.sort(cmds)
for _, cmd in pairs(cmds) do
LKTM:Message(0, "HELP: " .. SLASH_LORDKATOR_TRINITYMAGIC1 .. " " .. cmd .. " " .. (LKTM.slashCommands[cmd].usage or ""))
end
end
},
["debug"] = {
usage = "{level} - Set debug level from 0 (none) to 9 (most verbose)",
cmd = function(args)
LKTM:Message(0, string.format("CMD: [%s] ARGS: [%s]", "debug", args))
if args == nil or args == "" then
LKTM.debugLevel = LKTM.debugLevel > 0 and 0 or 9
else
LKTM:Message(0, "set to " .. args)
LKTM.debugLevel = tonumber(args)
end
LKTM:Message(0, string.format("debugLevel = %d", LKTM.debugLevel))
end
},
["version"] = {
usage = "- Show currently running version",
cmd = function() LKTM:Message(0, "Version " .. LKTM.version) end
},
["setcmd"] = {
usage = "- set the command for a macro run",
cmd = function(args)
if args == nil or args == "" then
LKTM:Message(0, "Please specify a command to run.")
return
end
local cmd = args
if string.sub(cmd, 1, 1) ~= '.' then
cmd = '.' .. cmd
end
LKTM:SetDefaultCommand(cmd)
end
},
["prompt"] = {
usage = "- set the command for a macro run",
cmd = function()
LKTM:PromptForCommand()
end
},
["do"] = {
usage = "- execute cmd",
cmd = function()
LKTM:DefaultCommandOnUnit("target", nil)
end
},
["dps"] = {
usage = "- Target dps for combat",
cmd = function(args)
if args == nil or args == "" then
LKTM:Message(0, "Please specify a target dps amount.")
return
end
local newTarget = tonumber(args)
if newTarget == nil or newTarget < 0 then
LKTM:Message(0, "Please specify a target dps amount of 0 or greater.")
return
end
LKTM:SetTargetDPS(args)
end
},
},
}
function LKTM:Message(level, msg, whisperTo, whisperMsg)
if level > LKTM.debugLevel then
return
end
if msg then
local displayMsg, _ = msg:gsub("\n$","");
(LKTM:GetActiveChatFrame()):AddMessage(string.format("%s =LKTM= %s", date("%H:%M:%S"), displayMsg), 1, 0, 1)
end
if whisperTo and (whisperMsg or msg) then
SendChatMessage("=LKTM=: " .. (whisperMsg or msg), "WHISPER", GetDefaultLanguage("player"), whisperTo)
end
end
function LKTM:GetActiveChatFrame()
for i = 1,NUM_CHAT_WINDOWS do
local name = "ChatFrame"..i
if _G[name]:IsShown() then
return _G[name]
end
end
return DEFAULT_CHAT_FRAME
end
function LKTM:UnitFramePostClick(frame, unit, button)
if not IsControlKeyDown() then
return
end
if button == "LeftButton" then
LKTM:DefaultCommandOnUnit("target", button)
return
end
if button == "RightButton" then
CloseDropDownMenus()
LKTM:Message(9, "Show LKTM Menu for " .. unit)
LKTMM:Show(frame, unit)
return
end
end
function LKTM:SetupPostClicks()
PlayerFrame:SetScript("PostClick", function(frame, button) LKTM:UnitFramePostClick(frame, "player", button) end)
PlayerFrame:SetAttribute("ctrl-type2", "target");
TargetFrame:SetScript("PostClick", function(frame, button) LKTM:UnitFramePostClick(frame, "target", button) end)
TargetFrame:SetAttribute("ctrl-type2", "target");
for i=1, MAX_PARTY_MEMBERS, 1 do
local partyMemberFrame = _G["PartyMemberFrame"..i]
if partyMemberFrame then
partyMemberFrame:SetScript("PostClick", function(frame, button) LKTM:UnitFramePostClick(frame, "party"..i, button) end)
partyMemberFrame:SetAttribute("ctrl-type2", "target");
end
end
end
function LKTM:SetTargetDPS(newTargetDPS)
local tdps = tonumber(newTargetDPS)
if tdps and tdps >= 0 then
LKTM:Message(0, "New target DPS [" .. tdps .. "]")
LKTM:SetSessionPreference(kPrefSessionTargetDPS, tdps)
end
end
function LKTM:GetTargetDPS()
return LKTM:GetSessionPreference(kPrefSessionTargetDPS) or ""
end
function LKTM:SetDefaultCommand(newCommand)
local history = LKTM:GetCommandHistory()
if history[newCommand] then
history[newCommand] = history[newCommand] + 1
else
history[newCommand] = 1
end
LKTM:SetGlobalPreference(kPrefDefaultCommandHistory, history)
LKTM:SetGlobalPreference(kPrefDefaultCommand, newCommand)
end
function LKTM:DefaultCommandOnUnit(unit, button) -- luacheck: no unused args
LKTM:CommandOnUnit(unit, LKTM:GetGlobalPreference(kPrefDefaultCommand))
end
function LKTM:GetCommandHistory()
local key = kPrefDefaultCommandHistory
local list = LKTM:GetGlobalPreference(key)
local count = 0
if list == nil then
list = {}
LKTM:SetGlobalPreference(key, list)
end
for _,_ in pairs(list) do
count = count + 1
end
return list, count
end
function LKTM:ClearCommandHistory()
local key = kPrefDefaultCommandHistory
local list = {}
LKTM:SetGlobalPreference(key, list)
end
function LKTM:GetTaxiHistory()
local key = kPrefTaxiHistory
local list = LKTM:GetCharacterPreference(key)
if list == nil then
list = {}
LKTM:SetCharacterPreference(key, list)
end
return list
end
function LKTM:GetSavedNPClist()
local key = kPrefSavedNPClist
local list = LKTM:GetCharacterPreference(key)
if list == nil then
list = {}
LKTM:SetCharacterPreference(key, list)
end
return list
end
function LKTM:GotoTaxiNode(nodeEntry)
local taxiNodeId = nodeEntry.arg1
LKTM:CommandOnUnit("player", ".go taxinode " .. taxiNodeId)
local history = LKTM:GetTaxiHistory()
if history[taxiNodeId] then
history[taxiNodeId].count = history[taxiNodeId].count + 1
else
history[taxiNodeId] = {
count = 1,
id = nodeEntry.arg1,
text = nodeEntry.toolTipTitle or nodeEntry.value,
}
end
LKTM:SetCharacterPreference(kPrefTaxiHistory, history)
end
function LKTM:CommandOnUnit(unit, command, quiet)
local displayCmd, _ = command:gsub("\n$", "");
if not quiet then
LKTM:Message(0, "Run Command: [" .. displayCmd .. "] on " .. UnitName(unit))
end
if unit ~= "target" and UnitIsPlayer(unit) then
command = command .. " " .. UnitName(unit)
end
-- Whispering to ourselves allows us to send commands even when the player is dead
SendChatMessage(command, "whisper", nil, UnitName("player"))
end
function LKTM:PromptForCommand()
StaticPopup_Show("LKTM_PromptCmd")
end
function LKTM:PromptForTargetDPS()
StaticPopup_Show("LKTM_PromptTargetDPS")
end
-- --------------------- --
-- Preferences Functions --
-- --------------------- --
function LKTM:IsGlobalPreferenceSet(key)
if LordKator_TrinityMagic_Prefs_Global and LordKator_TrinityMagic_Prefs_Global[key] then
return 1
end
return nil
end
function LKTM:GetGlobalPreference(key)
if LordKator_TrinityMagic_Prefs_Global then
return LordKator_TrinityMagic_Prefs_Global[key] or LKTM.globalDefaults[key]
else
return LKTM.globalDefaults[key]
end
end
function LKTM:SetGlobalPreference(key, value)
local oldValue = LKTM:GetGlobalPreference(key)
if LordKator_TrinityMagic_Prefs_Global == nil then
LordKator_TrinityMagic_Prefs_Global = { _preferencesVersion = 2 }
end
LordKator_TrinityMagic_Prefs_Global[key] = value
return value, oldValue
end
function LKTM:ConvertPreferences()
if LordKator_TrinityMagic_Prefs_Global == nil then
LordKator_TrinityMagic_Prefs_Global = { _preferencesVersion = 2 }
return
end
if LordKator_TrinityMagic_Prefs_Global and LordKator_TrinityMagic_Prefs_Global["_preferencesVersion"] >= 2 then
return
end
if LordKator_TrinityMagic_Prefs_Global["_preferencesVersion"] == 1 then
-- Version 1 to 2 - Move some global settings to the character
LordKator_TrinityMagic_Prefs_Character = { _preferencesVersion = 2 }
for _, key in pairs({ kPrefTaxiHistory, kPrefSavedNPClist, kPrefUserWaypoints }) do
if LordKator_TrinityMagic_Prefs_Global[key] then
LordKator_TrinityMagic_Prefs_Character[key] = LordKator_TrinityMagic_Prefs_Global[key]
LordKator_TrinityMagic_Prefs_Global[key] = nil
end
end
LordKator_TrinityMagic_Prefs_Global["_preferencesVersion"] = 2
LKTM:Message(0, "=INFO=: Converted preferences to version 2")
end
end
function LKTM:IsCharacterPreferenceSet(key)
if LordKator_TrinityMagic_Prefs_Character and LordKator_TrinityMagic_Prefs_Character[key] then
return 1
end
return nil
end
function LKTM:GetCharacterPreference(key)
if LordKator_TrinityMagic_Prefs_Character then
return LordKator_TrinityMagic_Prefs_Character[key] or LKTM.characterDefaults[key]
else
return LKTM.characterDefaults[key]
end
end
function LKTM:SetCharacterPreference(key, value)
local oldValue = LKTM:GetCharacterPreference(key)
if LordKator_TrinityMagic_Prefs_Character == nil then
LordKator_TrinityMagic_Prefs_Character = { _preferencesVersion = 2 }
end
LordKator_TrinityMagic_Prefs_Character[key] = value
return value, oldValue
end
function LKTM:GetSessionPreference(key)
if LKTM.sessionDefaults[key] then
return LKTM.sessionDefaults[key]
end
return nil
end
function LKTM:SetSessionPreference(key, value)
local oldValue = LKTM:GetSessionPreference(key)
LKTM.sessionDefaults[key] = value
return value, oldValue
end
-- User waypoint functions
function LKTM:UserWaypointNew(note, specificKey)
local wp = {}
local mx, my = GetPlayerMapPosition("player")
wp.key = "waypoint-" .. (specificKey or string.format("%X", 2^31*random()))
wp.note = note
wp.zone = {
x = mx * 100.0,
y = my * 100.0,
zoneId = LKTM_Data:findAreaId(GetZoneText()),
}
LKTM:UserWaypointFormatName(wp)
local wpList = LKTM:GetCharacterPreference(kPrefUserWaypoints)
wpList[wp.key] = wp
-- luacheck: no unused args
LKTM_Query:getGPS("", wp, function(status, gps, twp) LKTM:UserWaypointSetWithGPS(twp, gps) end)
return wp
end
function LKTM:UserWaypointFromHandle(wpHandle)
local wpList = LKTM:UserWaypointGetList()
local wpKey = type(wpHandle) == "string" and wpHandle or wpHandle.key
local wp = wpList[wpKey]
if wp == nil then
wp = LKTM:UserWaypointNew()
wpList[wpKey] = wp
end
return wp
end
function LKTM:UserWaypointDelete(wpHandle)
local wp = LKTM:UserWaypointFromHandle(wpHandle)
local wpList = LKTM:UserWaypointGetList()
if wpList[wp.key] then
wpList[wp.key] = nil
end
end
function LKTM:UserWaypointGetList()
local wpList = LKTM:GetCharacterPreference(kPrefUserWaypoints)
if wpList == nil then
wpList = {}
LKTM:SetCharacterPreference(kPrefUserWaypoints, wpList)
end
return wpList
end
function LKTM:UserWaypointFormatName(wp)
if wp.map then
wp.name = string.format("%s <%s:%s:%s @ %.01f,%.01f>",
wp.note or "",
wp.map.name or "-",
wp.map.zoneName or "-",
wp.map.areaName or "-",
wp.zone and wp.zone.x or wp.map.x or 0.0,
wp.zone and wp.zone.y or wp.map.y or 0.0
)
-- TODO: wpToolTipText ? detailed description of location
else
local name = GetZoneText()
if wp.zone.x == 0 and wp.zone.y == 0 then
name = "<" .. name .. " - Instance>"
else
name = string.format("<%s @ %.01f,%.01f>", name, wp.zone.x, wp.zone.y)
end
wp.name = (wp.note or "") .. " " .. name
end
end
function LKTM:UserWaypointSetWithGPS(wpHandle, gps)
local wp = LKTM:UserWaypointFromHandle(wpHandle)
wp.gpsResult = gps
wp.map = {
x = tonumber(gps.mapPosition.x),
y = tonumber(gps.mapPosition.y),
z = tonumber(gps.mapPosition.z),
o = tonumber(gps.mapPosition.o),
id = tonumber(gps.mapPosition.mapId),
name = gps.mapPosition.mapName,
zoneId = tonumber(gps.mapPosition.zoneId),
zoneName = gps.mapPosition.zoneName,
areaId = tonumber(gps.mapPosition.areaId),
areaName = gps.mapPosition.areaName,
}
wp.zone = {
x = tonumber(gps.gridPosition.zone.x),
y = tonumber(gps.gridPosition.zone.y),
zoneId = tonumber(gps.mapPosition.zoneId),
}
LKTM:UserWaypointFormatName(wp)
end
function LKTM:UserWaypointSetNote(wpHandle, note)
local wp = LKTM:UserWaypointFromHandle(wpHandle)
wp.note = note
LKTM:UserWaypointFormatName(wp)
end
function LKTM:UserWaypointGoto(wp)
local m = wp.map
if m ~= nil then
LKTM:CommandOnUnit("player", format(".go xyz %.4f %.4f %.4f %d %.4f\n", m.x, m.y, m.z, m.id, m.o))
elseif wp.zone and wp.zone.zoneId then
LKTM:CommandOnUnit("player", format(".go zonexy %.4f %.4f %d\n", wp.zone.x, wp.zone.y, wp.zone.zoneId))
else
LKTM:Message(0, "=ERROR=: Sorry this waypoint doesn't have enough data to teleport to it! - key: " .. wp.key)
end
end
-- NPC functions
function LKTM:CopyNPC(entry, unitName) -- luacheck: no unused args
LKTM.copyNPCstate = {
startTime = GetTime(),
unitName = unitName or UnitName("target"),
entryID = "unknown",
dbGUID = "unknown",
rawLines = {},
}
LKTM:CommandOnUnit("target", ".npc info")
end
function LKTM:FilterSystemChat (event, message) -- luacheck: no unused args
-- luacheck: globals arg1
local msg = arg1 or message
-- Look for output of .npc info
-- LANG_NPCINFO_CHAR (ID 539)
-- NPC currently selected by player:
-- DB GUID: %u, current GUID: %u.
-- Faction: %u.
-- npcFlags: %u.
-- Entry: %u.
if not LKTM.copyNPCstate then
return false
end
if GetTime() - LKTM.copyNPCstate.startTime > 5.0 then
LKTM:Message(0, "=ERROR=: Timeout parsing NPC information request.")
LKTM.copyNPCstate = nil
return false
end
if string.sub(msg, 1, 33) == "NPC currently selected by player:" then
LKTM.copyNPCstate.rawLines = {}
elseif string.sub(msg, 1, 19) == "MechanicImmuneMask:" then
local newList = LKTM:GetSavedNPClist()
newList[tostring(LKTM.copyNPCstate.entryID)] = {
parseTime = tonumber(string.format("%.02f", GetTime() - LKTM.copyNPCstate.startTime)),
lastUpdateDate = date(),
lastUpdateTime = time(),
unitName = LKTM.copyNPCstate.unitName,
entryID = LKTM.copyNPCstate.entryID,
dbGUID = LKTM.copyNPCstate.dbGUID,
rawLines = LKTM.copyNPCstate.rawLines,
zone = GetZoneText(),
subZone = GetSubZoneText(),
mapAreaId = GetCurrentMapAreaID(),
}
LKTM:Message(0, "Saved NPC " .. LKTM.copyNPCstate.unitName)
LKTM.copyNPCstate = nil
else
table.insert(LKTM.copyNPCstate.rawLines, msg)
local dbGUID = msg:match("DB GUID: (%d+),")
if dbGUID then
LKTM.copyNPCstate.dbGUID = dbGUID
else
local entryID = msg:match("Entry: (%d+)%.")
if entryID then
LKTM.copyNPCstate.entryID = entryID
end
end
end
return true
end
function LKTM:OnLoad(frame)
LKTM:Message(9, "OnLoad Start")
if RegisterAddonMessagePrefix then
RegisterAddonMessagePrefix("=LKTM=")
end
for event, _ in pairs(LKTM.eventHandlers) do
LKTM:Message(9, "Listening to " .. event)
frame:RegisterEvent(event)
end
LKTM:SetupPostClicks()
LKTM_Data:OnLoad(frame)
LKTMM:Init(frame)
ChatFrame_AddMessageEventFilter("CHAT_MSG_SYSTEM", LKTM.FilterSystemChat)
LKTM:Message(9, "OnLoad Complete")
end
function LKTM:OnEvent(frame, event, ...)
local arg1, arg2, arg3, arg4, arg5 = ...
LKTM:Message(10, "OnEvent: " .. tostring(event or "nil") .. "(" .. tostring(arg1 or "nil") .. ", " .. tostring(arg2 or "nil") .. ", " .. tostring(arg3 or "nil") .. ", " .. tostring(arg4 or "nil") .. ", " .. tostring(arg5 or "nil") .. ")")
local handler = LKTM.eventHandlers[event]
if handler ~= nil then
(handler)(frame, event, ...)
else
LKTM:Message(0, "Unexpected Event: " .. event .. "(" .. (arg1 or "nil") .. ", " .. (arg2 or "nil") .. ", " .. (arg3 or "nil") .. ", " .. (arg4 or "nil") .. ", " .. (arg5 or "nil") .. ")")
end
end
function LKTM:pairsByKeys(t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f)
local i = 0
return function ()
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
end
function LKTM:dumpObject(obj, save)
if LKTM_Inspect ~= nil then
local istr = LKTM_Inspect(obj)
local num_lines = select(2, istr:gsub('\n', '\n'))
if num_lines <= 55 then
LordKator_TrinityMagicConfirm:message("LKTM:dumpObject: " .. istr .. "\n")
else
istr = istr .. "\n" .. num_lines .. " line(s) dumped"
for ln in istr:gmatch("([^\r\n]*)[\r\n]") do
(LKTM:GetActiveChatFrame()):AddMessage(ln, 1, 1, 1)
end
end
else
UIParentLoadAddOn("Blizzard_DebugTools");
DevTools_Dump(obj);
end
if save then
LKTM:SetGlobalPreference("lastDumpedObject", obj)
end
end
SlashCmdList["LORDKATOR_TRINITYMAGIC"] = function(msg)
local cmd, args = msg:match("^(%S+)%s*(.*)$")
cmd = string.lower(cmd or "help")
local cmdEntry = LKTM.slashCommands[cmd]
if cmdEntry ~= nil then
cmdEntry.cmd(args)
else
LKTM:Message(0, "Unknown command [" .. cmd .. "]")
LKTM.slashCommands['help'].cmd(args)
end
end
SlashCmdList["LORDKATOR_TRINITYMAGIC_ONALL"] = function(msg)
local title, command = string.match(msg, '"(.-)"%s+(.*)')
if not title then
title = "Run:\n\n" .. msg .. "\n\nOn everyone in the party?"
command = msg
end
local playerName = UnitName("player")
local macroText = "/target player\n/whisper " .. playerName .. " " .. command .. "\n"
if GetNumPartyMembers() > 0 then
for i=1,GetNumPartyMembers(),1 do
macroText = macroText .. "/target party" .. i .. "\n/whisper " .. playerName .. " " .. command .. "\n"
end
end
macroText = macroText .. "/cleartarget\n"
LordKator_TrinityMagicConfirm:confirmMacro(title, macroText)
end
SlashCmdList["LORDKATOR_TRINITYMAGIC_GIVEME"] = function(msg)
-- http://us.battle.net/wow/en/item/34361
-- http://www.wowhead.com/item=34361/hard-khorium-band
local itm = msg:match("item[/=](%d+)")
if itm == nil then
DEFAULT_CHAT_FRAME:AddMessage("Invalid URL: " .. msg, 1, 0, 0)
end
LKTM:CommandOnUnit("player",".additem " .. itm)
end
StaticPopupDialogs["LKTM_PromptCmd"] = {
text = "What command would you like to use?",
button1 = "Set",
button2 = "Cancel",
hasEditBox = 1,
whileDead = 1,
hideOnEscape = 1,
timeout = 0,
OnShow = function()
local curCmd = ""
if LKTM:IsGlobalPreferenceSet(kPrefDefaultCommand) then
curCmd = LKTM:GetGlobalPreference(kPrefDefaultCommand)
end
getglobal(this:GetName().."EditBox"):SetText(curCmd)
end,
OnAccept = function()
local newCommand = getglobal(this:GetParent():GetName().."EditBox"):GetText()
LKTM:Message(0, "New command [" .. newCommand .. "]")
LKTM:SetDefaultCommand(newCommand)
end,
EditBoxOnEnterPressed = function(self)
local newCommand = self:GetParent().editBox:GetText();
LKTM:Message(0, "New command [" .. newCommand .. "]")
LKTM:SetDefaultCommand(newCommand)
self:GetParent():Hide();
end,
}
StaticPopupDialogs["LKTM_PromptTargetDPS"] = {
text = "What do you want your target DPS to be?",
button1 = "Set",
button2 = "Cancel",
button3 = "Zero",
hasEditBox = 1,
whileDead = 1,
hideOnEscape = 1,
timeout = 0,
OnShow = function()
getglobal(this:GetName().."EditBox"):SetText(LKTM:GetTargetDPS())
end,
OnAccept = function()
LKTM:SetTargetDPS(getglobal(this:GetParent():GetName().."EditBox"):GetText())
end,
OnAlt = function()
LKTM:SetTargetDPS("0")
end,
EditBoxOnEnterPressed = function(self)
LKTM:SetTargetDPS(self:GetParent().editBox:GetText())
self:GetParent():Hide();
end,
}