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

146 lines
5.4 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 ____custom_game_events = require("custom_game_events")
local ensurePlayerCardSystem = ____custom_game_events.ensurePlayerCardSystem
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 CARD_ID = 63
local DEFAULT_BONUS_SELECTION_COUNT = 3
local BONUS_SELECTION_SOURCE = "card_63_survivor_contract_bonus"
local hadNightDeathByPlayer = {}
local lastMorningSeqCard63ByPlayer = {}
local isDeathListenerInitialized = false
local function initializeNightDeathListener(self)
if not IsServer() or isDeathListenerInitialized then
return
end
isDeathListenerInitialized = true
ListenToGameEvent(
"entity_killed",
function(event)
local killed = EntIndexToHScript(event.entindex_killed)
if not killed or not IsValidEntity(killed) or not killed:IsRealHero() then
return
end
if GameRules:IsDaytime() then
return
end
local playerId = killed:GetPlayerOwnerID()
if playerId == nil or playerId < 0 then
return
end
hadNightDeathByPlayer[playerId] = true
end,
nil
)
end
____exports.card_63 = __TS__Class()
local card_63 = ____exports.card_63
card_63.name = "card_63"
card_63.____file_path = "scripts/vscripts/cards/examples/card_63.lua"
__TS__ClassExtends(card_63, CardBase)
function card_63.prototype.OnCreated(self)
initializeNightDeathListener(nil)
end
function card_63.prototype.GetModifierName(self)
return "modifier_card_63"
end
card_63 = __TS__Decorate(card_63, card_63, {RegisterCard}, {kind = "class", name = "card_63"})
____exports.card_63 = card_63
____exports.modifier_card_63 = __TS__Class()
local modifier_card_63 = ____exports.modifier_card_63
modifier_card_63.name = "modifier_card_63"
modifier_card_63.____file_path = "scripts/vscripts/cards/examples/card_63.lua"
__TS__ClassExtends(modifier_card_63, CardBaseModifier)
modifier_card_63 = __TS__Decorate(
modifier_card_63,
modifier_card_63,
{registerModifier(nil)},
{kind = "class", name = "modifier_card_63"}
)
____exports.modifier_card_63 = modifier_card_63
--- Начало ночи: сбрасываем флаг смертей для нового цикла ночи.
function ____exports.notifyCard63NightStarted(self)
if not IsServer() then
return
end
do
local i = 0
while i < DOTA_MAX_PLAYERS do
hadNightDeathByPlayer[i] = false
i = i + 1
end
end
end
--- Рассвет: если за ночь не было смертей, даём дополнительный выбор карты.
function ____exports.notifyCard63MorningStarted(self, _morningSequence)
if not IsServer() then
return
end
do
local i = 0
while i < DOTA_MAX_PLAYERS do
do
local pid = i
local player = PlayerResource:GetPlayer(pid)
if not player then
goto __continue15
end
local cardSystem = ensurePlayerCardSystem(nil, pid)
if not cardSystem then
goto __continue15
end
local copies = cardSystem:GetActiveCardCopies(CARD_ID)
if copies <= 0 then
goto __continue15
end
local hero = player:GetAssignedHero()
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
goto __continue15
end
local prevSeq = lastMorningSeqCard63ByPlayer[pid] or 0
if _morningSequence <= prevSeq then
goto __continue15
end
if hadNightDeathByPlayer[pid] == true then
goto __continue15
end
local baseBonusCount = math.max(
1,
getCardValueByLevel(
nil,
CARD_ID,
hero,
"bonus_card_choices",
DEFAULT_BONUS_SELECTION_COUNT
)
)
do
local copyIndex = 0
while copyIndex < copies do
cardSystem:ShowCardSelection(
baseBonusCount,
(BONUS_SELECTION_SOURCE .. "_") .. tostring(copyIndex + 1)
)
copyIndex = copyIndex + 1
end
end
lastMorningSeqCard63ByPlayer[pid] = _morningSequence
end
::__continue15::
i = i + 1
end
end
end
return ____exports