Quantcast

* Added the aggro and range checking modules.

James Whitehead II [12-31-06 - 21:21]
* Added the aggro and range checking modules.
Filename
Localization.enUS.lua
PerfectRaid.lua
PerfectRaid.toc
PerfectRaid_Aggro.lua
PerfectRaid_Range.lua
diff --git a/Localization.enUS.lua b/Localization.enUS.lua
index 10910a7..e0dfb82 100644
--- a/Localization.enUS.lua
+++ b/Localization.enUS.lua
@@ -2,4 +2,5 @@ PerfectRaidLocals = {
 	["Dead"] = "Dead",
 	["Ghost"] = "Ghost",
 	["Offline"] = "Offline",
+	["Aggro"] = "|cFFFF1111Aggro|r",
 }
diff --git a/PerfectRaid.lua b/PerfectRaid.lua
index 3d9ac4c..2d83b9d 100644
--- a/PerfectRaid.lua
+++ b/PerfectRaid.lua
@@ -31,6 +31,7 @@

 local frames = {}
 local unavail = {}
+local aggro = {}

 local L = PerfectRaidLocals
 local utils = DongleStub("DongleUtils")
@@ -38,6 +39,7 @@ PerfectRaid = DongleStub("Dongle"):New("PerfectRaid")

 function PerfectRaid:Initialize()
 	self.frames = frames
+	self.aggro = aggro
 	self.defaults = {
 		profile = {
 			headers = {},
@@ -46,7 +48,7 @@ function PerfectRaid:Initialize()
 	}

 	self.headerDefaults = {
-		Reverse = true,
+		Reverse = false,
 		ColorClass = false,
 		ColorSeverity = true,
 	}
@@ -189,6 +191,14 @@ function PerfectRaid:UNIT_HEALTH(event, unit)
 		deficit = ""
 	end

+	if aggro[unit] and aggro[unit] >= 15 then
+		if deficit == "" then
+			deficit = L["Aggro"]
+		else
+			deficit = "|cFFFF1111"..deficit.."|r"
+		end
+	end
+
 	if UnitIsDead(unit) or UnitIsGhost(unit) or not UnitIsConnected(unit) then
 		local status

diff --git a/PerfectRaid.toc b/PerfectRaid.toc
index 7b73cc1..b0dff01 100644
--- a/PerfectRaid.toc
+++ b/PerfectRaid.toc
@@ -12,5 +12,6 @@ PerfectRaid.xml
 PerfectRaid.lua

 PerfectRaid_Buffs.lua
-
+PerfectRaid_Range.lua
+PerfectRaid_Aggro.lua

diff --git a/PerfectRaid_Aggro.lua b/PerfectRaid_Aggro.lua
index 41794d1..643af34 100644
--- a/PerfectRaid_Aggro.lua
+++ b/PerfectRaid_Aggro.lua
@@ -29,37 +29,29 @@
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------]]

-local class = select(2, UnitClass("player"))
-local spells = {
-	DRUID = "Healing Touch",
-	SHAMAN = "Healing Wave",
-	PRIEST = "Lesser Heal",
-	PALADIN = "Holy Light",
-}
-
-local rangespell = spells[class]
+local Aggro = PerfectRaid:NewModule("PerfectRaid-Aggro")

+local frames,aggro
 local victims = {}
 local targets = {}
 local flashing = {}

-if rangespell then
-	local elapsed = 0
-	function PerfectRaid.OnUpdate(frame, arg1)
-		elapsed = elapsed + arg1
-		if elapsed >= 0.5 then
-			if rangespell then
-				for unit,tbl in pairs(frames) do
-					local range = IsSpellInRange(rangespell, unit) == 1
-					local alpha = range and 1.0 or 0.3
-					for frame in pairs(tbl) do
-						if not flashing[frame] then
-							frame:SetAlpha(alpha)
-						end
-					end
-				end
-			end
-
+function Aggro:Initialize()
+	frames = PerfectRaid.frames
+	aggro = PerfectRaid.aggro
+end
+
+function Aggro:Enable()
+	local frame = CreateFrame("Frame")
+	frame:SetScript("OnUpdate", self.OnUpdate)
+end
+
+local elapsed = 0
+function Aggro.OnUpdate()
+	local self = Aggro
+	elapsed = elapsed + arg1
+	if elapsed >= 0.2 then
+		for unit,tbl in pairs(frames) do
 			-- Aggro check
 			for unit,tbl in pairs(frames) do
 				if not targets[unit] then
@@ -86,87 +78,14 @@ if rangespell then
 					aggro[unit] = aggro[unit] - 5
 				end

+				-- Use this when a unit has aggro
 				if aggro[unit] >= 15 then
-					showaggro(unit)
+					--self:FlashAggro(unit)
 				end

 				local name = UnitName(unit)
 			end
-
-			elapsed = 0
-		end
-	end
-
-	local frame = CreateFrame("Frame", "PRUpdateFrame")
-	frame:SetScript("OnUpdate", PerfectRaid.OnUpdate)
-end
-
-function showaggro(unit)
-	if true then return end
-	for frame in pairs(frames[unit]) do
-		local name = frame:GetName()
-		local texture = frame.healthbar.aggro
-		if not texture then
-			local bar = frame.healthbar
-			texture = frame.healthbar:CreateTexture(name.."Aggro", "ARTWORK")
-			texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
-			texture:SetAllPoints(bar)
-			frame.healthbar.aggro = texture
-		end
-		texture:SetVertexColor(1,0,0)
-		UIFrameFlash(texture, 0.4, 0.4, 2, nil, 0.1, 0.1)
-	end
-end
-
-local textures = {}
-local handlers = {}
-function flashbar(frame, length, wait)
-	if not textures[frame] then
-		texture = frame:CreateTexture(nil, "ARTWORK")
-		texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
-		texture:SetPoint("TOPLEFT", 0, 0)
-		texture:SetPoint("BOTTOMLEFT", 0, 0)
-		textures[frame] = texture
-	end
-
-	frame.fadeLength = length or 0.4
-	frame.fadeTime = 0
-	frame.waitLength = wait or 0.1
-	frame.waitTime = 0
-	frame.waitHalf = true
-
-	if not handlers[frame] then
-		local function handler(frame, arg1)
-			frame.fadeTime = frame.fadeTime + arg1
-			local half = frame.fadeLength / 2
-			if frame.fadeTime < half then
-				-- We're fading out
-				local alpha = 1 - (frame.fadeTime / half)
-				frame:SetAlpha(alpha)
-			elseif frame.fadeTime <= frame.fadeLength then
-				if frame.waitHalf then
-					frame.fadeTime = frame.fadeTime - arg1
-					frame.waitTime = frame.waitTime + arg1
-					if frame.waitTime >= frame.waitLength then
-						frame.waitHalf = false
-					end
-				else
-					local alpha = (frame.fadeTime - half) / half
-					frame:SetAlpha(alpha)
-				end
-			else
-				frame.waitTime = frame.waitTime + arg1
-				if frame.waitTime >= frame.waitLength then
-					frame.fadeTime = 0
-					frame.waitTime = 0
-					frame.waitHalf = true
-				end
-			end
 		end
-		handlers[frame] = handler
-	end
-
-	frame:SetScript("OnUpdate", handlers[frame])
+		elapsed = 0
+	end
 end
-
---flashbar(PlayerFrame, 2, 1)
\ No newline at end of file
diff --git a/PerfectRaid_Range.lua b/PerfectRaid_Range.lua
index 41794d1..5fa8ce6 100644
--- a/PerfectRaid_Range.lua
+++ b/PerfectRaid_Range.lua
@@ -29,144 +29,39 @@
   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 ---------------------------------------------------------------------------]]

-local class = select(2, UnitClass("player"))
-local spells = {
-	DRUID = "Healing Touch",
-	SHAMAN = "Healing Wave",
-	PRIEST = "Lesser Heal",
-	PALADIN = "Holy Light",
-}
+local Range = PerfectRaid:NewModule("PerfectRaid-Range")
+local frames, rangespell

-local rangespell = spells[class]
-
-local victims = {}
-local targets = {}
-local flashing = {}
-
-if rangespell then
-	local elapsed = 0
-	function PerfectRaid.OnUpdate(frame, arg1)
-		elapsed = elapsed + arg1
-		if elapsed >= 0.5 then
-			if rangespell then
-				for unit,tbl in pairs(frames) do
-					local range = IsSpellInRange(rangespell, unit) == 1
-					local alpha = range and 1.0 or 0.3
-					for frame in pairs(tbl) do
-						if not flashing[frame] then
-							frame:SetAlpha(alpha)
-						end
-					end
-				end
-			end
-
-			-- Aggro check
-			for unit,tbl in pairs(frames) do
-				if not targets[unit] then
-					targets[unit] = unit.."target"
-					victims[unit] = unit.."targettarget"
-					aggro[unit] = 0
-				end
-
-				local target = targets[unit]
-				local victim = victims[unit]
-				if UnitIsUnit(victim, unit) and UnitCanAttack(unit, target) then
-					-- unit is being targeted by a hostile mob
-					if aggro[unit] < 20 then
-						local val = aggro[unit]
-						if val >= 5 and val <= 10 then
-							PerfectRaid:UNIT_HEALTH(nil, unit)
-						end
-						aggro[unit] = val + 10
-					end
-				end
-
-				-- Aggro decay (thanks BanzaiLib)
-				if aggro[unit] >= 5 then
-					aggro[unit] = aggro[unit] - 5
-				end
-
-				if aggro[unit] >= 15 then
-					showaggro(unit)
-				end
-
-				local name = UnitName(unit)
-			end
-
-			elapsed = 0
-		end
-	end
-
-	local frame = CreateFrame("Frame", "PRUpdateFrame")
-	frame:SetScript("OnUpdate", PerfectRaid.OnUpdate)
-end
-
-function showaggro(unit)
-	if true then return end
-	for frame in pairs(frames[unit]) do
-		local name = frame:GetName()
-		local texture = frame.healthbar.aggro
-		if not texture then
-			local bar = frame.healthbar
-			texture = frame.healthbar:CreateTexture(name.."Aggro", "ARTWORK")
-			texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
-			texture:SetAllPoints(bar)
-			frame.healthbar.aggro = texture
-		end
-		texture:SetVertexColor(1,0,0)
-		UIFrameFlash(texture, 0.4, 0.4, 2, nil, 0.1, 0.1)
-	end
+function Range:Initialize()
+	frames = PerfectRaid.frames
 end

-local textures = {}
-local handlers = {}
-function flashbar(frame, length, wait)
-	if not textures[frame] then
-		texture = frame:CreateTexture(nil, "ARTWORK")
-		texture:SetTexture("Interface\\AddOns\\PerfectRaid\\images\\smooth")
-		texture:SetPoint("TOPLEFT", 0, 0)
-		texture:SetPoint("BOTTOMLEFT", 0, 0)
-		textures[frame] = texture
-	end
+function Range:Enable()
+	local class = select(2, UnitClass("player"))
+	local spells = {
+		DRUID = "Healing Touch",
+		SHAMAN = "Healing Wave",
+		PRIEST = "Lesser Heal",
+		PALADIN = "Holy Light",
+	}

-	frame.fadeLength = length or 0.4
-	frame.fadeTime = 0
-	frame.waitLength = wait or 0.1
-	frame.waitTime = 0
-	frame.waitHalf = true
+	rangespell = spells[class]
+
+	local frame = CreateFrame("Frame")
+	frame:SetScript("OnUpdate", self.OnUpdate)
+end

-	if not handlers[frame] then
-		local function handler(frame, arg1)
-			frame.fadeTime = frame.fadeTime + arg1
-			local half = frame.fadeLength / 2
-			if frame.fadeTime < half then
-				-- We're fading out
-				local alpha = 1 - (frame.fadeTime / half)
-				frame:SetAlpha(alpha)
-			elseif frame.fadeTime <= frame.fadeLength then
-				if frame.waitHalf then
-					frame.fadeTime = frame.fadeTime - arg1
-					frame.waitTime = frame.waitTime + arg1
-					if frame.waitTime >= frame.waitLength then
-						frame.waitHalf = false
-					end
-				else
-					local alpha = (frame.fadeTime - half) / half
+local elapsed = 0
+function Range.OnUpdate()
+	elapsed = elapsed + arg1
+	if elapsed >= 0.2 then
+		for unit,tbl in pairs(frames) do
+			local range = IsSpellInRange(rangespell, unit) == 1
+			local alpha = range and 1.0 or 0.3
+			for frame in pairs(tbl) do
 					frame:SetAlpha(alpha)
-				end
-			else
-				frame.waitTime = frame.waitTime + arg1
-				if frame.waitTime >= frame.waitLength then
-					frame.fadeTime = 0
-					frame.waitTime = 0
-					frame.waitHalf = true
-				end
 			end
 		end
-		handlers[frame] = handler
-	end
-
-	frame:SetScript("OnUpdate", handlers[frame])
+		elapsed = 0
+	end
 end
-
---flashbar(PlayerFrame, 2, 1)
\ No newline at end of file