Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function(event, unitId)
- --[[ USER-CONFIG PART ]]--
- local thisUnitId = "player"; -- UnitId which should be watched (player, target, focus, pet, bossN, raidN)
- local thisUnitName = nil; -- UnitName which should be watched [optional]
- --[[ INTERNAL CODE PART ]]--
- -- Initialize
- if not WA_ABSORB_SpellIds then
- -- List of absorb spells to query
- WA_ABSORB_SpellIds = {
- [17] = true, -- Power Word: Shield
- [7812] = true, -- Sacrifice
- [114908] = true, -- Spirit Shell
- [47753] = true, -- Divine Aegis
- [77535] = true, -- Blood Shield
- [86273] = true, -- Illuminated Healing
- [65148] = true, -- Sacred Shield
- [112048] = true, -- Shield Barrier
- [122470] = true, -- Touch of Karma
- [116849] = true, -- Life Cocoon
- [1521180] = true, -- Clarity of Will
- [157128] = true, -- Saved by the Light
- [155783] = true, -- Primal Tenacity
- };
- -- Get localized spell names
- WA_ABSORB_SpellNames = {};
- for spellId, bool in pairs(WA_ABSORB_SpellIds) do
- -- Localize
- local spellName = GetSpellInfo(spellId);
- if spellName then
- WA_ABSORB_SpellNames[spellName] = spellId;
- end
- end
- -- Track max absorb value per spell per unit: WA_ABSORB_Max[unitId][spellName]= value
- WA_ABSORB_Max = {};
- -- Track cur/max absorb value per unit: WA_ABSORB_ComCurrent[unitId] = value, WA_ABSORB_ComMax[unitId] = value
- WA_ABSORB_ComCurrent = {};
- WA_ABSORB_ComMax = {};
- -- Remember name
- WA_ABSORB_Name2Id = {};
- -- Update a units absorb value
- WA_ABSORB_Update = function(unitId)
- -- Default
- if not unitId then unitId = "player" end
- -- Create per unit per spell max absorb buffer
- WA_ABSORB_Max[unitId] = WA_ABSORB_Max[unitId] or {};
- -- Comulative current/maximum
- WA_ABSORB_ComCurrent[unitId] = 0;
- WA_ABSORB_ComMax[unitId] = 0;
- -- Locals
- local name, rank, icon, count, dispelType, duration, expires, caster, isStealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, nameplateShowAll, timeMod, value1, value2, value3;
- local curAmount, maxAmount;
- -- Scan all abosrb spells
- for spellName, spellId in pairs(WA_ABSORB_SpellNames) do
- -- value1 will be remaining amount if aura is available
- name, rank, icon, count, dispelType, duration, expires, caster, isStealable, nameplateShowPersonal, spellID, canApplyAura, isBossDebuff, _, nameplateShowAll, timeMod, value1, value2, value3 = UnitAura(unitId, spellName);
- -- Save values
- if name and value1 > 0 then
- -- Remember values
- curAmount = value1;
- WA_ABSORB_Max[unitId][spellName] = math.max(WA_ABSORB_Max[unitId][spellName] or 0, value1);
- maxAmount = WA_ABSORB_Max[unitId][spellName];
- else
- -- No aura, reset to 0
- curAmount = 0;
- WA_ABSORB_Max[unitId][spellName] = 0;
- maxAmount = 0;
- end
- -- Calc comulative current/maximum
- WA_ABSORB_ComCurrent[unitId] = WA_ABSORB_ComCurrent[unitId] + curAmount;
- WA_ABSORB_ComMax[unitId] = WA_ABSORB_ComMax[unitId] + maxAmount;
- end
- -- Remember units name
- if thisUnitName then
- local name = UnitName(unitId);
- if name then
- WA_ABSORB_Name2Id[name] = unitId;
- end
- end
- end
- -- Reste unit data
- WA_ABSORB_ResetUnit = function(unitId)
- -- Reset unit-max per spell
- if WA_ABSORB_Max[unitId] then
- for spellName, data in pairs(WA_ABSORB_Max[unitId]) do
- WA_ABSORB_Max[unitId][spellName] = nil;
- end
- end
- -- Reset other variables
- WA_ABSORB_ComCurrent[unitId] = 0;
- WA_ABSORB_ComMax[unitId] = 0;
- local name = UnitName(unitId);
- if name then
- WA_ABSORB_Name2Id[name] = unitId;
- end
- end
- end
- -- Witch unit to reset
- local realUnitId = event == "PLAYER_TARGET_CHANGED" and "target" or event == "PLAYER_FOCUS_CHANGED" and "focus" or unitId;
- -- Reset when chaning target
- if event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_FOCUS_CHANGED" then
- WA_ABSORB_ResetUnit(realUnitId);
- end
- -- Reset raid units
- if event == "RAID_ROSTER_UPDATE"or event == "PARTY_MEMBERS_CHANGED" then
- if UnitInRaid("player") then
- for id = 1, GetNumRaidMembers() do
- local realUnitId = string.format("raid%d", id);
- WA_ABSORB_ResetUnit(realUnitId);
- end
- elseif UnitInParty("player") then
- for id = 1, GetNumPartyMembers() do
- local realUnitId = string.format("party%d", id);
- WA_ABSORB_ResetUnit(realUnitId);
- end
- end
- end
- -- Update
- if (
- event == "PLAYER_TARGET_CHANGED" or event == "PLAYER_FOCUS_CHANGED" or event == "UNIT_AURA"
- ) and (
- thisUnitId and realUnitId == thisUnitId or thisUnitName and UnitName(realUnitId) == thisUnitName
- ) then
- WA_ABSORB_Update(realUnitId);
- -- Show if absorb amount
- if WA_ABSORB_ComCurrent and WA_ABSORB_ComCurrent[realUnitId] and WA_ABSORB_ComCurrent[realUnitId] > 0 then
- return true;
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement