Skip to content

Commit

Permalink
start refactoring points handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Rathoz committed Dec 10, 2024
1 parent 61efb80 commit 7ae181b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 37 deletions.
50 changes: 25 additions & 25 deletions components/match2/commons/match_group_input_util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1460,17 +1460,7 @@ end
---@param match table
---@return {score: table, status: table, settings: table}
function MatchGroupInputUtil.parseSettings(match, opponentCount)
-- Score Settings
local scoreSettings = {
kill = Array.map(Array.range(1, opponentCount), function(index)
return tonumber(match['p' .. index .. '_kill']) or tonumber(match.p_kill) or 1
end),
placement = Array.map(Array.range(1, opponentCount), function(index)
return tonumber(match['p' .. index]) or 0
end)
}

-- Status colors (up/down etc)
-- Pre-parse Status colors (up/down etc)
local statusParsed = {}
Array.forEach(Array.parseCommaSeparatedString(match.bg, ','), function (status)
local placements, color = unpack(Array.parseCommaSeparatedString(status, '='))
Expand All @@ -1482,13 +1472,18 @@ function MatchGroupInputUtil.parseSettings(match, opponentCount)
end)
end)

local statusSettings = Array.map(Array.range(1, opponentCount), function(index)
return statusParsed[index] or ''
-- Info per Placement
local placementInfo = Array.map(Array.range(1, opponentCount), function(index)
return {
placement = index,
killPoints = tonumber(match['p' .. index .. '_kill']) or tonumber(match.p_kill),
placementPoints = tonumber(match['p' .. index]) or 0,
status = statusParsed[index],
}
end)

return {
score = scoreSettings,
status = statusSettings,
placementInfo = placementInfo,
settings = {
showGameDetails = Logic.nilOr(Logic.readBoolOrNil(match.showgamedetails), true),
showKills = Logic.nilOr(Logic.readBoolOrNil(match.showkills), true),
Expand All @@ -1498,9 +1493,9 @@ function MatchGroupInputUtil.parseSettings(match, opponentCount)
end

---@param scoreDataInput table?
---@param scoreSettings {kill: integer[], placement: integer[]}
---@param placementsInfo {killPoints: number, placement: integer, placementPoints: number}[]
---@return table
function MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(scoreDataInput, scoreSettings)
function MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(scoreDataInput, placementsInfo)
if not scoreDataInput then
return {}
end
Expand All @@ -1510,18 +1505,23 @@ function MatchGroupInputUtil.makeBattleRoyaleMapOpponentDetails(scoreDataInput,
local placement, kills = tonumber(scoreDataInput[1]), tonumber(scoreDataInput[2])
local manualPoints = tonumber(scoreDataInput.p)
if placement or kills then
local minimumKillPoints = Array.reduce(scoreSettings.kill, math.min, math.huge)
if placement then
scoreBreakdown.placePoints = scoreSettings.placement[placement] or 0
end
if kills then
scoreBreakdown.killPoints = kills * (scoreSettings.kill[placement] or minimumKillPoints)
scoreBreakdown.kills = kills
local minimumKillPoints = Array.reduce(
Array.map(placementsInfo, Operator.property('killPoints')),
math.min,
math.huge
)
local placementInfo = placementsInfo[placement] or {}
scoreBreakdown.placePoints = placementInfo.placementPoints or 0
scoreBreakdown.kills = kills

local pointsPerKill = placementInfo.killPoints or minimumKillPoints
if kills and pointsPerKill ~= math.huge then
scoreBreakdown.killPoints = scoreBreakdown.kills * pointsPerKill
end
scoreBreakdown.totalPoints = (scoreBreakdown.placePoints or 0) + (scoreBreakdown.killPoints or 0)
end

local opponent = {
local opponent ={
status = MatchGroupInputUtil.STATUS.SCORE,
scoreBreakdown = scoreBreakdown,
placement = placement,
Expand Down
16 changes: 6 additions & 10 deletions components/match2/commons/match_summary_ffa.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,26 +361,22 @@ end
---@param match table
---@return {kill: number, placement: {rangeStart: integer, rangeEnd: integer, score:number}[]}
function MatchSummaryFfa.createScoringData(match)
local scoreSettings = match.extradata.scoring

local scores = Array.map(scoreSettings.placement or {}, function(placementScore, placement)
return {placementPoints = placementScore, killPoints = (scoreSettings.kill or {})[placement]}
end)
local scoreSettings = match.extradata.placementinfo

local newScores = {}
local lastData = {}
for placement, score in ipairs(scores) do
if Table.deepEquals(lastData, score) then
for placement, placementData in ipairs(scoreSettings) do
if Table.deepEquals(lastData, placementData) then
newScores[#newScores].rangeEnd = newScores[#newScores].rangeEnd + 1
else
table.insert(newScores, {
rangeStart = placement,
rangeEnd = placement,
killScore = score.killPoints,
placementScore = score.placementPoints,
killScore = placementData.killPoints,
placementScore = placementData.placementPoints,
})
end
lastData = score
lastData = placementData
end
return newScores
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ end
---@return table
function MatchFunctions.getExtraData(match, games, opponents, settings)
return {
scoring = settings.score,
status = settings.status,
placementinfo = settings.placementInfo,
settings = settings.settings,
}
end
Expand Down

0 comments on commit 7ae181b

Please sign in to comment.