|
Asa@0
|
1 TankSpotter = select(2, ...)
|
|
Asa@0
|
2 TankSpotter = LibStub("AceAddon-3.0"):NewAddon(TankSpotter, "TankSpotter", "AceEvent-3.0")
|
|
Asa@0
|
3
|
|
Asa@0
|
4 local tankGUID = nil
|
|
Asa@0
|
5
|
|
Asa@0
|
6 function TankSpotter:Slash(msg, editBox)
|
|
Asa@0
|
7 msg = strlower(msg)
|
|
Asa@0
|
8 if msg == 'set' then
|
|
Asa@0
|
9 if UnitName("target") and UnitIsFriend("player", "target") then
|
|
Asa@0
|
10 tankGUID = UnitGUID("target")
|
|
Asa@0
|
11 if UnitGUID("pet") == tankGUID then
|
|
Asa@0
|
12 -- pets change GUIDs when spawned, so this GUID can't be used
|
|
Asa@0
|
13 tankGUID = 'pet'
|
|
Asa@0
|
14 end
|
|
Asa@0
|
15 else
|
|
Asa@0
|
16 print('You must select a friendly target to set it as your tank.')
|
|
Asa@0
|
17 end
|
|
Asa@0
|
18 elseif msg == 'clear' then
|
|
Asa@0
|
19 tankGUID = nil
|
|
Asa@0
|
20 elseif msg == 'update' then
|
|
Asa@0
|
21 -- UpdateAllMacros is called at the end of the function.
|
|
Asa@0
|
22 else
|
|
Asa@0
|
23 print('Usage: TODO: Implement instructions')
|
|
Asa@0
|
24 end
|
|
Asa@0
|
25 TankSpotter:UpdateAllMacros(msg)
|
|
Asa@0
|
26 end
|
|
Asa@0
|
27
|
|
Asa@0
|
28 function TankSpotter:findTank()
|
|
Asa@0
|
29 -- the guid is simply to make sure the pet still exists.
|
|
Asa@0
|
30 if tankGUID == 'pet' and UnitGUID("pet") then
|
|
Asa@0
|
31 return 'pet'
|
|
Asa@0
|
32 end
|
|
Asa@0
|
33
|
|
Asa@0
|
34 local tank = nil
|
|
Asa@0
|
35 for i = 1, GetNumRaidMembers()-1 do
|
|
Asa@0
|
36 local unit = 'raid'..i
|
|
Asa@0
|
37 if tankGUID and UnitGUID(unit) == tankGUID then
|
|
Asa@0
|
38 return unit
|
|
Asa@0
|
39 end
|
|
Asa@0
|
40 if UnitGroupRolesAssigned(unit) == 'TANK' then
|
|
Asa@0
|
41 if tank == nil then
|
|
Asa@0
|
42 tank = unit
|
|
Asa@0
|
43 else
|
|
Asa@0
|
44 -- Too many tanks.
|
|
Asa@0
|
45 tank = ''
|
|
Asa@0
|
46 end
|
|
Asa@0
|
47 end
|
|
Asa@0
|
48 end
|
|
Asa@0
|
49 if tank and tank ~= '' then
|
|
Asa@0
|
50 return tank
|
|
Asa@0
|
51 end
|
|
Asa@0
|
52
|
|
Asa@0
|
53 tank = nil
|
|
Asa@0
|
54 for i = 1, GetNumPartyMembers() do
|
|
Asa@0
|
55 local unit = 'party'..i
|
|
Asa@0
|
56 if tankGUID and UnitGUID(unit) == tankGUID then
|
|
Asa@0
|
57 return unit
|
|
Asa@0
|
58 end
|
|
Asa@0
|
59
|
|
Asa@0
|
60 if UnitGroupRolesAssigned(unit) == 'TANK' then
|
|
Asa@0
|
61 tank = unit
|
|
Asa@0
|
62 end
|
|
Asa@0
|
63 end
|
|
Asa@0
|
64
|
|
Asa@0
|
65 return tank or 'pet'
|
|
Asa@0
|
66 end
|
|
Asa@0
|
67
|
|
Asa@0
|
68 TankSpotter.former_tank = ''
|
|
Asa@0
|
69 function TankSpotter:updateMacro(index)
|
|
Asa@0
|
70 if index > 0 then
|
|
Asa@0
|
71 name, iconTexture, body, isLocal = GetMacroInfo(index);
|
|
Asa@0
|
72 local former_tank = body:match('#tank=(%w+)')
|
|
Asa@0
|
73 local new_tank = self:findTank()
|
|
Asa@0
|
74 if former_tank and new_tank ~= former_tank then
|
|
Asa@0
|
75 if self.former_tank ~= new_tank then
|
|
Asa@0
|
76 print(format('Updating tank macros from %s to %s', former_tank, new_tank))
|
|
Asa@0
|
77
|
|
Asa@0
|
78 end
|
|
Asa@0
|
79 self.former_tank = new_tank
|
|
Asa@0
|
80 local new_body = body:gsub(former_tank, new_tank)
|
|
Asa@0
|
81 name = name:gsub(former_tank, new_tank)
|
|
Asa@0
|
82 -- print('y', index, name, iconTexture, body, isLocal)
|
|
Asa@0
|
83 if new_body ~= body then
|
|
Asa@0
|
84 EditMacro(index, name, 0, new_body, nil)
|
|
Asa@0
|
85 end
|
|
Asa@0
|
86 end
|
|
Asa@0
|
87 end
|
|
Asa@0
|
88 end
|
|
Asa@0
|
89
|
|
Asa@0
|
90 local updateAfterCombat = false
|
|
Asa@0
|
91 function TankSpotter:UpdateAllMacros(event)
|
|
Asa@0
|
92 if InCombatLockdown() then
|
|
Asa@0
|
93 updateAfterCombat = true
|
|
Asa@0
|
94 TankSpotter:RegisterEvent("PLAYER_LEAVE_COMBAT", 'UpdateAllMacros')
|
|
Asa@0
|
95 return
|
|
Asa@0
|
96 end
|
|
Asa@0
|
97
|
|
Asa@0
|
98 if updateAfterCombat then
|
|
Asa@0
|
99 TankSpotter:UnregisterEvent("PLAYER_LEAVE_COMBAT")
|
|
Asa@0
|
100 end
|
|
Asa@0
|
101
|
|
Asa@0
|
102 local endGlobal, endChar = GetNumMacros()
|
|
Asa@0
|
103 endChar = endChar + 36 -- character specific macros start at 37
|
|
Asa@0
|
104 local i = 1
|
|
Asa@0
|
105
|
|
Asa@0
|
106 while i <= endChar do
|
|
Asa@0
|
107 self:updateMacro(i)
|
|
Asa@0
|
108 if i == endGlobal then
|
|
Asa@0
|
109 i = 36
|
|
Asa@0
|
110 end
|
|
Asa@0
|
111 i = i + 1
|
|
Asa@0
|
112 end
|
|
Asa@0
|
113 end
|
|
Asa@0
|
114
|
|
Asa@0
|
115
|
|
Asa@0
|
116 TankSpotter:RegisterEvent("PLAYER_ROLES_ASSIGNED", 'UpdateAllMacros')
|
|
Asa@0
|
117 TankSpotter:RegisterEvent("PLAYER_ENTERING_WORLD", 'UpdateAllMacros')
|
|
Asa@0
|
118 TankSpotter:RegisterEvent("PARTY_MEMBERS_CHANGED", 'UpdateAllMacros')
|
|
Asa@0
|
119 -- This is used to determine when a pet is summoned or dismissed
|
|
Asa@0
|
120 TankSpotter:RegisterEvent("UNIT_PET", 'UpdateAllMacros')
|
|
Asa@0
|
121
|
|
Asa@0
|
122 SLASH_TANKSPOTTER1, SLASH_TANKSPOTTER2 = '/tankspotter', '/ts'
|
|
Asa@0
|
123 SlashCmdList["TANKSPOTTER"] = function(msg, editBox)
|
|
Asa@0
|
124 TankSpotter:Slash(msg, editBox)
|
|
Asa@0
|
125 end
|
|
Asa@0
|
126
|
|
Asa@0
|
127
|
|
Asa@0
|
128 -- TankSpotter:UpdateAllMacros()
|