Compare with Previous | Blame | View Log
EEClient = LibStub("AceAddon-3.0"):NewAddon("EEClient", "AceConsole-3.0", "AceEvent-3.0", "AceComm-3.0") local __EERCCaption = "EasyEPGPClient" local __EERC = "EERC" local __UpdateRate = 0.2 local __IsDebugging = 0 local db local raidActiveGroups = 5 local __sysInterestToInterest = { ["NEEDMAIN"] = "Ðид мейнÑпек", ["GREEDMAIN"] = "ÐÑид мейнÑпек", ["NEEDOFF"] = "Ðид оÑÑÑпек", ["GREEDOFF"] = "ÐÑид оÑÑÑпек", ["PASS"] = "ÐаÑ", ["TIMEOUT"] = "ÐгноÑ", ["NA"] = "ÐÑÐµÐ´Ð¼ÐµÑ Ð½Ðµ Ð¿Ð¾Ð´Ñ Ð¾Ð´Ð¸Ñ, авÑомаÑиÑеÑкий паÑ" } -- FIXME: Name cannot be the same as the object name, otherwise cannot be properly hooked... or? :/ local RollLootTooltip = CreateFrame( "GameTooltip", "EERCGameTooltip", UIParent, "GameTooltipTemplate" ) 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, 'EEClient: ') if label then output = output.._color(0,0.7,0.7, label..': ') end output = output..msg print(output) end local function _alert(msg, label) PlaySound("RaidWarning") _message(msg, label) end local function _debug(msg, fatal) if __IsDebugging == 1 or fatal then EEClient:Print(_color(0.85,0,0,msg)) end end local function _itemToSlot(item) _debug("_itemToSlot "..item) local _,_,_,_,_,_,_,_,itemEquipLoc,_ = GetItemInfo(item) if itemEquipLoc == "INVTYPE_HEAD" then return 1 elseif itemEquipLoc == "INVTYPE_NECK" then return 2 elseif itemEquipLoc == "INVTYPE_SHOULDER" then return 3 elseif itemEquipLoc == "INVTYPE_BODY" then return 4 elseif itemEquipLoc == "INVTYPE_CHEST" or itemEquipLoc == "INVTYPE_ROBE" then return 5 elseif itemEquipLoc == "INVTYPE_WAIST" then return 6 elseif itemEquipLoc == "INVTYPE_LEGS" then return 7 elseif itemEquipLoc == "INVTYPE_FEET" then return 8 elseif itemEquipLoc == "INVTYPE_WRIST" then return 9 elseif itemEquipLoc == "INVTYPE_HAND" then return 10 elseif itemEquipLoc == "INVTYPE_CLOAK" then return 15 elseif itemEquipLoc == "INVTYPE_2HWEAPON" or itemEquipLoc == "INVTYPE_WEAPONMAINHAND" then return 16 elseif itemEquipLoc == "INVTYPE_SHIELD" or itemEquipLoc == "INVTYPE_WEAPONOFFHAND" or itemEquipLoc == "INVTYPE_HOLDABLE" then return 17 elseif itemEquipLoc == "INVTYPE_RANGED" or itemEquipLoc == "INVTYPE_THROWN" or itemEquipLoc == "INVTYPE_RANGEDRIGHT" or itemEquipLoc == "INVTYPE_RELIC" then return 18 elseif itemEquipLoc == "INVTYPE_TABARD" then return 19 else return nil end -- TODO: пока не ÑеÑил... -- "INVTYPE_FINGER" Fingers 11,12 -- "INVTYPE_TRINKET" Trinkets 13,14 -- "INVTYPE_WEAPON" One-Hand 16,17 end local function _getItemId(itemlink) local prestring = string.gsub(itemlink, ".-\124H([^\124]*)\124h.*", "%1") local _,itemId,_,_,_,_,_,_,_ = strsplit(":", prestring) return itemId end local function _sysInterestToInterest(message) local tokens = { strsplit(";", message) } return __sysInterestToInterest[tokens[2]] end -- borrowed from original code function _showCompareItem() local item,link = RollLootTooltip:GetItem(); if ( not link ) then return; end local item1 = nil; local item2 = nil; local side = "left"; if ( ShoppingTooltip1:SetHyperlinkCompareItem(link, 1) ) then item1 = true; end if ( ShoppingTooltip2:SetHyperlinkCompareItem(link, 2) ) then item2 = true; end local rightDist = GetScreenWidth() - RollLootTooltip:GetRight(); if (rightDist < RollLootTooltip:GetLeft()) then side = "left"; else side = "right"; end if ( RollLootTooltip:GetAnchorType() ) then local totalWidth = 0; if ( item1 ) then totalWidth = totalWidth + ShoppingTooltip1:GetWidth(); end if ( item2 ) then totalWidth = totalWidth + ShoppingTooltip2:GetWidth(); end if ( (side == "left") and (totalWidth > RollLootTooltip:GetLeft()) ) then RollLootTooltip:SetAnchorType(RollLootTooltip:GetAnchorType(), (totalWidth - RollLootTooltip:GetLeft()), 0); elseif ( (side == "right") and (RollLootTooltip:GetRight() + totalWidth) > GetScreenWidth() ) then RollLootTooltip:SetAnchorType(RollLootTooltip:GetAnchorType(), -((RollLootTooltip:GetRight() + totalWidth) - GetScreenWidth()), 0); end end -- anchor the compare tooltips if ( item1 ) then ShoppingTooltip1:SetOwner(RollLootTooltip, "ANCHOR_NONE"); ShoppingTooltip1:ClearAllPoints(); if ( side and side == "left" ) then ShoppingTooltip1:SetPoint("TOPRIGHT", RollLootTooltip, "TOPLEFT", 0, -10); else ShoppingTooltip1:SetPoint("TOPLEFT", RollLootTooltip, "TOPRIGHT", 0, -10); end ShoppingTooltip1:SetHyperlinkCompareItem(link, 1); ShoppingTooltip1:Show(); if ( item2 ) then ShoppingTooltip2:SetOwner(ShoppingTooltip1, "ANCHOR_NONE"); ShoppingTooltip2:ClearAllPoints(); if ( side and side == "left" ) then ShoppingTooltip2:SetPoint("TOPRIGHT", ShoppingTooltip1, "TOPLEFT", 0, 0); else ShoppingTooltip2:SetPoint("TOPLEFT", ShoppingTooltip1, "TOPRIGHT", 0, 0); end ShoppingTooltip2:SetHyperlinkCompareItem(link, 2); ShoppingTooltip2:Show(); end end end local function __________() -- ignore, IDE cheat end function EEClient:IsCompatibleItem(itemLink) _debug("IsCompatibleItem") local ScanTooltip = CreateFrame("GameTooltip", "ScanTooltip", UIParent, "GameTooltipTemplate") ScanTooltip:SetOwner(UIParent, "ANCHOR_NONE") ScanTooltip:ClearLines() ScanTooltip:SetHyperlink(itemLink) local compat = true if ScanTooltip:NumLines() > 3 then -- line 1 if getglobal("ScanTooltipTextLeft3"):GetText() then local r, g, b, a = getglobal("ScanTooltipTextLeft3"):GetTextColor() if r > 0.98 and g < 0.13 and b < 0.13 then compat = false end end -- line 2 if getglobal("ScanTooltipTextRight3"):GetText() then local r, g, b, a = getglobal("ScanTooltipTextRight3"):GetTextColor() if r > 0.98 and g < 0.13 and b < 0.13 then compat = false end end -- line 3 if getglobal("ScanTooltipTextLeft4"):GetText() then local r, g, b, a = getglobal("ScanTooltipTextLeft4"):GetTextColor() if r > 0.98 and g < 0.13 and b < 0.13 then compat = false end end -- line 4 if getglobal("ScanTooltipTextRight4"):GetText() then local r, g, b, a = getglobal("ScanTooltipTextRight4"):GetTextColor() if r > 0.98 and g < 0.13 and b < 0.13 then compat = false end end end ScanTooltip:Hide() return compat end function EEClient:InActiveRaid() _debug("InActiveRaid") -- simple if not UnitInRaid("player") then return false end -- detailed for i = 1, GetNumRaidMembers(), 1 do local name,_,subgroup,_,_,_,_,_,_,_,_ = GetRaidRosterInfo(i) if subgroup <= raidActiveGroups and name == UnitName("player") then return true end end return false end function EEClient:StartStandardPoll(item) _debug("StartStandardPoll: "..item) self:InitiateItem(item) -- self.NeedMain:Enable() self.NeedOff:Enable() self.GreedMain:Enable() --self.GreedOff:Enable() self.Pass:Enable() -- self.Anchor:Show() end function EEClient:StartQuickPoll(item) _debug("StartQuickPoll: "..item) self:InitiateItem(item) -- self.NeedMain:Disable() self.NeedOff:Disable() self.GreedMain:Enable() --self.GreedOff:Disable() self.Pass:Enable() -- self.Anchor:Show() end function EEClient:OnCommReceived(prefix, message, distribution, sender) _debug("OnCommReceived:"..prefix.." | "..message.." | "..distribution.." | "..sender) local tokens = { strsplit(";", message) } -- COMM prefix if prefix == "LSRA" then ---- RAID MESSAGES if self:InActiveRaid() then if tokens[1] == "POLL_STANDARD" then -- TODO: stub if self:IsCompatibleItem(tokens[2]) then self:StartStandardPoll(tokens[2]) else _alert(tokens[2], "ÐÑÑказÑваемÑÑ Ð¿Ð¾") self:FormCommMessage("LOOT;NA") end -- stub elseif tokens[1] == "POLL_QUICK" then self:StartQuickPoll(tokens[2]) elseif tokens[1] == "START_ROLL" then _message("Ролл") RandomRoll(1, 100) -- do not try to hack this, it wont work :) elseif tokens[1] == "POLL_EQUIP" then self:SendEquippedItemInfo(tokens[2]) elseif tokens[1] == "WINNER" then _alert(tokens[2], "ÐобедиÑелÑ") elseif tokens[1] == "ANNOUNCE_LOOT" then if db.__ShowAnnounceLoot == true then _message(tokens[2], "ÐÑÑ") end end end ---- GENERAL MESSAGES if tokens[1] == "BEER" then -- pivka ne hochesh? :) PlaySoundFile("Sound\\Creature\\DwarfMaleGrimNPC\\DwarfMaleGrimNPCGreeting06.wav") elseif tokens[1] == "KARMA" then _message(tokens[2], "ÐаÑма") elseif tokens[1] == "C_VER_POLL" then self:SendCommMessage("LSRC", "C_VER;"..GetAddOnMetadata("EEClient", "X-Curse-Packaged-Version"), "WHISPER", sender) elseif tokens[1] == "YOURKARMA" then _message(tokens[2], "ÐаÑа каÑма") end end end function EEClient:FormCommMessage(message) _debug("sending: "..message) self:SendCommMessage("LSRC", message, "GUILD") -- notify self local t_item = self.RollItemText:GetText() _message(_sysInterestToInterest(message), "ÐÐ°Ñ Ð¸Ð½ÑеÑеÑ") self:UnInitiateItem() end function EEClient:SendEquippedItemInfo(item) _debug("SendEquippedItemInfo: "..item) if not GetItemInfo(item) then _debug("ÐÑÐµÐ´Ð¼ÐµÑ Ð² кÑÑе не найден â пÑÑаÑÑÑ Ñ Ð°ÐºÐ½ÑÑÑ :)", true) -- caching item local tempTooltip = CreateFrame("GameTooltip", "TempTooltip", UIParent, "GameTooltipTemplate") tempTooltip:SetHyperlink("item:".._getItemId(item)..":0:0:0:0:0:0:0") tempTooltip:Show(); tempTooltip:Hide() self:SendCommMessage("LSRC", "EQUIP;FAIL", "RAID") return end local t_slot = nil local t_item = nil local t_itemid = nil local t_slot = _itemToSlot(item) if t_slot then t_item = GetInventoryItemLink("player", t_slot) if t_item then --local t_itemid = _getItemId(t_item) self:SendCommMessage("LSRC", "EQUIP;"..t_item, "RAID") else _debug("Nothing equipt on that slot") end else _debug("Unwearable") end end function EEClient:InitiateItem(item) _alert(item, "ÐÑÑказÑваемÑÑ Ð¿Ð¾") self.RollItemText:SetText(item) self.TimeoutPane.TimeoutText:SetText(30) self.TimeoutPane.TimeStart = time() self.TimeoutPane:Show() end function EEClient:UnInitiateItem() self.RollItemText:SetText("ÐÐµÑ ÐÑедмеÑа") self.TimeoutPane.TimeStart = 0 self.TimeoutPane:Hide() -- self.NeedMain:Disable() self.NeedOff:Disable() self.GreedMain:Disable() --self.GreedOff:Disable() self.Pass:Disable() self.Anchor:Hide() end function EEClient:ParseChatCommand(input) _debug("OnCommReceived") local input = strtrim(input) if input ~= '' then input = string.gsub(input, "(%s+)", " ") local tokens = { strsplit(" ", input) } -- if string.lower(tokens[1]) == "version" or string.lower(tokens[1]) == "ver" then _message(GetAddOnMetadata(__EERCCaption, "X-Curse-Packaged-Version"), "ÐеÑÑÐ¸Ñ ÐºÐ»Ð¸ÐµÐ½Ñа") elseif string.lower(tokens[1]) == "compare" then if db.__ShowCompareTooltips == true then db.__ShowCompareTooltips = false _message( _color(0.85,0,0,"ÐÑклÑÑено"), "ÐоказÑваÑÑ ÑÑавниÑелÑнÑе подÑказки") else db.__ShowCompareTooltips = true _message( _color(0,0.85,0,"ÐклÑÑено"), "ÐоказÑваÑÑ ÑÑавниÑелÑнÑе подÑказки") end elseif string.lower(tokens[1]) == "announce" then if db.__ShowAnnounceLoot == true then db.__ShowAnnounceLoot = false _message( _color(0.85,0,0,"ÐÑклÑÑено"), "ÐоказÑваÑÑ Ð°Ð½Ð¾Ð½ÑиÑование лÑÑа") else db.__ShowAnnounceLoot = true _message( _color(0,0.85,0,"ÐклÑÑено"), "ÐоказÑваÑÑ Ð°Ð½Ð¾Ð½ÑиÑование лÑÑа") end elseif string.lower(tokens[1]) == "beer" then PlaySoundFile("Sound\\Creature\\DwarfMaleGrimNPC\\DwarfMaleGrimNPCGreeting06.wav") elseif string.lower(tokens[1]) == "mypr" or string.lower(tokens[1]) == "my" then self:SendCommMessage("LSRC", "GETKARMA", "GUILD") end else _message("ÐапÑоÑиÑÑ ÑекÑÑее колиÑеÑÑво каÑмÑ", "/eerc myPR") _message("ÐоказаÑÑ Ð²ÐµÑÑÐ¸Ñ ÐºÐ»Ð¸ÐµÐ½Ñа", "/eerc version") _message("ÐоказÑваÑÑ ÑÑавниÑелÑнÑе подÑказки", "/eerc compare") _message("ÐоказÑваÑÑ Ð°Ð½Ð¾Ð½ÑиÑование лÑÑа", "/eerc announce") --_message("Ðивка не Ñ Ð¾ÑеÑÑ?", "/eerc beer") end end function EEClient:UpdateTimeout(elapsed) -- antispam wrapper self.TimeoutPane.LastUpdate = self.TimeoutPane.LastUpdate + elapsed if (self.TimeoutPane.LastUpdate > __UpdateRate) then -- update code if(self.TimeoutPane.TimeStart > 0) then local sec = time()-self.TimeoutPane.TimeStart if(sec >= 30) then -- time is up self.TimeoutPane.TimeStart = 0 self:FormCommMessage("LOOT;TIMEOUT") self.Anchor:Hide() end self.TimeoutPane.TimeoutText:SetText(30 - sec) end self.TimeoutPane.LastUpdate = 0 end end local function __________() -- ignore, IDE cheat end function EEClient:CreateFrames() -- local window settings local inset = 20 local fontsize = 14 -- Anchor self.Anchor = CreateFrame("Frame", "LSRCAnchor", UIParent) self.Anchor:SetFrameStrata("DIALOG") self.Anchor:SetToplevel(true) self.Anchor:SetMovable(true) self.Anchor:EnableMouse(true) self.Anchor:SetWidth(400) self.Anchor:SetHeight(200) self.Anchor:SetBackdrop({ bgFile="Interface\\DialogFrame\\UI-DialogBox-Background", edgeFile="Interface\\DialogFrame\\UI-DialogBox-Border", tile=true, tileSize=32, edgeSize=32, insets={left=10, right=10, top=10, bottom=10} }) self.Anchor:SetScript("OnShow", function() EEClient:OnShow() end ) self.Anchor:SetScript("OnHide", function() EEClient:OnHide() end ) self.Anchor:SetScript("OnMouseDown", self.Anchor.StartMoving) self.Anchor:SetScript("OnMouseUp", self.Anchor.StopMovingOrSizing) self.Anchor:SetClampedToScreen( true ) self.Anchor:SetPoint("CENTER") -- Caption and cancel button local t = self.Anchor:CreateTexture() t:SetTexture("Interface\\DialogFrame\\UI-DialogBox-Header") t:SetWidth(350) t:SetHeight(64) t:SetPoint("TOP",0,12) self.Anchor.texture = t local fs = self.Anchor:CreateFontString("$parentTitle","ARTWORK","GameFontNormal") fs:SetText(__EERCCaption) fs:SetPoint("TOP",t,0,-14) -- local cb = CreateFrame("Button", nil, self.Anchor, "UIPanelCloseButton") -- cb:SetPoint("TOPRIGHT",self.Anchor,-2,-3) ------ roll buttons self.Pass = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") self.Pass:SetHeight(28) self.Pass:SetText("ÐаÑÑ") self.Pass:SetScript("OnClick", function() EEClient:FormCommMessage("LOOT;PASS") end ) self.Pass:SetPoint("BOTTOMRIGHT",self.Anchor,"BOTTOMRIGHT",-inset,inset) -- greed self.GreedMain = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") self.GreedMain:SetHeight(28) self.GreedMain:SetWidth(200) self.GreedMain:SetText("Greed") self.GreedMain:SetScript("OnClick", function() EEClient:FormCommMessage("LOOT;GREEDMAIN") end ) self.GreedMain:SetPoint("BOTTOMLEFT",self.Anchor,"BOTTOMLEFT", inset,inset) --self.GreedMain:SetPoint("RIGHT",self.Pass,"LEFT",-inset,0) -- -- need off self.NeedOff = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") self.NeedOff:SetHeight(28) self.NeedOff:SetWidth(200) self.NeedOff:SetText("Off-spec") self.NeedOff:SetScript("OnClick", function() EEClient:FormCommMessage("LOOT;NEEDOFF") end ) self.NeedOff:SetPoint("BOTTOM",self.GreedMain,"TOP",0,5) ---- need main self.NeedMain = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") self.NeedMain:SetHeight(28) self.NeedMain:SetWidth(200) self.NeedMain:SetText("Main-spec") self.NeedMain:SetScript("OnClick", function() EEClient:FormCommMessage("LOOT;NEEDMAIN") end ) self.NeedMain:SetPoint("BOTTOM",self.NeedOff,"TOP",0,5) -- --local TextNeed = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") --TextNeed:SetText("Ðейн Ñпек") --TextNeed:SetPoint("BOTTOM",self.NeedMain,"TOP",0,5) ---- ÐÑид --self.GreedOff = CreateFrame("Button",nil,self.Anchor,"OptionsButtonTemplate") --self.GreedOff:SetHeight(28) --self.GreedOff:SetText("ÐÑид") --self.GreedOff:SetScript("OnClick", function() -- EEClient:FormCommMessage("LOOT;GREEDOFF") --end ) --self.GreedOff:SetPoint("LEFT",self.GreedMain,"RIGHT",20,0) --local TextGreed = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") --TextGreed:SetText("ÐÑÑ Ñпек") --TextGreed:SetPoint("BOTTOM",self.NeedOff,"TOP",0,5) -- TODO: i hate this stiff part, refactor self.RollItemPane = CreateFrame("Frame",nil,self.Anchor) self.RollItemPane:EnableMouse(true) self.RollItemPane:SetWidth(self.Anchor:GetWidth()-60) self.RollItemPane:SetPoint("TOP",self.Anchor, 0, -40) self.RollItemPane:SetPoint("BOTTOM",self.NeedMain, 0, 30) self.RollItemPane:SetScript("OnEnter", function() -- if GetItemInfo(self.RollItemText:GetText()) then RollLootTooltip:SetOwner( self.RollItemPane, "ANCHOR_BOTTOMLEFT" ) RollLootTooltip:ClearAllPoints(); RollLootTooltip:SetHyperlink(self.RollItemText:GetText()) if db.__ShowCompareTooltips == true then _showCompareItem() end RollLootTooltip:Show() end end) self.RollItemPane:SetScript("OnLeave", function() RollLootTooltip:Hide(); ShoppingTooltip1:Hide(); ShoppingTooltip2:Hide(); ShoppingTooltip3:Hide(); end) self.RollItemPane.texture = self.RollItemPane:CreateTexture() self.RollItemPane.texture:SetAllPoints(self.RollItemPane) self.RollItemPane.texture:SetTexture(1,1,1,0.1) self.RollItemText = self.Anchor:CreateFontString(nil,"ARTWORK","GameFontNormal") self.RollItemText:SetFont("Fonts\\FRIZQT__.TTF", 16) self.RollItemText:SetJustifyH("CENTER") self.RollItemText:SetJustifyV("MIDDLE") self.RollItemText:SetAllPoints(self.RollItemPane) -- nerf the pane? self.TimeoutPane = CreateFrame("Frame",nil,self.Anchor) self.TimeoutPane.TimeoutText = self.TimeoutPane:CreateFontString(nil,"ARTWORK","GameFontNormal") self.TimeoutPane.TimeoutText:SetFont("Fonts\\FRIZQT__.TTF", 32) self.TimeoutPane.TimeoutText:SetJustifyH("CENTER") self.TimeoutPane:SetScript("OnUpdate", function(self, elapsed) EEClient:UpdateTimeout(elapsed) end ) self.TimeoutPane.TimeoutText:SetPoint("BOTTOM",self.Pass,"TOP",0,10) self.TimeoutPane.LastUpdate = 0 self.TimeoutPane.TimeStart = 0 self.tab1 = CreateFrame("Button", "$parentTab1", self.Anchor, "CharacterFrameTabButtonTemplate" ) self.tab1:SetText("ÐÑÑ") self.tab1:Disable() self.tab1:SetPoint("LEFT", self.Anchor,"BOTTOMLEFT",10,-10) end function EEClient:OnInitialize() _debug("OnInitialize") self.db = LibStub("AceDB-3.0"):New("EEClientDB") db = self.db.global if db.__ShowCompareTooltips == nil then db.__ShowCompareTooltips = true; end if db.__ShowUnwearableLoot == nil then db.__ShowUnwearableLoot = false; end if db.__ShowAnnounceLoot == nil then db.__ShowAnnounceLoot = true; end -- register chat command self:RegisterChatCommand(__EERC, "ParseChatCommand") self:CreateFrames() self.Anchor:Hide() PanelTemplates_SetNumTabs(self.Anchor, 1) PanelTemplates_SetTab(self.Anchor, 1) self:RegisterComm("LSRA") tinsert(UISpecialFrames, self.Anchor:GetName()) end function EEClient:OnEnable() -- Called when the addon is enabled end function EEClient:OnDisable() -- Called when the addon is disabled end function EEClient:OnShow() PlaySound("UChatScrollButton") PanelTemplates_TabResize(self.tab1, 20) end function EEClient:OnHide() PlaySound("UChatScrollButton"); if (self.RollItemText:GetText() and (not (self.RollItemText:GetText() == "ÐÐµÑ ÐÑедмеÑа"))) then EEClient:FormCommMessage("LOOT;PASS"); end self:UnInitiateItem() end