refactor: update incoming heal tracking to support multiple targets and add resurrection event handling

This commit is contained in:
Bluewhale1337
2026-09-06 22:38:33 +02:00
parent e9cfd2fcc7
commit 1f9d3af81e
+48 -20
View File
@@ -73,7 +73,7 @@ end
if not HealBot_IncomingHealers then HealBot_IncomingHealers = {} end
local function SetIncomingHeal(sender, target, amount, protocol)
local function SetIncomingHeal(sender, targets, 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
@@ -81,20 +81,24 @@ local function SetIncomingHeal(sender, target, amount, protocol)
-- remove old heal if it exists
if HealBot_IncomingHealers[sender] then
local oldTarget = HealBot_IncomingHealers[sender].target
local oldTargets = HealBot_IncomingHealers[sender].targets
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))
for _, oldTarget in ipairs(oldTargets) do
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
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))
if amount > 0 and targets and #targets > 0 then
HealBot_IncomingHealers[sender] = { targets = targets, amount = amount, protocol = protocol }
for _, target in ipairs(targets) do
if not HealBot_HealsIn[target] then HealBot_HealsIn[target] = 0 end
HealBot_HealsIn[target] = HealBot_HealsIn[target] + amount
HealBot_RecalcHeals(HealBot_FindUnitID(target))
end
else
HealBot_IncomingHealers[sender] = nil
end
@@ -105,18 +109,42 @@ function HealBot_OnEvent_AddonMsg(this, addon_id, inc_msg, dist_target, sender_i
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")
-- HealComm protocol
local args = {}
for word in string.gfind(inc_msg, "[^/]+") do
table.insert(args, word)
end
local cmd = args[1]
if cmd == "Heal" and args[2] and args[3] then
SetIncomingHeal(sender_id, {args[2]}, tonumber(args[3]) 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 == "GrpHeal" and args[2] then
local amount = tonumber(args[2]) or 0
local targets = {}
for i = 4, 8 do
if args[i] and args[i] ~= "" then
table.insert(targets, args[i])
end
end
SetIncomingHeal(sender_id, targets, amount, "HealComm")
elseif cmd == "GrpHealstop" then
SetIncomingHeal(sender_id, nil, 0, "HealComm")
elseif cmd == "Resurrection" then
if args[2] == "stop" then
HealBot_AddDebug(sender_id .. " Stopped ressing");
for unit, resser in pairs(HealBot_Ressing) do
if resser == sender_id then
HealBot_Ressing[unit] = nil;
HealBot_RecalcHeals(HealBot_FindUnitID(unit));
end
end
elseif args[2] and args[3] == "start" then
HealBot_AddDebug(sender_id .. " is ressing " .. args[2]);
HealBot_Ressing[args[2]] = sender_id;
HealBot_RecalcHeals(HealBot_FindUnitID(args[2]));
end
end
elseif addon_id == HEALBOT_ADDON_ID then
@@ -124,7 +152,7 @@ function HealBot_OnEvent_AddonMsg(this, addon_id, inc_msg, dist_target, sender_i
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")
SetIncomingHeal(sender_id, {unitname}, amount, "HealBot")
end
elseif addon_id == "HealBot" then