Advertisement
Exality

Untitled

Sep 12th, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.35 KB | None | 0 0
  1. function(event, unitId)
  2.  
  3. --[[ USER-CONFIG PART ]]--
  4. local thisUnitId = "player"; -- UnitId which should be watched (player, target, focus, pet, bossN, raidN)
  5. local thisUnitName = nil; -- UnitName which should be watched [optional]
  6.  
  7.  
  8. --[[ INTERNAL CODE PART ]]--
  9. -- Initialize
  10. if not WA_ABSORB_SpellIds then
  11. -- List of absorb spells to query
  12. WA_ABSORB_SpellIds = {
  13. [17] = true, -- Power Word: Shield
  14. [7812] = true, -- Sacrifice
  15. [114908] = true, -- Spirit Shell
  16. [47753] = true, -- Divine Aegis
  17. [77535] = true, -- Blood Shield
  18. [86273] = true, -- Illuminated Healing
  19. [65148] = true, -- Sacred Shield
  20. [112048] = true, -- Shield Barrier
  21. [122470] = true, -- Touch of Karma
  22. [116849] = true, -- Life Cocoon
  23. [1521180] = true, -- Clarity of Will
  24. [157128] = true, -- Saved by the Light
  25. [155783] = true, -- Primal Tenacity
  26. };
  27.  
  28. -- Get localized spell names
  29. WA_ABSORB_SpellNames = {};
  30. for spellId, bool in pairs(WA_ABSORB_SpellIds) do
  31. -- Localize
  32. local spellName = GetSpellInfo(spellId);
  33. if spellName then
  34. WA_ABSORB_SpellNames[spellName] = spellId;
  35. end
  36. end
  37.  
  38. -- Track max absorb value per spell per unit: WA_ABSORB_Max[unitId][spellName]= value
  39. WA_ABSORB_Max = {};
  40.  
  41. -- Track cur/max absorb value per unit: WA_ABSORB_ComCurrent[unitId] = value, WA_ABSORB_ComMax[unitId] = value
  42. WA_ABSORB_ComCurrent = {};
  43. WA_ABSORB_ComMax = {};
  44.  
  45. -- Remember name
  46. WA_ABSORB_Name2Id = {};
  47.  
  48. -- Update a units absorb value
  49. WA_ABSORB_Update = function(unitId)
  50. -- Default
  51. if not unitId then unitId = "player" end
  52.  
  53. -- Create per unit per spell max absorb buffer
  54. WA_ABSORB_Max[unitId] = WA_ABSORB_Max[unitId] or {};
  55.  
  56. -- Comulative current/maximum
  57. WA_ABSORB_ComCurrent[unitId] = 0;
  58. WA_ABSORB_ComMax[unitId] = 0;
  59.  
  60. -- Locals
  61. local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3;
  62. local curAmount, maxAmount;
  63.  
  64. -- Scan all abosrb spells
  65. for spellName, spellId in pairs(WA_ABSORB_SpellNames) do
  66. -- value1 will be remaining amount if aura is available
  67. name, rank, icon, count, dispelType, duration, expires, caster, isStealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, _, nameplateShowAll, timeMod, value1, value2, value3 = UnitAura(unitId, spellName);
  68.  
  69. -- Save values
  70. if name and value1 > 0 then
  71. -- Remember values
  72. curAmount = value1;
  73. WA_ABSORB_Max[unitId][spellName] = math.max(WA_ABSORB_Max[unitId][spellName] or 0, value1);
  74. maxAmount = WA_ABSORB_Max[unitId][spellName];
  75. else
  76. -- No aura, reset to 0
  77. curAmount = 0;
  78. WA_ABSORB_Max[unitId][spellName] = 0;
  79. maxAmount = 0;
  80. end
  81.  
  82. -- Calc comulative current/maximum
  83. WA_ABSORB_ComCurrent[unitId] = WA_ABSORB_ComCurrent[unitId] + curAmount;
  84. WA_ABSORB_ComMax[unitId] = WA_ABSORB_ComMax[unitId] + maxAmount;
  85. end
  86.  
  87. -- Remember units name
  88. if thisUnitName then
  89. local name = UnitName(unitId);
  90. if name then
  91. WA_ABSORB_Name2Id[name] = unitId;
  92. end
  93. end
  94. end
  95.  
  96. -- Reste unit data
  97. WA_ABSORB_ResetUnit = function(unitId)
  98. -- Reset unit-max per spell
  99. if WA_ABSORB_Max[unitId] then
  100. for spellName, data in pairs(WA_ABSORB_Max[unitId]) do
  101. WA_ABSORB_Max[unitId][spellName] = nil;
  102. end
  103. end
  104.  
  105. -- Reset other variables
  106. WA_ABSORB_ComCurrent[unitId] = 0;
  107. WA_ABSORB_ComMax[unitId] = 0;
  108. local name = UnitName(unitId);
  109. if name then
  110. WA_ABSORB_Name2Id[name] = unitId;
  111. end
  112. end
  113. end
  114.  
  115. -- Witch unit to reset
  116. local realUnitId = event == "PLAYER_TARGET_CHANGED" and "target" or event == "PLAYER_FOCUS_CHANGED" and "focus" or unitId;
  117.  
  118. -- Reset when chaning target
  119. if event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_FOCUS_CHANGED" then
  120. WA_ABSORB_ResetUnit(realUnitId);
  121. end
  122.  
  123. -- Reset raid units
  124. if event == "RAID_ROSTER_UPDATE"or event == "PARTY_MEMBERS_CHANGED" then
  125. if UnitInRaid("player") then
  126. for id = 1, GetNumRaidMembers() do
  127. local realUnitId = string.format("raid%d", id);
  128.  
  129. WA_ABSORB_ResetUnit(realUnitId);
  130. end
  131. elseif UnitInParty("player") then
  132. for id = 1, GetNumPartyMembers() do
  133. local realUnitId = string.format("party%d", id);
  134.  
  135. WA_ABSORB_ResetUnit(realUnitId);
  136. end
  137. end
  138. end
  139.  
  140. -- Update
  141. if (
  142. event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_FOCUS_CHANGED" or event == "UNIT_AURA"
  143. ) and (
  144. thisUnitId and realUnitId == thisUnitId or thisUnitName and UnitName(realUnitId) == thisUnitName
  145. ) then
  146. WA_ABSORB_Update(realUnitId);
  147.  
  148. -- Show if absorb amount
  149. if WA_ABSORB_ComCurrent and WA_ABSORB_ComCurrent[realUnitId] and WA_ABSORB_ComCurrent[realUnitId] > 0 then
  150. return true;
  151. end
  152. end
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement