fix: add summoner roles only to specific gamemodes

This commit is contained in:
Valentin Kaelin 2020-06-16 21:36:39 +02:00
parent 9552d2b103
commit 30301e7cd2
4 changed files with 26 additions and 6 deletions

View file

@ -55,7 +55,7 @@ class BasicMatchTransformer extends MatchTransformer {
const playerInfos = { const playerInfos = {
account_id: summoner.player.currentAccountId, account_id: summoner.player.currentAccountId,
name: summoner.player.summonerName, name: summoner.player.summonerName,
role: super.getRoleName(allData.timeline), role: super.getRoleName(allData.timeline, match.queueId),
champion: super.getChampion(allData.championId) champion: super.getChampion(allData.championId)
} }

View file

@ -3,6 +3,7 @@
const MatchTransformer = use('App/Transformers/MatchTransformer') const MatchTransformer = use('App/Transformers/MatchTransformer')
const RoleIdentificationService = use('App/Services/RoleIdentificationService') const RoleIdentificationService = use('App/Services/RoleIdentificationService')
const SummonerService = use('App/Services/SummonerService') const SummonerService = use('App/Services/SummonerService')
const { queuesWithRole } = use('App/helpers')
/** /**
* LiveMatchTransformer class * LiveMatchTransformer class
@ -42,7 +43,7 @@ class LiveMatchTransformer extends MatchTransformer {
const redTeam = [] // 200 const redTeam = [] // 200
let blueRoles = [] let blueRoles = []
let redRoles = [] let redRoles = []
if (this.championRoles) { if (this.championRoles && queuesWithRole.includes(match.gameQueueConfigId)) {
match.participants.map(p => { match.participants.map(p => {
const playerRole = { champion: p.championId, jungle: p.spell1Id === 11 || p.spell2Id === 11 } const playerRole = { champion: p.championId, jungle: p.spell1Id === 11 || p.spell2Id === 11 }
p.teamId === 100 ? blueTeam.push(playerRole) : redTeam.push(playerRole) p.teamId === 100 ? blueTeam.push(playerRole) : redTeam.push(playerRole)

View file

@ -1,8 +1,8 @@
'use strict' 'use strict'
const Jax = use('App/Services/Jax') const Jax = use('App/Services/Jax')
const Helpers = use('App/helpers')
const RoleIdentificationService = use('App/Services/RoleIdentificationService') const RoleIdentificationService = use('App/Services/RoleIdentificationService')
const { queuesWithRole, sortTeamByRole } = use('App/helpers')
/** /**
* MatchTransformer class * MatchTransformer class
@ -27,7 +27,7 @@ class MatchTransformer {
this.perkstyles = perkstyles.styles this.perkstyles = perkstyles.styles
this.summonerSpells = summonerSpells this.summonerSpells = summonerSpells
this.championRoles = championRoles this.championRoles = championRoles
this.sortTeamByRole = Helpers.sortTeamByRole this.sortTeamByRole = sortTeamByRole
// League of Legends seasons timestamps // League of Legends seasons timestamps
this.seasons = { this.seasons = {
@ -79,7 +79,7 @@ class MatchTransformer {
const identity = match.participantIdentities.find(p => p.participantId === player.participantId) const identity = match.participantIdentities.find(p => p.participantId === player.participantId)
const name = identity.player.summonerName const name = identity.player.summonerName
const champion = this.getChampion(player.championId) const champion = this.getChampion(player.championId)
const role = this.getRoleName(player.timeline) const role = this.getRoleName(player.timeline, match.queueId)
const level = player.stats.champLevel const level = player.stats.champLevel
// Regular stats / Full match stats // Regular stats / Full match stats
@ -193,11 +193,17 @@ class MatchTransformer {
/** /**
* Return the lane of the summoner according to timeline * Return the lane of the summoner according to timeline
* @param timeline from Riot Api * @param timeline from Riot Api
* @param gamemode of the match to check if a role is needed
*/ */
getRoleName(timeline) { getRoleName(timeline, gamemode) {
if(!queuesWithRole.includes(gamemode)) {
return 'NONE'
}
if (timeline.lane === 'BOTTOM' && timeline.role.includes('SUPPORT')) { if (timeline.lane === 'BOTTOM' && timeline.role.includes('SUPPORT')) {
return 'SUPPORT' return 'SUPPORT'
} }
return timeline.lane return timeline.lane
} }

View file

@ -1,3 +1,15 @@
/**
* League of Legends queues with defined role for each summoner
*/
const queuesWithRole = [
0, // Custom
400, // Draft
420, // Solo/Duo
430, // Blind,
440, // Flex
700, // Clash
]
/** /**
* League of Legends seasons timestamps * League of Legends seasons timestamps
*/ */
@ -7,6 +19,7 @@ const seasons = {
} }
module.exports = { module.exports = {
queuesWithRole,
seasons, seasons,
/** /**
* Get season number for a match * Get season number for a match