Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local AddonName, Addon = ...
- Addon.__Events__ = {}
- Addon.Events = {}
- --[[ ----------------------------------------------------------------------------------
- Event Functions
- -------------------------------------------------------------------------------------]]
- function Addon:RegisterEvent(Event, Handler)
- self.EventFrame:RegisterEvent(Event)
- self.__Events__[Event] = Handler
- end
- function Addon:UnregisterEvent(Event)
- self.EventFrame:UnregisterEvent(Event)
- self.__Events__[Event] = nil
- end
- function Addon:RegisterEventTable(EventTable)
- for i,v in pairs(EventTable) do
- self:RegisterEvent(i, v)
- end
- end
- function Addon:UnregisterEventTable(EventTable)
- for i,v in pairs(EventTable) do
- self:UnregisterEvent(i, v)
- end
- end
- --[[ ----------------------------------------------------------------------------------
- Permanent Events
- -------------------------------------------------------------------------------------]]
- function Addon.__Events__:ADDON_LOADED(addonName)
- if not (AddonName == addonName) then return end
- Addon.TomTom = IsAddOnLoaded("TomTom")
- Addon.InitConfig()
- Addon:InitUI()
- end
- function Addon.__Events__:PLAYER_ENTERING_WORLD(...)
- local Player, Realm = UnitFullName("player")
- Addon.FullPlayerName = Player.."-"..Realm
- Addon:InitModule()
- Addon:InitModuleConfig()
- Addon:InitModuleUI()
- end
- function Addon.__Events__:ZONE_CHANGED(...)
- Addon:InitModule()
- end
- function Addon.__Events__:ZONE_CHANGED_NEW_AREA(...)
- Addon:InitModule()
- end
- Addon:RegisterEventTable(Addon.__Events__)
- Addon.EventFrame:SetScript("OnEvent", function(self, event, ...)
- Addon.__Events__[event](self, ...)
- end)
- --[[ ----------------------------------------------------------------------------------
- Dynamic Events
- -------------------------------------------------------------------------------------]]
- function Addon.Events:CHAT_MSG_CHANNEL(message, author, _, _, _, _, _, _, channelName, ...)
- if channelName == RareShareDB["Config"]["CChannel"]["CName"] and author ~= Addon.FullPlayerName then
- if message:find("%s"..Addon.Loc.Died.."%.") then
- local _, NameReverse = strsplit(" ", message:reverse(), 2)
- local Name = NameReverse:reverse()
- for _, Val in pairs(RareShare.Modules[RareShare.LastMap].Rares) do
- if Val[1] == Name then
- Val[4] = true
- if TomTomLastWaypoint ~= nil then
- TomTom:RemoveWaypoint(TomTomLastWaypoint)
- TomTomExpireTimer = nil
- end
- return
- end
- end
- elseif message:find("%%") and message:find("~%(") and message:find("%)") then
- local Part1, Part2 = strsplit("%", message);
- local Name = Part1:sub(1, Part1:len()-(string.find(Part1:reverse(), "%s")))
- local Module = Addon:GetModule(Addon.LastMap)
- for ID, Val in pairs(Module.Rares) do
- if Val[1] == Name then
- Val[2] = time()
- Val[4] = false
- if Module.Duplicates then Module:Duplicates(ID) end
- if (RareShareDB["Config"]["Sound"]["Master"] == true) and (RareShareDB["Config"]["Sound"]["Rares"] == true) then
- Addon:PlaySound()
- end
- if (Addon.TomTom == true) and (RareShareDB["Config"]["TomTom"]["Master"] == true) and (RareShareDB["Config"]["TomTom"]["Rares"] == true) then
- local x, y = strsplit(",", Part2:match("%d+%.?%d+%,%s%d+%.?%d+"))
- Addon:CreateTomTomWaypoint(x / 100, y / 100, Name);
- end
- return
- end
- end
- end
- end
- end
- function Addon.Events:VIGNETTE_MINIMAP_UPDATED(vignetteGUID, onMinimap)
- local vignetteInfo = C_VignetteInfo.GetVignetteInfo(vignetteGUID)
- if RareShareDB["Config"]["ChatAnnounce"] and vignetteInfo ~= nil then
- local ID = Addon:GetNPCID(vignetteInfo.objectGUID)
- if ID == nil or RareShare.Modules[Addon.LastMap].Rares[ID] == nil then return end
- local vignetteInfo = C_VignetteInfo.GetVignetteInfo(vignetteGUID)
- local vignettePosition = C_VignetteInfo.GetVignettePosition(vignetteInfo.vignetteGUID, Addon.LastMap)
- local Module = Addon:GetModule(Addon.LastMap)
- local Name = Module.Rares[ID][1];
- local X, Y = (C_VignetteInfo.GetVignettePosition(vignetteInfo.vignetteGUID, Addon.LastMap)):GetXY()
- local X, Y = RareShare:Round(X * 100, 2), RareShare:Round(Y * 100, 2)
- if Module.Rares[ID][2] < time() - RareShare.Cooldown then
- Addon:PreAnnounceRare(ID, Name, X, Y)
- Module.Rares[ID][3] = true
- elseif Module.Rares[ID][3] == false then
- Addon:Log(Name.." "..Addon.Loc.AlreadyAnnounced, 1, Addon.LastMap)
- Module.Rares[ID][3] = true
- end
- end
- end
- function Addon.Events:PLAYER_TARGET_CHANGED(...)
- if RareShareDB["Config"]["ChatAnnounce"] then
- local ID = Addon:GetNPCID(UnitGUID("target"))
- if ID == nil or RareShare.Modules[Addon.LastMap].Rares[ID] == nil then return end
- local Module = Addon:GetModule(Addon.LastMap)
- local Name = UnitName("target");--Module.Rares[ID][1];
- local Health = UnitHealth("target");
- local HealthMax = UnitHealthMax("target");
- local X, Y = Addon:GetRarePos(ID)
- if Health > 0 then
- if Module.Rares[ID][2] < time() - RareShare.Cooldown then
- Addon:AnnounceRare(ID, Name, Health, HealthMax, X, Y)
- Module.Rares[ID][3] = true
- elseif Module.Rares[ID][3] == false then
- Addon:Log(Name.." "..Addon.Loc.AlreadyAnnounced, 1, Addon.LastMap)
- Module.Rares[ID][3] = true
- end
- end
- end
- end
- function Addon.Events:UNIT_COMBAT(...)
- if RareShareDB["Config"]["ChatAnnounce"] then
- local ID = Addon:GetNPCID(UnitGUID("target"))
- if ID == nil or RareShare.Modules[Addon.LastMap].Rares[ID] == nil then return end
- local Module = Addon:GetModule(Addon.LastMap)
- local Name = UnitName("target");--Module.Rares[ID][1];
- local Health = UnitHealth("target");
- local HealthMax = UnitHealthMax("target");
- local X, Y = Addon:GetRarePos(ID)
- if Health > 0 then
- if Module.Rares[ID][2] < time() - RareShare.Cooldown then
- Addon:AnnounceRare(ID, Name, Health, HealthMax, X, Y)
- Module.Rares[ID][3] = true
- elseif Module.Rares[ID][3] == false then
- Addon:Log(Name.." "..Addon.Loc.AlreadyAnnounced, 1, Addon.LastMap)
- Module.Rares[ID][3] = true
- end
- end
- end
- end
- function Addon.Events:COMBAT_LOG_EVENT_UNFILTERED(...)
- if (RareShareDB["Config"]["OnDeath"] == true) then
- local _, event, _, _, _, sourceFlags, _, destGUID, _, destFlags = CombatLogGetCurrentEventInfo()
- if bit.band(destFlags, COMBATLOG_OBJECT_TARGET) > 0 then
- if (event == "UNIT_DIED") then
- local ID = Addon:GetNPCID(destGUID)
- local Module = Addon:GetModule(Addon.LastMap)
- if (Module.Rares[ID]) then
- C_Timer.After(math.random(0, 3), function()
- if (Module.Rares[ID][4] == false and ID ~= 151623) then
- SendChatMessage(Module.Rares[ID][1].." "..Addon.Loc.Died..".", "CHANNEL", nil, RareShareDB["Config"]["CChannel"]["CID"])
- Module.Rares[ID][4] = true
- end
- end)
- end
- end
- end
- end
- end
- --function Addon.Events:VIGNETTES_UPDATED(...)
- -- print("VIGNETTES_UPDATED", ...)
- -- Addon:CheckVignettes()
- --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement