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

132 lines
4.6 KiB
Lua

local ____lualib = require("lualib_bundle")
local __TS__Class = ____lualib.__TS__Class
local __TS__ClassExtends = ____lualib.__TS__ClassExtends
local __TS__Decorate = ____lualib.__TS__Decorate
local ____exports = {}
local ____CardSystem = require("cards.CardSystem")
local CardBase = ____CardSystem.CardBase
local RegisterCard = ____CardSystem.RegisterCard
local ____CardBaseModifier = require("cards.CardBaseModifier")
local CardBaseModifier = ____CardBaseModifier.CardBaseModifier
local ____dota_ts_adapter = require("lib.dota_ts_adapter")
local registerModifier = ____dota_ts_adapter.registerModifier
local ____vampirism = require("utils.vampirism")
local addPhysicalVampirism = ____vampirism.addPhysicalVampirism
local reducePhysicalVampirism = ____vampirism.reducePhysicalVampirism
local ____incoming_damage_reduction_combine = require("utils.incoming_damage_reduction_combine")
local removeIncomingDamageReductionSource = ____incoming_damage_reduction_combine.removeIncomingDamageReductionSource
local setIncomingDamageReductionSource = ____incoming_damage_reduction_combine.setIncomingDamageReductionSource
local CARD_ID = 29
local CARD_29_INCOMING_SOURCE = "modifier_card_29"
____exports.card_29 = __TS__Class()
local card_29 = ____exports.card_29
card_29.name = "card_29"
card_29.____file_path = "scripts/vscripts/cards/examples/card_29.lua"
__TS__ClassExtends(card_29, CardBase)
function card_29.prototype.GetModifierName(self)
return "modifier_card_29"
end
card_29 = __TS__Decorate(card_29, card_29, {RegisterCard}, {kind = "class", name = "card_29"})
____exports.card_29 = card_29
____exports.modifier_card_29 = __TS__Class()
local modifier_card_29 = ____exports.modifier_card_29
modifier_card_29.name = "modifier_card_29"
modifier_card_29.____file_path = "scripts/vscripts/cards/examples/card_29.lua"
__TS__ClassExtends(modifier_card_29, CardBaseModifier)
function modifier_card_29.prototype.____constructor(self, ...)
CardBaseModifier.prototype.____constructor(self, ...)
self.nightBonusApplied = false
self.appliedVampirism = 0
end
function modifier_card_29.prototype.getValue(self, key, fallback)
return self:getCardValue(key, fallback, CARD_ID)
end
function modifier_card_29.prototype.OnCustomCreated(self, params)
if not IsServer() then
return
end
setIncomingDamageReductionSource(
nil,
self:GetParent(),
CARD_29_INCOMING_SOURCE,
function()
if GameRules:IsDaytime() then
return 0
end
return math.max(
0,
self:getScaledCardValue("night_incoming_damage_reduce_pct", 5)
)
end
)
self:updateNightState()
self:StartIntervalThink(0.5)
end
function modifier_card_29.prototype.OnCustomRefresh(self, _params)
if not IsServer() then
return
end
local hero = self:GetParent()
if hero and IsValidEntity(hero) and self.nightBonusApplied then
self:removeNightBonus(hero)
end
self:updateNightState()
end
function modifier_card_29.prototype.OnDestroy(self)
if not IsServer() then
return
end
local hero = self:GetParent()
if not hero or not IsValidEntity(hero) then
return
end
removeIncomingDamageReductionSource(nil, hero, CARD_29_INCOMING_SOURCE)
self:removeNightBonus(hero)
end
function modifier_card_29.prototype.OnIntervalThink(self)
if not IsServer() then
return
end
self:updateNightState()
end
function modifier_card_29.prototype.updateNightState(self)
local hero = self:GetParent()
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
return
end
if GameRules:IsDaytime() then
self:removeNightBonus(hero)
return
end
self:applyNightBonus(hero)
end
function modifier_card_29.prototype.applyNightBonus(self, hero)
if self.nightBonusApplied then
return
end
local vampirismBonus = self:getScaledCardValue("night_vampirism_pct", 10)
if vampirismBonus > 0 then
addPhysicalVampirism(nil, hero, vampirismBonus)
self.appliedVampirism = vampirismBonus
end
self.nightBonusApplied = true
end
function modifier_card_29.prototype.removeNightBonus(self, hero)
if not self.nightBonusApplied then
return
end
if self.appliedVampirism > 0 then
reducePhysicalVampirism(nil, hero, self.appliedVampirism)
self.appliedVampirism = 0
end
self.nightBonusApplied = false
end
modifier_card_29 = __TS__Decorate(
modifier_card_29,
modifier_card_29,
{registerModifier(nil)},
{kind = "class", name = "modifier_card_29"}
)
____exports.modifier_card_29 = modifier_card_29
return ____exports