Files
Dota-Zombie-Invasion/scripts/vscripts/utils/damage_event_attribution.lua
T
2026-05-29 15:11:31 +07:00

64 lines
2.7 KiB
Lua

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
--- Привязка entity_hurt к игроку для статистики урона.
-- GetRawPlayerDamage в кастомке часто пустой; BP раньше смотрел только IsRealHero + GetOwner — терялся урон с иллюзий/призывов.
local function resolvePlayerIdFromUnitChain(self, start)
if not start or not IsValidEntity(start) then
return nil
end
local current = start
do
local depth = 0
while depth < 8 and current and IsValidEntity(current) do
local pid = current:GetPlayerOwnerID()
if pid ~= nil and pid >= 0 then
return pid
end
local anyC = current
local owner = type(anyC.GetOwnerEntity) == "function" and anyC:GetOwnerEntity() or type(anyC.GetOwner) == "function" and anyC:GetOwner()
if not owner or not IsValidEntity(owner) then
break
end
current = owner
depth = depth + 1
end
end
return nil
end
--- Атакующий юнит (меч, иллюзия, призванное).
function ____exports.resolvePlayerIdFromDamageAttacker(self, attacker)
return resolvePlayerIdFromUnitChain(nil, attacker)
end
--- Источник нанесённого урона из события: сначала attacker, если пусто/без владельца — inflictor (способность/предмет) → кастер.
function ____exports.resolvePlayerIdFromEntityHurtForOutgoing(self, event)
local aIdx = event.entindex_attacker
if aIdx ~= nil and aIdx ~= nil and tonumber(tostring(aIdx)) > 0 then
local ent = EntIndexToHScript(aIdx)
if ent and IsValidEntity(ent) then
local p = ____exports.resolvePlayerIdFromDamageAttacker(nil, ent)
if p ~= nil and p >= 0 then
return p
end
end
end
local iIdx = event.entindex_inflictor
if iIdx ~= nil and iIdx ~= nil and tonumber(tostring(iIdx)) > 0 then
local inf = EntIndexToHScript(iIdx)
if not inf or not IsValidEntity(inf) then
return nil
end
local caster
if type(inf.GetCaster) == "function" then
caster = inf:GetCaster()
end
if (not caster or not IsValidEntity(caster)) and type(inf.GetOwner) == "function" then
caster = inf:GetOwner()
end
if caster and IsValidEntity(caster) then
return ____exports.resolvePlayerIdFromDamageAttacker(nil, caster)
end
end
return nil
end
return ____exports