forked from RestedXP/RXPGuides
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTargeting.lua
More file actions
82 lines (64 loc) · 2.52 KB
/
Copy pathTargeting.lua
File metadata and controls
82 lines (64 loc) · 2.52 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
local _, addon = ...
local fmt = string.format
local GetMacroInfo, CreateMacro, EditMacro, InCombatLockdown, GetNumMacros =
GetMacroInfo, CreateMacro, EditMacro, InCombatLockdown, GetNumMacros
local L = addon.locale.Get
addon.targeting = addon:NewModule("Targeting", "AceEvent-3.0")
addon.targeting.macroName = "RXPTargeting"
local newTargets
local announcedTargets = {}
function addon.targeting:UpdateMacro(targets)
if not addon.settings.db.profile.enableTargetMacro or _G.unitscan_targets then
return
end
if InCombatLockdown() then
newTargets = targets
return
end
if not GetMacroInfo(self.macroName) then
if not self:CanCreateMacro() then return end
CreateMacro(self.macroName, "Ability_eyeoftheowl", "")
end
targets = targets or {}
local content
for _, t in ipairs(targets) do
content = fmt('/targetexact %s\n%s', t, content or "")
-- Prevent multiple spams
if not announcedTargets[t] and
addon.settings.db.profile.notifyOnTargetUpdates then
C_Timer.After(2, function()
addon.comms.PrettyPrint(L(
"You have a new target (%s) for step %d"),
t, RXPCData.currentStep) -- TODO locale
end)
end
announcedTargets[t] = true
end
content = content or
fmt('//%s - %s', addon.title,
L("current step has no configured targets")) -- TODO locale
EditMacro(self.macroName, self.macroName, nil, content)
if not addon.settings.db.profile.macroAnnounced and
addon.settings.db.profile.notifyOnTargetUpdates and next(targets) ~= nil then
C_Timer.After(5, function()
addon.comms.PrettyPrint(L(
"A macro has been automatically built to aid in leveling. Please move %s to your action bars."),
self.macroName)
end)
addon.settings.db.profile.macroAnnounced = true
end
newTargets = nil
end
function addon.targeting:PLAYER_REGEN_ENABLED()
if newTargets then
C_Timer.After(2, function() self:UpdateMacro(newTargets) end)
end
end
function addon.targeting:Setup()
if not addon.settings.db.profile.enableTargetMacro or _G.unitscan_targets then
DeleteMacro(self.macroName)
return
end
self:RegisterEvent("PLAYER_REGEN_ENABLED")
end
function addon.targeting:CanCreateMacro() return GetNumMacros() < 119 end