2021-09-13 20:00:04 +00:00
|
|
|
import { getSeasonNumber, sortTeamByRole } from 'App/helpers'
|
2021-09-12 20:55:46 +00:00
|
|
|
import Match from 'App/Models/Match'
|
|
|
|
|
import MatchPlayer from 'App/Models/MatchPlayer'
|
2021-09-13 22:06:12 +00:00
|
|
|
import CDragonService from 'App/Services/CDragonService'
|
2021-09-12 20:55:46 +00:00
|
|
|
import MatchSerializer from './MatchSerializer'
|
2021-09-13 11:50:04 +00:00
|
|
|
import {
|
|
|
|
|
SerializedMatch,
|
|
|
|
|
SerializedMatchChampion,
|
|
|
|
|
SerializedMatchItem,
|
|
|
|
|
SerializedMatchPerks,
|
|
|
|
|
SerializedMatchStats,
|
|
|
|
|
SerializedMatchTeamPlayer,
|
|
|
|
|
} from './SerializedTypes'
|
2021-09-12 20:55:46 +00:00
|
|
|
|
|
|
|
|
class BasicMatchSerializer extends MatchSerializer {
|
|
|
|
|
/**
|
|
|
|
|
* Get champion specific data
|
|
|
|
|
* @param id of the champion
|
|
|
|
|
*/
|
|
|
|
|
protected getChampion(id: number): SerializedMatchChampion {
|
2021-09-13 22:06:12 +00:00
|
|
|
const originalChampionData = CDragonService.champions.find((c) => c.id === id)
|
2021-09-12 20:55:46 +00:00
|
|
|
const icon =
|
|
|
|
|
'https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/' +
|
|
|
|
|
originalChampionData!.squarePortraitPath.split('/assets/')[1].toLowerCase()
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
icon,
|
|
|
|
|
id: originalChampionData!.id,
|
|
|
|
|
name: originalChampionData!.name,
|
|
|
|
|
alias: originalChampionData!.alias,
|
|
|
|
|
roles: originalChampionData!.roles,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 11:50:04 +00:00
|
|
|
protected getPlayerSummary(player: MatchPlayer): SerializedMatchTeamPlayer {
|
|
|
|
|
return {
|
|
|
|
|
puuid: player.summonerPuuid,
|
|
|
|
|
champion: this.getChampion(player.championId),
|
|
|
|
|
name: player.summonerName,
|
|
|
|
|
role: player.teamPosition,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected getTeamSummary(players: MatchPlayer[]): SerializedMatchTeamPlayer[] {
|
2021-09-13 20:00:04 +00:00
|
|
|
return players.map((p) => this.getPlayerSummary(p)).sort(sortTeamByRole)
|
2021-09-13 11:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected getItems(player: MatchPlayer): Array<SerializedMatchItem | null> {
|
|
|
|
|
const items: (SerializedMatchItem | null)[] = []
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
const id = player['item' + i]
|
|
|
|
|
if (id === 0) {
|
|
|
|
|
items.push(null)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-13 22:06:12 +00:00
|
|
|
const item = CDragonService.items.find((i) => i.id === id)
|
2021-09-13 11:50:04 +00:00
|
|
|
if (!item) {
|
|
|
|
|
items.push(null)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const itemUrl = item.iconPath.split('/assets/')[1].toLowerCase()
|
|
|
|
|
items.push({
|
|
|
|
|
image: `https://raw.communitydragon.org/latest/plugins/rcp-be-lol-game-data/global/default/${itemUrl}`,
|
|
|
|
|
name: item.name,
|
|
|
|
|
description: item.description,
|
|
|
|
|
price: item.priceTotal,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
return items
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected getPerks(player: MatchPlayer): SerializedMatchPerks {
|
|
|
|
|
return {
|
|
|
|
|
primaryStyle: player.perksPrimaryStyle,
|
|
|
|
|
secondaryStyle: player.perksSecondaryStyle,
|
|
|
|
|
selected: player.perksSelected,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected getStats(player: MatchPlayer): SerializedMatchStats {
|
|
|
|
|
return {
|
|
|
|
|
kills: player.kills,
|
|
|
|
|
deaths: player.deaths,
|
|
|
|
|
assists: player.assists,
|
|
|
|
|
minions: player.minions,
|
|
|
|
|
vision: player.visionScore,
|
|
|
|
|
gold: player.gold,
|
|
|
|
|
dmgChamp: player.damageDealtChampions,
|
|
|
|
|
dmgObj: player.damageDealtObjectives,
|
|
|
|
|
dmgTaken: player.damageTaken,
|
|
|
|
|
kp: player.kp,
|
|
|
|
|
kda: player.kills + player.assists !== 0 && player.deaths === 0 ? '∞' : player.kda,
|
|
|
|
|
realKda: player.kda,
|
|
|
|
|
criticalStrike: player.criticalStrike,
|
|
|
|
|
killingSpree: player.killingSpree,
|
|
|
|
|
doubleKills: player.doubleKills,
|
|
|
|
|
tripleKills: player.tripleKills,
|
|
|
|
|
quadraKills: player.quadraKills,
|
|
|
|
|
pentaKills: player.pentaKills,
|
|
|
|
|
heal: player.heal,
|
|
|
|
|
towers: player.turretKills,
|
|
|
|
|
longestLiving: player.timeSpentLiving,
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-12 20:55:46 +00:00
|
|
|
|
2021-09-13 22:06:12 +00:00
|
|
|
public serializeOneMatch(match: Match, puuid: string): SerializedMatch {
|
2021-09-13 20:00:04 +00:00
|
|
|
const identity = match.players.find((p) => p.summonerPuuid === puuid)!
|
2021-09-12 20:55:46 +00:00
|
|
|
|
2021-09-13 11:50:04 +00:00
|
|
|
const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam'
|
2021-09-13 20:00:04 +00:00
|
|
|
const allyTeam = match[allyTeamColor]
|
2021-09-13 11:50:04 +00:00
|
|
|
|
|
|
|
|
const allyPlayers: MatchPlayer[] = []
|
|
|
|
|
const enemyPlayers: MatchPlayer[] = []
|
|
|
|
|
|
2021-09-13 20:00:04 +00:00
|
|
|
for (const p of match.players) {
|
2021-09-13 22:06:12 +00:00
|
|
|
p.team === identity.team ? allyPlayers.push(p) : enemyPlayers.push(p)
|
2021-09-13 11:50:04 +00:00
|
|
|
}
|
|
|
|
|
|
2021-09-12 20:55:46 +00:00
|
|
|
return {
|
2021-09-13 11:50:04 +00:00
|
|
|
allyTeam: this.getTeamSummary(allyPlayers),
|
2021-09-12 20:55:46 +00:00
|
|
|
champion: this.getChampion(identity.championId),
|
|
|
|
|
date: match.date,
|
2021-09-13 11:50:04 +00:00
|
|
|
enemyTeam: this.getTeamSummary(enemyPlayers),
|
2021-09-12 20:55:46 +00:00
|
|
|
firstSum: identity.summoner1Id,
|
|
|
|
|
matchId: match.id,
|
|
|
|
|
gamemode: match.gamemode,
|
2021-09-13 11:50:04 +00:00
|
|
|
items: this.getItems(identity),
|
2021-09-12 20:55:46 +00:00
|
|
|
level: identity.champLevel,
|
|
|
|
|
map: match.map,
|
|
|
|
|
name: identity.summonerName,
|
2021-09-13 11:50:04 +00:00
|
|
|
perks: this.getPerks(identity),
|
2021-09-12 20:55:46 +00:00
|
|
|
region: match.region,
|
2021-09-13 21:04:52 +00:00
|
|
|
result: allyTeam.result,
|
2021-09-13 22:06:12 +00:00
|
|
|
role: identity.teamPosition.length ? identity.teamPosition : 'NONE',
|
2021-09-12 20:55:46 +00:00
|
|
|
season: getSeasonNumber(match.date),
|
|
|
|
|
secondSum: identity.summoner2Id,
|
2021-09-13 11:50:04 +00:00
|
|
|
stats: this.getStats(identity),
|
2021-09-12 20:55:46 +00:00
|
|
|
summonerId: identity.summonerId,
|
|
|
|
|
summonerPuuid: puuid,
|
|
|
|
|
time: match.gameDuration,
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-09-13 22:06:12 +00:00
|
|
|
public serialize(matches: Match[], puuid: string): SerializedMatch[] {
|
|
|
|
|
return matches.map((match) => this.serializeOneMatch(match, puuid))
|
2021-09-12 20:55:46 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default new BasicMatchSerializer()
|