/Tukui/modules/notifications/selfbuffs.lua

http://github.com/Asphyxia/Tukui · Lua · 217 lines · 195 code · 18 blank · 4 comment · 75 complexity · b21d4121c9c7ceee53b7eb934ec2eb12 MD5 · raw file

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