127 lines
4.3 KiB
Lua
127 lines
4.3 KiB
Lua
local ____lualib = require("lualib_bundle")
|
|
local __TS__Number = ____lualib.__TS__Number
|
|
local __TS__NumberIsFinite = ____lualib.__TS__NumberIsFinite
|
|
local ____exports = {}
|
|
local ____card_data = require("cards.card_data")
|
|
local CARD_DATABASE = ____card_data.CARD_DATABASE
|
|
local CARD_ID = 52
|
|
--- Минимальная длительность ночи (сек.) после суммарного сокращения от карты 52.
|
|
____exports.CARD_52_MIN_NIGHT_DURATION_SEC = 30
|
|
local function resolveNumeric(self, value, fallback)
|
|
local numeric = __TS__Number(value)
|
|
if not __TS__NumberIsFinite(numeric) then
|
|
return fallback
|
|
end
|
|
return numeric
|
|
end
|
|
local function getCard52LevelValue(self, playerId, key, fallback)
|
|
local ____opt_2 = CARD_DATABASE[CARD_ID]
|
|
local ____opt_0 = ____opt_2 and ____opt_2.values
|
|
local raw = ____opt_0 and ____opt_0[key]
|
|
if raw == nil or raw == nil then
|
|
return fallback
|
|
end
|
|
if type(raw) ~= "table" then
|
|
return resolveNumeric(nil, raw, fallback)
|
|
end
|
|
local player = PlayerResource:GetPlayer(playerId)
|
|
local ____opt_4 = player and player.cardSystem
|
|
local levelRaw = __TS__Number(____opt_4 and ____opt_4:GetCardLevel(CARD_ID) or 1)
|
|
local level = __TS__NumberIsFinite(levelRaw) and levelRaw > 0 and math.floor(levelRaw) or 1
|
|
local tableRaw = raw
|
|
local byLevel = resolveNumeric(nil, tableRaw[level], 0 / 0)
|
|
if __TS__NumberIsFinite(byLevel) then
|
|
return byLevel
|
|
end
|
|
local byLevelString = resolveNumeric(
|
|
nil,
|
|
tableRaw[tostring(level)],
|
|
0 / 0
|
|
)
|
|
if __TS__NumberIsFinite(byLevelString) then
|
|
return byLevelString
|
|
end
|
|
local levelOne = resolveNumeric(nil, tableRaw[1], 0 / 0)
|
|
if __TS__NumberIsFinite(levelOne) then
|
|
return levelOne
|
|
end
|
|
local levelOneString = resolveNumeric(nil, tableRaw["1"], 0 / 0)
|
|
if __TS__NumberIsFinite(levelOneString) then
|
|
return levelOneString
|
|
end
|
|
return fallback
|
|
end
|
|
--- Сумма копий карты 52 у всех игроков.
|
|
function ____exports.getTotalCard52Copies(self)
|
|
if not IsServer() then
|
|
return 0
|
|
end
|
|
local totalCopies = 0
|
|
do
|
|
local i = 0
|
|
while i < DOTA_MAX_PLAYERS do
|
|
do
|
|
local player = PlayerResource:GetPlayer(i)
|
|
if not player or not player.cardSystem then
|
|
goto __continue13
|
|
end
|
|
totalCopies = totalCopies + player.cardSystem:GetActiveCardCopies(CARD_ID)
|
|
end
|
|
::__continue13::
|
|
i = i + 1
|
|
end
|
|
end
|
|
return totalCopies
|
|
end
|
|
local function forEachPlayerCard52(self, handler)
|
|
if not IsServer() then
|
|
return
|
|
end
|
|
do
|
|
local i = 0
|
|
while i < DOTA_MAX_PLAYERS do
|
|
do
|
|
local player = PlayerResource:GetPlayer(i)
|
|
if not player or not player.cardSystem then
|
|
goto __continue17
|
|
end
|
|
local copies = player.cardSystem:GetActiveCardCopies(CARD_ID)
|
|
if copies <= 0 then
|
|
goto __continue17
|
|
end
|
|
handler(nil, i, copies)
|
|
end
|
|
::__continue17::
|
|
i = i + 1
|
|
end
|
|
end
|
|
end
|
|
--- Множитель статов врагов от карты 52: 1 + X% за каждую копию.
|
|
function ____exports.getEnemyStatsMultiplierFromCard52(self)
|
|
local totalBonusPct = 0
|
|
forEachPlayerCard52(
|
|
nil,
|
|
function(____, playerId, copies)
|
|
local bonusPctPerCopy = getCard52LevelValue(nil, playerId, "enemy_stats_bonus_pct", 8)
|
|
totalBonusPct = totalBonusPct + bonusPctPerCopy * copies
|
|
end
|
|
)
|
|
return 1 + totalBonusPct / 100
|
|
end
|
|
--- На сколько секунд сокращается ночь от карты 52 (суммарно по всем копиям).
|
|
function ____exports.getNightDurationReductionSecFromCard52(self)
|
|
local totalReduceSec = 0
|
|
forEachPlayerCard52(
|
|
nil,
|
|
function(____, playerId, copies)
|
|
local reduceSecPerCopy = getCard52LevelValue(nil, playerId, "night_duration_reduce_sec", 30)
|
|
totalReduceSec = totalReduceSec + reduceSecPerCopy * copies
|
|
end
|
|
)
|
|
return math.max(
|
|
0,
|
|
math.floor(totalReduceSec)
|
|
)
|
|
end
|
|
return ____exports
|