WoWInterface SVN Thanks4Buff

[/] [trunk/] [Thanks4Buff.lua] - Rev 11

Compare with Previous | Blame | View Log

local t4bf = CreateFrame('Frame');
t4bf:SetScript('OnEvent', function(self, event, ...) getglobal("T4B_"..event)(event, ...) end);
t4bf:RegisterEvent("VARIABLES_LOADED")

function T4B_VARIABLES_LOADED(event, ...)
        if T4BOpts == nil then
                T4BOpts = {}
        end
        
        if T4BOpts["macro"] == nil then
                T4BOpts["macro"] = false
        end
        
        if T4BOpts["npc"] == nil then
                T4BOpts["npc"] = true
        end
        
        if T4BOpts["spell"] == nil then
                T4BOpts["spell"] = true
        end
    t4bf:UnregisterEvent("VARIABLES_LOADED")
        t4bf:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
        
        T4BAbout = LibStub("tekKonfig-AboutPanel").new(nil, "Thanks4Buff")
        
                -- Create the Main Options
        local T4BOptFrame = CreateFrame("Frame", "T4BOptions", InterfaceOptionsFramePanelContainer)
        T4BOptFrame.name = "General Options"
        T4BOptFrame.parent = "Thanks4Buff"
        local title, subtitle = LibStub("tekKonfig-Heading").new(T4BOptFrame, "Thanks 4 Buff Options", "This panel controls the various T4B options.")
        
        -- Add the option to have T4B create a buffing macro.
        local macrocheck = LibStub("tekKonfig-Checkbox").new(T4BOptFrame, nil, "Create a macro that can be used to automatically buff those that buff you?", "TOPLEFT", subtitle, "BOTTOMLEFT", -2, -8)
        local checksound = macrocheck:GetScript("OnClick")
        macrocheck:SetScript("OnClick", function(self) checksound(self); T4BOpts["macro"] = not T4BOpts["macro"]; end)
        local _, englishName = UnitClass("player")
        if T4B_Buffs[englishName] == nil then
                macrocheck:Disable()
                macrocheck:SetChecked(false)
        else
                macrocheck:Enable()
                macrocheck:SetChecked(T4BOpts["macro"])
        end
        
                -- Add the option to include the spellname
        local spellcheck = LibStub("tekKonfig-Checkbox").new(T4BOptFrame, nil, "Add the name of the buff to the thank you emote?", "TOPLEFT", macrocheck, "BOTTOMLEFT", -2, -8)
        local checksound = spellcheck:GetScript("OnClick")
        spellcheck:SetScript("OnClick", function(self) checksound(self); T4BOpts["spell"] = not T4BOpts["spell"]; end)
        spellcheck:SetChecked(T4BOpts["spell"])
        
                -- Add the option to ignore buffs from NPCs
        local npccheck = LibStub("tekKonfig-Checkbox").new(T4BOptFrame, nil, "Thank NPCs for their buffs?", "TOPLEFT", spellcheck, "BOTTOMLEFT", -2, -8)
        local checksound = npccheck:GetScript("OnClick")
        npccheck:SetScript("OnClick", function(self) checksound(self); T4BOpts["npc"] = not T4BOpts["npc"]; end)
        npccheck:SetChecked(T4BOpts["npc"])
        
        InterfaceOptions_AddCategory(T4BOptFrame)
end



function T4B_COMBAT_LOG_EVENT_UNFILTERED(event, ...)
        local timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags = select(1, ...)
        local filter
        if T4BOpts["npc"] then
                filter = bit.bor(COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, COMBATLOG_OBJECT_REACTION_FRIENDLY, COMBATLOG_OBJECT_CONTROL_MASK, COMBATLOG_OBJECT_TYPE_MASK)
        else
                filter = bit.bor(COMBATLOG_OBJECT_AFFILIATION_OUTSIDER, COMBATLOG_OBJECT_REACTION_FRIENDLY, COMBATLOG_OBJECT_CONTROL_MASK, COMBATLOG_OBJECT_TYPE_PLAYER)
        end
        if ( eventType == "SPELL_AURA_APPLIED" or eventType== "SPELL_AURA_REFRESH" ) and destGUID == UnitGUID("player") and (CombatLog_Object_IsA(sourceFlags, filter) == 1) then
                local emotetext
                if T4BOpts["spell"] then
                        local spellId, spellName, spellSchool = select(10, ...)
                        if GetLocale() == "frFR" then
                                local firstLetter = strsub(spellName, 1, 1)
                                if firstLetter == "a" or firstLetter == "e" or firstLetter == "i" or firstLetter == "o" or firstLetter == "u" then
                                        emotetext = T4B_Sayings["spell"]["vowel"][random(#(T4B_Sayings["spell"]))]
                                else
                                        emotetext = T4B_Sayings["spell"]["cons"][random(#(T4B_Sayings["spell"]))]
                                end
                        else
                                emotetext = T4B_Sayings["spell"][random(#(T4B_Sayings["spell"]))]
                        end
                        emotetext = gsub(emotetext, "#s", spellName)
                else
                        emotetext = T4B_Sayings["nospell"][random(#(T4B_Sayings["nospell"]))]
                end
                emotetext = gsub(emotetext, "#n", sourceName)
                
                SendChatMessage(emotetext, "EMOTE")
                local _, englishName = UnitClass("player")
                if not InCombatLockdown() and T4B_Buffs[englishName] then
                        local t4bIndex = GetMacroIndexByName("T4B_Macro")
                        local numglobal,numperchar = GetNumMacros();

                        local macrotext = "/targetexact "..sourceName.."\n/cast [exists] "..T4B_Buffs[englishName].."\n/targetlasttarget"

                        if  t4bIndex == 0 and numglobal < 36 then
                                CreateMacro("T4B_Macro",120, macrotext, nil, nil)
                        elseif t4bIndex > 0 then
                                EditMacro(t4bIndex, "T4B_Macro", 120, macrotext, 1, 1)
                        end
                end
        end
end

T4B_Buffs = {}
T4B_Buffs = {
                        ["DRUID"] = GetSpellInfo(1126),         --MotW
                        ["PALADIN"] = GetSpellInfo(20217),      --BoK
                        ["PRIEST"] = GetSpellInfo(1243),        --Fort
                        ["MAGE"] = GetSpellInfo(1459)           --AI
                        }


-- The T4B_Sayings table holds the list of strings for the emotes.                      
T4B_Sayings = {}
T4B_Sayings["spell"] = {}
T4B_Sayings["nospell"] = {}

if GetLocale() == "frFR" then
        T4B_Sayings["spell"]["vowel"] = {
                                                                                "remercie #n pour sa #s.",
                                                                                "est reconnaissant pour l'#s de #n.",
                                                                                "apprécie l'#s de #n."
                                                                        }
        T4B_Sayings["spell"]["cons"] = {
                                                                                "remercie #n pour sa #s.",
                                                                                "est reconnaissant pour la #s de #n.",
                                                                                "apprécie la #s de #n."
                                                                        }
                                                                        
        T4B_Sayings["nospell"] = {                                      
                                                                "remercie #n.",
                                                                "est reconnaissant envers #n.",
                                                                "apprécie #n."
                                                        }

else
        T4B_Sayings["spell"] = {
                                                        "thanks #n for their #s.",
                                                        "is grateful for #n's #s.",
                                                        "appreciates #n's #s."
                                                        }

        T4B_Sayings["nospell"] = {                                      
                                                                "thanks #n.",
                                                                "is grateful to #n.",
                                                                "is appreciative towards #n."
                                                        }
end 

Compare with Previous | Blame