diff Hansgar_And_Franzok_Assist.lua @ 4:1c3534391efb

- Added timeout for stampers.
author Tercio
date Mon, 02 Mar 2015 21:28:33 -0300
parents 23e19ba2b62c
children 789bf9e40966
line wrap: on
line diff
--- a/Hansgar_And_Franzok_Assist.lua	Tue Feb 24 14:53:29 2015 -0300
+++ b/Hansgar_And_Franzok_Assist.lua	Mon Mar 02 21:28:33 2015 -0300
@@ -3,10 +3,14 @@
 local UnitExists = UnitExists
 local GetPlayerMapPosition = GetPlayerMapPosition
 local UnitHealth = UnitHealth
+local GetNumGroupMembers = GetNumGroupMembers
+local abs = abs
 
 local f = CreateFrame ("frame", "Hansgar_And_Franzok_Assist", UIParent)
 f:SetFrameStrata ("DIALOG")
 
+local tframe = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_PTrack", UIParent)
+
 f:SetSize (155, 156)
 f:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
 edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8})
@@ -44,8 +48,67 @@
 
 --
 
+local player_pos_frame = CreateFrame ("frame", "Hansgar_And_Franzok_Assist_DanceBar", UIParent)
+player_pos_frame:SetPoint ("topleft", player_bar, "bottomleft", 0, -3)
+player_pos_frame:SetPoint ("topright", player_bar, "bottomright", 0, -3)
+player_pos_frame:SetHeight (14)
+player_pos_frame:SetBackdrop ({bgFile = "Interface\\Tooltips\\UI-Tooltip-Background", tile = true, tileSize = 16, insets = {left = -1, right = -1, top = -1, bottom = -1},
+edgeFile = "Interface\\AddOns\\Hansgar_And_Franzok_Assist\\border_2", edgeSize = 8})
+player_pos_frame:SetBackdropColor (0, 0, 0, 1)
+player_pos_frame:Hide()
+
+--red
+local t1 = player_pos_frame:CreateTexture (nil, "artwork")
+t1:SetPoint ("left", player_pos_frame, "left")
+t1:SetSize (player_pos_frame:GetWidth()*0.30, 14)
+t1:SetTexture (1, 1, 1)
+--t1:SetTexCoord (260/512, 430/512, 29/256, 82/256)
+t1:SetVertexColor (1, 0.2, 0.2, 0.4)
+
+--green
+local t2 = player_pos_frame:CreateTexture (nil, "artwork")
+t2:SetPoint ("left", t1, "right")
+t2:SetSize (player_pos_frame:GetWidth()*0.15, 14)
+t2:SetTexture (0.2, 1, 0.2, 0.4)
+
+--red
+local middle = player_pos_frame:CreateTexture (nil, "artwork")
+middle:SetPoint ("left", t2, "right")
+middle:SetSize (player_pos_frame:GetWidth()*0.10, 14)
+middle:SetTexture (1, 1, 1)
+--middle:SetTexCoord (260/512, 430/512, 29/256, 82/256)
+middle:SetVertexColor (1, 0.2, 0.2, 0.4)
+
+--green
+local t3 = player_pos_frame:CreateTexture (nil, "artwork")
+t3:SetPoint ("left", middle, "right")
+t3:SetSize (player_pos_frame:GetWidth()*0.15, 14)
+t3:SetTexture (0.2, 1, 0.2, 0.4)
+
+--red
+local t4 = player_pos_frame:CreateTexture (nil, "artwork")
+t4:SetPoint ("left", t3, "right")
+t4:SetSize (player_pos_frame:GetWidth()*0.30, 14)
+t4:SetTexture (1, 1, 1)
+--t4:SetTexCoord (260/512, 430/512, 29/256, 82/256)
+t4:SetVertexColor (1, 0.2, 0.2, 0.4)
+
+local div = player_pos_frame:CreateTexture (nil, "overlay")
+div:SetPoint ("left", player_pos_frame, "left", 0, 0)
+div:SetTexture (1, 1, 1, 1)
+div:SetSize (1, 16)
+div:Hide()
+--
+
+local AceTimer = LibStub:GetLibrary ("AceTimer-3.0")
+AceTimer:Embed (f)
+local AceComm = LibStub:GetLibrary ("AceComm-3.0")
+AceComm:Embed (f)
+
 local db
 
+f.block_tracker = {}
+
 frame_event:SetFrameStrata ("FULLSCREEN")
 
 frame_event:SetScript ("OnEvent", function (self, event, ...)
@@ -57,8 +120,15 @@
 			db = {}
 			Hansgar_And_Franzok_DB = db
 		end
+		--
 		db.STAMPERS_DELAY = db.STAMPERS_DELAY or 5
-		
+		if (db.CD_NUMBER == nil) then
+			db.CD_NUMBER = false
+		end
+		if (db.SHOW_DANCE == nil) then
+			db.SHOW_DANCE = true
+		end
+		--
 		SLASH_Hansgar_And_Franzok_Assist1, SLASH_Hansgar_And_Franzok_Assist2 = "/hansgar", "/franzok"
 		function SlashCmdList.Hansgar_And_Franzok_Assist (msg, editbox)
 		
@@ -75,18 +145,40 @@
 				
 			elseif (command == "test" or command == "show") then
 				if (f.StampersPhase) then
+					f:EndTrackPlayerPosition()
 					return f:StopTracking()
 				end
+				
 				f:StartTracking()
+				f:StartTrackPlayerPosition()
 				
 			elseif (command == "hide") then
 				if (f.StampersPhase) then
 					return f:StopTracking()
 				end
+				f:EndTrackPlayerPosition()
 
+			elseif (command == "dance") then
+				db.SHOW_DANCE = not db.SHOW_DANCE
+				if (db.SHOW_DANCE) then
+					if (f.on_encounter) then
+						f:StartTrackPlayerPosition()
+					end
+					print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars enabled.")
+				else
+					f:EndTrackPlayerPosition()
+					print ("|cFFFFAA00Hansgar and Franzok Assist|r dance bars disabled.")
+				end
+			
+			elseif (command == "cooldown") then
+				db.CD_NUMBER = not db.CD_NUMBER
+				f:RefreshCooldownSettings()
+				
 			else
-				print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00v0.4|r Commands:")
+				print ("|cFFFFAA00Hansgar and Franzok Assist|r |cFF00FF00v0.5|r Commands:")
 				print ("|cFFFFFF00/hansgar delay <time>|r: time in seconds until the percentage goes from 0 to 100.")
+				print ("|cFFFFFF00/hansgar cooldown|r: show the countdown for each stamper go back up to the ceiling.")
+				--print ("|cFFFFFF00/hansgar dance|r: toggle dance bar (used to dodge regular stampers and searing plates).")
 				print ("|cFFFFFF00/hansgar test|r: active the addon on test mode.")
 				print ("|cFFFFFF00/hansgar show|r: show the window and start test mode.")
 				print ("|cFFFFFF00/hansgar hide|r: hide the window.")
@@ -96,6 +188,24 @@
 	elseif (event == "ENCOUNTER_START" or event == "ENCOUNTER_END") then
 	
 		local encounterID, encounterName, difficultyID, raidSize = select (1, ...)
+		
+		if (encounterID == 1693) then
+			if (event == "ENCOUNTER_START") then
+				f.on_encounter = true
+			elseif (event == "ENCOUNTER_END") then
+				f.on_encounter = false
+			end
+		end
+		
+		if (encounterID == 1693 and db.SHOW_DANCE) then
+			if (event == "ENCOUNTER_START") then
+				SetMapToCurrentZone()
+				f:StartTrackPlayerPosition()
+			elseif (event == "ENCOUNTER_END") then
+				f:EndTrackPlayerPosition()
+			end
+		end
+		
 		if (encounterID == 1693 and difficultyID == 16) then
 		
 			if (event == "ENCOUNTER_START") then
@@ -113,6 +223,8 @@
 				if (f.StampersPhase) then
 					f:StopTracking()
 				end
+				
+				f:EndTrackPlayerPosition()
 			end
 		end
 	end
@@ -137,7 +249,9 @@
 local frame_tracker = CreateFrame ("frame", "Hansgar_And_Franzok_AssistTracker", UIParent)
 local on_update_tracker = function (self, elapsed)
 	
-	for i = 1, GetNumGroupMembers() do
+	local raid_size = GetNumGroupMembers()
+	
+	for i = 1, raid_size do
 		local x, y = GetPlayerMapPosition ("raid"..i)
 		if (UnitExists ("raid"..i) and UnitHealth ("raid"..i) > 1 and x and y) then
 			local block = f:WhichBlock (x, y)
@@ -152,7 +266,7 @@
 	
 	local px, py = GetPlayerMapPosition ("player")
 	local player_block = f:WhichBlock (px, py)
-	if (player_block) then
+	if (player_block and raid_size > 0) then
 		
 		local time_limit_at = f.block_tracker [player_block] + db.STAMPERS_DELAY
 		local time_now = GetTime()
@@ -236,23 +350,53 @@
 			self:SetScript ("OnUpdate", nil)
 			self.stamper_icon:Show()
 			self.number:Hide()
+			self.cooldown:SetCooldown (GetTime(), 37 - db.STAMPERS_DELAY, 0, 0)
 		end
 	end
 end
+
+function f:UnPaint (block)
+	f:ResetBlock (block)
+end
 function f:Paint (block)
 	block.step = 0
 	block.total_time = 0
 	block:SetScript ("OnUpdate", painting)
+	local unpaint = f:ScheduleTimer ("UnPaint", 37, block)
+	block.unpaint_process = unpaint
+end
+
+function f:ResetBlock (block)
+	block:SetScript ("OnUpdate", nil)
+	block:SetBackdropColor (.8, .8, .8, 0.5)
+	block.number:SetText (block.id)
+	block.number:SetTextColor (1, 1, 1, 0.5)
+	block.number:Show()
+	block.stamper_icon:Hide()
+	block.cooldown:SetCooldown (0, 0, 0, 0)
+	
+	f.block_tracker [block.id] = nil
+	if (block.unpaint_process) then
+		f:CancelTimer (block.unpaint_process)
+		block.unpaint_process = nil
+	end
 end
 
 function f:ResetBlocks()
 	for _, block in ipairs (f.all_blocks) do
-		block:SetScript ("OnUpdate", nil)
-		block:SetBackdropColor (.8, .8, .8, 0.5)
-		block.number:SetText (block.id)
-		block.number:SetTextColor (1, 1, 1, 0.5)
-		block.number:Show()
-		block.stamper_icon:Hide()
+		f:ResetBlock (block)
+	end
+end
+
+function f:RefreshCooldownSettings()
+	for _, block in ipairs (f.all_blocks) do
+		if (not db.CD_NUMBER) then
+			block.cooldown:SetHideCountdownNumbers (true)
+			block.cooldown:SetDrawEdge (false)
+		else
+			block.cooldown:SetHideCountdownNumbers (false)
+			block.cooldown:SetDrawEdge (true)
+		end
 	end
 end
 
@@ -280,6 +424,17 @@
 		block:SetScript ("OnMouseDown", on_mouse_down)
 		block:SetScript ("OnMouseUp", on_mouse_up)
 		
+		local cooldown = CreateFrame ("cooldown", "Hansgar_And_Franzok_Assist_BlockCooldown" .. i, block, "CooldownFrameTemplate")
+		cooldown:SetAllPoints()
+		cooldown:SetFrameLevel (block:GetFrameLevel()+2)
+		
+		if (not db.CD_NUMBER) then
+			cooldown:SetHideCountdownNumbers (true)
+			cooldown:SetDrawEdge (false)
+		end
+		
+		block.cooldown = cooldown
+		
 		block.id = i
 		
 		local number = block:CreateFontString (nil, "artwork", "GameFontHighlight")
@@ -310,6 +465,117 @@
 	
 end
 
+local safe_track = {
+	--space 1
+	{
+		block = {x1 = 0.50154542922974, x2 = 0.49563668874741},
+		left = {x1 = 0.49963343143463, x2 = 0.49963343143463 - 0.000935000000000}, 
+		right = {x1 = 0.49710285663605, x2 = 0.49710285663605 + 0.001012229919432}, 
+		-- {x1 = 0.49963343143463, y1 = 0.73492467403412} -- {x1 = 0.49710285663605, y1 = 0.74445152282715}
+	},
+	--space 2
+	{
+		block = {x1 = 0.4858917593956, x2 = 0.48044270277023},
+		left = {x1 = 0.48433673381805, x2 = 0.48433673381805 - 0.00091059207916}, 
+		right = {x1 = 0.48206025362015, x2 = 0.48206025362015 + 0.00075059207916},
+		-- {x1 = 0.48433673381805, y1 = 0.74292266368866} -- {x1 = 0.48206025362015, y1 = 0.78930181264877}
+	},
+	--space 3
+	{
+		block = {x1 = 0.47047740221024, x2 = 0.4648859500885},
+		left = {x1 = 0.46893924474716, x2 = 0.46893924474716 - 0.001032948493956},  
+		right = {x1 = 0.46635687351227, x2 = 0.46635687351227 + 0.001032948493956},
+		--{x1 = 0.46893924474716, y1 = 0.7981019616127} -- {x1 = 0.46635687351227, y1 = 0.73558133840561}
+	},
+	--space 4
+	{
+		block = {x1 = 0.45503282546997, x2 = 0.44976264238358},
+		left = {x1 = 0.4533554315567, x2 = 0.4533554315567 - 0.000774573974608}, 
+		right = {x1 = 0.45124399662018, x2 = 0.45124399662018 + 0.000770009999999},
+		--{x1 = 0.4533554315567, y1 = 0.74078941345215} -- {x1 = 0.45124399662018, y1 = 0.74088287353516}
+	}
+}
+Hansgar_safe_track = safe_track
+
+--	/hansgar test
+--	/run Hansgar_safe_track [1].block.x1 = 0.50154542922974
+
+local red_alpha_disabled = 0.15
+local red_alpha_enabled = 0.5
+
+local green_alpha_disabled = 0.05
+local green_alpha_enabled = 0.9
+
+local track_function = function (self, elapsed)
+	
+	local x, _ = GetPlayerMapPosition ("player")
+	local block
+	
+	for i = 1, #safe_track do
+		local loc = safe_track [i]
+		if (x >= loc.block.x2 and x <= loc.block.x1) then
+			block = i
+			break
+		end
+	end
+	
+	if (block) then
+	
+		player_pos_frame:Show()
+		block = safe_track [block]
+		
+		if (x >= block.left.x2 and x <= block.left.x1) then
+			t2:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
+			t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			
+			t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
+			t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 
+			middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
+			
+		elseif (x <= block.right.x2 and x >= block.right.x1) then
+			t3:SetTexture (0.1, 1, 0.1, green_alpha_enabled)
+			t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			
+			t1:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
+			t4:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red 
+			middle:SetVertexColor (1, 0.2, 0.2, red_alpha_disabled) --red
+			
+		else
+			t1:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red
+			t4:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red 
+			middle:SetVertexColor (1, 0.2, 0.2, red_alpha_enabled) --red
+			
+			t2:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			t3:SetTexture (0.2, 1, 0.2, green_alpha_disabled)
+			
+		end
+		
+		--x = x - block.block.x2
+		--local at = abs ((x / (block.block.x1 - block.block.x2) * 100) - 100)
+		--div:SetPoint ("left", player_pos_frame, "left", self.width_pixel * at, 0)
+
+	else
+		player_pos_frame:Hide()
+	end
+end
+
+function f:StartTrackPlayerPosition()
+
+	--> under development
+	if (true) then
+		return
+	end
+
+	player_pos_frame:Show()
+	tframe.width = player_pos_frame:GetWidth()
+	tframe.width_pixel = tframe.width / 100
+	tframe:SetScript ("OnUpdate", track_function)
+end
+function f:EndTrackPlayerPosition()
+	player_pos_frame:Hide()
+	tframe:SetScript ("OnUpdate", nil)
+end
+
 local locs = {
 	--block 1:
 	{x1 = 0.51103663444519, y1 = 0.79726493358612, x2 = 0.50061076879501, y2 = 0.8241291642189},