mirror of
https://github.com/Bluewhale1337/HealBotBlue.git
synced 2026-09-11 09:50:21 +00:00
refactor: update incoming heal tracking to support multiple targets and add resurrection event handling
This commit is contained in:
@@ -73,7 +73,7 @@ end
|
|||||||
|
|
||||||
if not HealBot_IncomingHealers then HealBot_IncomingHealers = {} 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
|
-- prioritize HealComm over HealBot protocol to avoid double-counting
|
||||||
if HealBot_IncomingHealers[sender] and HealBot_IncomingHealers[sender].protocol == "HealComm" and protocol == "HealBot" then
|
if HealBot_IncomingHealers[sender] and HealBot_IncomingHealers[sender].protocol == "HealComm" and protocol == "HealBot" then
|
||||||
return
|
return
|
||||||
@@ -81,20 +81,24 @@ local function SetIncomingHeal(sender, target, amount, protocol)
|
|||||||
|
|
||||||
-- remove old heal if it exists
|
-- remove old heal if it exists
|
||||||
if HealBot_IncomingHealers[sender] then
|
if HealBot_IncomingHealers[sender] then
|
||||||
local oldTarget = HealBot_IncomingHealers[sender].target
|
local oldTargets = HealBot_IncomingHealers[sender].targets
|
||||||
local oldAmount = HealBot_IncomingHealers[sender].amount
|
local oldAmount = HealBot_IncomingHealers[sender].amount
|
||||||
|
for _, oldTarget in ipairs(oldTargets) do
|
||||||
if HealBot_HealsIn[oldTarget] then
|
if HealBot_HealsIn[oldTarget] then
|
||||||
HealBot_HealsIn[oldTarget] = HealBot_HealsIn[oldTarget] - oldAmount
|
HealBot_HealsIn[oldTarget] = HealBot_HealsIn[oldTarget] - oldAmount
|
||||||
if HealBot_HealsIn[oldTarget] < 0 then HealBot_HealsIn[oldTarget] = 0 end
|
if HealBot_HealsIn[oldTarget] < 0 then HealBot_HealsIn[oldTarget] = 0 end
|
||||||
HealBot_RecalcHeals(HealBot_FindUnitID(oldTarget))
|
HealBot_RecalcHeals(HealBot_FindUnitID(oldTarget))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if amount > 0 then
|
if amount > 0 and targets and #targets > 0 then
|
||||||
HealBot_IncomingHealers[sender] = { target = target, amount = amount, protocol = protocol }
|
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
|
if not HealBot_HealsIn[target] then HealBot_HealsIn[target] = 0 end
|
||||||
HealBot_HealsIn[target] = HealBot_HealsIn[target] + amount
|
HealBot_HealsIn[target] = HealBot_HealsIn[target] + amount
|
||||||
HealBot_RecalcHeals(HealBot_FindUnitID(target))
|
HealBot_RecalcHeals(HealBot_FindUnitID(target))
|
||||||
|
end
|
||||||
else
|
else
|
||||||
HealBot_IncomingHealers[sender] = nil
|
HealBot_IncomingHealers[sender] = nil
|
||||||
end
|
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 sender_id == UnitName("player") then return end
|
||||||
|
|
||||||
if addon_id == "HealComm" then
|
if addon_id == "HealComm" then
|
||||||
-- HealComm protocol (e.g. "Heal/TargetName/Amount/CastTime/")
|
-- HealComm protocol
|
||||||
local cmd, target, amount, cast_time = strsplit("/", inc_msg)
|
local args = {}
|
||||||
if cmd == "Heal" and target and amount then
|
for word in string.gfind(inc_msg, "[^/]+") do
|
||||||
SetIncomingHeal(sender_id, target, tonumber(amount) or 0, "HealComm")
|
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
|
elseif cmd == "Healstop" then
|
||||||
SetIncomingHeal(sender_id, nil, 0, "HealComm")
|
SetIncomingHeal(sender_id, nil, 0, "HealComm")
|
||||||
elseif cmd == "GrpHeal" and amount then
|
elseif cmd == "GrpHeal" and args[2] then
|
||||||
-- Note: Group heals technically have multiple targets, but this is a simple implementation
|
local amount = tonumber(args[2]) or 0
|
||||||
-- We'll just track it against the first target to keep it simple, or ignore it.
|
local targets = {}
|
||||||
-- Full GrpHeal parsing would split target1,target2,target3
|
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
|
elseif cmd == "GrpHealstop" then
|
||||||
SetIncomingHeal(sender_id, nil, 0, "HealComm")
|
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
|
end
|
||||||
|
|
||||||
elseif addon_id == HEALBOT_ADDON_ID then
|
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
|
if heal_val and unitname then
|
||||||
local amount = tonumber(heal_val) or 0
|
local amount = tonumber(heal_val) or 0
|
||||||
if amount < 0 then amount = 0 end -- HealBot sends negative to cancel
|
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
|
end
|
||||||
|
|
||||||
elseif addon_id == "HealBot" then
|
elseif addon_id == "HealBot" then
|
||||||
|
|||||||
Reference in New Issue
Block a user