changeset 1:726745261b87

updates
author tercio
date Mon, 19 May 2014 05:50:51 -0300
parents ce416064d8a1
children f2456f1454af
files PVPScan.lua PVPScan.xml
diffstat 2 files changed, 181 insertions(+), 49 deletions(-) [+]
line wrap: on
line diff
--- a/PVPScan.lua	Sat May 17 02:17:10 2014 -0300
+++ b/PVPScan.lua	Mon May 19 05:50:51 2014 -0300
@@ -8,14 +8,15 @@
 local _bit_band = bit.band
 
 local REACTION_HOSTILE = 0x00000040
+local REACTION_NEUTRAL = 0x00000020
+
 local OBJECT_TYPE_PLAYER = 0x00000400
 
-PVPScan.SpotBars = {}
-PVPScan.NeedClass = {}
-PVPScan.NextSpotBar = 1
-PVPScan.CurrentShownIndex = {}
-PVPScan.CurrentShownHash = {}
-PVPScan.CurrentShownTime = {}
+PVPScan.IsInBattleground = false
+PVPScan.IsInCity = false
+PVPScan.IsInArena = false
+PVPScan.IsInOutDoors = true
+PVPScan.ScanEnabled = true
 
 local default_db = {
 	profile = {
@@ -74,11 +75,11 @@
 		},
 		Locked = {
 			type = "toggle",
-			name = "Lock Frame",
+			name = "Lock Scan Frame",
 			desc = "Lock or unlock the SpotBars Frame.",
 			order = 4,
 			get = function() return PVPScan.db.profile.Locked end,
-			set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked end,
+			set = function (self, val) PVPScan.db.profile.Locked = not PVPScan.db.profile.Locked; PVPScan:LockScanFrame (PVPScan.db.profile.Locked) end,
 		},
 		SoundPlay = {
 			type = "toggle",
@@ -151,7 +152,7 @@
 	end
 	
 	PVPScan:RefreshSpotBars()
-	
+	PVPScan:LockScanFrame (PVPScan.db.profile.Locked)
 end
 
 PVPScan:RegisterChatCommand ("pvpscan", function() 
@@ -159,11 +160,90 @@
 	InterfaceOptionsFrame_OpenToCategory ("PVPScan")
 end)
 
+
 ------------------------------------------------------------------------------------------------------------------------------------------------------------
---> parser stuff
+--> general
 
-	local event_frame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
-	event_frame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
+function PVPScan:ChangeZones()
+
+	local name, type, difficulty, difficultyName, maxPlayers, playerDifficulty, isDynamicInstance, mapID, instanceGroupSize = GetInstanceInfo()
+	local pvpType, isFFA, faction = GetZonePVPInfo()
+	
+	PVPScan.IsInBattleground = false
+	PVPScan.IsInCity = false
+	PVPScan.IsInArena = false
+	PVPScan.IsInOutDoors = false
+	PVPScan.ScanEnabled = false
+	
+	if (pvpType == "contested" and (not type or type == "none")) then
+		PVPScan.IsInOutDoors = true
+		PVPScan.ScanEnabled = true
+	
+	elseif (type == "pvp") then
+		PVPScan.IsInBattleground = true
+	
+	elseif (type == "arena") then
+		PVPScan.IsInArena = true
+	
+	elseif (type and (type == "scenario" or type == "party" or type == "raid" or pvpType == "friendly" or pvpType == "sanctuary")) then
+		PVPScan.ScanEnabled = false
+	
+	else
+		PVPScan.IsInOutDoors = true
+		PVPScan.ScanEnabled = true
+	end
+
+	if (PVPScan.ScanEnabled) then
+		PVPScan:EnableScan()
+	else
+		PVPScan:DisableScan()
+	end
+	
+end
+
+PVPScan:RegisterEvent ("ZONE_CHANGED_NEW_AREA", "ChangeZones")
+PVPScan:RegisterEvent ("PLAYER_ENTERING_WORLD", "ChangeZones")
+
+function PVPScan:EnableScan()
+	PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
+	PVPScan:RefreshSpotBars()
+end
+
+function PVPScan:DisableScan()
+	PVPScan.EventFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
+	PVPScan:RefreshSpotBars()
+end
+
+function PVPScan:LockScanFrame (IsLocked)
+	if (IsLocked) then
+		PVPScanFrame.text:SetText ("")
+		PVPScanFrame:SetBackdrop (nil)
+		PVPScanFrame:EnableMouse (false)
+	else
+		PVPScanFrame.text:SetText ("PVPScan Anchor")
+		PVPScanFrame:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tile = true, TileSize = 64})
+		PVPScanFrame:SetBackdropColor (0, 0, 0, 1)
+		PVPScanFrame:EnableMouse (true)
+	end
+end
+------------------------------------------------------------------------------------------------------------------------------------------------------------
+--> outside world scan
+
+	--> parser
+
+	PVPScan.SpotBars = {}
+	PVPScan.NeedClass = {}
+	PVPScan.NextSpotBar = 1
+	
+	local CurrentShownIndex = {}
+	local CurrentShownHash = {}
+	local CurrentShownTime = {}
+	local NeutralCandidate = {}
+	
+	local find_neutral_players = false
+
+	PVPScan.EventFrame = CreateFrame ("frame", "PVPScanCombatLobReader", UIParent)
+	PVPScan.EventFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
 
 	function PVPScan:OnParserEvent (event, time, token, hidding, who_serial, who_name, who_flags, who_flags2, target_serial, target_name, target_flags, target_flags2, ...)
 
@@ -184,23 +264,53 @@
 			end
 			return
 		end
-
-		if (not PVPScan.CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
-			if (_bit_band (target_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
+		
+		if (not CurrentShownHash [target_name] and _bit_band (target_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
+			if (_bit_band (target_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
 				local class = PVPScan:GuessClass (...)
 				PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
+				
+			elseif (find_neutral_players and _bit_band (target_flags, REACTION_NEUTRAL) ~= 0) then
+				if (NeutralCandidate [target_name]) then
+					NeutralCandidate [target_name] = NeutralCandidate [target_name] + 1
+					if (NeutralCandidate [target_name] == 5) then
+						--print ("neutral", target_name)
+						local class = PVPScan:GuessClass (...)
+						PVPScan:EnemySpoted (target_name, target_serial, target_flags, class)
+					end
+				else
+					NeutralCandidate [target_name] = 1
+				end
+				
+			elseif (NeutralCandidate [target_name]) then
+				NeutralCandidate [target_name] = nil
 			end
 		end
 		
-		if (not PVPScan.CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
-			if (_bit_band (who_flags, REACTION_HOSTILE ) ~= 0) then --> is hostile
+		if (not CurrentShownHash [who_name] and _bit_band (who_flags, OBJECT_TYPE_PLAYER) ~= 0) then --> is player
+			if (_bit_band (who_flags, REACTION_HOSTILE) ~= 0) then --> is hostile
 				local class = PVPScan:GuessClass (...)
 				PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
+			
+			elseif (find_neutral_players and _bit_band (who_flags, REACTION_NEUTRAL) ~= 0) then
+				if (NeutralCandidate [who_name]) then
+					NeutralCandidate [who_name] = NeutralCandidate [who_name] + 1
+					if (NeutralCandidate [who_name] == 5) then
+						--print ("neutral", who_name)
+						local class = PVPScan:GuessClass (...)
+						PVPScan:EnemySpoted (who_name, who_serial, who_flags, class)
+					end
+				else
+					NeutralCandidate [who_name] = 1
+				end
+				
+			elseif (NeutralCandidate [who_name]) then
+				NeutralCandidate [who_name] = nil
 			end
 		end
 	end
 
-	event_frame:SetScript ("OnEvent", PVPScan.OnParserEvent)
+	PVPScan.EventFrame:SetScript ("OnEvent", PVPScan.OnParserEvent)
 	
 	function PVPScan:LeftCombatLockdown()
 		if (PVPScan.schedule_frame_update) then
@@ -214,10 +324,16 @@
 	PVPScan:RegisterEvent ("PLAYER_REGEN_DISABLED", "GotCombatLockdown")
 	PVPScan:RegisterEvent ("PLAYER_REGEN_ENABLED", "LeftCombatLockdown")
 
+	-- found a enemy on the scan
+	
 	function PVPScan:EnemySpoted (name, serial, flags, class)
 
+		if (not name) then
+			return
+		end
+
 		--> check for overwrite
-		local current_player_shown = PVPScan.CurrentShownIndex [PVPScan.NextSpotBar]
+		local current_player_shown = CurrentShownIndex [PVPScan.NextSpotBar]
 		if (current_player_shown) then
 			PVPScan.NeedClass [current_player_shown] = nil
 		end
@@ -231,12 +347,12 @@
 			PVPScan.NeedClass [name] = PVPScan.NextSpotBar
 		end
 		
-		PVPScan.CurrentShownIndex [PVPScan.NextSpotBar] = name
-		PVPScan.CurrentShownHash [name] = PVPScan.NextSpotBar
-		PVPScan.CurrentShownTime [name] = GetTime()
+		CurrentShownIndex [PVPScan.NextSpotBar] = name
+		CurrentShownHash [name] = PVPScan.NextSpotBar
+		CurrentShownTime [name] = GetTime()
 		
 		if (not UnitAffectingCombat ("player") and not InCombatLockdown()) then
-			SpotBar:SetAttribute("macrotext", "/cleartarget\n/targetexact " .. name)
+			SpotBar:SetAttribute ("macrotext", "/cleartarget\n/targetexact " .. name)
 		end
 		
 		SpotBar:Show()
@@ -248,27 +364,36 @@
 
 	end
 	
+	-- frames
 
-	
-------------------------------------------------------------------------------------------------------------------------------------------------------------
---> frames
-
-	function PVPScanOnFrameMouseDown (self)
-		if (not self.IsMoving) then
-			self:StartMoving()
-			self.IsMoving = true
+	function PVPScanOnFrameMouseDown (self, button)
+		if (button == "LeftButton") then
+			if (not self.IsMoving) then
+				self:StartMoving()
+				self.IsMoving = true
+			end
 		end
 	end
 
-	function PVPScanOnFrameMouseUp (self)
-		if (self.IsMoving) then
-			self:StopMovingOrSizing()
-			self.IsMoving = false
+	function PVPScanOnFrameMouseUp (self, button)
+		if (button == "LeftButton") then
+			if (self.IsMoving) then
+				self:StopMovingOrSizing()
+				self.IsMoving = false
+			end
+			
+		elseif (button == "RightButton") then
+			InterfaceOptionsFrame_OpenToCategory ("PVPScan")
+			InterfaceOptionsFrame_OpenToCategory ("PVPScan")
 		end
 	end
 
 	function PVPScan:UpdateBar (index, class, name)
 	
+		if (UnitAffectingCombat ("player") or InCombatLockdown()) then
+			--return
+		end
+	
 		local SpotBar = PVPScan.SpotBars [index]
 		
 		if (class) then
@@ -296,8 +421,14 @@
 			return
 		end
 		
+		if (not PVPScan.ScanEnabled) then
+			PVPScanFrame:Hide()
+		else
+			PVPScanFrame:Show()
+		end
+		
 		local amount_bars = PVPScan.db.profile.SpotBarAmount
-		PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
+		PVPScanFrame:SetSize (PVPScan.db.profile.SpotBarWidth, 20)
 
 		--> we need extra bars?
 		if (amount_bars > #PVPScan.SpotBars) then
@@ -317,11 +448,11 @@
 		if (#PVPScan.SpotBars > amount_bars) then
 			for i = #PVPScan.SpotBars, amount_bars+1, -1 do
 				PVPScan.SpotBars [i]:Hide()
-				local name = PVPScan.CurrentShownIndex [i]
+				local name = CurrentShownIndex [i]
 				if (name) then
-					tremove (PVPScan.CurrentShownIndex, i)
-					PVPScan.CurrentShownHash [name] = nil
-					PVPScan.CurrentShownTime [name] = nil
+					tremove (CurrentShownIndex, i)
+					CurrentShownHash [name] = nil
+					CurrentShownTime [name] = nil
 					PVPScan.NeedClass [name] = nil
 				end
 			end
@@ -330,18 +461,15 @@
 		--> refresh existing
 		for index, bar in ipairs (PVPScan.SpotBars) do
 			local y = (index-1) * PVPScan.db.profile.SpotBarHeight * -1
-			bar:SetPoint ("topleft", PVPScanFrame, "topleft", 0, y)
+			bar:SetPoint ("topleft", PVPScanFrame, "bottomleft", 0, y)
 			bar:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
+			bar.classtexture:SetSize (PVPScan.db.profile.SpotBarWidth, PVPScan.db.profile.SpotBarHeight)
+			bar.classicon:SetSize (PVPScan.db.profile.SpotBarHeight, PVPScan.db.profile.SpotBarHeight)
 		end
 		
 	end
 
-
-
-
-
-------------------------------------------------------------------------------------------------------------------------------------------------------------
---> misc
+	--> misc
 
 	function PVPScan:GuessClass (...)
 		local arg1, arg2, arg3, arg4 = select (1, ...)
@@ -373,3 +501,7 @@
 		return nil
 	end
 
+
+------------------------------------------------------------------------------------------------------------------------------------------------------------
+--> battlegrounds
+
--- a/PVPScan.xml	Sat May 17 02:17:10 2014 -0300
+++ b/PVPScan.xml	Mon May 19 05:50:51 2014 -0300
@@ -18,11 +18,11 @@
 		
 		<Scripts>
 			<OnMouseDown>
-				PVPScanOnFrameMouseDown (self)
+				PVPScanOnFrameMouseDown (self, button)
 			</OnMouseDown>
 			
 			<OnMouseUp>
-				PVPScanOnFrameMouseUp (self)
+				PVPScanOnFrameMouseUp (self, button)
 			</OnMouseUp>
 			
 			<OnLoad>