local class = select(2, UnitClass("player")) --ARE YOU A SHAMAN?-- if class ~= "SHAMAN" then return end --DEFINE MY LOCALS-- local Broadcaster = LibStub("AceAddon-3.0"):GetAddon("Broadcaster") local Shaman = Broadcaster:NewModule("Shaman", "AceEvent-3.0", "AceConsole-3.0") ------------------- local L = LibStub("AceLocale-3.0"):GetLocale("Broadcaster") local db, msgs local list, replacee, replacer, custom, msg local pick = {"Default", "Custom", "Both"} local player = UnitName("player") local ancSpiritSpellID = { [2008] = true, --rank 1 ancSpirit [20609] = true, --rank 2 ancSpirit [20610] = true, --rank 3 ancSpirit [20776] = true, --rank 4 ancSpirit [20777] = true, --rank 5 ancSpirit } local defaults = { profile = { ancspenable = true, ancspchoose = "Default", }, } local options = { ancsp = { name = L["Ancestral Spirit"], type = "group", arg = class, args = { enable = { name = L["Enable"], desc = L["Announce messages for this spell."], type = "toggle", order = 1, get = function() return db.ancspenable end, set = function() db.ancspenable = not db.ancspenable end, }, pick = { name = L["Pull messages from..."], desc = L["Use the default messages, your own, or both."], type = "select", order = 2, values = {L["Default"], L["Custom"], L["Both"]}, get = function() for k, v in pairs(pick) do if db.ancspchoose == v then return k end end end, set = function(_, choose) db.ancspchoose = pick[choose] end, }, custom = { name = L["Custom messages"], desc = L["Enter in any custom messages you would like to use, one per line."].."\n\n%t = "..L["the spell's target"], type = "input", order = 3, multiline = true, width = "double", get = function() return db.customancsp end, set = function(_, value) db.customancsp = value end, }, }, }, } -- INITIALIZE ADDON -- function Shaman:OnInitialize() self.db = Broadcaster.db:RegisterNamespace(class, defaults) db = self.db.profile coredb = Broadcaster.db.profile msgs = BroadcasterShamanMsgs Broadcaster:InjectOptions(class, options) end function Shaman:OnEnable() self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") end -- CREATE AND SEND MESSAGES -- function Shaman:CompileMessage(list, custom, replacee, replacer) if custom then local pool = (#list + #custom) if math.random(pool) <= #custom then list = custom end end local max = #list local random = math.random(max) if replacee and replacer then msg = string.gsub(list[random], replacee, replacer) else msg = list[random] end if coredb.channel == L["Self"] then self:Print(msg) else SendChatMessage(msg, coredb.channel) end custom, replacee, replacer = nil end -------------------------------------- --VOODOO MAGIC STUFF-- -------------------------------------- function Broadcaster:COMBAT_LOG_EVENT_UNFILTERED(event, _, eventType, _, srcName, _, _, _, dstFlags, spellID, spellName, spellSchool, eID, eName) if not coredb.standby then if eventType == "SPELL_CAST_START" and srcName == player then --AND AM I CASTING ANCESTRALSPIRIT?-- if ancSpiritSpellID[spellID] then list = msgs.AncestralSpirit if db.ancspchoose == "Custom" then list = {strsplit("\n", db.customancsp)} elseif db.ancspchoose == "Both" then custom = {strsplit("\n", db.customancsp)} end self:CompileMessage(list, custom) end end end end