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

153 lines
5.8 KiB
Lua

local ____lualib = require("lualib_bundle")
local __TS__Number = ____lualib.__TS__Number
local __TS__NumberIsFinite = ____lualib.__TS__NumberIsFinite
local __TS__ObjectEntries = ____lualib.__TS__ObjectEntries
local ____exports = {}
local applyCard69OtherCardsEfficiencyMul, asLeveledValues, getCardLevel, CARD_GLOBAL_EFFICIENCY_DEBUFF_ID
local ____card_data = require("cards.card_data")
local CARD_DATABASE = ____card_data.CARD_DATABASE
function applyCard69OtherCardsEfficiencyMul(self, value, cardId, hero)
if cardId == CARD_GLOBAL_EFFICIENCY_DEBUFF_ID then
return value
end
if not hero or not IsValidEntity(hero) or not hero:IsRealHero() then
return value
end
if not hero:HasModifier("modifier_card_69") then
return value
end
local weakerPct = ____exports.getCardValueByLevel(
nil,
CARD_GLOBAL_EFFICIENCY_DEBUFF_ID,
hero,
"other_cards_effectiveness_pct",
50
)
local clamped = math.max(
0,
math.min(100, weakerPct)
)
local mult = 1 - clamped / 100
return value * mult
end
function asLeveledValues(self, raw)
if raw == nil or raw == nil then
return nil
end
if type(raw) ~= "table" then
return nil
end
local result = {}
local tableRaw = raw
do
local i = 1
while i <= 32 do
local value = tableRaw[i]
local numeric = __TS__Number(value)
if value ~= nil and value ~= nil and __TS__NumberIsFinite(numeric) then
result[i] = numeric
end
i = i + 1
end
end
for ____, ____value in ipairs(__TS__ObjectEntries(tableRaw)) do
local keyRaw = ____value[1]
local value = ____value[2]
do
local level = __TS__Number(keyRaw)
if not __TS__NumberIsFinite(level) then
goto __continue11
end
local levelInt = math.floor(level)
if levelInt < 1 then
goto __continue11
end
local numeric = __TS__Number(value)
if not __TS__NumberIsFinite(numeric) then
goto __continue11
end
result[levelInt] = numeric
end
::__continue11::
end
return result
end
function getCardLevel(self, hero, cardId)
local level = 1
if hero and IsValidEntity(hero) then
local heroUnsafe = hero
if type(heroUnsafe.IsRealHero) == "function" and not heroUnsafe:IsRealHero() then
return 1
end
local owner = type(heroUnsafe.GetPlayerOwner) == "function" and heroUnsafe:GetPlayerOwner() or nil
if owner and owner.cardSystem then
level = owner.cardSystem:GetCardLevel(cardId)
else
local playerOwnerId = type(heroUnsafe.GetPlayerOwnerID) == "function" and heroUnsafe:GetPlayerOwnerID() or -1
local directPlayerId = type(heroUnsafe.GetPlayerID) == "function" and heroUnsafe:GetPlayerID() or -1
local playerId = playerOwnerId >= 0 and playerOwnerId or directPlayerId
local safePlayerResource = _G.PlayerResource
if playerId >= 0 and safePlayerResource then
local player = safePlayerResource:GetPlayer(playerId)
local ____opt_2 = player and player.cardSystem
local levelFromSystem = ____opt_2 and ____opt_2:GetCardLevel(cardId)
if __TS__NumberIsFinite(levelFromSystem) then
level = levelFromSystem
end
end
if level <= 1 and playerId >= 0 then
local levelsData = CustomNetTables:GetTableValue(
"cards",
"card_levels_" .. tostring(playerId)
)
local levelEntry = levelsData and levelsData[tostring(cardId)]
local levelFromNettable = __TS__Number(levelEntry and levelEntry.level or 1)
if __TS__NumberIsFinite(levelFromNettable) and levelFromNettable > 0 then
level = levelFromNettable
end
end
end
end
local safeLevel = __TS__NumberIsFinite(level) and level or 1
return math.max(
1,
math.floor(safeLevel)
)
end
--- Значение карты с учетом уровня (если в каталоге указан массив значений по уровням).
function ____exports.getCardValueByLevel(self, cardId, hero, key, fallback, explicitLevel)
local safeFallback = __TS__NumberIsFinite(fallback) and fallback or 0
local ____opt_12 = CARD_DATABASE[cardId]
local ____opt_10 = ____opt_12 and ____opt_12.values
local raw = ____opt_10 and ____opt_10[key]
if raw == nil or raw == nil then
return applyCard69OtherCardsEfficiencyMul(nil, safeFallback, cardId, hero)
end
local level = explicitLevel ~= nil and __TS__NumberIsFinite(explicitLevel) and math.max(
1,
math.floor(explicitLevel)
) or getCardLevel(nil, hero, cardId)
if type(raw) ~= "table" then
local numeric = __TS__Number(raw)
local resolved = __TS__NumberIsFinite(numeric) and numeric or safeFallback
return applyCard69OtherCardsEfficiencyMul(nil, resolved, cardId, hero)
end
local leveled = asLeveledValues(nil, raw)
if not leveled then
return applyCard69OtherCardsEfficiencyMul(nil, safeFallback, cardId, hero)
end
do
local current = level
while current >= 1 do
local value = leveled[current]
if value ~= nil and value ~= nil and __TS__NumberIsFinite(value) then
return applyCard69OtherCardsEfficiencyMul(nil, value, cardId, hero)
end
current = current - 1
end
end
return applyCard69OtherCardsEfficiencyMul(nil, safeFallback, cardId, hero)
end
CARD_GLOBAL_EFFICIENCY_DEBUFF_ID = 69
return ____exports