WoWInterface SVN DEEP

[/] [trunk/] [DEEP/] [DEEPMRTplugin.lua] - Rev 27

Compare with Previous | Blame | View Log


local parent = DEEP
local modName = "MRTplugin"
local mod = DEEP:NewModule(modName, "AceEvent-3.0")
local MRT_ExternalLootNotifier = {}
local MsgToBlock
local GARuned = false
local functiontoback = nil
local needsendlog = false
local sendlogtoofficer = function() end
local senditemtoofficer = function() end


local registelootnotify = function(functionToCall) --becouse MRT_ExternalLootNotifier is local, we must to hook this functions
    local isRegistered = nil;
    for i, val in ipairs(MRT_ExternalLootNotifier) do
        if (val == functionToCall) then
            isRegistered = true;
        end
    end
    DEEP:Print('registered?')
    if (isRegistered) then
        return false;
    else
        tinsert(MRT_ExternalLootNotifier, functionToCall);
        return true;
    end
    --MRT_RegisterLootNotifyCore(functionToCall)
end
local unregisterlootnotify = function(functionCalled) --becouse MRT_ExternalLootNotifier is local, we must to hook this functions
    local isRegistered = nil;
    for i, val in ipairs(MRT_ExternalLootNotifier) do
        if (val == functionCalled) then
            isRegistered = i;
        end
    end
    if (isRegistered) then
        tremove(MRT_ExternalLootNotifier, isRegistered);
        return true;
    else
        return false;
    end
    --MRT_UnregisterLootNotifyCore(functionCalled)
end
local addloot = function(itemLink, looter, cost, anothername)
    if (not MRT_NumOfCurrentRaid) then
        MRT_Print(MRT_L["GUI"]["No active raid"]);
        return; 
    end
    if (not MRT_NumOfLastBoss) then MRT_AddBosskill(MRT_L.Core["Trash Mob"]); end
    local itemName, _, itemId, itemString, itemRarity, itemColor, itemLevel, _, itemType, itemSubType, _, _, _, _ = MRT_GetDetailedItemInformation(itemLink);
    if (not itemName) then 
        MRT_Debug("MRT_ManualAddLoot(): Failed horribly when trying to get item informations.");
        return; 
    end
    if anothername then 
        itemName = anothername 
        itemId = 0
        itemString = "item:0:0:0:0:0:0:0:0:85:0"
    end
    local lootInfo = {
        ["ItemLink"] = itemLink,
        ["ItemString"] = itemString,
        ["ItemId"] = itemId,
        ["ItemName"] = itemName,
        ["ItemColor"] = itemColor,
        ["ItemCount"] = 1,
        ["Looter"] = looter,
        ["DKPValue"] = cost,
        ["RaidNumber"] = MRT_NumOfCurrentRaid,
        ["BossNumber"] = MRT_NumOfLastBoss,
        ["Time"] = MRT_GetCurrentTime(),
    };
    tinsert(MRT_RaidLog[MRT_NumOfCurrentRaid]["Loot"], lootInfo);
    local itemNum = #MRT_RaidLog[MRT_NumOfCurrentRaid]["Loot"];
    if (#MRT_ExternalLootNotifier > 0) then
        local itemInfo = {};
        for key, val in pairs(MRT_RaidLog[MRT_NumOfCurrentRaid]["Loot"][itemNum]) do
            itemInfo[key] = val;
        end
       if (itemInfo.Looter == "bank") then
           itemInfo.Action = MRT_LOOTACTION_BANK;
        elseif (itemInfo.Looter == "disenchanted") then
            itemInfo.Action = MRT_LOOTACTION_DISENCHANT;
        elseif (itemInfo.Looter == "_deleted_") then
            itemInfo.Action = MRT_LOOTACTION_DELETE;
        else
            itemInfo.Action = MRT_LOOTACTION_NORMAL;
        end
        for i, val in ipairs(MRT_ExternalLootNotifier) do
            pcall(val, itemInfo, MRT_NOTIFYSOURCE_ADD_GUI, MRT_NumOfCurrentRaid, itemNum);
        end
    end
    return true;
end
local attwhisper = function(player, source)
    if (MRT_NumOfCurrentRaid ~= nil) then
        local sendMsg = nil;
        local player_exist = nil;
        if (MRT_NumOfLastBoss) then
            for i, v in ipairs(MRT_RaidLog[MRT_NumOfCurrentRaid]["Bosskills"][MRT_NumOfLastBoss]["Players"]) do
                if (v == player) then player_exist = true; end;
            end
            if (player_exist == nil) then tinsert(MRT_RaidLog[MRT_NumOfCurrentRaid]["Bosskills"][MRT_NumOfLastBoss]["Players"], player); end;
        end
        if (player_exist) then
            sendMsg = "MRT: "..string.format(MRT_L.Core.GuildAttendanceReplyFail, player);
            MRT_Print(string.format(MRT_L.Core.GuildAttendanceFailNotice, source, player)); -- this line might just be deleted
        else
            sendMsg = "MRT: "..string.format(MRT_L.Core.GuildAttendanceReply, player);
            SendChatMessage("MRT: "..string.format(MRT_L.Core.GuildAttendanceAddNotice, source, player), "OFFICER"); 
            --MRT_Print(string.format(MRT_L.Core.GuildAttendanceAddNotice, source, player));
        end
        SendChatMessage(sendMsg, "WHISPER", nil, source);
        MsgToBlock = sendMsg;
    end
end
sendlogtoofficer = function(timer)
    if timer == "MRT: "..MRT_L.Core["GuildAttendanceTimeUpText"] then
        if not functiontoback then
                StaticPopup_Show("DEEPsendMRTlog")
                functiontoback = function()
                        sendlogtoofficer(timer)
                end
                return  
        end
        if needsendlog then
        GARuned = false
        local id = tostring(time())
        local flag = false
        local msg = "\028*TYPE*\028RAIDCHECK"
        msg = msg.."\028*NAME*\028"..MRT_RaidLog[MRT_NumOfCurrentRaid]["Bosskills"][MRT_NumOfLastBoss]["Name"]
        msg = msg.."\028*RAIDID*\028"..MRT_NumOfCurrentRaid
        msg = msg.."\028*BOSSID*\028"..MRT_NumOfLastBoss
        msg = msg.."\028*COUNT*\028"
        for i, v in ipairs(MRT_RaidLog[MRT_NumOfCurrentRaid]["Bosskills"][MRT_NumOfLastBoss]["Players"]) do
                if flag then
                        msg = msg..","..v
                else
                        msg = msg..v
                        flag = true
                end
        end
        DEEP:SendCommMessage("DEEPLOG", msg.."\028*ID*\028"..id.."\028*SENDER*\028"..UnitName("player").."\028*END*\028", "OFFICER")
        end
    end
end
senditemtoofficer = function(itemInfoTable, source, raidNum, itemNum, oldItemInfoTable)
    if source ~= 4 and source ~= 5 then 
        if not functiontoback then
                StaticPopup_Show("DEEPsendMRTlog")
                functiontoback = function()
                        senditemtoofficer(itemInfoTable, source, raidNum, itemNum, oldItemInfoTable)
                end
                return  
        end
        if needsendlog then
        local id = tostring(time())
        local msg = "\028*TYPE*\028ITEM"
        msg = msg.."\028*NAME*\028"..itemInfoTable["ItemName"]
        msg = msg.."\028*PLAYER*\028"..itemInfoTable["Looter"]
        msg = msg.."\028*DKP*\028"..itemInfoTable["DKPValue"]
        msg = msg.."\028*RAIDID*\028"..itemInfoTable["RaidNumber"]
        msg = msg.."\028*BOSSID*\028"..itemInfoTable["BossNumber"]
        DEEP:SendCommMessage("DEEPLOG", msg.."\028*ID*\028"..id.."\028*SENDER*\028"..UnitName("player").."\028*END*\028", "OFFICER")
        end
    end
end
local attendancestartednoconf = function(bossname)
        if not MRT_Options["Attendance_GuildAttendanceCheckEnabled"] then
                if bossname == MRT_L.Core["GuildAttendanceBossEntry"] then
                        GARuned = true                  
                else
                        sendlogtoofficer("MRT: "..MRT_L.Core["GuildAttendanceTimeUpText"])              
                end
        end
end
local attendancestartedyesconf = function(bossname)
        if MRT_Options["Attendance_GuildAttendanceCheckEnabled"] then
                GARuned = true                  
        end
end
local chatfilter = function(self, event, msg, from, ...)
    if (not GARuned) then return false; end
    if (msg == MsgToBlock) then
        return true;
    end
    return false;
end

function mod:ADDON_LOADED()
        if MRT_GUIFrame then
                hooksecurefunc("MRT_RegisterLootNotifyCore",         registelootnotify)
                hooksecurefunc("MRT_UnregisterLootNotifyCore",         unregisterlootnotify)
                --local function MRT_LootNotify(itemInfoTable, source, raidNum, itemNum, oldItemInfoTable)
                --      DEEP:Print("LootNotify! Item is "..itemInfoTable["ItemLink"].." - Source is "..tostring(source).." - raidNum/itemnum: "..tostring(raidNum).."/"..tostring(itemNum));
                --      DEEP:Print("ItemAction is: "..itemInfoTable.Action);
                --end
                local registrationSuccess = MRT_RegisterLootNotify(senditemtoofficer);
                hooksecurefunc("MRT_StartGuildAttendanceCheck",         attendancestartedyesconf)
                hooksecurefunc("MRT_AddBosskill",         attendancestartednoconf)
                hooksecurefunc("MRT_GuildAttendanceSendAnnouncement",         sendlogtoofficer)
                MRT_ManualAddLoot = addloot
                MRT_GuildAttendanceWhisper = attwhisper
                ChatFrame_AddMessageEventFilter("CHAT_MSG_WHISPER_INFORM", chatfilter)
                local cb = CreateFrame("CheckButton", nil, MRT_GUIFrame, "UICheckButtonTemplate")
                cb:SetWidth(20)
                cb:SetHeight(20)
                cb:SetPoint("BOTTOMLEFT", MRT_GUIFrame, "BOTTOMLEFT", 140,90)
                cb:SetScript(
                        "OnClick",
                        function(self)
                        needsendlog = self:GetChecked()
                end) 
                local t = cb:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
                t:SetText("Send log?")
                t:SetPoint("RIGHT", cb, "LEFT", 0, 2)
                StaticPopupDialogs["DEEPsendMRTlog"] = {
                        text = "Send your MRT log?",
                        button1 = YES,
                        button2 = NO,
                        sound = "levelup2",
                        whileDead = 1,
                        hideOnEscape = 1,
                        timeout = 0,
                        OnAccept = function()
                                cb:SetChecked(true)
                                needsendlog = true
                                functiontoback()
                        end,
                }
                mod:UnregisterEvent("ADDON_LOADED")
        end
end



mod:RegisterEvent("ADDON_LOADED")

Compare with Previous | Blame