1. --[[
  2. -- custom.lua for Kui_Nameplates
  3. -- By Kesava at curse.com
  4. --
  5. -- changes colour of health bars for specific units in the table
  6. ]]
  7. local addon = LibStub('AceAddon-3.0'):GetAddon('KuiNameplates')
  8. local mod = addon:NewModule('CustomInjector', 'AceEvent-3.0')
  9. local units = {
  10. --['Training Dummy'] = { 1, 0, 1.25 },
  11. ["Kor'kron Assassin"] = { 1, 0.96, 0.41 },
  12. ["Kor'kron Arcweaver"] = { 0.41, 0.80, 0.94 },
  13. ["Kor'kron Warshaman"] = { 0, 0.44, 0.87 },
  14. ['Farseer Wolf Rider'] = { 1, 0, 1.25 },
  15. ['Dragonmaw Tidal Shaman'] = { 0, 0.44, 0.87 },
  16. ['Garrosh Hellscream'] = {1, 1, 1},
  17. ['Leafmender'] = {1, 1, 1},
  18. --['Great Turtle'] = {1, 1, 1},
  19. --['Embodied Gloom'] = {1, 1, 1},
  20. --['Immerseus'] = {1, 1, 1},
  21. --['Rook Stonetoe'] = {1, 1, 1},
  22. }
  23. local MIND_HARVEST_GLYPH_ID = 1202
  24. local MIND_HARVEST_KNOWN
  25. local MIND_HARVEST_USED = {}
  26. local usedIndex = {}
  27. function mod:COMBAT_LOG_EVENT_UNFILTERED(event,...)
  28. local sourceGUID = select(4,...)
  29. if sourceGUID ~= UnitGUID('player') then return end
  30. local log_event = select(2,...)
  31. if log_event ~= 'SPELL_DAMAGE' then return end
  32. local spellID = select(12,...)
  33. if spellID ~= 8092 then return end
  34. local targetGUID = select(8,...)
  35. if not MIND_HARVEST_USED[targetGUID] then
  36. MIND_HARVEST_USED[targetGUID] = true
  37. tinsert(usedIndex, targetGUID)
  38. -- purge index over 100
  39. if #usedIndex > 100 then
  40. MIND_HARVEST_USED[tremove(usedIndex, 1)] = nil
  41. end
  42. local frame = addon:GetNameplate(targetGUID, nil)
  43. if frame then
  44. self:HideNotifier(nil, frame)
  45. end
  46. end
  47. end
  48. function mod:PLAYER_ENTERING_WORLD()
  49. self:ScanGlyphs()
  50. end
  51. function mod:GLYPH_ADDED()
  52. self:ScanGlyphs()
  53. end
  54. function mod:GLYPH_UPDATED()
  55. self:ScanGlyphs()
  56. end
  57. function mod:ScanGlyphs()
  58. for i=1,GetNumGlyphSockets() do
  59. local glyph_id = select(6,GetGlyphSocketInfo(i))
  60. if glyph_id and glyph_id == MIND_HARVEST_GLYPH_ID then
  61. MIND_HARVEST_KNOWN = true
  62. return
  63. end
  64. end
  65. MIND_HARVEST_KNOWN = false
  66. end
  67. function mod:CreateNotifier(msg, frame)
  68. frame.mindharvest = frame.overlay:CreateTexture(nil, 'ARTWORK')
  69. local mh = frame.mindharvest
  70. mh:SetDrawLayer('ARTWORK',2)
  71. mh:SetTexture('Interface\\AddOns\\Kui_Nameplates\\media\\combopoint-round')
  72. mh:SetSize(9,9)
  73. mh:SetVertexColor(1,.4,1)
  74. mh:Hide()
  75. mh:SetPoint('LEFT', frame.overlay, 'RIGHT', 2, 0)
  76. end
  77. function mod:HideNotifier(msg, frame)
  78. frame.mindharvest:Hide()
  79. end
  80. function mod:GUIDStored(msg, f, unit)
  81. if f.friend then return end
  82. if MIND_HARVEST_KNOWN and not MIND_HARVEST_USED[f.guid] then
  83. f.mindharvest:Show()
  84. end
  85. end
  86. local LOW_HEALTH_COLOR = { 1, 1, 1 }
  87. local function OnHealthValueChanged(oldHealth,current)
  88. local frame = oldHealth:GetParent():GetParent().kui
  89. local percent = frame.health.percent
  90. if percent <= 19.9 then
  91. frame:SetHealthColour(true, unpack(LOW_HEALTH_COLOR))
  92. else
  93. frame:SetHealthColour(false)
  94. end
  95. end
  96. function mod:PostShow(msg, frame)
  97. local mycol = units[frame.name.text]
  98. if mycol then
  99. frame:SetHealthColour(true, unpack(mycol))
  100. end
  101. end
  102. function mod:PostCreate(msg, frame)
  103. frame.oldHealth:HookScript('OnValueChanged', OnHealthValueChanged)
  104. if select(2,UnitClass('player')) == 'PRIEST' then
  105. self:CreateNotifier(nil,frame)
  106. end
  107. end
  108. function mod:OnInitialize()
  109. self:RegisterMessage('KuiNameplates_PostCreate', 'PostCreate')
  110. if select(2,UnitClass('player')) == 'PRIEST' then
  111. self:RegisterMessage('KuiNameplates_PostHide', 'HideNotifier')
  112. self:RegisterMessage('KuiNameplates_GUIDStored', 'GUIDStored')
  113. self:RegisterEvent('COMBAT_LOG_EVENT_UNFILTERED')
  114. self:RegisterEvent('PLAYER_ENTERING_WORLD')
  115. self:RegisterEvent('GLYPH_ADDED')
  116. self:RegisterEvent('GLYPH_UPDATED')
  117. end
  118. end
  119. mod:RegisterMessage('KuiNameplates_PostShow', 'PostShow')