2019-11-03 17:49:58 +00:00
|
|
|
'use strict'
|
|
|
|
|
|
|
|
|
|
const MatchTransformer = use('App/Transformers/MatchTransformer')
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* BasicMatchTransformer class
|
|
|
|
|
*
|
|
|
|
|
* @class BasicMatchTransformer
|
|
|
|
|
*/
|
|
|
|
|
class BasicMatchTransformer extends MatchTransformer {
|
|
|
|
|
/**
|
2019-11-03 19:59:21 +00:00
|
|
|
* Transform raw data from Riot API
|
2019-11-16 16:43:55 +00:00
|
|
|
* @param matches data from Riot API, Array of match or a single match
|
2019-11-03 19:59:21 +00:00
|
|
|
* @param ctx context
|
2019-11-03 17:49:58 +00:00
|
|
|
*/
|
2019-11-16 16:43:55 +00:00
|
|
|
async transform(matches, { account }) {
|
|
|
|
|
await super.getContext()
|
2019-11-03 19:59:21 +00:00
|
|
|
|
2019-11-16 16:43:55 +00:00
|
|
|
if (Array.isArray(matches)) {
|
|
|
|
|
matches.forEach((match, index) => {
|
|
|
|
|
matches[index] = this.transformOneMatch(match, account)
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
matches = this.transformOneMatch(matches, account)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Transform raw data for 1 match
|
|
|
|
|
*/
|
|
|
|
|
transformOneMatch(match, account) {
|
2019-11-03 19:59:21 +00:00
|
|
|
// Global data about the match
|
2019-11-16 16:43:55 +00:00
|
|
|
const globalInfos = super.getGameInfos(match)
|
2019-11-03 19:59:21 +00:00
|
|
|
|
2019-11-03 17:49:58 +00:00
|
|
|
const participantId = match.participantIdentities.find((p) => p.player.currentAccountId === account.accountId).participantId
|
|
|
|
|
const player = match.participants[participantId - 1]
|
|
|
|
|
|
2019-11-03 19:59:21 +00:00
|
|
|
let win = match.teams.find((t) => t.teamId === player.teamId).win
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
// Match less than 5min
|
|
|
|
|
if (match.gameDuration < 300) {
|
|
|
|
|
win = 'Remake'
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-03 19:59:21 +00:00
|
|
|
// Player data
|
2019-11-16 16:43:55 +00:00
|
|
|
const playerData = super.getPlayerData(match, player, false)
|
2019-11-03 17:49:58 +00:00
|
|
|
|
2019-11-03 19:59:21 +00:00
|
|
|
// Teams data
|
2019-11-03 17:49:58 +00:00
|
|
|
const allyTeam = []
|
|
|
|
|
const enemyTeam = []
|
|
|
|
|
for (let summoner of match.participantIdentities) {
|
|
|
|
|
const allData = match.participants[summoner.participantId - 1]
|
|
|
|
|
const playerInfos = {
|
|
|
|
|
name: summoner.player.summonerName,
|
2019-11-16 16:43:55 +00:00
|
|
|
role: super.getRoleName(allData.timeline),
|
|
|
|
|
champion: (({ id, name }) => ({ id, name }))(Object.entries(this.champions).find(([, champion]) => Number(champion.key) === allData.championId)[1])
|
2019-11-03 17:49:58 +00:00
|
|
|
}
|
|
|
|
|
|
2019-11-03 19:59:21 +00:00
|
|
|
if (allData.teamId === player.teamId) {
|
2019-11-03 17:49:58 +00:00
|
|
|
allyTeam.push(playerInfos)
|
|
|
|
|
} else {
|
|
|
|
|
enemyTeam.push(playerInfos)
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-11-16 16:43:55 +00:00
|
|
|
allyTeam.sort(super.sortTeamByRole)
|
|
|
|
|
enemyTeam.sort(super.sortTeamByRole)
|
2019-11-03 17:49:58 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
summoner_puuid: account.puuid,
|
|
|
|
|
gameId: match.gameId,
|
|
|
|
|
result: win,
|
|
|
|
|
allyTeam,
|
2019-11-03 19:59:21 +00:00
|
|
|
enemyTeam,
|
|
|
|
|
...globalInfos,
|
|
|
|
|
...playerData
|
2019-11-03 17:49:58 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = new BasicMatchTransformer()
|