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

76 lines
3.2 KiB
Lua

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
local ____store_manager = require("store_manager")
local StoreManager = ____store_manager.StoreManager
--- Микрокэш на один вызов GetGameTime() — снижает давление CustomNetTables при частых GetEffectName.
local clientGetEffectCacheKey = ""
local clientGetEffectCacheTime = -999999
local clientGetEffectCacheValue = nil
--- Получить все активные эффекты героя
--
-- @param hero - Герой игрока
-- @returns Объект с активными эффектами по типам: { "effect": "skin_effect_fire", "wings": "wings_demon", "model": null }
function ____exports.GetAllEffects(self, hero)
local playerId = hero:GetPlayerOwnerID()
if playerId < 0 then
return {}
end
local storeManager = StoreManager:getInstance()
return storeManager:getPlayerActiveEffects(playerId)
end
--- Получить активный эффект конкретного типа для героя
--
-- @param hero - Герой игрока
-- @param effectType - Тип эффекта ("effect", "wings", "model")
-- @returns ID эффекта или null
function ____exports.GetEffect(self, hero, effectType)
local playerId = hero:GetPlayerOwnerID()
if playerId < 0 then
return nil
end
if IsClient() then
local now = GameRules:GetGameTime()
local cacheKey = (tostring(playerId) .. ":") .. effectType
if clientGetEffectCacheKey == cacheKey and clientGetEffectCacheTime == now then
return clientGetEffectCacheValue
end
local playerInfo = CustomNetTables:GetTableValue(
"player_info",
tostring(playerId)
)
local value = nil
if playerInfo and playerInfo.active_effects and playerInfo.active_effects[effectType] then
value = playerInfo.active_effects[effectType]
end
clientGetEffectCacheKey = cacheKey
clientGetEffectCacheTime = now
clientGetEffectCacheValue = value
return value
end
local storeManager = StoreManager:getInstance()
return storeManager:getPlayerActiveEffect(playerId, effectType)
end
--- Проверить, надёт ли конкретный эффект на героя
--
-- @param hero - Герой игрока
-- @param effectId - ID эффекта
-- @param effectType - Опционально: тип эффекта для проверки конкретного типа
-- @returns true если эффект надёт, false если нет
function ____exports.HasEffect(self, hero, effectId, effectType)
local playerId = hero:GetPlayerOwnerID()
if playerId < 0 then
return false
end
local storeManager = StoreManager:getInstance()
return storeManager:isEffectEquipped(playerId, effectId, effectType)
end
local g = _G
g.GetAllEffects = ____exports.GetAllEffects
g.GetEffect = ____exports.GetEffect
g.HasEffect = ____exports.HasEffect
local env = getfenv(nil, 0)
env.GetAllEffects = ____exports.GetAllEffects
env.GetEffect = ____exports.GetEffect
env.HasEffect = ____exports.HasEffect
return ____exports