From f44904495845b6859f2fab0f8c4ebbcb7a7f0b31 Mon Sep 17 00:00:00 2001 From: Cortes-Jeremy <56119078+Cortes-Jeremy@users.noreply.github.com> Date: Fri, 30 Apr 2021 23:05:54 +0200 Subject: [PATCH 1/3] Trying to add predictive healing to arena units --- Gladius/Gladius.lua | 161 +- Gladius/Gladius.toc | 2 +- Gladius/cooldownlist.lua | 4 + Gladius/embeds.xml | 29 +- Gladius/frame.lua | 62 +- .../AbsorbsMonitor-1.0/AbsorbsMonitor-1.0.lua | 739 +++-- .../Changelog-LibHealComm-4.0-v1.6.6.txt | 13 + .../LibHealCommArena-4.0/ChatThrottleLib.lua | 503 +++ .../LibHealCommArena-4.0.lua | 2861 +++++++++++++++++ .../LibHealCommArena-4.0.toc | 14 + .../LibHealCommArena-4.0.xml | 5 + .../CallbackHandler-1.0.toc | 15 + .../CallbackHandler-1.0.lua | 239 ++ .../CallbackHandler-1.0.xml | 4 + .../CallbackHandler-1.0/LibStub/LibStub.lua | 30 + .../libs/LibStub/LibStub.lua | 30 + .../libs/LibStub/LibStub.toc | 13 + Gladius/libs/LibStub/LibStub.lua | 13 +- Gladius/localization/enUS.lua | 1 + Gladius/options.lua | 27 +- 20 files changed, 4325 insertions(+), 440 deletions(-) create mode 100644 Gladius/libs/LibHealCommArena-4.0/Changelog-LibHealComm-4.0-v1.6.6.txt create mode 100644 Gladius/libs/LibHealCommArena-4.0/ChatThrottleLib.lua create mode 100644 Gladius/libs/LibHealCommArena-4.0/LibHealCommArena-4.0.lua create mode 100644 Gladius/libs/LibHealCommArena-4.0/LibHealCommArena-4.0.toc create mode 100644 Gladius/libs/LibHealCommArena-4.0/LibHealCommArena-4.0.xml create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/CallbackHandler-1.0/CallbackHandler-1.0.toc create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/CallbackHandler-1.0/CallbackHandler-1.0/CallbackHandler-1.0.lua create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/CallbackHandler-1.0/CallbackHandler-1.0/CallbackHandler-1.0.xml create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/CallbackHandler-1.0/LibStub/LibStub.lua create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/LibStub/LibStub.lua create mode 100644 Gladius/libs/LibHealCommArena-4.0/libs/LibStub/LibStub.toc diff --git a/Gladius/Gladius.lua b/Gladius/Gladius.lua index e2fcb46..e6c6cb5 100644 --- a/Gladius/Gladius.lua +++ b/Gladius/Gladius.lua @@ -2,6 +2,7 @@ Gladius = LibStub("AceAddon-3.0"):NewAddon("Gladius", "AceEvent-3.0", "AceConsol local L = LibStub("AceLocale-3.0"):GetLocale("Gladius", true) local LSM = LibStub("LibSharedMedia-3.0") local LCG = LibStub("LibCustomGlow-1.0") +local LHC = LibStub("LibHealCommArena-4.0") local LAM = LibStub:GetLibrary("AbsorbsMonitor-1.0", true) local arenaUnits = {} @@ -24,6 +25,14 @@ function Gladius:OnInitialize() self.buttons = {} self.currentBracket = nil + LHC.UnregisterAllCallbacks(Gladius); + LHC.RegisterCallback(Gladius, "HealCommArena_HealStarted", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealUpdated", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealDelayed", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealStopped", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_ModifierChanged", "HealCommArena_Modified") + LHC.RegisterCallback(Gladius, "HealCommArena_GUIDDisappeared", "HealCommArena_Modified") + -- Populate the arenaUnits table for i=1, 5 do arenaUnits["arena" .. i] = "playerUnit" @@ -222,6 +231,22 @@ function Gladius:JoinedArena() -- Special arena event self:RegisterEvent("ARENA_OPPONENT_UPDATE") + -- HealComm Events + --[[ LHC.UnregisterAllCallbacks(Gladius); + LHC.UnregisterAllCallbacks(Gladius); + LHC.RegisterCallback(Gladius, "HealCommArena_HealStarted", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealUpdated", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealDelayed", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_HealStopped", "HealCommArena_Heal_Update") + LHC.RegisterCallback(Gladius, "HealCommArena_ModifierChanged", "HealCommArena_Modified") + LHC.RegisterCallback(Gladius, "HealCommArena_GUIDDisappeared", "HealCommArena_Modified")]] + + -- HealComm Events + LAM.UnregisterAllCallbacks(Gladius); + LAM.RegisterCallback(Gladius, "EffectApplied"); + LAM.RegisterCallback(Gladius, "EffectUpdated"); + LAM.RegisterCallback(Gladius, "EffectRemoved"); + -- Find out the current bracket size for i=1, MAX_BATTLEFIELD_QUEUES do local status, _, _, _, _, teamSize = GetBattlefieldStatus(i) @@ -242,6 +267,7 @@ function Gladius:JoinedArena() button = self:CreateButton(i) self.buttons[unit] = button self.buttons[pet] = button.pet + self.buttons[unit].unit = unit end button:Show() @@ -324,7 +350,7 @@ function Gladius:UNIT_HEALTH(event, unit) -- update absorb bar if( db.absorbBar and (arenaUnits[unit] == "playerUnit" or (arenaUnits[unit] ~= "playerUnit" and db.showPets)) ) then - Gladius:UpdateAbsorb(event, unit, button) + Gladius:UpdateAbsorbBar(event, unit, button) end -- update cutaway @@ -457,7 +483,7 @@ function Gladius:UNIT_AURA(event, unit) -- update absorb bar if( db.absorbBar and (arenaUnits[unit] == "playerUnit" or (arenaUnits[unit] ~= "playerUnit" and db.showPets)) ) then - Gladius:UpdateAbsorb(event, unit, button) + Gladius:UpdateAbsorbBar(event, unit, button) end local aura = button.auraFrame @@ -617,7 +643,7 @@ function Gladius:UNIT_SPELLCAST_START(event, unit) if(not button) then return end local castBar = button.castBar - if( db.castBarOnCast ) then + if (db.castBar and db.castBarOnCast) then castBar:Show() end castBar.isCasting = true @@ -651,7 +677,7 @@ function Gladius:UNIT_SPELLCAST_CHANNEL_START(event, unit) if(not button) then return end local castBar = self.buttons[unit].castBar - if ( db.castBarOnCast ) then + if (db.castBar and db.castBarOnCast) then castBar:Show() end castBar.isChanneling = true @@ -705,7 +731,7 @@ function Gladius:UNIT_SPELLCAST_DELAYED(event, unit) end function Gladius:CastEnd(bar) - if ( db.castBarOnCast ) then + if (db.castBar and db.castBarOnCast) then bar:Hide() end bar.isCasting = nil @@ -1703,15 +1729,6 @@ function Gladius:Test() button.manaText:Hide() end - --set fake absorb value - if( db.absorbBar ) then - button.absorb.totalAbsorb:SetWidth(100-(i^2)) - button.absorb.totalAbsorbOverlay:SetWidth(100-(i^2)) - else - button.absorb.totalAbsorb:SetWidth(0) - button.absorb.totalAbsorbOverlay:SetWidth(0) - end - --Check if it's a pet class and in that case update the frame to fit button.isPetClass = petClasses[class] and true or false @@ -1744,8 +1761,37 @@ function Gladius:Test() end +-- Utils used by absorbar +function Gladius:SearchButtonByGUID(GUID) + for _, button in pairs(self.buttons) do + if( GUID and button.GUID == GUID) then + return button + end + end +end + -- Absorb Update -function Gladius:UpdateAbsorb(event, unit, button) +function Gladius:EffectApplied(event, ...) + local sourceGUID, sourceName, destGUID, destName, spellId, value, quality, duration = ... + self:PreUpdateAbsorbBar(event, destGUID, destName) +end +function Gladius:EffectUpdated(event, ...) + local guid, spellId, value, duration = ... + self:PreUpdateAbsorbBar(event, guid) +end +function Gladius:EffectRemoved(event, ...) + local guid, spellId = ... + self:PreUpdateAbsorbBar(event, guid) +end +function Gladius:PreUpdateAbsorbBar(event, destGUID, name) + local button = self:SearchButtonByGUID(destGUID) + if (button) then + if( db.absorbBar and (arenaUnits[button.unit] == "playerUnit" or (arenaUnits[button.unit] ~= "playerUnit" and db.showPets)) ) then + self:UpdateAbsorbBar(event, button.unit, button) + end + end +end +function Gladius:UpdateAbsorbBar(event, unit, button) local health = UnitHealth(unit) local maxHealth = UnitHealthMax(unit) @@ -1789,4 +1835,87 @@ function Gladius:UpdateAbsorb(event, unit, button) button.absorb.overAbsorbGlow:Hide(); end -end \ No newline at end of file +end + +-- HealComm (Heal Prediction) +local function Update(self) + local unit = self.unit + local element = self.HealCommBar + + --[[ Callback: HealthPrediction:PreUpdate(unit) + Called before the element has been updated. + + * 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 timeFrame = self.HealCommTimeframe and GetTime() + self.HealCommTimeframe or nil + local myIncomingHeal = HealComm:GetHealAmount(guid, HealComm.ALL_HEALS, timeFrame, UnitGUID("player")) or 0 + local allIncomingHeal = HealComm:GetHealAmount(guid, HealComm.ALL_HEALS, timeFrame) or 0 + local health = UnitHealth(unit) + local maxHealth = UnitHealthMax(unit) + local maxOverflowHP = maxHealth * element.maxOverflow + local otherIncomingHeal = 0 + + if health + allIncomingHeal > maxOverflowHP then + allIncomingHeal = maxOverflowHP - health + end + + if allIncomingHeal < myIncomingHeal then + myIncomingHeal = allIncomingHeal + else + otherIncomingHeal = allIncomingHeal - myIncomingHeal + 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) + 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) + --]] + if element.PostUpdate then + return element:PostUpdate(unit, myIncomingHeal, otherIncomingHeal) + end +end +local function MultiUpdate(...) + for i = 1, select("#", ...) do + --[[ for j = 1, #enabledUF do + local frame = enabledUF[j] + + if frame.unit and frame:IsVisible() and UnitGUID(frame.unit) == select(i, ...) then + Path(frame) + end + end ]] + if (UnitGUID('arena1') == select(i, ...)) then + local allIncomingHeal = LHC:GetHealAmount(select(i, ...), LHC.ALL_HEALS, nil) or 0 + print('updated arena1', allIncomingHeal) + elseif (UnitGUID('arena2') == select(i, ...)) then + local allIncomingHeal = LHC:GetHealAmount(select(i, ...), LHC.ALL_HEALS, nil) or 0 + print('updated arena2', allIncomingHeal) + end + end +end +function Gladius:HealCommArena_Heal_Update(event, casterGUID, spellID, spellType, endTime, ...) -- ... = unpacked guid + MultiUpdate(...) +end +function Gladius:HealCommArena_Modified(event, guid) + MultiUpdate(guid) +end diff --git a/Gladius/Gladius.toc b/Gladius/Gladius.toc index b2a1b56..45fe78c 100644 --- a/Gladius/Gladius.toc +++ b/Gladius/Gladius.toc @@ -4,7 +4,7 @@ ## Version: v1.2.2 ## Author: Proditor, Rinu, Enhanced by Cortes ## SavedVariables: GladiusDB -## OptionalDeps: Ace3, LibStub, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets, LibCustomGlow-1.0, AbsorbsMonitor-1.0 +## OptionalDeps: Ace3, LibStub, LibSharedMedia-3.0, AceGUI-3.0-SharedMediaWidgets, LibCustomGlow-1.0, AbsorbsMonitor-1.0, LibHealCommArena-4.0 ## LoadManagers: AddonLoader ## X-LoadOn-Slash: /gladius ## X-LoadOn-InterfaceOptions: Gladius diff --git a/Gladius/cooldownlist.lua b/Gladius/cooldownlist.lua index bc47844..68b5cae 100644 --- a/Gladius/cooldownlist.lua +++ b/Gladius/cooldownlist.lua @@ -14,6 +14,7 @@ function Gladius:GetCooldownList() [12472] = { cd = 180, spec = L["Frost"], }, -- Icy Veins [31687] = { cd = 180, spec = L["Frost"], }, -- Summon Water Elemental [12043] = { cd = 120, spec = L["Arcane"], }, -- Presence of Mind + [42950] = { cd = 20, spec = L["Fire"] }, -- Combustion [11129] = { cd = 120, spec = L["Fire"] }, -- Combustion [12042] = { cd = 120, spec = L["Arcane"], }, -- Arcane Power [11958] = { cd = 480, spec = L["Frost"], -- Coldsnap @@ -48,6 +49,8 @@ function Gladius:GetCooldownList() [49576] = 35, -- Death Grip [47568] = 300, -- Empower Rune Weapon [48743] = 120, -- Death Pact + [49039] = 120, -- Lichborne + [47481] = { cd = 60, spec = L["Unholy"], }, -- Pet Gnaw [51052] = { cd = 120, spec = L["Unholy"], }, -- Anti-Magic Zone [46584] = { cd = 180, notSpec = L["Unholy"], }, -- Raise Dead [49206] = { cd = 180, spec = L["Unholy"], }, -- Summon Gargoyle @@ -83,6 +86,7 @@ function Gladius:GetCooldownList() [10278] = 300, -- Hand of Protection [1044] = 25, -- Hand of Freedom [54428] = 60, -- Divine Plea + [6940] = 120, -- Hand of Sacrifice [64205] = 120, -- Divine Sacrifice [10308] = { cd = 60, [L["Protection"]] = 40, }, -- Hammer of Justice [642] = { cd = 300, -- Divine Shield diff --git a/Gladius/embeds.xml b/Gladius/embeds.xml index 73d45cb..8477ca5 100644 --- a/Gladius/embeds.xml +++ b/Gladius/embeds.xml @@ -1,18 +1,19 @@ -