Compare with Previous | Blame | View Log
EERaid = EERaidAdmin:NewModule("EERaid", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0") ------ VARIABLES ---- GLOBALS local db --= EERaidAdmin.db local __IsDebugging = 0 local __raidActiveGroups = EERaidAdmin.__raidActiveGroups local __raidActivePlayers = EERaidAdmin.__raidActivePlayers local ServerDateTime = EERaidAdmin.ServerDateTime --EERaid.db = db.global ---- LOCALS local _RaidUpdateInterval = 30 -- seconds local _RaidKarmaEmissionInterval = 60 * 15 -- 15 minutes ------ HELPER FUNCTIONS local function _color(r, g, b, msg) if type(r) == "table" then if r.r then r, g, b = r.r, r.g, r.b else r, g, b = unpack(r) end end t_color = string.format("|cff%02x%02x%02x", r*255, g*255, b*255) if msg ~= '' then return t_color..msg..'|r' else return t_color end end local function _message(msg, label) local output = "" output = _color(0,1,1, 'EERaid: ') if label then output = output.._color(0,0.7,0.7, label..': ') end output = output..msg print(output) end local function _debug(msg, fatal) if __IsDebugging == 1 or fatal then EERaid:Print("|cffdd0000debug: "..msg.."|r") end end local function _sortRaidSubgroupAsc(a, b) if (not a) then return false elseif (not b) then return true else return (a.subgroup < b.subgroup) end end function EERaid:GetRaidPlayers() _debug("GetRaidPlayers") local raidPlayers = {} local raidPlayersIndexes = {} -- name, rank, rankIndex, level, class, zone, note, officernote, online, status, classFileName = GetGuildRosterInfo(index) for i = 1, GetNumRaidMembers() do local name, _, subgroup, _, _, class, _, online, _, _, _ = GetRaidRosterInfo(i) raidPlayers[i] = { name=name, class=class, subgroup=subgroup, online=online } end -- sort, according to the subgroup number (1,2..) table.sort(raidPlayers, _sortRaidSubgroupAsc) -- fill the playerToBarIndex lookup table for i, v in pairs(raidPlayers) do raidPlayersIndexes[v.name] = i end return raidPlayers, raidPlayersIndexes end function EERaid:GetActiveRaidPlayers() _debug("GetActiveRaidPlayers") local raidPlayers = {} local raidPlayersIndexes = {} for i = 1, GetNumRaidMembers() do local name, _, subgroup, _, _, class, _, online, _, _, _ = GetRaidRosterInfo(i) if subgroup <= __raidActiveGroups then raidPlayers[i] = { name=name, class=class, subgroup=subgroup, online=online } end end -- sort, according to the subgroup number (1,2..) table.sort(raidPlayers, _sortRaidSubgroupAsc) -- fill the playerToBarIndex lookup table for i, v in pairs(raidPlayers) do raidPlayersIndexes[v.name] = i end return raidPlayers, raidPlayersIndexes end function EERaid:IsRaidActive() _debug("IsRaidActive") if db._RaidStartedAt and db._RaidStartedAt ~= 0 then _debug("> active") return true else _debug("> inactive") return false end end function EERaid:ContinueRaid() _debug("ContinueRaid") self.SwitchRaid:SetText("ÐÑÑановиÑÑ Ñейд") self.Updater:Show() _message(db._RaidStartedAt, "Рейд пÑодолжаеÑÑÑ") end function EERaid:StartRaid() _debug("StartRaid") if EERaid:IsRaidActive() then _debug("Рейд Ñже наÑаÑ", 1); return false; end db._RaidStartedAt = ServerDateTime() db._TimeSinceLastUpdate = 0 --db._TimeSinceLastPeriodicKarma = 0 -- self.SwitchRaid:SetText("ÐÑÑановиÑÑ Ñейд") --EEKarma:KarmaMassAdd("GUILD", 2, 3, "ÐаÑма за наÑало Ñейда: "..GetRealZoneText()) EPGP:StartRecurringEP(GetRealZoneText().."(EERA)", 100); -- start recurring EP self.Updater:Show() -- _message(db._RaidStartedAt, "Рейд наÑаÑ") end function EERaid:EndRaid() _debug("EndRaid") if not EERaid:IsRaidActive() then _debug("Рейд Ñже законÑен", 1); return false; end db._RaidStartedAt = nil db._TimeSinceLastUpdate = 0 --db._TimeSinceLastPeriodicKarma = 0 -- self.SwitchRaid:SetText("ÐаÑаÑÑ Ñейд") --EEKarma:KarmaMassAdd("GUILD", 2, 3, "ÐаÑма за ÐºÐ¾Ð½ÐµÑ Ñейда") --EEKarma:DBCompact() EPGP:StopRecurringEP(); -- stop recurring EP self.Updater:Hide() -- _message(ServerDateTime(), "Рейд законÑен") end function EERaid:PeriodicalUpdater(self, elapsed) db._TimeSinceLastUpdate = db._TimeSinceLastUpdate + elapsed end function EERaid:CreateFrames() self.Anchor = CreateFrame("Frame",nil,UIParent) self.Anchor:SetScript("OnShow", function() EERaid:OnShow() end ) self.Anchor:SetScript("OnHide", function() EERaid:OnHide() end ) self.Anchor:SetFrameStrata("HIGH") -- FIXME: est' li drugie varianty delat' pereodicheskie zapuski self.Updater = CreateFrame("Frame",nil, UIParent) self.Updater:SetScript("OnUpdate", function(self, elapsed) EERaid:PeriodicalUpdater(self, elapsed) end ) self.Updater:Hide() self.SwitchRaid = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") self.SwitchRaid:SetText("ÐаÑаÑÑ Ñейд") self.SwitchRaid:SetHeight(30) self.SwitchRaid:SetWidth(160) self.SwitchRaid:SetScript("OnClick", function() if not EERaid:IsRaidActive() then EERaid:StartRaid() else EERaid:EndRaid() end end ) self.SwitchRaid:SetPoint("CENTER", self.Anchor) end function EERaid:OnShow() _debug("OnShow") end function EERaid:OnHide() _debug("OnHide") end function EERaid:OnInitialize() _debug("OnInitialize") self.db = LibStub("AceDB-3.0"):New("EERaidAdminDB") db = self.db.global -- preinitialize if db._RaidStartedAt == nil then db._RaidStartedAt = 0; end if db._TimeSinceLastUpdate == nil then db._TimeSinceLastUpdate = 0; end --if db._TimeSinceLastPeriodicKarma == nil then db._TimeSinceLastPeriodicKarma = 0; end self:RegisterComm("LSRC") -- self:RegisterEvent("RAID_ROSTER_UPDATE") -- self:RegisterEvent("LOOT_OPENED") -- self:RegisterEvent("LOOT_CLOSED") -- self:RegisterEvent("LOOT_SLOT_CLEARED") -- self:RegisterEvent("PLAYER_TARGET_CHANGED") -- self:RegisterEvent("CHAT_MSG_SYSTEM") self:CreateFrames() self.Anchor:Hide() -- TODO: continue raid if db._RaidStartedAt and db._RaidStartedAt ~= 0 then self:ContinueRaid() end end function EERaid:OnCommReceived(prefix, message, distribution, sender) _debug("OnCommReceived") local tokens = { strsplit(";", message) } if prefix == "LSRC" then -- end end function EERaid:OnEnable() _debug("OnEnable") end function EERaid:OnDisable() _debug("OnDisable") end