-- incoming.lua -- 2020 Aleksi Blinnikka local _; local UnitGUID, UnitIsEnemy = UnitGUID, UnitIsEnemy; local _, addon = ...; local guids = addon.FrameGuids; local abilities = { [260741] = true, -- Jagged Nettles (Waycrest Manor) [342675] = true, -- Bone Spear (Theater of Pain) [320788] = true, -- Frozen Binds (Necrotic Wake) }; local frame = CreateFrame("Frame", "kehysIncoming"); local function event(_, event, target, cast, id) if event == "PLAYER_REGEN_ENABLED" then for _, f in pairs(guids) do f.incoming = {}; end return end if abilities[id] and UnitIsEnemy("player", target) then local f = guids[UnitGUID(target .. "target")]; if f then if event == "UNIT_SPELLCAST_START" then if f.incoming[id] then f.incoming[id] = f.incoming[id] + 1; else f.incoming[id] = 1; end elseif f.incoming[id] then f.incoming[id] = f.incoming[id] - 1; if f.incoming[id] == 0 then f.incoming[id] = nil; end end end end end local function setup() frame:UnregisterAllEvents(); frame:SetScript("OnEvent", event); frame:RegisterEvent("UNIT_SPELLCAST_START"); frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START"); frame:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP"); frame:RegisterEvent("UNIT_SPELLCAST_STOP"); frame:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED"); frame:RegisterEvent("UNIT_SPELLCAST_FAILED"); frame:RegisterEvent("UNIT_SPELLCAST_FAILED_QUIET"); frame:RegisterEvent("PLAYER_REGEN_ENABLED"); end frame:SetScript("OnEvent", setup); frame:RegisterEvent("PLAYER_LOGIN");