comparison PVPScan.lua @ 0:ce416064d8a1

first commit
author tercio
date Sat, 17 May 2014 02:17:10 -0300
parents
children 726745261b87
comparison
equal deleted inserted replaced
-1:000000000000 0:ce416064d8a1
1
2 PVPScan = LibStub ("AceAddon-3.0"):NewAddon ("PVPScan", "AceConsole-3.0", "AceEvent-3.0")
3
4 local LDB = LibStub ("LibDataBroker-1.1", true)
5 local LDBIcon = LDB and LibStub ("LibDBIcon-1.0", true)
6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
7
8 local _bit_band = bit.band
9
10 local REACTION_HOSTILE = 0x00000040
11 local OBJECT_TYPE_PLAYER = 0x00000400
12
13 PVPScan.SpotBars = {}
14 PVPScan.NeedClass = {}
15 PVPScan.NextSpotBar = 1
16 PVPScan.CurrentShownIndex = {}
17 PVPScan.CurrentShownHash = {}
18 PVPScan.CurrentShownTime = {}
19
20 local default_db = {
21 profile = {
22 SpotBarHeight = 20,
23 SpotBarAmount = 5,
24 SpotBarWidth = 150,
25 Locked = false,
26 SoundPlay = false,
27 SoundFile = "",
28 Minimap = {hide = false, radius = 160, minimapPos = 220},
29 },
30 }
31
32 function PVPScan:OnEnable()
33 end
34
35 function PVPScan:OnDisable()
36 end
37
38 local OptionsTable = {
39 name = "PVPScan",
40 type = "group",
41 args = {
42 SpotBarHeight = {
43 type = "range",
44 name = "Bar Height",
45 desc = "Change the height of spot bars.",
46 min = 10,
47 max = 40,
48 step = 1,
49 get = function() return PVPScan.db.profile.SpotBarHeight end,
50 set = function (self, val) PVPScan.db.profile.SpotBarHeight = val; PVPScan:RefreshSpotBars() end,
51 order = 1,
52 },
53 SpotBarWidth = {
54 type = "range",
55 name = "Bar Width",
56 desc = "Change the width of spot bars.",
57 min = 50,
58 max = 250,
59 step = 1,
60 get = function() return PVPScan.db.profile.SpotBarWidth end,
61 set = function (self, val) PVPScan.db.profile.SpotBarWidth = val; PVPScan:RefreshSpotBars() end,
62 order = 2,
63 },
64 SpotBarAmount = {
65 type = "range",
66 name = "Bar Amount",
67 desc = "Change the amount of spot bars.",
68 min = 1,
69 max = 40,
70 step = 1,
71 get = function() return PVPScan.db.profile.SpotBarAmount end,
72 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
73 order = 3,
74 },
75 Locked = {
76 type = "toggle",
77 name = "Lock Frame",
78 desc = "Lock or unlock the SpotBars Frame.",
79 order = 4,
80 get = function() return PVPScan.db.profile.Locked end,
81 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked end,
82 },
83 SoundPlay = {
84 type = "toggle",
85 name = "Play Sound",
86 desc = "Play a sound when a enemy is found.",
87 order = 5,
88 get = function() return PVPScan.db.profile.SoundPlay end,
89 set = function (self, val) PVPScan.db.profile.SoundPlay = not PVPScan.db.profile.SoundPlay end,
90 },
91 SoundFile = {
92 type = "select",
93 name = "Sound File",
94 desc = "Choose the sound to play when a enemy is found.",
95 values = function()
96 local SoundTable = {}
97 for name, _ in pairs (SharedMedia:HashTable ("sound")) do
98 SoundTable [name] = name
99 end
100 return SoundTable
101 end,
102 get = function() return PVPScan.db.profile.SoundFile end,
103 set = function (self, file) PVPScan.db.profile.SoundFile = file end,
104 order = 6,
105 },
106 Minimap = {
107 type = "toggle",
108 name = "Hide Minimap Icon",
109 desc = "Show or hide the minimap icon.",
110 order = 7,
111 get = function() return PVPScan.db.profile.Minimap.hide end,
112 set = function (self, val)
113 PVPScan.db.profile.Minimap.hide = not PVPScan.db.profile.Minimap.hide
114 LDBIcon:Refresh ("PVPScan", PVPScan.db.profile.Minimap)
115 if (PVPScan.db.profile.Minimap.hide) then
116 LDBIcon:Hide ("PVPScan")
117 else
118 LDBIcon:Show ("PVPScan")
119 end
120 end,
121 },
122 },
123 }
124
125 function PVPScan:OnInitialize()
126
127 --declarar primeiro o db usando a global que é declarada no toc.
128 self.db = LibStub ("AceDB-3.0"):New ("PVPScanDB", default_db, true)
129
130 --declara agora as opções da tab raiz
131 LibStub("AceConfig-3.0"):RegisterOptionsTable ("PVPScan", OptionsTable)
132 PVPScan.OptionsFrame1 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan", "PVPScan")
133 --sub tab
134 LibStub ("AceConfig-3.0"):RegisterOptionsTable ("PVPScan-Profiles", LibStub ("AceDBOptions-3.0"):GetOptionsTable (self.db))
135 PVPScan.OptionsFrame2 = LibStub ("AceConfigDialog-3.0"):AddToBlizOptions ("PVPScan-Profiles", "Profiles", "PVPScan")
136
137 if LDB then
138 local databroker = LDB:NewDataObject ("PVPScan", {
139 type = "launcher",
140 icon = [[Interface\PvPRankBadges\PvPRank15]],
141 --HotCornerIgnore = true,
142 OnClick = function (self, button)
143 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
144 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
145 end
146 })
147
148 if (databroker and not LDBIcon:IsRegistered ("PVPScan")) then
149 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap)
150 end
151 end
152
153 PVPScan:RefreshSpotBars()
154
155 end
156
157 PVPScan:RegisterChatCommand ("pvpscan", function()
158 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
159 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
160 end)
161
162 ------------------------------------------------------------------------------------------------------------------------------------------------------------
163 --> parser stuff
164
165 local event_frame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
166 event_frame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
167
168 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
169
170 if (PVPScan.NeedClass [who_name]) then
171 local class = PVPScan:GuessClass (...)
172 if (class) then
173 PVPScan:UpdateBar (PVPScan.NeedClass [who_name], class, who_name)
174 PVPScan.NeedClass [who_name] = nil
175 end
176 return
177 end
178
179 if (PVPScan.NeedClass [target_name]) then
180 local class = PVPScan:GuessClass (...)
181 if (class) then
182 PVPScan:UpdateBar (PVPScan.NeedClass [target_name], class, target_name)
183 PVPScan.NeedClass [target_name] = nil
184 end
185 return
186 end
187
188 if (not PVPScan.CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
189 if (_bit_band (target_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
190 local class = PVPScan:GuessClass (...)
191 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
192 end
193 end
194
195 if (not PVPScan.CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
196 if (_bit_band (who_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
197 local class = PVPScan:GuessClass (...)
198 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
199 end
200 end
201 end
202
203 event_frame:SetScript ("OnEvent", PVPScan.OnParserEvent)
204
205 function PVPScan:LeftCombatLockdown()
206 if (PVPScan.schedule_frame_update) then
207 PVPScan.schedule_frame_update = false
208 PVPScan:RefreshSpotBars()
209 end
210 end
211 function PVPScan:GotCombatLockdown()
212 end
213
214 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
215 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
216
217 function PVPScan:EnemySpoted (name, serial, flags, class)
218
219 --> check for overwrite
220 local current_player_shown = PVPScan.CurrentShownIndex [PVPScan.NextSpotBar]
221 if (current_player_shown) then
222 PVPScan.NeedClass [current_player_shown] = nil
223 end
224
225 local SpotBar = PVPScan.SpotBars [PVPScan.NextSpotBar]
226
227 if (class) then
228 PVPScan:UpdateBar (PVPScan.NextSpotBar, class, name)
229 else
230 PVPScan:UpdateBar (PVPScan.NextSpotBar, nil, name)
231 PVPScan.NeedClass [name] = PVPScan.NextSpotBar
232 end
233
234 PVPScan.CurrentShownIndex [PVPScan.NextSpotBar] = name
235 PVPScan.CurrentShownHash [name] = PVPScan.NextSpotBar
236 PVPScan.CurrentShownTime [name] = GetTime()
237
238 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
239 SpotBar:SetAttribute("macrotext", "/cleartarget\n/targetexact " .. name)
240 end
241
242 SpotBar:Show()
243
244 PVPScan.NextSpotBar = PVPScan.NextSpotBar + 1
245 if (PVPScan.NextSpotBar > PVPScan.db.profile.SpotBarAmount) then
246 PVPScan.NextSpotBar = 1
247 end
248
249 end
250
251
252
253 ------------------------------------------------------------------------------------------------------------------------------------------------------------
254 --> frames
255
256 function PVPScanOnFrameMouseDown (self)
257 if (not self.IsMoving) then
258 self:StartMoving()
259 self.IsMoving = true
260 end
261 end
262
263 function PVPScanOnFrameMouseUp (self)
264 if (self.IsMoving) then
265 self:StopMovingOrSizing()
266 self.IsMoving = false
267 end
268 end
269
270 function PVPScan:UpdateBar (index, class, name)
271
272 local SpotBar = PVPScan.SpotBars [index]
273
274 if (class) then
275 local color = RAID_CLASS_COLORS [class]
276 SpotBar.classtexture:SetVertexColor (color.r, color.g, color.b)
277
278 local texcoord = CLASS_ICON_TCOORDS [class]
279 SpotBar.classicon:SetTexture ([[Interface\Glues\CHARACTERCREATE\UI-CHARACTERCREATE-CLASSES]])
280 SpotBar.classicon:SetTexCoord (unpack (texcoord))
281 else
282 SpotBar.classtexture:SetVertexColor (.7, .7, .7)
283 SpotBar.classicon:SetTexture ([[Interface\InventoryItems\WoWUnknownItem01]])
284 SpotBar.classicon:SetTexCoord (0, 1, 0, 1)
285 end
286
287 SpotBar.name:SetText (name)
288
289 end
290
291 function PVPScan:RefreshSpotBars()
292
293 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
294 PVPScan.schedule_frame_update = true
295 PVPScan:Print ("When the combat finishes, the frame will be updated.")
296 return
297 end
298
299 local amount_bars = PVPScan.db.profile.SpotBarAmount
300 PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
301
302 --> we need extra bars?
303 if (amount_bars > #PVPScan.SpotBars) then
304 for i = #PVPScan.SpotBars+1, amount_bars do
305
306 local new_bar = CreateFrame ("Button", "PVPScanSpotBar" .. i, PVPScanFrame, "PVPScanSpotBarTemplate")
307
308 local y = (i-1) * PVPScan.db.profile.SpotBarHeight * -1
309
310 new_bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
311 new_bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
312
313 tinsert (PVPScan.SpotBars, new_bar)
314 end
315 end
316
317 if (#PVPScan.SpotBars > amount_bars) then
318 for i = #PVPScan.SpotBars, amount_bars+1, -1 do
319 PVPScan.SpotBars [i]:Hide()
320 local name = PVPScan.CurrentShownIndex [i]
321 if (name) then
322 tremove (PVPScan.CurrentShownIndex, i)
323 PVPScan.CurrentShownHash [name] = nil
324 PVPScan.CurrentShownTime [name] = nil
325 PVPScan.NeedClass [name] = nil
326 end
327 end
328 end
329
330 --> refresh existing
331 for index, bar in ipairs (PVPScan.SpotBars) do
332 local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1
333 bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
334 bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
335 end
336
337 end
338
339
340
341
342
343 ------------------------------------------------------------------------------------------------------------------------------------------------------------
344 --> misc
345
346 function PVPScan:GuessClass (...)
347 local arg1, arg2, arg3, arg4 = select (1, ...)
348
349 if (type (arg1) == "number") then
350 if (PVPScan.ClassSpellList [arg1]) then
351 return PVPScan.ClassSpellList [arg1]
352 end
353 end
354
355 if (type (arg3) == "number") then
356 if (PVPScan.ClassSpellList [arg3]) then
357 return PVPScan.ClassSpellList [arg3]
358 end
359 end
360
361 if (type (arg2) == "number") then
362 if (PVPScan.ClassSpellList [arg3]) then
363 return PVPScan.ClassSpellList [arg3]
364 end
365 end
366
367 if (type (arg4) == "number") then
368 if (PVPScan.ClassSpellList [arg4]) then
369 return PVPScan.ClassSpellList [arg4]
370 end
371 end
372
373 return nil
374 end
375