Thread: Table Iteration
View Single Post
03-31-13, 12:04 AM   #16
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I'd go with something like this:
Code:
local healBuffs = {
	[(GetSpellInfo(47788))] = 1.6,  -- Guardian Spirit
	[(GetSpellInfo(55233))] = 1.25, -- Vampiric Blood; needs to be adjusted for glyph
}

local healDebuffs = {
	[(GetSpellInfo(8680))] = 0.75, -- Wound Poison
}

local unitIncomingHeals = {}
local unitModifiedHeals = {}

local MyAddon = CreateFrame("Frame")
MyAddon:SetScript("OnEvent", function(self, event, ...) return self[event] and self[event](self, ...) end)
MyAddon:RegisterEvent("UNIT_INCOMING_HEALS")

function MyAddon:UNIT_AURA(unit)
	local amount = unitIncomingHeals[unit]
	if not amount then return end

	for buff, mult in pairs(healBuffs) do
		local exists, _, _, count = UnitBuff(unit, buff)
		if exists then
			amount = amount * (mult * (count or 1))
		end
	end
	for debuff, mult in pairs(healDebuffs) do
		local exists, _, _, count = UnitDebuff(unit, buff)
		if exists then
			amount = amount * (mult * (count or 1))
		end
	end

	if unitModifiedHeals == amount then return end
	unitModifiedHeals[unit] = amount
	
	print("New heal amount on", unit, "is", floor(amount))
end

function MyAddon:UNIT_HEAL_PREDICTION(unit)
	local amount = UnitGetIncomingHeals(unit)
	if amount and amount > 0 then
		if not next(unitIncomingHeals) then
			self:RegisterEvent("UNIT_AURA")
		end
		unitIncomingHeals[unit] = amount
		return self:UNIT_AURA(unit)
	else
		unitIncomingHeals[unit] = nil
		if not next(unitIncomingHeals) then
			self:UnregisterEvent("UNIT_AURA")
		end
	end
end
Also, if you want a spreadsheet of all currently known healing debuffs, including spellIDs, amounts, stacks, sources, etc. send me a PM with your email address.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote