Commit e55d82ff authored by Azilroka's avatar Azilroka 💬
Browse files

LHC

parent 1c191beb
This diff is collapsed.
......@@ -15,7 +15,7 @@
<Include file='LibQuestXP\LibQuestXP.xml'/>
<Script file='LibClassicSpellActionCount-1.0\LibClassicSpellActionCount-1.0.lua'/>
<Script file='Libraries\LibHealComm-4.0.lua'/>
<Include file='oUF\oUF.xml'/>
<Include file='oUF_Plugins\oUF_Plugins.xml'/>
......
--[[
# Element: Health Prediction Bars
Handles the visibility and updating of incoming heals and heal/damage absorbs.
## Widget
HealthPrediction - A `table` containing references to sub-widgets and options.
## Sub-Widgets
myBar - A `StatusBar` used to represent incoming heals from the player.
otherBar - A `StatusBar` used to represent incoming heals from others.
absorbBar - A `StatusBar` used to represent damage absorbs.
healAbsorbBar - A `StatusBar` used to represent heal absorbs.
overAbsorb - A `Texture` used to signify that the amount of damage absorb is greater than the unit's missing health.
overHealAbsorb - A `Texture` used to signify that the amount of heal absorb is greater than the unit's current health.
## Notes
A default texture will be applied to the StatusBar widgets if they don't have a texture set.
A default texture will be applied to the Texture widgets if they don't have a texture or a color set.
## Options
.maxOverflow - The maximum amount of overflow past the end of the health bar. Set this to 1 to disable the overflow.
Defaults to 1.05 (number)
## Examples
-- Position and size
local myBar = CreateFrame('StatusBar', nil, self.Health)
myBar:SetPoint('TOP')
myBar:SetPoint('BOTTOM')
myBar:SetPoint('LEFT', self.Health:GetStatusBarTexture(), 'RIGHT')
myBar:SetWidth(200)
local otherBar = CreateFrame('StatusBar', nil, self.Health)
otherBar:SetPoint('TOP')
otherBar:SetPoint('BOTTOM')
otherBar:SetPoint('LEFT', myBar:GetStatusBarTexture(), 'RIGHT')
otherBar:SetWidth(200)
local absorbBar = CreateFrame('StatusBar', nil, self.Health)
absorbBar:SetPoint('TOP')
absorbBar:SetPoint('BOTTOM')
absorbBar:SetPoint('LEFT', otherBar:GetStatusBarTexture(), 'RIGHT')
absorbBar:SetWidth(200)
local healAbsorbBar = CreateFrame('StatusBar', nil, self.Health)
healAbsorbBar:SetPoint('TOP')
healAbsorbBar:SetPoint('BOTTOM')
healAbsorbBar:SetPoint('RIGHT', self.Health:GetStatusBarTexture())
healAbsorbBar:SetWidth(200)
healAbsorbBar:SetReverseFill(true)
local overAbsorb = self.Health:CreateTexture(nil, "OVERLAY")
overAbsorb:SetPoint('TOP')
overAbsorb:SetPoint('BOTTOM')
overAbsorb:SetPoint('LEFT', self.Health, 'RIGHT')
overAbsorb:SetWidth(10)
local overHealAbsorb = self.Health:CreateTexture(nil, "OVERLAY")
overHealAbsorb:SetPoint('TOP')
overHealAbsorb:SetPoint('BOTTOM')
overHealAbsorb:SetPoint('RIGHT', self.Health, 'LEFT')
overHealAbsorb:SetWidth(10)
-- Register with oUF
self.HealthPrediction = {
myBar = myBar,
otherBar = otherBar,
absorbBar = absorbBar,
healAbsorbBar = healAbsorbBar,
overAbsorb = overAbsorb,
overHealAbsorb = overHealAbsorb,
maxOverflow = 1.05,
}
--]]
-- ShestakUI use old version of HealPrediction. Do not update if you are not sure what you are doing.
local _, ns = ...
local oUF = ns.oUF
local HealComm = LibStub("LibHealComm-4.0")
local function Update(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.HealthPrediction
--[[ Callback: HealthPrediction:PreUpdate(unit)
Called before the element has been updated.
local hp = self.HealPrediction
if(hp.PreUpdate) then hp:PreUpdate(unit) end
* self - the HealthPrediction element
* unit - the unit for which the update has been triggered (string)
--]]
if(element.PreUpdate) then
element:PreUpdate(unit)
end
local GUID = UnitGUID(unit)
local OverTimeHeals = (HealComm:GetHealAmount(GUID, HealComm.OVERTIME_AND_BOMB_HEALS) or 0) * (HealComm:GetHealModifier(GUID) or 1)
local DirectHeals = UnitGetIncomingHeals(unit) or 0
local IncomingHeals = DirectHeals >= DirectHeals + OverTimeHeals and DirectHeals or DirectHeals + OverTimeHeals
local Health = UnitHealth(unit)
local MaxHealth = UnitHealthMax(unit)
local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
local absorb = 0
local healAbsorb = 0
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
local otherIncomingHeal = 0
local hasOverHealAbsorb = false
if(healAbsorb > allIncomingHeal) then
healAbsorb = healAbsorb - allIncomingHeal
allIncomingHeal = 0
myIncomingHeal = 0
if(health < healAbsorb) then
hasOverHealAbsorb = true
end
else
allIncomingHeal = allIncomingHeal - healAbsorb
healAbsorb = 0
if self.HealPrediction then
self.HealPrediction:SetMinMaxValues(0, MaxHealth)
if(health + allIncomingHeal > maxHealth * element.maxOverflow) then
allIncomingHeal = maxHealth * element.maxOverflow - health
end
if(allIncomingHeal < myIncomingHeal) then
myIncomingHeal = allIncomingHeal
if (IncomingHeals == 0) then
self.HealPrediction:SetValue(0)
elseif (Health + IncomingHeals >= MaxHealth) then
self.HealPrediction:SetValue(MaxHealth)
else
otherIncomingHeal = allIncomingHeal - myIncomingHeal
self.HealPrediction:SetValue(Health + IncomingHeals)
end
end
local hasOverAbsorb = false
if(health + allIncomingHeal + absorb >= maxHealth) and (absorb > 0) then
hasOverAbsorb = true
end
if(element.myBar) then
element.myBar:SetMinMaxValues(0, maxHealth)
element.myBar:SetValue(myIncomingHeal)
element.myBar:Show()
end
if(element.otherBar) then
element.otherBar:SetMinMaxValues(0, maxHealth)
element.otherBar:SetValue(otherIncomingHeal)
element.otherBar:Show()
end
--[[ Callback: HealthPrediction:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb)
Called after the element has been updated.
* self - the HealthPrediction element
* unit - the unit for which the update has been triggered (string)
* myIncomingHeal - the amount of incoming healing done by the player (number)
* otherIncomingHeal - the amount of incoming healing done by others (number)
* absorb - the amount of damage the unit can absorb without losing health (number)
* healAbsorb - the amount of healing the unit can absorb without gaining health (number)
* hasOverAbsorb - indicates if the amount of damage absorb is higher than the unit's missing health (boolean)
* hasOverHealAbsorb - indicates if the amount of heal absorb is higher than the unit's current health (boolean)
--]]
if(element.PostUpdate) then
return element:PostUpdate(unit, myIncomingHeal, otherIncomingHeal, absorb, healAbsorb, hasOverAbsorb, hasOverHealAbsorb, health, maxHealth)
end
end
local function Path(self, ...)
--[[ Override: HealthPrediction.Override(self, event, unit)
Used to completely override the internal update function.
* self - the parent object
* event - the event triggering the update (string)
* unit - the unit accompanying the event
--]]
return (self.HealthPrediction.Override or Update) (self, ...)
return (self.HealPrediction.Override or Update) (self, ...)
end
local function ForceUpdate(element)
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local function Enable(self)
local element = self.HealthPrediction
local element = self.HealPrediction
if(element) then
element.__owner = self
element.ForceUpdate = ForceUpdate
element.healType = element.healType or HealComm.ALL_HEALS
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
self:RegisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
local function HealCommUpdate(...)
if self.HealPrediction and self:IsVisible() then
for i = 1, select('#', ...) do
if self.unit and UnitGUID(self.unit) == select(i, ...) then
Path(self, nil, self.unit)
end
end
end
end
local function HealComm_Heal_Update(event, casterGUID, spellID, healType, _, ...)
HealCommUpdate(...)
end
local function HealComm_Modified(event, guid)
HealCommUpdate(guid)
end
HealComm.RegisterCallback(element, 'HealComm_HealStarted', HealComm_Heal_Update)
HealComm.RegisterCallback(element, 'HealComm_HealUpdated', HealComm_Heal_Update)
HealComm.RegisterCallback(element, 'HealComm_HealDelayed', HealComm_Heal_Update)
HealComm.RegisterCallback(element, 'HealComm_HealStopped', HealComm_Heal_Update)
HealComm.RegisterCallback(element, 'HealComm_ModifierChanged', HealComm_Modified)
HealComm.RegisterCallback(element, 'HealComm_GUIDDisappeared', HealComm_Modified)
if(not element.maxOverflow) then
element.maxOverflow = 1.05
end
......@@ -207,7 +96,7 @@ local function Enable(self)
end
local function Disable(self)
local element = self.HealthPrediction
local element = self.HealPrediction
if(element) then
if(element.myBar) then
element.myBar:Hide()
......@@ -217,14 +106,18 @@ local function Disable(self)
element.otherBar:Hide()
end
if(element.absorbBar) then
element.absorbBar:Hide()
end
HealComm.UnregisterCallback(element, 'HealComm_HealStarted')
HealComm.UnregisterCallback(element, 'HealComm_HealUpdated')
HealComm.UnregisterCallback(element, 'HealComm_HealDelayed')
HealComm.UnregisterCallback(element, 'HealComm_HealStopped')
HealComm.UnregisterCallback(element, 'HealComm_ModifierChanged')
HealComm.UnregisterCallback(element, 'HealComm_GUIDDisappeared')
self:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH_FREQUENT', Path)
self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
end
end
oUF:AddElement('HealthPrediction', Path, Enable, Disable)
oUF:AddElement('HealPrediction', Path, Enable, Disable)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment