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

243 lines
8.9 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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 ____custom_game_events = require("custom_game_events")
local ensurePlayerCardSystem = ____custom_game_events.ensurePlayerCardSystem
local sendZiMorningGoldCard = ____custom_game_events.sendZiMorningGoldCard
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 ____card_value_resolver = require("cards.card_value_resolver")
local getCardValueByLevel = ____card_value_resolver.getCardValueByLevel
local ____WaveManager = require("WaveManager")
local WaveManager = ____WaveManager.WaveManager
local CARD_ID = 22
local lastMorningSeqCard22ByPlayer = {}
--- Сколько раз уже выдали бонус «при взятии» (по числу копий, без повтора при апгрейде).
local card22PickupGrantsByPlayer = {}
--- Золото на рассвете после ночи `nightIndex` (1 → base, 2 → basedecay, …).
function ____exports.computeCard22MorningGold(self, hero, nightIndex, explicitLevel)
local night = math.max(
1,
math.floor(nightIndex)
)
local base = getCardValueByLevel(
nil,
CARD_ID,
hero,
"morning_gold_base",
700,
explicitLevel
)
local decay = getCardValueByLevel(
nil,
CARD_ID,
hero,
"morning_gold_decay_per_night",
100,
explicitLevel
)
return math.max(
0,
math.floor(base - decay * (night - 1))
)
end
--- Следующая утренняя выплата от текущего номера ночи в WaveManager.
local function computeCard22NextMorningGold(self, hero, explicitLevel)
local currentNight = WaveManager:getInstance():GetCurrentNight()
local nextMorningNightIndex = math.max(1, currentNight + 1)
return ____exports.computeCard22MorningGold(nil, hero, nextMorningNightIndex, explicitLevel)
end
local function grantCard22Gold(self, playerId, goldAmount, nightIndex, morningSequence)
if goldAmount <= 0 then
return
end
PlayerResource:ModifyGold(playerId, goldAmount, true, DOTA_ModifyGold_Unspecified)
sendZiMorningGoldCard(nil, playerId, {morningSequence = morningSequence, nightIndex = nightIndex, goldAmount = goldAmount})
end
____exports.card_22 = __TS__Class()
local card_22 = ____exports.card_22
card_22.name = "card_22"
card_22.____file_path = "scripts/vscripts/cards/examples/card_22.lua"
__TS__ClassExtends(card_22, CardBase)
function card_22.prototype.GetModifierName(self)
return "modifier_card_22"
end
card_22 = __TS__Decorate(card_22, card_22, {RegisterCard}, {kind = "class", name = "card_22"})
____exports.card_22 = card_22
____exports.modifier_card_22 = __TS__Class()
local modifier_card_22 = ____exports.modifier_card_22
modifier_card_22.name = "modifier_card_22"
modifier_card_22.____file_path = "scripts/vscripts/cards/examples/card_22.lua"
__TS__ClassExtends(modifier_card_22, CardBaseModifier)
function modifier_card_22.prototype.OnCustomCreated(self)
if not IsServer() then
return
end
local hero = self:GetParent()
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
return
end
local pickupPct = self:getCardValue("pickup_gold_pct", 0, CARD_ID)
if not (pickupPct > 0) then
return
end
local playerId = hero:GetPlayerOwnerID()
if playerId == nil or playerId < 0 then
return
end
local cardSystem = ensurePlayerCardSystem(nil, playerId)
local activeCopies = cardSystem and cardSystem:GetActiveCardCopies(CARD_ID) or 1
local alreadyGranted = card22PickupGrantsByPlayer[playerId] or 0
if alreadyGranted >= activeCopies then
return
end
local nextMorningGold = computeCard22NextMorningGold(nil, hero)
local instantGold = math.floor(nextMorningGold * pickupPct / 100)
if instantGold <= 0 then
return
end
grantCard22Gold(
nil,
playerId,
instantGold,
WaveManager:getInstance():GetCurrentNight(),
0
)
card22PickupGrantsByPlayer[playerId] = alreadyGranted + 1
end
function modifier_card_22.prototype.DeclareFunctions(self)
return {MODIFIER_PROPERTY_TOOLTIP}
end
function modifier_card_22.prototype.OnTooltip(self)
local hero = self:GetParent()
if not hero or not IsValidEntity(hero) then
return 0
end
return computeCard22NextMorningGold(nil, hero)
end
modifier_card_22 = __TS__Decorate(
modifier_card_22,
modifier_card_22,
{registerModifier(nil)},
{kind = "class", name = "modifier_card_22"}
)
____exports.modifier_card_22 = modifier_card_22
--- Рассвет: полная утренняя выплата.
function ____exports.notifyCard22MorningStarted(self, currentNight, morningSequence)
if not IsServer() then
return
end
local nightIndex = math.max(
1,
math.floor(currentNight)
)
do
local i = 0
while i < DOTA_MAX_PLAYERS do
do
local pid = i
local player = PlayerResource:GetPlayer(pid)
if not player then
goto __continue19
end
local cardSystem = ensurePlayerCardSystem(nil, pid)
if not cardSystem then
goto __continue19
end
local copies = cardSystem:GetActiveCardCopies(CARD_ID)
if copies <= 0 then
goto __continue19
end
local hero = player:GetAssignedHero()
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
goto __continue19
end
local prevSeq = lastMorningSeqCard22ByPlayer[pid] or 0
if morningSequence <= prevSeq then
goto __continue19
end
local morningGold = ____exports.computeCard22MorningGold(nil, hero, nightIndex)
local goldReward = math.max(
0,
math.floor(morningGold * copies)
)
if goldReward > 0 then
grantCard22Gold(
nil,
pid,
goldReward,
nightIndex,
morningSequence
)
end
lastMorningSeqCard22ByPlayer[pid] = morningSequence
end
::__continue19::
i = i + 1
end
end
end
--- Начало ночи (ур. 3+): 50% от золота следующего рассвета.
function ____exports.notifyCard22NightStarted(self)
if not IsServer() then
return
end
local currentNight = WaveManager:getInstance():GetCurrentNight()
local nextMorningNightIndex = math.max(1, currentNight + 1)
do
local i = 0
while i < DOTA_MAX_PLAYERS do
do
local pid = i
local player = PlayerResource:GetPlayer(pid)
if not player then
goto __continue28
end
local cardSystem = ensurePlayerCardSystem(nil, pid)
if not cardSystem then
goto __continue28
end
local copies = cardSystem:GetActiveCardCopies(CARD_ID)
if copies <= 0 then
goto __continue28
end
local hero = player:GetAssignedHero()
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
goto __continue28
end
local preNightPct = getCardValueByLevel(
nil,
CARD_ID,
hero,
"pre_night_gold_pct",
0
)
if not (preNightPct > 0) then
goto __continue28
end
local nextMorningGold = ____exports.computeCard22MorningGold(nil, hero, nextMorningNightIndex)
local preNightGold = math.floor(nextMorningGold * preNightPct / 100 * copies)
if preNightGold > 0 then
grantCard22Gold(
nil,
pid,
preNightGold,
nextMorningNightIndex,
0
)
end
end
::__continue28::
i = i + 1
end
end
end
return ____exports