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

173 lines
6.2 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 ____WaveManager = require("WaveManager")
local WaveManager = ____WaveManager.WaveManager
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 = 48
local BUFF_NAME = "modifier_card_48_insurance_buff"
local CARD_48_INSURANCE_BUFF_INCOMING_SOURCE = BUFF_NAME
____exports.card_48 = __TS__Class()
local card_48 = ____exports.card_48
card_48.name = "card_48"
card_48.____file_path = "scripts/vscripts/cards/examples/card_48.lua"
__TS__ClassExtends(card_48, CardBase)
function card_48.prototype.GetModifierName(self)
return "modifier_card_48"
end
card_48 = __TS__Decorate(card_48, card_48, {RegisterCard}, {kind = "class", name = "card_48"})
____exports.card_48 = card_48
____exports.modifier_card_48 = __TS__Class()
local modifier_card_48 = ____exports.modifier_card_48
modifier_card_48.name = "modifier_card_48"
modifier_card_48.____file_path = "scripts/vscripts/cards/examples/card_48.lua"
__TS__ClassExtends(modifier_card_48, CardBaseModifier)
function modifier_card_48.prototype.____constructor(self, ...)
CardBaseModifier.prototype.____constructor(self, ...)
self.insuranceReady = true
self.trackedNight = -1
end
function modifier_card_48.prototype.getValue(self, key, fallback)
return self:getCardValue(key, fallback, CARD_ID)
end
function modifier_card_48.prototype.OnCustomCreated(self, params)
if not IsServer() then
return
end
self.trackedNight = WaveManager:getInstance():GetCurrentNight()
self.insuranceReady = true
self:StartIntervalThink(1)
end
function modifier_card_48.prototype.OnIntervalThink(self)
if not IsServer() then
return
end
local night = WaveManager:getInstance():GetCurrentNight()
if night ~= self.trackedNight then
self.trackedNight = night
self.insuranceReady = true
end
end
function modifier_card_48.prototype.DeclareFunctions(self)
return {MODIFIER_EVENT_ON_TAKEDAMAGE, MODIFIER_PROPERTY_TOOLTIP}
end
function modifier_card_48.prototype.OnTakeDamage(self, event)
if not IsServer() then
return
end
local parent = self:GetParent()
if not parent or not IsValidEntity(parent) or not parent:IsAlive() then
return
end
if event.unit ~= parent then
return
end
if not parent:IsRealHero() then
return
end
if not self.insuranceReady then
return
end
local maxHp = parent:GetMaxHealth()
if maxHp <= 0 then
return
end
local hpPct = parent:GetHealth() / maxHp * 100
local triggerPct = self:getValue("trigger_hp_pct", 25)
if hpPct >= triggerPct then
return
end
self.insuranceReady = false
local copies = self:getCardCopies()
local healPct = self:getValue("shield_heal_max_hp_pct", 10) * copies
local heal = maxHp * (healPct / 100)
if heal > 0 then
parent:Heal(heal, nil)
end
local duration = self:getValue("insurance_duration", 3)
parent:AddNewModifier(
parent,
getModifierSourceAbility(nil, parent),
BUFF_NAME,
{duration = duration}
)
end
modifier_card_48 = __TS__Decorate(
modifier_card_48,
modifier_card_48,
{registerModifier(nil)},
{kind = "class", name = "modifier_card_48"}
)
____exports.modifier_card_48 = modifier_card_48
____exports.modifier_card_48_insurance_buff = __TS__Class()
local modifier_card_48_insurance_buff = ____exports.modifier_card_48_insurance_buff
modifier_card_48_insurance_buff.name = "modifier_card_48_insurance_buff"
modifier_card_48_insurance_buff.____file_path = "scripts/vscripts/cards/examples/card_48.lua"
__TS__ClassExtends(modifier_card_48_insurance_buff, CardBaseModifier)
function modifier_card_48_insurance_buff.prototype.getCardCopiesFromOwner(self)
local owner = self:GetCaster()
if not owner or not IsValidEntity(owner) then
return 1
end
local cardMod = owner:FindModifierByName("modifier_card_48")
return math.max(
1,
math.floor(cardMod and cardMod:GetStackCount() or 0)
)
end
function modifier_card_48_insurance_buff.prototype.getValue(self, key, fallback)
return self:getCardValue(key, fallback, CARD_ID) * self:getCardCopiesFromOwner()
end
function modifier_card_48_insurance_buff.prototype.IsPurgable(self)
return true
end
function modifier_card_48_insurance_buff.prototype.OnCustomCreated(self, params)
if not IsServer() then
return
end
setIncomingDamageReductionSource(
nil,
self:GetParent(),
CARD_48_INSURANCE_BUFF_INCOMING_SOURCE,
function()
local reduce = self:getValue("incoming_damage_reduction_pct", 25)
return math.max(0, reduce)
end
)
end
function modifier_card_48_insurance_buff.prototype.OnDestroy(self)
if not IsServer() then
return
end
removeIncomingDamageReductionSource(
nil,
self:GetParent(),
CARD_48_INSURANCE_BUFF_INCOMING_SOURCE
)
end
function modifier_card_48_insurance_buff.prototype.GetEffectName(self)
return "particles/items_fx/aegis_timer.vpcf"
end
function modifier_card_48_insurance_buff.prototype.GetEffectAttachType(self)
return PATTACH_ABSORIGIN_FOLLOW
end
modifier_card_48_insurance_buff = __TS__Decorate(
modifier_card_48_insurance_buff,
modifier_card_48_insurance_buff,
{registerModifier(nil)},
{kind = "class", name = "modifier_card_48_insurance_buff"}
)
____exports.modifier_card_48_insurance_buff = modifier_card_48_insurance_buff
return ____exports