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

100 lines
3.8 KiB
Lua

local ____lualib = require("lualib_bundle")
local __TS__StringStartsWith = ____lualib.__TS__StringStartsWith
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 THINK_INTERVAL = 0.2
--- Волновые боссы + только npc_boss_nevermore (остальные npc_boss_* — без верхнего бара)
function ____exports.isBossHudHealthBarUnit(self, unitName)
return __TS__StringStartsWith(unitName, "npc_wave_boss_") or unitName == "npc_boss_nevermore"
end
--- Локализованное имя в HUD для Nevermore из spawn_boss_units / кат-сцены
____exports.BOSS_NEVERMORE_NAME_TOKEN = "#npc_boss_nevermore"
function ____exports.applyBossHudHealthBar(self, unit, nameToken)
if not IsServer() or unit == nil or not unit:IsAlive() then
return
end
if unit:HasModifier(____exports.modifier_boss_hud_health_bar.name) then
return
end
unit:AddNewModifier(
unit,
getModifierSourceAbility(nil, unit),
____exports.modifier_boss_hud_health_bar.name,
{name_token = nameToken}
)
end
____exports.modifier_boss_hud_health_bar = __TS__Class()
local modifier_boss_hud_health_bar = ____exports.modifier_boss_hud_health_bar
modifier_boss_hud_health_bar.name = "modifier_boss_hud_health_bar"
modifier_boss_hud_health_bar.____file_path = "scripts/vscripts/abilities/modifiers/modifier_boss_hud_health_bar.lua"
__TS__ClassExtends(modifier_boss_hud_health_bar, BaseModifier)
function modifier_boss_hud_health_bar.prototype.____constructor(self, ...)
BaseModifier.prototype.____constructor(self, ...)
self.nameToken = ""
end
function modifier_boss_hud_health_bar.prototype.IsHidden(self)
return true
end
function modifier_boss_hud_health_bar.prototype.IsPurgable(self)
return false
end
function modifier_boss_hud_health_bar.prototype.RemoveOnDeath(self)
return true
end
function modifier_boss_hud_health_bar.prototype.OnCreated(self, params)
self.parent = self:GetParent()
self.nameToken = params.name_token or "#" .. self.parent:GetUnitName()
self:sendUpdate()
self:StartIntervalThink(THINK_INTERVAL)
end
function modifier_boss_hud_health_bar.prototype.DeclareFunctions(self)
return {MODIFIER_EVENT_ON_TAKEDAMAGE}
end
function modifier_boss_hud_health_bar.prototype.OnTakeDamage(self)
self:sendUpdate()
end
function modifier_boss_hud_health_bar.prototype.OnIntervalThink(self)
if not IsValidEntity(self.parent) or not self.parent:IsAlive() then
self:StartIntervalThink(-1)
return
end
self:sendUpdate()
end
function modifier_boss_hud_health_bar.prototype.OnDestroy(self)
if IsServer() then
CustomGameEventManager:Send_ServerToAllClients("boss_health_bar_hide", {})
end
end
function modifier_boss_hud_health_bar.prototype.sendUpdate(self)
if not IsServer() then
return
end
if not IsValidEntity(self.parent) or not self.parent:IsAlive() then
return
end
CustomGameEventManager:Send_ServerToAllClients(
"boss_health_bar_update",
{
health = math.floor(self.parent:GetHealth()),
maxHealth = math.max(
1,
math.floor(self.parent:GetMaxHealth())
),
nameToken = self.nameToken
}
)
end
modifier_boss_hud_health_bar = __TS__Decorate(
modifier_boss_hud_health_bar,
modifier_boss_hud_health_bar,
{registerModifier(nil)},
{kind = "class", name = "modifier_boss_hud_health_bar"}
)
____exports.modifier_boss_hud_health_bar = modifier_boss_hud_health_bar
return ____exports