116 lines
4.6 KiB
Lua
116 lines
4.6 KiB
Lua
local ____lualib = require("lualib_bundle")
|
||
local Set = ____lualib.Set
|
||
local __TS__New = ____lualib.__TS__New
|
||
local __TS__ObjectAssign = ____lualib.__TS__ObjectAssign
|
||
local __TS__Class = ____lualib.__TS__Class
|
||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||
local __TS__Decorate = ____lualib.__TS__Decorate
|
||
local ____exports = {}
|
||
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
||
local BaseModifier = ____dota_ts_adapter.BaseModifier
|
||
local registerModifier = ____dota_ts_adapter.registerModifier
|
||
--- Модификаторы владельца, которые не пробрасываем (крит обрабатывается на самом призыве).
|
||
local OWNER_ATTACK_FORWARD_EXCLUDED_MODIFIERS = __TS__New(Set, {"modifier_stacking_crit", "modifier_summon_owner_attack_proxy"})
|
||
--- Герой-владелец для призыва или illusions-like юнита с SetOwner.
|
||
function ____exports.getRealOwnerHeroFromUnit(self, unit)
|
||
if not unit or not IsValidEntity(unit) then
|
||
return nil
|
||
end
|
||
if unit:IsRealHero() then
|
||
return unit
|
||
end
|
||
local owner = unit:GetOwner()
|
||
if not owner or not IsValidEntity(owner) or not owner:IsRealHero() then
|
||
return nil
|
||
end
|
||
return owner
|
||
end
|
||
local function forEachOwnerAttackModifier(self, owner, visitor)
|
||
local seenNames = __TS__New(Set)
|
||
do
|
||
local i = 0
|
||
while i < owner:GetModifierCount() do
|
||
do
|
||
local modifierName = owner:GetModifierNameByIndex(i)
|
||
if not modifierName or OWNER_ATTACK_FORWARD_EXCLUDED_MODIFIERS:has(modifierName) or seenNames:has(modifierName) then
|
||
goto __continue7
|
||
end
|
||
seenNames:add(modifierName)
|
||
local modifier = owner:FindModifierByName(modifierName)
|
||
if not modifier or not IsValidEntity(modifier) then
|
||
goto __continue7
|
||
end
|
||
visitor(nil, modifier, modifierName)
|
||
end
|
||
::__continue7::
|
||
i = i + 1
|
||
end
|
||
end
|
||
end
|
||
--- Пробрасывает атаку призыва в on-hit/on-attack модификаторы героя-владельца.
|
||
function ____exports.forwardOwnerAttackModifiersFromSummon(self, owner, summonEvent, hook)
|
||
if not IsServer() then
|
||
return
|
||
end
|
||
if not owner or not IsValidEntity(owner) or not owner:IsAlive() then
|
||
return
|
||
end
|
||
local ownerEvent = __TS__ObjectAssign({}, summonEvent, {attacker = owner})
|
||
forEachOwnerAttackModifier(
|
||
nil,
|
||
owner,
|
||
function(____, modifier)
|
||
local hookFn = modifier[hook]
|
||
if type(hookFn) ~= "function" then
|
||
return
|
||
end
|
||
hookFn(modifier, ownerEvent)
|
||
end
|
||
)
|
||
end
|
||
____exports.modifier_summon_owner_attack_proxy = __TS__Class()
|
||
local modifier_summon_owner_attack_proxy = ____exports.modifier_summon_owner_attack_proxy
|
||
modifier_summon_owner_attack_proxy.name = "modifier_summon_owner_attack_proxy"
|
||
modifier_summon_owner_attack_proxy.____file_path = "scripts/vscripts/utils/summon_owner_attack_proxy.lua"
|
||
__TS__ClassExtends(modifier_summon_owner_attack_proxy, BaseModifier)
|
||
function modifier_summon_owner_attack_proxy.prototype.IsHidden(self)
|
||
return true
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.IsPurgable(self)
|
||
return false
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.RemoveOnDeath(self)
|
||
return false
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.DeclareFunctions(self)
|
||
return {MODIFIER_EVENT_ON_ATTACK, MODIFIER_EVENT_ON_ATTACK_LANDED}
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.forwardToOwner(self, event, hook)
|
||
if not IsServer() then
|
||
return
|
||
end
|
||
local parent = self:GetParent()
|
||
if not parent or not IsValidEntity(parent) or event.attacker ~= parent then
|
||
return
|
||
end
|
||
local owner = ____exports.getRealOwnerHeroFromUnit(nil, parent)
|
||
if not owner then
|
||
return
|
||
end
|
||
____exports.forwardOwnerAttackModifiersFromSummon(nil, owner, event, hook)
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.OnAttack(self, event)
|
||
self:forwardToOwner(event, "OnAttack")
|
||
end
|
||
function modifier_summon_owner_attack_proxy.prototype.OnAttackLanded(self, event)
|
||
self:forwardToOwner(event, "OnAttackLanded")
|
||
end
|
||
modifier_summon_owner_attack_proxy = __TS__Decorate(
|
||
modifier_summon_owner_attack_proxy,
|
||
modifier_summon_owner_attack_proxy,
|
||
{registerModifier(nil)},
|
||
{kind = "class", name = "modifier_summon_owner_attack_proxy"}
|
||
)
|
||
____exports.modifier_summon_owner_attack_proxy = modifier_summon_owner_attack_proxy
|
||
return ____exports
|