local version = 3.0 MythicGuildKeys = LibStub("AceAddon-3.0"):NewAddon("MythicGuildKeys","AceEvent-3.0","AceComm-3.0") local prefixG = "_MMshareG" local prefixP = "_MMshareP" local prefixDBR = "_MMDBreq" local frame = CreateFrame("Frame","MythicGuildKeysFrame",UIParent,"BasicFrameTemplateWithInset") frame.bar = {} frame:SetMovable(true) frame:EnableMouse(true) frame:RegisterForDrag("LeftButton") frame:SetScript("OnDragStart", frame.StartMoving) frame:SetScript("OnDragStop", frame.StopMovingOrSizing) local KEYSTONE_ITEM_ID = 138019 local RAID_CLASS_COLORS = RAID_CLASS_COLORS local BAG_ITEM_QUALITY_COLORS = BAG_ITEM_QUALITY_COLORS --starts @ 2 local affixCol = {"ff99ffff","ff99ffff", "ff99ff99","ff99ff99","ff99ff99", "ffffff99","ffffff99","ffffff99", "ffff9999","ffff9999","ffff9999","ffff9999","ffff9999","ffff9999","ffff9999"} local xSize, ySize, yBar SLASH_MythicGuildKeys1 = "/mgk" SlashCmdList.MythicGuildKeys = function() MythicGuildKeys:Toggle() end local defaults = { global = { shareP = true, buttonSettings = {}, keys = {} --[Name-Realm] -- 1 mapID, -- 2 mapLevel, -- 3 ¬depleted, -- 4 timeAdded, -- 5 classFileName }, } -- updateMessage { " 1 fullName : 2 mapID : 3 mapLevel : 4 ¬depleted : 5 timeAdded : 6 classFileName" } function MythicGuildKeys:OnInitialize() RegisterAddonMessagePrefix(prefixG) RegisterAddonMessagePrefix(prefixP) RegisterAddonMessagePrefix(prefixDBR) self.db = LibStub("AceDB-3.0"):New("MythicGuildKeysDB", defaults, true) local LDB = LibStub("LibDataBroker-1.1", true) local LDBIcon = LDB and LibStub("LibDBIcon-1.0", true) if LDB then local MythicGuildKeysLauncher = LDB:NewDataObject("MythicGuildKeys", { type = "launcher", icon = "Interface\\AddOns\\MythicGuildKeys\\icon", OnClick = function(clickedframe, button) MythicGuildKeys:Toggle() end, OnTooltipShow = function(tt) tt:AddLine(self.defaultTitle) tt:AddLine("|cff99ff99MythicGuildKeys|r") end, }) if LDBIcon then LDBIcon:Register("MythicGuildKeys", MythicGuildKeysLauncher, self.db.global.buttonSettings) end end frame:SetShown(false) xSize = 350 ySize = 16 yBar = 16 frame:SetPoint("CENTER",UIParent,"CENTER",-xSize-128,0) MythicGuildKeys:BaseFrame() end function MythicGuildKeys:BaseFrame() frame:EnableMouse(true) frame:SetSize(xSize,ySize) frame.title = frame:CreateFontString(nil, frame) frame.title:SetFontObject("GameFontHighlight") frame.title:SetPoint("LEFT", frame.TitleBg, "LEFT", 8, 0) frame.title:SetText("|cff99ff99MythicGuildKeys|r ") frame:SetAlpha(0.75) frame.titleRegion = frame:CreateTitleRegion() frame.titleRegion:SetSize(xSize,ySize) frame.titleRegion:SetPoint("TOPLEFT") end function MythicGuildKeys:Toggle() frame:SetShown(not frame:IsShown()) end function MythicGuildKeys:PLAYER_ENTERING_WORLD() MythicGuildKeys:RegisterComm(prefixG, "DataRecieved") MythicGuildKeys:RegisterComm(prefixDBR, "DBRequestRecieved") if self.db.global.shareP then MythicGuildKeys:RegisterComm(prefixP, "DataRecieved") end MythicGuildKeys:RegisterEvent("BAG_UPDATE", "evaluateIfKey") for i=0,4 do found = MythicGuildKeys:evaluateIfKey("INIT",i) if found then break end end MythicGuildKeys:UpdateFrame() MythicGuildKeys:SendCommMessage(prefixDBR, "", "GUILD") end function MythicGuildKeys:OnCommReceived(p, msg, dist, ...) -- unknown message or ignored (prefixP) end function MythicGuildKeys:DataRecieved(p, msg, dist, sender) local selfN = UnitFullName("player") if sender == selfN then return end --ignore local msgV = {strsplit(":",msg)} local keyN = msgV[1] -- if own message if self.db.global.keys[keyN] == nil or (tonumber(msgV[5]) > tonumber(self.db.global.keys[keyN][4])) then self.db.global.keys[keyN] = {msgV[2],msgV[3],msgV[4], msgV[5], msgV[6]} end MythicGuildKeys:UpdateFrame() end function MythicGuildKeys:DBRequestRecieved(p, msg, dist, sender) -- if own message local selfN = UnitFullName("player") if sender == selfN then return end --ignore for key,vals in pairs(self.db.global.keys) do MythicGuildKeys:SendCommMessage(prefixG, (key .. ":" .. vals[1] .. ":" .. vals[2] .. ":" .. vals[3] .. ":" .. vals[4] .. ":" .. vals[5]), "GUILD") end -- handle the message end function MythicGuildKeys:evaluateIfKey(event, bagID) for slot = 1,GetContainerNumSlots(bagID) do local itemID = GetContainerItemID(bagID,slot) if itemID == KEYSTONE_ITEM_ID then local itemString = string.match(GetContainerItemLink(bagID,slot), "item[%-?%d:]+") local info = { strsplit(":", itemString) } local PlayerN,RealmN = UnitFullName("player") local _,classFileName = UnitClass("player") local fullName = PlayerN .. "-" .. RealmN if self.db.global.keys[fullName] == nil or self.db.global.keys[fullName][1] ~= info[15] or self.db.global.keys[fullName][2] ~= info[16] or (GetServerTime() - self.db.global.keys[fullName][4]) > 60*60*3 then local j = 0 local lvl = tonumber(info[16]) if lvl < 4 then j = 1 elseif lvl < 7 then j = 2 elseif lvl < 10 then j = 3 else j = 4 end self.db.global.keys[fullName] = {info[15],info[16],info[16+j], GetServerTime(), classFileName, true} MythicGuildKeys:SendCommMessage(prefixG, (fullName .. ":" .. info[15] .. ":" .. info[16] .. ":" .. info[16+j] .. ":" .. GetServerTime() .. ":" .. classFileName), "GUILD") MythicGuildKeys:UpdateFrame() return true end end end return false end function MythicGuildKeys:UpdateFrame() local i = 0 for key,vals in pairs(self.db.global.keys) do i = i+1 local deplC = "|c" if tonumber(vals[3]) ~= 1 then deplC = deplC .. "ff9d9d9d{D} " else deplC = deplC .. "ffa335ee" end local kc,kr = strsplit("-", key) if frame.bar[key] == nil then frame.bar[key] = {} frame.bar[key].lefttext = frame:CreateFontString(nil, ParentUI) frame.bar[key].lefttext:SetFontObject("GameFontNormal") frame.bar[key].righttext = frame:CreateFontString(nil, ParentUI) frame.bar[key].righttext:SetFontObject("GameFontNormal") end frame.bar[key].lefttext:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -ySize-(yBar*i)-2) frame.bar[key].lefttext:SetText("|c" .. RAID_CLASS_COLORS[vals[5]].colorStr .. kc .. "|r")--" .. kr) frame.bar[key].lefttext:Show() frame.bar[key].righttext:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -16, -ySize-(yBar*i)-2) frame.bar[key].righttext:SetText(deplC .. C_ChallengeMode.GetMapInfo(vals[1]) .. "|r: |c" .. affixCol[(vals[2]-1)] .. vals[2]) frame.bar[key].righttext:Show() if i%2 ~= 1 then if frame.bar[key].texture == nil then frame.bar[key].texture = frame:CreateTexture(nil, "BACKGROUND") frame.bar[key].texture:SetPoint("TOPLEFT",frame,"TOPLEFT", 6, -ySize-(yBar*i)) frame.bar[key].texture:SetColorTexture(1.0, 1.0, 1.0, 0.25) frame.bar[key].texture:SetSize(xSize-12,yBar) frame.bar[key].texture:SetBlendMode("BLEND") end end end frame:SetHeight((ySize*2)+(yBar*(i+1))) end function MythicGuildKeys:OnEnable() MythicGuildKeys:RegisterEvent("PLAYER_ENTERING_WORLD") end function MythicGuildKeys:OnDisable() end