initial commit
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
local ____lualib = require("lualib_bundle")
|
||||
local __TS__Class = ____lualib.__TS__Class
|
||||
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
|
||||
local __TS__Decorate = ____lualib.__TS__Decorate
|
||||
local __TS__NumberToFixed = ____lualib.__TS__NumberToFixed
|
||||
local ____exports = {}
|
||||
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
|
||||
local BaseAbility = ____dota_ts_adapter.BaseAbility
|
||||
local BaseModifier = ____dota_ts_adapter.BaseModifier
|
||||
local registerAbility = ____dota_ts_adapter.registerAbility
|
||||
local registerModifier = ____dota_ts_adapter.registerModifier
|
||||
print("[DPS Tracker] ===== Файл dps_tracker.ts загружен ===== ")
|
||||
--- Модификатор для отслеживания урона, нанесенного юнитом
|
||||
-- Отображает DPS и последний урон снизу юнита
|
||||
--
|
||||
-- Использование:
|
||||
-- const modifier = unit.AddNewModifier(unit, getModifierSourceAbility(unit), "modifier_dps_tracker", {});
|
||||
____exports.dps_tracker = __TS__Class()
|
||||
local dps_tracker = ____exports.dps_tracker
|
||||
dps_tracker.name = "dps_tracker"
|
||||
dps_tracker.____file_path = "scripts/vscripts/abilities/modifiers/dps_tracker.lua"
|
||||
__TS__ClassExtends(dps_tracker, BaseAbility)
|
||||
function dps_tracker.prototype.GetIntrinsicModifierName(self)
|
||||
print("[DPS Tracker] GetIntrinsicModifierName вызван")
|
||||
return "modifier_dps_tracker"
|
||||
end
|
||||
dps_tracker = __TS__Decorate(
|
||||
dps_tracker,
|
||||
dps_tracker,
|
||||
{registerAbility(nil)},
|
||||
{kind = "class", name = "dps_tracker"}
|
||||
)
|
||||
____exports.dps_tracker = dps_tracker
|
||||
____exports.modifier_dps_tracker = __TS__Class()
|
||||
local modifier_dps_tracker = ____exports.modifier_dps_tracker
|
||||
modifier_dps_tracker.name = "modifier_dps_tracker"
|
||||
modifier_dps_tracker.____file_path = "scripts/vscripts/abilities/modifiers/dps_tracker.lua"
|
||||
__TS__ClassExtends(modifier_dps_tracker, BaseModifier)
|
||||
function modifier_dps_tracker.prototype.____constructor(self)
|
||||
BaseModifier.prototype.____constructor(self)
|
||||
self.totalDamage = 0
|
||||
self.lastHitDamage = 0
|
||||
self.startTime = 0
|
||||
self.lastHitTime = 0
|
||||
self.INACTIVE_TIMEOUT = 14
|
||||
print("[DPS Tracker] Конструктор modifier_dps_tracker вызван")
|
||||
end
|
||||
function modifier_dps_tracker.prototype.IsHidden(self)
|
||||
return true
|
||||
end
|
||||
function modifier_dps_tracker.prototype.IsDebuff(self)
|
||||
return false
|
||||
end
|
||||
function modifier_dps_tracker.prototype.IsPurgable(self)
|
||||
return false
|
||||
end
|
||||
function modifier_dps_tracker.prototype.OnCreated(self, params)
|
||||
print((("[DPS Tracker] OnCreated вызван, IsServer: " .. tostring(IsServer())) .. ", IsClient: ") .. tostring(IsClient()))
|
||||
if not IsServer() then
|
||||
print("[DPS Tracker] OnCreated: не на сервере, выходим")
|
||||
return
|
||||
end
|
||||
self.totalDamage = 0
|
||||
self.lastHitDamage = 0
|
||||
self.startTime = GameRules:GetGameTime()
|
||||
self.lastHitTime = self.startTime
|
||||
local unit = self:GetParent()
|
||||
if unit and IsValidEntity(unit) then
|
||||
print((("[DPS Tracker] Модификатор создан для юнита (цели): " .. unit:GetUnitName()) .. ", индекс: ") .. tostring(unit:entindex()))
|
||||
else
|
||||
print("[DPS Tracker] ОШИБКА: юнит невалиден при создании модификатора!")
|
||||
end
|
||||
self:StartIntervalThink(1)
|
||||
print("[DPS Tracker] StartIntervalThink установлен на 1.0")
|
||||
end
|
||||
function modifier_dps_tracker.prototype.DeclareFunctions(self)
|
||||
return {MODIFIER_EVENT_ON_TAKEDAMAGE, MODIFIER_PROPERTY_MIN_HEALTH}
|
||||
end
|
||||
function modifier_dps_tracker.prototype.GetMinHealth(self)
|
||||
return 1
|
||||
end
|
||||
function modifier_dps_tracker.prototype.OnTakeDamage(self, event)
|
||||
if not IsServer() then
|
||||
print("[DPS Tracker] OnTakeDamage: не на сервере")
|
||||
return
|
||||
end
|
||||
local victim = self:GetParent()
|
||||
local attacker = event.attacker
|
||||
if not attacker or not IsValidEntity(attacker) then
|
||||
return
|
||||
end
|
||||
if event.unit ~= self:GetParent() then
|
||||
return
|
||||
end
|
||||
self:GetParent():StartGesture(ACT_DOTA_FLINCH)
|
||||
local currentTime = GameRules:GetGameTime()
|
||||
local damage = event.damage
|
||||
if self.totalDamage == 0 then
|
||||
self.startTime = currentTime
|
||||
end
|
||||
self:GetParent():SetHealth(self:GetParent():GetHealth() + damage)
|
||||
self.totalDamage = self.totalDamage + damage
|
||||
self.lastHitDamage = damage
|
||||
self.lastHitTime = currentTime
|
||||
print((((((("[DPS Tracker] Урон получен: " .. tostring(math.floor(damage + 0.5))) .. ", всего урона: ") .. tostring(math.floor(self.totalDamage + 0.5))) .. ", от ") .. attacker:GetUnitName()) .. ", цель: ") .. victim:GetUnitName())
|
||||
self:updateDPSDisplay(victim:entindex())
|
||||
end
|
||||
function modifier_dps_tracker.prototype.OnIntervalThink(self)
|
||||
if not IsServer() then
|
||||
print("[DPS Tracker] OnIntervalThink: не на сервере")
|
||||
return
|
||||
end
|
||||
local currentTime = GameRules:GetGameTime()
|
||||
local victim = self:GetParent()
|
||||
local victimIndex = victim:entindex()
|
||||
local timeSinceLastHit = currentTime - self.lastHitTime
|
||||
if timeSinceLastHit > self.INACTIVE_TIMEOUT then
|
||||
print(("[DPS Tracker] Цель не получала урон " .. __TS__NumberToFixed(timeSinceLastHit, 1)) .. " секунд, удаляем отображение")
|
||||
CustomGameEventManager:Send_ServerToAllClients("unit_dps_remove", {unitIndex = victimIndex})
|
||||
else
|
||||
self:updateDPSDisplay(victimIndex)
|
||||
end
|
||||
end
|
||||
function modifier_dps_tracker.prototype.updateDPSDisplay(self, victimIndex)
|
||||
if not IsServer() then
|
||||
return
|
||||
end
|
||||
local currentTime = GameRules:GetGameTime()
|
||||
local elapsedTime = currentTime - self.startTime
|
||||
local dps = elapsedTime > 0 and self.totalDamage / elapsedTime or 0
|
||||
local updateData = {
|
||||
unitIndex = victimIndex,
|
||||
attackerIndex = 0,
|
||||
totalDamage = math.floor(self.totalDamage + 0.5),
|
||||
dps = math.floor(dps + 0.5),
|
||||
lastHitDamage = math.floor(self.lastHitDamage + 0.5)
|
||||
}
|
||||
CustomGameEventManager:Send_ServerToAllClients("unit_dps_update", updateData)
|
||||
end
|
||||
function modifier_dps_tracker.prototype.OnDestroy(self)
|
||||
if not IsServer() then
|
||||
return
|
||||
end
|
||||
local unit = self:GetParent()
|
||||
if unit and IsValidEntity(unit) then
|
||||
local victimIndex = unit:entindex()
|
||||
print((((("[DPS Tracker] Модификатор уничтожен для юнита: " .. unit:GetUnitName()) .. ", индекс: ") .. tostring(victimIndex)) .. ", финальный урон: ") .. tostring(math.floor(self.totalDamage + 0.5)))
|
||||
CustomGameEventManager:Send_ServerToAllClients("unit_dps_remove", {unitIndex = victimIndex})
|
||||
else
|
||||
print("[DPS Tracker] Ошибка: юнит невалиден при уничтожении модификатора")
|
||||
end
|
||||
end
|
||||
modifier_dps_tracker = __TS__Decorate(
|
||||
modifier_dps_tracker,
|
||||
modifier_dps_tracker,
|
||||
{registerModifier(nil)},
|
||||
{kind = "class", name = "modifier_dps_tracker"}
|
||||
)
|
||||
____exports.modifier_dps_tracker = modifier_dps_tracker
|
||||
return ____exports
|
||||
Reference in New Issue
Block a user