comparison PVPScan.lua @ 1:726745261b87

updates
author tercio
date Mon, 19 May 2014 05:50:51 -0300
parents ce416064d8a1
children f2456f1454af
comparison
equal deleted inserted replaced
0:ce416064d8a1 1:726745261b87
6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0") 6 local SharedMedia = LibStub:GetLibrary("LibSharedMedia-3.0")
7 7
8 local _bit_band = bit.band 8 local _bit_band = bit.band
9 9
10 local REACTION_HOSTILE = 0x00000040 10 local REACTION_HOSTILE = 0x00000040
11 local REACTION_NEUTRAL = 0x00000020
12
11 local OBJECT_TYPE_PLAYER = 0x00000400 13 local OBJECT_TYPE_PLAYER = 0x00000400
12 14
13 PVPScan.SpotBars = {} 15 PVPScan.IsInBattleground = false
14 PVPScan.NeedClass = {} 16 PVPScan.IsInCity = false
15 PVPScan.NextSpotBar = 1 17 PVPScan.IsInArena = false
16 PVPScan.CurrentShownIndex = {} 18 PVPScan.IsInOutDoors = true
17 PVPScan.CurrentShownHash = {} 19 PVPScan.ScanEnabled = true
18 PVPScan.CurrentShownTime = {}
19 20
20 local default_db = { 21 local default_db = {
21 profile = { 22 profile = {
22 SpotBarHeight = 20, 23 SpotBarHeight = 20,
23 SpotBarAmount = 5, 24 SpotBarAmount = 5,
72 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end, 73 set = function (self, val) PVPScan.db.profile.SpotBarAmount = val; PVPScan:RefreshSpotBars() end,
73 order = 3, 74 order = 3,
74 }, 75 },
75 Locked = { 76 Locked = {
76 type = "toggle", 77 type = "toggle",
77 name = "Lock Frame", 78 name = "Lock Scan Frame",
78 desc = "Lock or unlock the SpotBars Frame.", 79 desc = "Lock or unlock the SpotBars Frame.",
79 order = 4, 80 order = 4,
80 get = function() return PVPScan.db.profile.Locked end, 81 get = function() return PVPScan.db.profile.Locked end,
81 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked end, 82 set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end,
82 }, 83 },
83 SoundPlay = { 84 SoundPlay = {
84 type = "toggle", 85 type = "toggle",
85 name = "Play Sound", 86 name = "Play Sound",
86 desc = "Play a sound when a enemy is found.", 87 desc = "Play a sound when a enemy is found.",
149 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap) 150 LDBIcon:Register ("PVPScan", databroker, PVPScan.db.profile.Minimap)
150 end 151 end
151 end 152 end
152 153
153 PVPScan:RefreshSpotBars() 154 PVPScan:RefreshSpotBars()
154 155 PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
155 end 156 end
156 157
157 PVPScan:RegisterChatCommand ("pvpscan", function() 158 PVPScan:RegisterChatCommand ("pvpscan", function()
158 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 159 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
159 InterfaceOptionsFrame_OpenToCategory ("PVPScan") 160 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
160 end) 161 end)
161 162
163
162 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 164 ------------------------------------------------------------------------------------------------------------------------------------------------------------
163 --> parser stuff 165 --> general
164 166
165 local event_frame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent) 167 function PVPScan:ChangeZones()
166 event_frame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED") 168
169 local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo()
170 local pvpType, isFFA, faction = GetZonePVPInfo()
171
172 PVPScan.IsInBattleground = false
173 PVPScan.IsInCity = false
174 PVPScan.IsInArena = false
175 PVPScan.IsInOutDoors = false
176 PVPScan.ScanEnabled = false
177
178 if (pvpType == "contested" and (not type or type == "none")) then
179 PVPScan.IsInOutDoors = true
180 PVPScan.ScanEnabled = true
181
182 elseif (type == "pvp") then
183 PVPScan.IsInBattleground = true
184
185 elseif (type == "arena") then
186 PVPScan.IsInArena = true
187
188 elseif (type and (type == "scenario" or type == "party" or type == "raid" or pvpType == "friendly" or pvpType == "sanctuary")) then
189 PVPScan.ScanEnabled = false
190
191 else
192 PVPScan.IsInOutDoors = true
193 PVPScan.ScanEnabled = true
194 end
195
196 if (PVPScan.ScanEnabled) then
197 PVPScan:EnableScan()
198 else
199 PVPScan:DisableScan()
200 end
201
202 end
203
204 PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones")
205 PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones")
206
207 function PVPScan:EnableScan()
208 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
209 PVPScan:RefreshSpotBars()
210 end
211
212 function PVPScan:DisableScan()
213 PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
214 PVPScan:RefreshSpotBars()
215 end
216
217 function PVPScan:LockScanFrame (IsLocked)
218 if (IsLocked) then
219 PVPScanFrame.text:SetText ("")
220 PVPScanFrame:SetBackdrop (nil)
221 PVPScanFrame:EnableMouse (false)
222 else
223 PVPScanFrame.text:SetText ("PVPScan Anchor")
224 PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64})
225 PVPScanFrame:SetBackdropColor (0, 0, 0, 1)
226 PVPScanFrame:EnableMouse (true)
227 end
228 end
229 ------------------------------------------------------------------------------------------------------------------------------------------------------------
230 --> outside world scan
231
232 --> parser
233
234 PVPScan.SpotBars = {}
235 PVPScan.NeedClass = {}
236 PVPScan.NextSpotBar = 1
237
238 local CurrentShownIndex = {}
239 local CurrentShownHash = {}
240 local CurrentShownTime = {}
241 local NeutralCandidate = {}
242
243 local find_neutral_players = false
244
245 PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
246 PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
167 247
168 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...) 248 function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
169 249
170 if (PVPScan.NeedClass [who_name]) then 250 if (PVPScan.NeedClass [who_name]) then
171 local class = PVPScan:GuessClass (...) 251 local class = PVPScan:GuessClass (...)
182 PVPScan:UpdateBar (PVPScan.NeedClass [target_name], class, target_name) 262 PVPScan:UpdateBar (PVPScan.NeedClass [target_name], class, target_name)
183 PVPScan.NeedClass [target_name] = nil 263 PVPScan.NeedClass [target_name] = nil
184 end 264 end
185 return 265 return
186 end 266 end
187 267
188 if (not PVPScan.CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player 268 if (not 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 269 if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
190 local class = PVPScan:GuessClass (...) 270 local class = PVPScan:GuessClass (...)
191 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class) 271 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
192 end 272
193 end 273 elseif (find_neutral_players and _bit_band (target_flags, REACTION_NEUTRAL) ~= 0) then
194 274 if (NeutralCandidate [target_name]) then
195 if (not PVPScan.CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player 275 NeutralCandidate [target_name] = NeutralCandidate [target_name] + 1
196 if (_bit_band (who_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile 276 if (NeutralCandidate [target_name] == 5) then
277 --print ("neutral", target_name)
278 local class = PVPScan:GuessClass (...)
279 PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
280 end
281 else
282 NeutralCandidate [target_name] = 1
283 end
284
285 elseif (NeutralCandidate [target_name]) then
286 NeutralCandidate [target_name] = nil
287 end
288 end
289
290 if (not CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
291 if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
197 local class = PVPScan:GuessClass (...) 292 local class = PVPScan:GuessClass (...)
198 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class) 293 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
199 end 294
200 end 295 elseif (find_neutral_players and _bit_band (who_flags, REACTION_NEUTRAL) ~= 0) then
201 end 296 if (NeutralCandidate [who_name]) then
202 297 NeutralCandidate [who_name] = NeutralCandidate [who_name] + 1
203 event_frame:SetScript ("OnEvent", PVPScan.OnParserEvent) 298 if (NeutralCandidate [who_name] == 5) then
299 --print ("neutral", who_name)
300 local class = PVPScan:GuessClass (...)
301 PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
302 end
303 else
304 NeutralCandidate [who_name] = 1
305 end
306
307 elseif (NeutralCandidate [who_name]) then
308 NeutralCandidate [who_name] = nil
309 end
310 end
311 end
312
313 PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
204 314
205 function PVPScan:LeftCombatLockdown() 315 function PVPScan:LeftCombatLockdown()
206 if (PVPScan.schedule_frame_update) then 316 if (PVPScan.schedule_frame_update) then
207 PVPScan.schedule_frame_update = false 317 PVPScan.schedule_frame_update = false
208 PVPScan:RefreshSpotBars() 318 PVPScan:RefreshSpotBars()
212 end 322 end
213 323
214 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown") 324 PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
215 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown") 325 PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
216 326
327 -- found a enemy on the scan
328
217 function PVPScan:EnemySpoted (name, serial, flags, class) 329 function PVPScan:EnemySpoted (name, serial, flags, class)
218 330
331 if (not name) then
332 return
333 end
334
219 --> check for overwrite 335 --> check for overwrite
220 local current_player_shown = PVPScan.CurrentShownIndex [PVPScan.NextSpotBar] 336 local current_player_shown = CurrentShownIndex [PVPScan.NextSpotBar]
221 if (current_player_shown) then 337 if (current_player_shown) then
222 PVPScan.NeedClass [current_player_shown] = nil 338 PVPScan.NeedClass [current_player_shown] = nil
223 end 339 end
224 340
225 local SpotBar = PVPScan.SpotBars [PVPScan.NextSpotBar] 341 local SpotBar = PVPScan.SpotBars [PVPScan.NextSpotBar]
229 else 345 else
230 PVPScan:UpdateBar (PVPScan.NextSpotBar, nil, name) 346 PVPScan:UpdateBar (PVPScan.NextSpotBar, nil, name)
231 PVPScan.NeedClass [name] = PVPScan.NextSpotBar 347 PVPScan.NeedClass [name] = PVPScan.NextSpotBar
232 end 348 end
233 349
234 PVPScan.CurrentShownIndex [PVPScan.NextSpotBar] = name 350 CurrentShownIndex [PVPScan.NextSpotBar] = name
235 PVPScan.CurrentShownHash [name] = PVPScan.NextSpotBar 351 CurrentShownHash [name] = PVPScan.NextSpotBar
236 PVPScan.CurrentShownTime [name] = GetTime() 352 CurrentShownTime [name] = GetTime()
237 353
238 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then 354 if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
239 SpotBar:SetAttribute("macrotext", "/cleartarget\n/targetexact " .. name) 355 SpotBar:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. name)
240 end 356 end
241 357
242 SpotBar:Show() 358 SpotBar:Show()
243 359
244 PVPScan.NextSpotBar = PVPScan.NextSpotBar + 1 360 PVPScan.NextSpotBar = PVPScan.NextSpotBar + 1
246 PVPScan.NextSpotBar = 1 362 PVPScan.NextSpotBar = 1
247 end 363 end
248 364
249 end 365 end
250 366
251 367 -- frames
252 368
253 ------------------------------------------------------------------------------------------------------------------------------------------------------------ 369 function PVPScanOnFrameMouseDown (self, button)
254 --> frames 370 if (button == "LeftButton") then
255 371 if (not self.IsMoving) then
256 function PVPScanOnFrameMouseDown (self) 372 self:StartMoving()
257 if (not self.IsMoving) then 373 self.IsMoving = true
258 self:StartMoving() 374 end
259 self.IsMoving = true 375 end
260 end 376 end
261 end 377
262 378 function PVPScanOnFrameMouseUp (self, button)
263 function PVPScanOnFrameMouseUp (self) 379 if (button == "LeftButton") then
264 if (self.IsMoving) then 380 if (self.IsMoving) then
265 self:StopMovingOrSizing() 381 self:StopMovingOrSizing()
266 self.IsMoving = false 382 self.IsMoving = false
383 end
384
385 elseif (button == "RightButton") then
386 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
387 InterfaceOptionsFrame_OpenToCategory ("PVPScan")
267 end 388 end
268 end 389 end
269 390
270 function PVPScan:UpdateBar (index, class, name) 391 function PVPScan:UpdateBar (index, class, name)
392
393 if (UnitAffectingCombat ("player") or InCombatLockdown()) then
394 --return
395 end
271 396
272 local SpotBar = PVPScan.SpotBars [index] 397 local SpotBar = PVPScan.SpotBars [index]
273 398
274 if (class) then 399 if (class) then
275 local color = RAID_CLASS_COLORS [class] 400 local color = RAID_CLASS_COLORS [class]
294 PVPScan.schedule_frame_update = true 419 PVPScan.schedule_frame_update = true
295 PVPScan:Print ("When the combat finishes, the frame will be updated.") 420 PVPScan:Print ("When the combat finishes, the frame will be updated.")
296 return 421 return
297 end 422 end
298 423
424 if (not PVPScan.ScanEnabled) then
425 PVPScanFrame:Hide()
426 else
427 PVPScanFrame:Show()
428 end
429
299 local amount_bars = PVPScan.db.profile.SpotBarAmount 430 local amount_bars = PVPScan.db.profile.SpotBarAmount
300 PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) 431 PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, 20)
301 432
302 --> we need extra bars? 433 --> we need extra bars?
303 if (amount_bars > #PVPScan.SpotBars) then 434 if (amount_bars > #PVPScan.SpotBars) then
304 for i = #PVPScan.SpotBars+1, amount_bars do 435 for i = #PVPScan.SpotBars+1, amount_bars do
305 436
315 end 446 end
316 447
317 if (#PVPScan.SpotBars > amount_bars) then 448 if (#PVPScan.SpotBars > amount_bars) then
318 for i = #PVPScan.SpotBars, amount_bars+1, -1 do 449 for i = #PVPScan.SpotBars, amount_bars+1, -1 do
319 PVPScan.SpotBars [i]:Hide() 450 PVPScan.SpotBars [i]:Hide()
320 local name = PVPScan.CurrentShownIndex [i] 451 local name = CurrentShownIndex [i]
321 if (name) then 452 if (name) then
322 tremove (PVPScan.CurrentShownIndex, i) 453 tremove (CurrentShownIndex, i)
323 PVPScan.CurrentShownHash [name] = nil 454 CurrentShownHash [name] = nil
324 PVPScan.CurrentShownTime [name] = nil 455 CurrentShownTime [name] = nil
325 PVPScan.NeedClass [name] = nil 456 PVPScan.NeedClass [name] = nil
326 end 457 end
327 end 458 end
328 end 459 end
329 460
330 --> refresh existing 461 --> refresh existing
331 for index, bar in ipairs (PVPScan.SpotBars) do 462 for index, bar in ipairs (PVPScan.SpotBars) do
332 local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1 463 local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1
333 bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y) 464 bar:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
334 bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight) 465 bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
335 end 466 bar.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
336 467 bar.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
337 end 468 end
338 469
339 470 end
340 471
341 472 --> misc
342
343 ------------------------------------------------------------------------------------------------------------------------------------------------------------
344 --> misc
345 473
346 function PVPScan:GuessClass (...) 474 function PVPScan:GuessClass (...)
347 local arg1, arg2, arg3, arg4 = select (1, ...) 475 local arg1, arg2, arg3, arg4 = select (1, ...)
348 476
349 if (type (arg1) == "number") then 477 if (type (arg1) == "number") then
371 end 499 end
372 500
373 return nil 501 return nil
374 end 502 end
375 503
504
505 ------------------------------------------------------------------------------------------------------------------------------------------------------------
506 --> battlegrounds
507