2021-12-11 18:30:04 +00:00
|
|
|
import { PlayerRole, queuesWithRole, smiteIds } from 'App/helpers'
|
2021-09-17 20:57:57 +00:00
|
|
|
import CDragonService from 'App/Services/CDragonService'
|
|
|
|
|
import { CurrentGameInfoDTO } from 'App/Services/Jax/src/Endpoints/SpectatorEndpoint'
|
|
|
|
|
import { RoleComposition } from 'App/Services/RoleIdentificationService'
|
|
|
|
|
import SummonerService from 'App/Services/SummonerService'
|
|
|
|
|
import MatchSerializer from './MatchSerializer'
|
|
|
|
|
import { SerializedLiveMatch, SerializedLiveMatchPlayer } from './SerializedTypes'
|
|
|
|
|
|
|
|
|
|
class LiveMatchSerializer extends MatchSerializer {
|
|
|
|
|
public async serializeOneMatch(
|
|
|
|
|
liveMatch: CurrentGameInfoDTO,
|
|
|
|
|
region: string
|
|
|
|
|
): Promise<SerializedLiveMatch> {
|
|
|
|
|
// Roles
|
|
|
|
|
const blueTeam: PlayerRole[] = [] // 100
|
|
|
|
|
const redTeam: PlayerRole[] = [] // 200
|
|
|
|
|
let blueRoles: RoleComposition = {}
|
|
|
|
|
let redRoles: RoleComposition = {}
|
|
|
|
|
const needsRole =
|
|
|
|
|
CDragonService.championRoles &&
|
|
|
|
|
(queuesWithRole.includes(liveMatch.gameQueueConfigId) ||
|
|
|
|
|
(liveMatch.gameType === 'CUSTOM_GAME' && liveMatch.participants.length === 10))
|
|
|
|
|
|
|
|
|
|
if (needsRole) {
|
|
|
|
|
liveMatch.participants.map((p) => {
|
|
|
|
|
const playerRole = {
|
|
|
|
|
champion: p.championId,
|
2021-12-11 18:30:04 +00:00
|
|
|
jungle: smiteIds.includes(p.spell1Id) || smiteIds.includes(p.spell2Id),
|
2021-09-17 20:57:57 +00:00
|
|
|
}
|
|
|
|
|
p.teamId === 100 ? blueTeam.push(playerRole) : redTeam.push(playerRole)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
blueRoles = super.getTeamRoles(blueTeam)
|
|
|
|
|
redRoles = super.getTeamRoles(redTeam)
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-07 18:57:59 +00:00
|
|
|
// Accounts
|
|
|
|
|
const requestsAccounts = liveMatch.participants.map((p) =>
|
|
|
|
|
SummonerService.getAccount(p.puuid, region)
|
|
|
|
|
)
|
|
|
|
|
const accounts = await Promise.all(requestsAccounts)
|
|
|
|
|
|
2021-09-17 20:57:57 +00:00
|
|
|
// Ranks
|
|
|
|
|
const requestsRanks = liveMatch.participants.map((p) =>
|
2025-08-12 20:10:58 +00:00
|
|
|
SummonerService.getRanked(p.puuid, region)
|
2021-09-17 20:57:57 +00:00
|
|
|
)
|
|
|
|
|
const ranks = await Promise.all(requestsRanks)
|
|
|
|
|
|
|
|
|
|
// Players
|
|
|
|
|
const players: SerializedLiveMatchPlayer[] = liveMatch.participants.map((player, index) => {
|
|
|
|
|
let role: string | undefined
|
|
|
|
|
|
|
|
|
|
// Roles
|
|
|
|
|
if (needsRole) {
|
|
|
|
|
const roles = player.teamId === 100 ? blueRoles : redRoles
|
|
|
|
|
role = Object.entries(roles).find(([, champion]) => player.championId === champion)![0]
|
|
|
|
|
}
|
2021-09-29 20:28:35 +00:00
|
|
|
|
|
|
|
|
const perks = player.perks
|
|
|
|
|
? {
|
|
|
|
|
primaryStyle: player.perks.perkStyle,
|
|
|
|
|
secondaryStyle: player.perks.perkSubStyle,
|
|
|
|
|
selected: player.perks.perkIds,
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
|
2021-09-17 20:57:57 +00:00
|
|
|
return {
|
|
|
|
|
...player,
|
|
|
|
|
role,
|
2024-11-07 18:57:59 +00:00
|
|
|
...accounts[index],
|
2021-09-17 20:57:57 +00:00
|
|
|
rank: ranks[index],
|
|
|
|
|
champion: this.getChampion(player.championId),
|
2021-09-29 20:28:35 +00:00
|
|
|
perks,
|
2021-12-11 18:24:10 +00:00
|
|
|
summonerSpell1: this.getSummonerSpell(player.spell1Id),
|
|
|
|
|
summonerSpell2: this.getSummonerSpell(player.spell2Id),
|
2021-09-17 20:57:57 +00:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
gameId: liveMatch.gameId,
|
|
|
|
|
gameType: liveMatch.gameType,
|
|
|
|
|
gameStartTime: liveMatch.gameStartTime,
|
|
|
|
|
mapId: liveMatch.mapId,
|
|
|
|
|
gameLength: liveMatch.gameLength,
|
|
|
|
|
platformId: liveMatch.platformId,
|
|
|
|
|
gameMode: liveMatch.gameMode,
|
|
|
|
|
bannedChampions: liveMatch.bannedChampions,
|
|
|
|
|
gameQueueConfigId: liveMatch.gameQueueConfigId,
|
|
|
|
|
observers: liveMatch.observers,
|
|
|
|
|
participants: players,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new LiveMatchSerializer()
|