diff --git a/HealBot_Controller_Comms.lua b/HealBot_Controller_Comms.lua index 1614742..5b6073c 100644 --- a/HealBot_Controller_Comms.lua +++ b/HealBot_Controller_Comms.lua @@ -71,33 +71,72 @@ function HealBot_SendAddonMessage(prefix, text) end end +if not HealBot_IncomingHealers then HealBot_IncomingHealers = {} end + +local function SetIncomingHeal(sender, target, amount, protocol) + -- prioritize HealComm over HealBot protocol to avoid double-counting + if HealBot_IncomingHealers[sender] and HealBot_IncomingHealers[sender].protocol == "HealComm" and protocol == "HealBot" then + return + end + + -- remove old heal if it exists + if HealBot_IncomingHealers[sender] then + local oldTarget = HealBot_IncomingHealers[sender].target + local oldAmount = HealBot_IncomingHealers[sender].amount + if HealBot_HealsIn[oldTarget] then + HealBot_HealsIn[oldTarget] = HealBot_HealsIn[oldTarget] - oldAmount + if HealBot_HealsIn[oldTarget] < 0 then HealBot_HealsIn[oldTarget] = 0 end + HealBot_RecalcHeals(HealBot_FindUnitID(oldTarget)) + end + end + + if amount > 0 then + HealBot_IncomingHealers[sender] = { target = target, amount = amount, protocol = protocol } + if not HealBot_HealsIn[target] then HealBot_HealsIn[target] = 0 end + HealBot_HealsIn[target] = HealBot_HealsIn[target] + amount + HealBot_RecalcHeals(HealBot_FindUnitID(target)) + else + HealBot_IncomingHealers[sender] = nil + end +end + -- HealBot_OnEvent_AddonMsg: Parses incoming heal data from other clients. function HealBot_OnEvent_AddonMsg(this, addon_id, inc_msg, dist_target, sender_id) - if addon_id == HEALBOT_ADDON_ID then - local tmpTest, unitname, heal_val - tmpTest, tmpTest, unitname, heal_val = string.find(inc_msg, ">> (%a+) <<=>> (.%d+) <<" ); - if heal_val then - if sender_id == UnitName("player") then return end - if not HealBot_HealsIn[unitname] then - HealBot_HealsIn[unitname] = 0; - end - HealBot_Healers[sender_id] = ">> " .. unitname .. " <<=>> " .. heal_val .. " <<"; - HealBot_HealsIn[unitname] = HealBot_HealsIn[unitname] + tonumber(heal_val); - if tonumber(heal_val) > 0 then - HealBot_RecalcHeals(HealBot_FindUnitID(unitname)) - elseif HealBot_HealsIn[unitname] < 0 then - HealBot_HealsIn[unitname] = 0; - end + if sender_id == UnitName("player") then return end + + if addon_id == "HealComm" then + -- HealComm protocol (e.g. "Heal/TargetName/Amount/CastTime/") + local cmd, target, amount, cast_time = strsplit("/", inc_msg) + if cmd == "Heal" and target and amount then + SetIncomingHeal(sender_id, target, tonumber(amount) or 0, "HealComm") + elseif cmd == "Healstop" then + SetIncomingHeal(sender_id, nil, 0, "HealComm") + elseif cmd == "GrpHeal" and amount then + -- Note: Group heals technically have multiple targets, but this is a simple implementation + -- We'll just track it against the first target to keep it simple, or ignore it. + -- Full GrpHeal parsing would split target1,target2,target3 + elseif cmd == "GrpHealstop" then + SetIncomingHeal(sender_id, nil, 0, "HealComm") end + + elseif addon_id == HEALBOT_ADDON_ID then + local tmpTest, tmpTest, unitname, heal_val = string.find(inc_msg, ">> (.-) <<=>> (.-) <<" ); + if heal_val and unitname then + local amount = tonumber(heal_val) or 0 + if amount < 0 then amount = 0 end -- HealBot sends negative to cancel + SetIncomingHeal(sender_id, unitname, amount, "HealBot") + end + elseif addon_id == "HealBot" then local tmpTest, datatype, datamsg, sender local PName = UnitName("player"); - tmpTest, tmpTest, datatype, sender, datamsg = string.find(inc_msg, ">> (%a+) <<=>> (%a+) <<=>> (.+)"); + tmpTest, tmpTest, datatype, sender, datamsg = string.find(inc_msg, ">> (.-) <<=>> (.-) <<=>> (.+)"); if datatype == "RequestVersion" then HealBot_SendAddonMessage("HealBot", ">> SendVersion <<=>> " .. sender .. " <<=>> Version=" .. HEALBOT_VERSION); elseif datatype == "SendVersion" and PName == sender then HealBot_AddChat(sender_id .. ": " .. datamsg); end + elseif addon_id == "CTRA" then if ( string.sub(inc_msg, 1, 3) == "RES" ) then if ( inc_msg == "RESNO" ) then diff --git a/HealBot_Controller_Spells.lua b/HealBot_Controller_Spells.lua index b05015b..8f53793 100644 --- a/HealBot_Controller_Spells.lua +++ b/HealBot_Controller_Spells.lua @@ -159,6 +159,7 @@ function HealBot_Process_HealValue(spell, target) local uname = UnitName(target) if uname then HealBot_SendAddonMessage(HEALBOT_ADDON_ID, ">> " .. uname .. " <<=>> " .. HealBot_HealValue .. " << "); + HealBot_SendAddonMessage("HealComm", "Heal/" .. uname .. "/" .. HealBot_HealValue .. "/1500/"); if not HealBot_HealsIn[uname] then HealBot_HealsIn[uname] = 0; end @@ -217,6 +218,7 @@ function HealBot_StopCasting() local uname = UnitName(HealBot_CastingTarget) if uname then HealBot_SendAddonMessage(HEALBOT_ADDON_ID, ">> " .. uname .. " <<=>> " .. 0 - HealBot_HealValue .. " << "); + HealBot_SendAddonMessage("HealComm", "Healstop"); if HealBot_HealsIn[uname] then HealBot_HealsIn[uname] = HealBot_HealsIn[uname] - HealBot_HealValue; if HealBot_HealsIn[uname] < 0 then diff --git a/HealBot_Integrations.lua b/HealBot_Integrations.lua index f0f8cfb..4dd03b3 100644 --- a/HealBot_Integrations.lua +++ b/HealBot_Integrations.lua @@ -36,22 +36,24 @@ function HealBot_Integrations_Toggle() HealBot_NampowerFrame:RegisterEvent("AURA_CAST_ON_OTHER") HealBot_NampowerFrame:SetScript("OnEvent", function() if not HealBot_Integrations_Nampower_Active then return end - local spellID, caster, target, _, _, _, _, duration = arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 - if not caster or not target or duration <= 0 then return end - - local spellName = GetSpellRecField(spellID, "name") - if not spellName then return end - - if not HealBot_Nampower_Auras[target] then - HealBot_Nampower_Auras[target] = {} - end - - local expirationTime = GetTime() + (duration / 1000) - HealBot_Nampower_Auras[target][spellName] = expirationTime - - local unitID = HealBot_Model:GetUnitIDByName(target) - if unitID then - HealBot_OnEvent_UnitAura(nil, unitID) + if event == "AURA_CAST_ON_SELF" or event == "AURA_CAST_ON_OTHER" then + local spellID, caster, target, _, _, _, _, duration = arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 + if not caster or not target or duration <= 0 then return end + + local spellName = GetSpellRecField(spellID, "name") + if not spellName then return end + + if not HealBot_Nampower_Auras[target] then + HealBot_Nampower_Auras[target] = {} + end + + local expirationTime = GetTime() + (duration / 1000) + HealBot_Nampower_Auras[target][spellName] = expirationTime + + local unitID = HealBot_Model:GetUnitIDByName(target) + if unitID then + HealBot_OnEvent_UnitAura(nil, unitID) + end end end) end diff --git a/README.md b/README.md index 00301f5..3643863 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ Default installation path: `C:\Program Files\World of Warcraft\Interface\AddOns\ ### Change Log **v1.7.1** +* **Bug Fix - Incoming Heals Comms** - Fixed a regex string parsing bug that caused incoming heals from other HealBot instances to drop if a unit's name contained non-alphabetic characters (e.g. dashes or spaces in pet names). +* **Feature - Standard HealComm Sync** - Implemented lightweight parsing of the standard `HealComm` addon channel. HealBot now perfectly syncs incoming heals with modern raid frames like Luna, Grid, and pfUI, while retaining backwards compatibility with older versions of HealBot. * **UI Update - Raid Marks** - Anchored raid target icons to top of unit frames instead of center. * **Bug Fix** - Fixed an issue where the debuff warning sound and UI message would spam repeatedly on every aura update. The warning now only plays once per unique dispellable debuff type applied to a unit. Increased warning trigger range to 40 yards.