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

148 lines
5.2 KiB
Lua

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
local manageVampirismModifier
require("lib.dota_ts_adapter")
local ____modifier_vampirism = require("abilities.modifiers.modifier_vampirism")
local modifier_vampirism = ____modifier_vampirism.modifier_vampirism
function ____exports.getPhysicalVampirism(self, hero)
if not hero or not IsValidEntity(hero) then
return 0
end
local playerId = hero:GetPlayerOwnerID()
if playerId == nil or playerId == nil or playerId < 0 then
return 0
end
local key = "physical_vampirism_" .. tostring(playerId)
local data = CustomNetTables:GetTableValue("custom_stats", key)
local ____data_0
if data then
____data_0 = data.value
else
____data_0 = 0
end
local value = ____data_0
return value
end
function ____exports.getMagicalVampirism(self, hero)
if not hero or not IsValidEntity(hero) then
return 0
end
local playerId = hero:GetPlayerOwnerID()
if playerId == nil or playerId == nil or playerId < 0 then
return 0
end
local key = "magical_vampirism_" .. tostring(playerId)
local data = CustomNetTables:GetTableValue("custom_stats", key)
local ____data_1
if data then
____data_1 = data.value
else
____data_1 = 0
end
local value = ____data_1
return value
end
function manageVampirismModifier(self, hero)
if not IsServer() then
return
end
local physicalVampirism = ____exports.getPhysicalVampirism(nil, hero)
local magicalVampirism = ____exports.getMagicalVampirism(nil, hero)
local hasVampirism = physicalVampirism > 0 or magicalVampirism > 0
local hasModifier = hero:HasModifier("modifier_vampirism")
if hasVampirism and not hasModifier then
hero:AddNewModifier(
hero,
getModifierSourceAbility(nil, hero),
modifier_vampirism.name,
{}
)
elseif not hasVampirism and hasModifier then
hero:RemoveModifierByName("modifier_vampirism")
end
end
--- Партикл эффекта вампиризма (modifier без своего Precache в KV)
function ____exports.precacheVampirismParticle(self, context)
PrecacheResource("particle", "particles/units/heroes/hero_bloodseeker/bloodseeker_bloodbath.vpcf", context)
end
local playerIdToPhysicalVampirism = {}
local playerIdToMagicalVampirism = {}
if not playerIdToPhysicalVampirism then
playerIdToPhysicalVampirism = {}
end
if not playerIdToMagicalVampirism then
playerIdToMagicalVampirism = {}
end
local function getPlayerKey(self, hero, ____type)
local playerId = hero:GetPlayerOwnerID()
if playerId == nil or playerId == nil or playerId < 0 then
return nil
end
return (____type .. "_") .. tostring(playerId)
end
function ____exports.setPhysicalVampirism(self, hero, vampirism)
if not IsServer() then
return
end
local playerId = hero:GetPlayerOwnerID()
local key = "physical_vampirism_" .. tostring(playerId)
CustomNetTables:SetTableValue("custom_stats", key, {value = vampirism})
end
function ____exports.addPhysicalVampirism(self, hero, delta)
if not IsServer() then
return
end
local current = ____exports.getPhysicalVampirism(nil, hero)
local newValue = current + delta
____exports.setPhysicalVampirism(nil, hero, newValue)
manageVampirismModifier(nil, hero)
end
function ____exports.reducePhysicalVampirism(self, hero, delta)
if not IsServer() then
return
end
local current = ____exports.getPhysicalVampirism(nil, hero)
local newValue = math.max(0, current - delta)
____exports.setPhysicalVampirism(nil, hero, newValue)
manageVampirismModifier(nil, hero)
end
function ____exports.setMagicalVampirism(self, hero, vampirism)
if not IsServer() then
return
end
local playerId = hero:GetPlayerOwnerID()
if playerId == nil or playerId == nil or playerId < 0 then
return
end
local key = "magical_vampirism_" .. tostring(playerId)
CustomNetTables:SetTableValue("custom_stats", key, {value = vampirism})
end
function ____exports.addMagicalVampirism(self, hero, delta)
if not IsServer() then
return
end
local current = ____exports.getMagicalVampirism(nil, hero)
local newValue = current + delta
____exports.setMagicalVampirism(nil, hero, newValue)
manageVampirismModifier(nil, hero)
end
function ____exports.reduceMagicalVampirism(self, hero, delta)
if not IsServer() then
return
end
local current = ____exports.getMagicalVampirism(nil, hero)
local newValue = math.max(0, current - delta)
____exports.setMagicalVampirism(nil, hero, newValue)
manageVampirismModifier(nil, hero)
end
local g = _G
g.setPhysicalVampirism = ____exports.setPhysicalVampirism
g.addPhysicalVampirism = ____exports.addPhysicalVampirism
g.reducePhysicalVampirism = ____exports.reducePhysicalVampirism
g.getPhysicalVampirism = ____exports.getPhysicalVampirism
g.setMagicalVampirism = ____exports.setMagicalVampirism
g.addMagicalVampirism = ____exports.addMagicalVampirism
g.reduceMagicalVampirism = ____exports.reduceMagicalVampirism
g.getMagicalVampirism = ____exports.getMagicalVampirism
return ____exports