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

43 lines
1.8 KiB
Lua

--[[ Generated with https://github.com/TypeScriptToLua/TypeScriptToLua ]]
local ____exports = {}
--- Максимум игроков, между которыми делится командный пул наград квеста.
____exports.QUEST_REWARD_MAX_PLAYERS = 4
--- Золото на одного игрока при полной команде → суммарный пул команды.
function ____exports.questTeamGold(self, perPlayerGold)
if perPlayerGold <= 0 then
return 0
end
return math.floor(perPlayerGold * ____exports.QUEST_REWARD_MAX_PLAYERS)
end
--- Сколько частей при делении награды (не больше игроков в матче и не больше лимита).
function ____exports.getQuestRewardSplitCount(self, activePlayerCount)
if activePlayerCount <= 0 then
return 1
end
return math.min(activePlayerCount, ____exports.QUEST_REWARD_MAX_PLAYERS)
end
--- Делит сумму поровну; +1 к первым `remainder` игрокам.
function ____exports.splitQuestTeamReward(self, total, splitCount)
if total <= 0 or splitCount <= 0 then
return {}
end
local share = math.floor(total / splitCount)
local remainder = total % splitCount
local parts = {}
do
local i = 0
while i < splitCount do
parts[#parts + 1] = share + (i < remainder and 1 or 0)
i = i + 1
end
end
return parts
end
--- Доля золота на игрока при текущем размере команды (для UI).
function ____exports.getQuestGoldPerPlayerShare(self, teamGold, activePlayerCount)
local splitCount = ____exports.getQuestRewardSplitCount(nil, activePlayerCount)
local parts = ____exports.splitQuestTeamReward(nil, teamGold, splitCount)
return parts[1] or 0
end
return ____exports