NanamiPlates_Castbar = {} local GetTime = GetTime local UnitGUID = UnitGUID local UnitName = UnitName local superwow_active = (SpellInfo ~= nil) or (UnitGUID ~= nil) or (SUPERWOW_VERSION ~= nil) local castDB local function InitReferences() castDB = NanamiPlates.castDB end local function HandleUnitCastEvent(guid, target, eventType, spellId, timer) if not castDB then castDB = NanamiPlates.castDB end if not castDB then return false end local SpellDB = NanamiPlates_SpellDB if eventType == "START" or eventType == "CAST" or eventType == "CHANNEL" then local spell, icon if SpellInfo and spellId then spell, _, icon = SpellInfo(spellId) end spell = spell or "Casting" icon = icon or "Interface\\Icons\\INV_Misc_QuestionMark" if SpellDB and eventType == "CAST" then local effectTarget = target local isOwn = (guid == (UnitGUID and UnitGUID("player"))) if (not effectTarget or effectTarget == "") and isOwn then if UnitExists("target") then effectTarget = UnitGUID and UnitGUID("target") or UnitName("target") end end if effectTarget and effectTarget ~= "" then local duration = SpellDB:GetDuration(spell, 0) if duration and duration > 0 then SpellDB:RefreshEffect(effectTarget, 0, spell, duration, isOwn) if NanamiPlates_Auras and NanamiPlates_Auras.timers then NanamiPlates_Auras.timers[effectTarget .. "_" .. spell] = nil end if isOwn then local targetName = UnitExists("target") and UnitName("target") if targetName and targetName ~= effectTarget then SpellDB:RefreshEffect(targetName, 0, spell, duration, true) NanamiPlates_Auras.timers[targetName .. "_" .. spell] = nil end if SpellDB.OWNER_BOUND_DEBUFFS and SpellDB.OWNER_BOUND_DEBUFFS[spell] then SpellDB:TrackOwnerBoundDebuff(effectTarget, spell, duration) if targetName and targetName ~= effectTarget then SpellDB:TrackOwnerBoundDebuff(targetName, spell, duration) end end end end end end if eventType == "CAST" then if castDB[guid] and castDB[guid].spell ~= spell then return true end end castDB[guid] = { spell = spell, startTime = GetTime(), duration = timer or 2000, icon = icon, channel = (eventType == "CHANNEL") } elseif eventType == "FAIL" then if castDB[guid] then castDB[guid] = nil end end return false end local function ClearCastData() if not castDB then castDB = NanamiPlates.castDB end if castDB then for k in pairs(castDB) do castDB[k] = nil end end end local function GetCast(guid) if not castDB then castDB = NanamiPlates.castDB end return castDB and castDB[guid] end local function RemoveCast(guid) if not castDB then castDB = NanamiPlates.castDB end if castDB and castDB[guid] then castDB[guid] = nil end end NanamiPlates_Castbar = { InitReferences = InitReferences, HandleUnitCastEvent = HandleUnitCastEvent, ClearCastData = ClearCastData, GetCast = GetCast, RemoveCast = RemoveCast, } NanamiPlates.Castbar = NanamiPlates_Castbar