DaVis/healalarm.lua

172 lines
4.4 KiB
Lua

local name,addon = ...
local healers = {}
local spells = {}
local ha,db,hi
local soundlist = { -- https://de.wowhead.com/sound=79829/7-1-5-brawlers-guild-mushroom-laughter-dqv
18871
}
local hw = CreateFrame("Frame",name.."Healwarning",addon.scrollframe)
hw:SetWidth(32)
hw:SetHeight(32)
hw:SetScript("OnEnter", function(self)
addon.cTip:SetOwner(self, "BOTTOMRIGHT");
addon.cTip:ClearLines()
addon.cTip:AddLine("Healerlist")
for k in pairs(healers) do
addon.cTip:AddLine(k)
end
addon.cTip:Show()
end)
hw:SetScript("OnLeave", function()
addon.cTip:Hide()
end)
hw:SetPoint("BOTTOMRIGHT",addon.scrollframe,"TOPRIGHT")
local tex = hw:CreateTexture()
tex:SetTexture("Interface\\Icons\\spell_holy_renew")
tex:SetAllPoints(hw)
hw:Hide()
hw:RegisterEvent("PLAYER_REGEN_ENABLED")
hw:SetScript("OnEvent",function(self)
self:Hide()
end)
function addon:ShowHeal()
hw:Show()
end
function addon:HideHeal()
hw:Hide()
end
local lastPlayed = 0
function addon:AddHealer(healerName,spellID)
if(not UnitInParty(healerName)) then
healers[healerName] = healers[healerName] or {}
db['healdb'][healerName] = db['healdb'][healerName] or {}
if(not InCombatLockdown()) then return end
if(spellID) then
if(lastPlayed<GetTime()) then
local willPlay, soundHandle = PlaySound(soundlist[1],"Master",false)
if(willPlay) then
C_Timer.After(2,function() if(soundHandle) then StopSound(soundHandle,2) end end)
end
lastPlayed = GetTime() + 4
end
spells[spellID] = true
db['healdb'][healerName]['spells'] = db['healdb'][healerName]['spells'] or {}
db['healdb'][healerName]['info'] = db['healdb'][healerName]['info'] or {}
healers[healerName]['spells'] = healers[healerName]['spells'] or {}
local mapID = C_Map.GetBestMapForUnit("player")
db['healdb'][healerName]['spells'][spellID] = db['healdb'][healerName]['spells'][spellID] or {}
if(mapID) then
db['healdb'][healerName]['info'][mapID] = db['healdb'][healerName]['info'][mapID] or C_Map.GetMapInfo(mapID)
end
healers[healerName]['spells'][spellID] = true
end
end
self:ShowHeal()
ha:Show()
addon:UpdateUnits()
end
function addon:GetHealers()
return healers
end
function addon:GetHeals()
return spells
end
function addon:GetNumHealers()
local n = 0
for k,v in pairs(healers) do
n = n + 1
end
return n
end
function addon:GetAreaHealers(mapID)
local list = {}
if(mapID) then
for k,v in pairs(db['healdb']) do
if(v['info']) then
for a,b in pairs(v['info']) do
if(a==mapID) then
list[#list+1] = k
end
end
end
end
end
return list
end
addon.inits[#addon.inits + 1] = function()
db = addon['db']['profile'][name] or {}
db['healdb'] = db['healdb'] or {}
for k,v in pairs(db['healdb']) do
v['spells'] = v['spells'] or {}
for a,b in pairs(v['spells']) do
spells[a] = true
end
end
hi = addon:AddInfoButton(12883,function(self)
addon.cTip:SetOwner(self, "BOTTOMRIGHT");
addon.cTip:ClearLines()
local mapID = C_Map.GetBestMapForUnit("player")
if(mapID) then
local cnt = 0
local mapInfo = C_Map.GetMapInfo(mapID)
addon.cTip:AddLine(mapInfo["name"])
local list = addon:GetAreaHealers(mapID)
for k,v in pairs(list) do
addon.cTip:AddLine(v)
end
if(#list>0) then
addon.cTip:Show()
end
else
addon.cTip:Hide()
end
end,function(self)
addon.cTip:Hide()
end)
hi:SetScript("OnEvent", function(self,event)
local mapID,list = C_Map.GetBestMapForUnit("player"),{}
if(mapID) then
list = addon:GetAreaHealers(mapID)
end
if(#list>0) then
self:Show()
else
self:Hide()
end
if(GetZonePVPInfo()=='sactuary') then -- hide in sanctuary
addon.scrollframe:Hide()
else
local mapID = C_Map.GetBestMapForUnit("player")
if(mapID) then
local info = C_Map.GetMapInfo(mapID)
if(info and (info['mapID'] == 1161 or info['mapID'] == 1165)) then -- hide in dazar'alor / boralus
addon.scrollframe:Hide()
end
end
end
end)
hi:RegisterEvent("ZONE_CHANGED")
hi:RegisterEvent("ZONE_CHANGED_INDOORS")
hi:RegisterEvent("ZONE_CHANGED_NEW_AREA")
hi:RegisterEvent("NEW_WMO_CHUNK")
hi:RegisterEvent("PLAYER_REGEN_ENABLED")
hi:GetScript("OnEvent")(hi,"FIRE")
ha = addon:AddInfoButton(139, function(self)
addon.cTip:SetOwner(self, "BOTTOMRIGHT");
addon.cTip:ClearLines()
addon.cTip:AddLine("Healerlist")
for k in pairs(healers) do
addon.cTip:AddLine(k)
end
addon.cTip:Show()
end,function(self)
addon.cTip:Hide()
end)
if(addon:GetNumHealers()>0) then
ha:Show()
else
ha:Hide()
end
end