Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lua/wikis/commons/Icon/Data.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ return {
defuse = 'fas fa-wrench',
outoftime = 'fas fa-hourglass',
ace_valorant = 'fas fa-dagger',
round_winner = 'far fa-trophy-alt',
flawless_valorant = 'fas fa-gem',

-- Usage: Rumors, Predictions, etc.
correct = 'fas fa-check',
Expand Down
3 changes: 3 additions & 0 deletions lua/wikis/valorant/MatchGroup/Input/Custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ local VALORANT_REGIONS = {'eu', 'na', 'ap', 'kr', 'latam', 'br', 'pbe1', 'esport
---@field t1side ValorantSides
---@field t2side ValorantSides
---@field winningSide ValorantSides
---@field flawless boolean
---@field ceremony string
---@field ceremonyFor string?

---@class ValorantMapParserInterface
---@field getMap fun(mapInput: table): table
Expand Down Expand Up @@ -207,6 +209,7 @@ function MatchFunctions.calculateOverallStatsForOpponent(maps, opponentIndex)

return {
firstKills = getSumOf('firstKills'),
flawless = getSumOf('flawless'),
thrifties = getSumOf('thrifties'),
clutches = getSumOf('clutches'),
postPlant = postPlant,
Expand Down
65 changes: 54 additions & 11 deletions lua/wikis/valorant/MatchGroup/Input/Custom/MatchPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,31 @@ function CustomMatchGroupInputMatchPage.getRounds(map)
return ceremonyCode:sub(9)
end

---@param ceremony string?
---@param roundKills valorantMatchApiRoundKill[]
---@param winningTeam integer
---@return string?
local function processCeremony(ceremony, roundKills, winningTeam)
if ceremony == 'Clutch' then
local killsFromWinningTeam = Array.filter(
roundKills,
function (roundKill)
return Table.includes(map.teams[winningTeam].puuids, roundKill.killer)
end
)
return killsFromWinningTeam[#killsFromWinningTeam].killer
elseif ceremony == 'Ace' then
local _, killsByPlayer = Array.groupBy(roundKills, function (roundKill)
return roundKill.killer
end)
for killer, kills in pairs(killsByPlayer) do
if #kills >= 5 then
return killer
end
end
end
end

local t1start = CustomMatchGroupInputMatchPage.getFirstSide(map, 1, 'normal')
local t1startot = CustomMatchGroupInputMatchPage.getFirstSide(map, 1, 'ot')
local nextOvertimeSide = t1startot
Expand Down Expand Up @@ -249,27 +274,38 @@ function CustomMatchGroupInputMatchPage.getRounds(map)
return nil
end

---@type valorantMatchApiRoundKill
local firstKill = Array.min(
---@type valorantMatchApiRoundKill[]
local roundKills = Array.sortBy(
Array.flatMap(round.player_stats, function (player)
return player.kills or {}
end),
function (kill, fastestKill)
return (kill.time_since_round_start_millis or math.huge) < (
fastestKill.time_since_round_start_millis or math.huge)
Operator.property('time_since_round_start_millis')
)

local winningTeam = (t1side == makeShortSideName(round.winning_team_role)) and 1 or 2
local ceremony = mapCeremonyCodes(round.round_ceremony)
local flawless = Array.all(
roundKills,
function (roundKill)
return Table.includes(map.teams[winningTeam].puuids, roundKill.killer)
end
)

---@type valorantMatchApiRoundKill
local firstKill = roundKills[1]

---@type ValorantRoundData
return {
ceremony = mapCeremonyCodes(round.round_ceremony),
ceremony = ceremony,
ceremonyFor = processCeremony(ceremony, roundKills, winningTeam),
firstKill = Logic.isNotEmpty(firstKill) and {
killer = firstKill.killer,
victim = firstKill.victim,
byTeam = Table.includes(map.teams[1].puuids, firstKill.killer) and 1 or 2
} or {},
planted = round.plant_round_time > 0,
defused = round.defuse_round_time > 0,
flawless = flawless,
round = roundNumber,
t1side = t1side,
t2side = t2side,
Expand Down Expand Up @@ -302,16 +338,23 @@ function CustomMatchGroupInputMatchPage.extendMapOpponent(map, opponentIndex)
return round[teamSideKey] == 'atk' and round.planted
end)

---@param ceremony string
---@return integer
local function countCeremonies(ceremony)
return #Array.filter(rounds, function (round)
return round[teamSideKey] == round.winningSide and round.ceremony == ceremony
end)
end

return {
thrifties = #Array.filter(rounds, function (round)
return round[teamSideKey] == round.winningSide and round.ceremony == 'Thrifty'
thrifties = countCeremonies('Thrifty'),
flawless = #Array.filter(rounds, function (round)
return round[teamSideKey] == round.winningSide and round.flawless
end),
firstKills = #Array.filter(rounds, function (round)
return round.firstKill.byTeam == opponentIndex
end),
clutches = #Array.filter(rounds, function (round)
return round[teamSideKey] == round.winningSide and round.ceremony == 'Clutch'
end),
clutches = countCeremonies('Clutch'),
postPlant = {
#Array.filter(plantedRounds, function (round)
return round.winningSide == 'atk'
Expand Down
20 changes: 19 additions & 1 deletion lua/wikis/valorant/MatchPage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,12 @@ function MatchPage:_renderTeamStats(game)
team1Value = game.teams[1].thrifties,
team2Value = game.teams[2].thrifties
},
{
icon = IconFa{iconName = 'flawless_valorant'},
name = 'Flawless',
team1Value = game.teams[1].flawless,
team2Value = game.teams[2].flawless,
},
{
icon = IconImage{
imageLight = 'VALORANT Spike lightmode.png',
Expand Down Expand Up @@ -377,6 +383,9 @@ end
---@param puuid string
---@return {player: string, displayName: string}?
function MatchPage._findPlayerByPuuid(game, puuid)
if Logic.isEmpty(puuid) then
return
end
for _, opponent in ipairs(game.opponents) do
for _, player in ipairs(opponent.players) do
if player.puuid == puuid then
Expand Down Expand Up @@ -409,6 +418,8 @@ MatchPage._displayCeremony = FnUtil.memoize(function (ceremony)
imageDark = 'VALORANT Creds darkmode.png',
size = '16px',
}
elseif ceremony == 'Flawless' then
return IconFa{iconName = 'flawless_valorant'}
end
end

Expand Down Expand Up @@ -452,6 +463,7 @@ end
---@return Widget
function MatchPage:_renderRoundDetail(findPlayer, round, roundIndex)
local firstKillPlayer = findPlayer(round.firstKill.killer) or {}
local ceremonyPlayer = findPlayer(round.ceremonyFor)
local roundWinType = WIN_TYPES[round.winBy] or {}

return Div{
Expand Down Expand Up @@ -496,7 +508,13 @@ function MatchPage:_renderRoundDetail(findPlayer, round, roundIndex)
' ',
Link{link = firstKillPlayer.player, children = firstKillPlayer.displayName}
}},
MatchPage._displayCeremony(round.ceremony)
Span{children = WidgetUtil.collect(
MatchPage._displayCeremony(Logic.emptyOr(round.ceremony, round.flawless and 'Flawless' or nil)),
ceremonyPlayer and {
' ',
Link{link = ceremonyPlayer.player, children = ceremonyPlayer.displayName}
} or nil
)}
}

}
Expand Down
Loading