/Tukui/modules/notifications/selfbuffs.lua
Lua | 217 lines | 195 code | 18 blank | 4 comment | 43 complexity | b21d4121c9c7ceee53b7eb934ec2eb12 MD5 | raw file
1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales 2if C["buffreminder"].enable ~= true then return end 3 4-------------------------------------------------------------------------------------------- 5-- Spells that should be shown with an icon in the middle of the screen when not buffed. 6-------------------------------------------------------------------------------------------- 7 8T.remindbuffs = { 9 PRIEST = { 10 588, -- inner fire 11 73413, -- inner will 12 }, 13 HUNTER = { 14 13165, -- hawk 15 5118, -- cheetah 16 13159, -- pack 17 20043, -- wild 18 82661, -- fox 19 }, 20 MAGE = { 21 7302, -- frost armor 22 6117, -- mage armor 23 30482, -- molten armor 24 }, 25 WARLOCK = { 26 28176, -- fel armor 27 687, -- demon armor 28 }, 29 SHAMAN = { 30 52127, -- water shield 31 324, -- lightning shield 32 974, -- earth shield 33 }, 34 WARRIOR = { 35 469, -- commanding Shout 36 6673, -- battle Shout 37 }, 38 DEATHKNIGHT = { 39 57330, -- horn of Winter 40 31634, -- strength of earth totem 41 6673, -- battle Shout 42 93435, -- roar of courage (hunter pet) 43 }, 44} 45 46T.remindenchants = { 47 ROGUE = { 48 2842, -- poison 49 }, 50 SHAMAN = { 51 8024, -- flametongue 52 8232, -- windfury 53 51730, -- earthliving 54 }, 55} 56 57-- Nasty stuff below. Don't touch. 58local class = select(2, UnitClass("Player")) 59local buffs = T.remindbuffs[class] 60local enchants = T.remindenchants[class] 61 62if (buffs and buffs[1]) then 63 local sound 64 local function BuffsOnEvent(self, event) 65 if (event == "PLAYER_LOGIN" or event == "LEARNED_SPELL_IN_TAB") then 66 for i, buff in pairs(buffs) do 67 local name = GetSpellInfo(buff) 68 local usable, nomana = IsUsableSpell(name) 69 if (usable or nomana) then 70 self.icon:SetTexture(select(3, GetSpellInfo(buff))) 71 break 72 end 73 end 74 if (not self.icon:GetTexture() and event == "PLAYER_LOGIN") then 75 self:UnregisterAllEvents() 76 self:RegisterEvent("LEARNED_SPELL_IN_TAB") 77 return 78 elseif (self.icon:GetTexture() and event == "LEARNED_SPELL_IN_TAB") then 79 self:UnregisterAllEvents() 80 self:RegisterEvent("UNIT_AURA") 81 self:RegisterEvent("PLAYER_LOGIN") 82 self:RegisterEvent("PLAYER_REGEN_ENABLED") 83 self:RegisterEvent("PLAYER_REGEN_DISABLED") 84 end 85 end 86 87 if (UnitAffectingCombat("player") and not UnitInVehicle("player")) then 88 for i, buff in pairs(buffs) do 89 local name = GetSpellInfo(buff) 90 if (name and UnitBuff("player", name)) then 91 self:Hide() 92 sound = true 93 return 94 end 95 end 96 self:Show() 97 if C["buffreminder"].sound == true and sound == true then 98 PlaySoundFile(C["media"].warning) 99 sound = false 100 end 101 else 102 self:Hide() 103 sound = true 104 end 105 end 106 107 local frame = CreateFrame("Frame", "TukuiBuffsWarningFrame", UIParent) 108 109 frame.icon = frame:CreateTexture(nil, "OVERLAY") 110 frame.icon:SetPoint("CENTER") 111 frame:CreatePanel("Default", 40, 40, "CENTER", UIParent, "CENTER", 0, 200) 112 frame.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9) 113 frame.icon:Size(36) 114 frame:Hide() 115 116 frame:RegisterEvent("UNIT_AURA") 117 frame:RegisterEvent("PLAYER_LOGIN") 118 frame:RegisterEvent("PLAYER_REGEN_ENABLED") 119 frame:RegisterEvent("PLAYER_REGEN_DISABLED") 120 frame:RegisterEvent("UNIT_ENTERING_VEHICLE") 121 frame:RegisterEvent("UNIT_ENTERED_VEHICLE") 122 frame:RegisterEvent("UNIT_EXITING_VEHICLE") 123 frame:RegisterEvent("UNIT_EXITED_VEHICLE") 124 125 frame:SetScript("OnEvent", BuffsOnEvent) 126end 127 128if (enchants and enchants[1]) then 129 local sound 130 local currentlevel = UnitLevel("player") 131 132 local function EnchantsOnEvent(self, event) 133 if (event == "PLAYER_LOGIN") or (event == "ACTIVE_TALENT_GROUP_CHANGED") or (event == "PLAYER_LEVEL_UP") then 134 if class == "ROGUE" then 135 self:UnregisterEvent("ACTIVE_TALENT_GROUP_CHANGED") 136 self:UnregisterEvent("PLAYER_LEVEL_UP") 137 self.icon:SetTexture(select(3, GetSpellInfo(enchants[1]))) 138 return 139 elseif class == "SHAMAN" then 140 local ptt = GetPrimaryTalentTree() 141 if ptt and ptt == 3 and currentlevel > 53 then 142 self.icon:SetTexture(select(3, GetSpellInfo(enchants[3]))) 143 elseif ptt and ptt == 2 and currentlevel > 31 then 144 self.icon:SetTexture(select(3, GetSpellInfo(enchants[2]))) 145 else 146 self.icon:SetTexture(select(3, GetSpellInfo(enchants[1]))) 147 end 148 return 149 end 150 end 151 152 if (class == "ROGUE" or class =="SHAMAN") and currentlevel < 10 then return end 153 154 if (UnitAffectingCombat("player") and not UnitInVehicle("player")) then 155 local mainhand, _, _, offhand, _, _, thrown = GetWeaponEnchantInfo() 156 if class == "ROGUE" then 157 local itemid = GetInventoryItemID("player", GetInventorySlotInfo("RangedSlot")) 158 if itemid and select(7, GetItemInfo(itemid)) == INVTYPE_THROWN and currentlevel > 61 then 159 if mainhand and offhand and thrown then 160 self:Hide() 161 sound = true 162 return 163 end 164 else 165 if mainhand and offhand then 166 self:Hide() 167 sound = true 168 return 169 end 170 end 171 elseif class == "SHAMAN" then 172 local itemid = GetInventoryItemID("player", GetInventorySlotInfo("SecondaryHandSlot")) 173 if itemid and select(6, GetItemInfo(itemid)) == ENCHSLOT_WEAPON then 174 if mainhand and offhand then 175 self:Hide() 176 sound = true 177 return 178 end 179 elseif mainhand then 180 self:Hide() 181 sound = true 182 return 183 end 184 end 185 self:Show() 186 if C["buffreminder"].sound == true and sound == true then 187 PlaySoundFile(C["media"].warning) 188 sound = false 189 end 190 else 191 self:Hide() 192 sound = true 193 end 194 end 195 196 local frame = CreateFrame("Frame", "TukuiEnchantsWarningFrame", UIParent) 197 198 frame.icon = frame:CreateTexture(nil, "OVERLAY") 199 frame.icon:SetPoint("CENTER") 200 frame:CreatePanel("Default", 40, 40, "CENTER", UIParent, "CENTER", 0, 200) 201 frame.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9) 202 frame.icon:Size(36) 203 frame:Hide() 204 205 frame:RegisterEvent("PLAYER_LOGIN") 206 frame:RegisterEvent("PLAYER_LEVEL_UP") 207 frame:RegisterEvent("PLAYER_REGEN_ENABLED") 208 frame:RegisterEvent("PLAYER_REGEN_DISABLED") 209 frame:RegisterEvent("UNIT_INVENTORY_CHANGED") 210 frame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED") 211 frame:RegisterEvent("UNIT_ENTERING_VEHICLE") 212 frame:RegisterEvent("UNIT_ENTERED_VEHICLE") 213 frame:RegisterEvent("UNIT_EXITING_VEHICLE") 214 frame:RegisterEvent("UNIT_EXITED_VEHICLE") 215 216 frame:SetScript("OnEvent", EnchantsOnEvent) 217end