From 7bbf5edb4acab88ab26903e43c0523fabaac1cb2 Mon Sep 17 00:00:00 2001 From: Valentin Kaelin Date: Thu, 25 Jun 2020 14:05:44 +0200 Subject: [PATCH] feat: set player role to support if 1 player in the team has a supp item --- .../app/Services/RoleIdentificationService.js | 9 ++++++-- server/app/Transformers/MatchTransformer.js | 23 ++++++++++++------- server/app/helpers.js | 6 +++++ 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/server/app/Services/RoleIdentificationService.js b/server/app/Services/RoleIdentificationService.js index 1829e38..9393079 100644 --- a/server/app/Services/RoleIdentificationService.js +++ b/server/app/Services/RoleIdentificationService.js @@ -143,8 +143,9 @@ class RoleIdentificationService { * @param championPositions * @param composition * @param jungle + * @param support */ - getRoles(championPositions, composition, jungle = null) { + getRoles(championPositions, composition, jungle = null, support = null) { const identified = {} let positions = {} let secondaryPositions = null @@ -154,10 +155,14 @@ class RoleIdentificationService { identified['JUNGLE'] = jungle } + if (support) { + identified['UTILITY'] = support + } + while (Object.keys(identified).length < composition.length - 1) { let { bestPositions, bestMetric: metric, secondBestPositions: sbp } = this._getPositions(championPositions, composition, - identified.TOP, identified.JUNGLE, identified.MIDDLE, identified.ADC, identified.SUPPORT + identified.TOP, identified.JUNGLE, identified.MIDDLE, identified.ADC, identified.UTILITY ) positions = bestPositions diff --git a/server/app/Transformers/MatchTransformer.js b/server/app/Transformers/MatchTransformer.js index 7f35d2d..bfa5b03 100644 --- a/server/app/Transformers/MatchTransformer.js +++ b/server/app/Transformers/MatchTransformer.js @@ -2,7 +2,7 @@ const Jax = use('App/Services/Jax') const RoleIdentificationService = use('App/Services/RoleIdentificationService') -const { getSeasonNumber, queuesWithRole, sortTeamByRole } = use('App/helpers') +const { getSeasonNumber, queuesWithRole, sortTeamByRole, supportItems } = use('App/helpers') /** * MatchTransformer class @@ -198,10 +198,12 @@ class MatchTransformer { * @param team 5 champions + smite from a team */ getTeamRoles(team) { - const teamJunglers = team.filter(p => p.jungle) + const teamJunglers = team.filter(p => p.jungle && !p.support) const jungle = teamJunglers.length === 1 ? teamJunglers[0].champion : null + const teamSupports = team.filter(p => p.support && !p.jungle) + const support = teamSupports.length === 1 ? teamSupports[0].champion : null - return RoleIdentificationService.getRoles(this.championRoles, team.map(p => p.champion), jungle) + return RoleIdentificationService.getRoles(this.championRoles, team.map(p => p.champion), jungle, support) } /** @@ -211,10 +213,10 @@ class MatchTransformer { * @param {Object} playerData data of the searched player, only for basic matches */ updateTeamRoles(team, champs, playerData = null) { - const actualRoles = [...new Set(team.map(p => p.role))] - if (actualRoles.length === 5) { - return - } + // const actualRoles = [...new Set(team.map(p => p.role))] + // if (actualRoles.length === 5) { + // return + // } champs = this.getTeamRoles(champs) for (const summoner of team) { @@ -242,7 +244,12 @@ class MatchTransformer { let allyChamps = [] let enemyChamps = [] match.participants.map(p => { - const playerRole = { champion: p.championId, jungle: p.spell1Id === 11 || p.spell2Id === 11 } + const items = [p.stats.item0, p.stats.item1, p.stats.item2, p.stats.item3, p.stats.item4, p.stats.item5] + const playerRole = { + champion: p.championId, + jungle: p.spell1Id === 11 || p.spell2Id === 11, + support: supportItems.some(suppItem => items.includes(suppItem)) + } p.teamId === allyTeamId ? allyChamps.push(playerRole) : enemyChamps.push(playerRole) }) diff --git a/server/app/helpers.js b/server/app/helpers.js index 09ee708..56f070c 100644 --- a/server/app/helpers.js +++ b/server/app/helpers.js @@ -18,9 +18,15 @@ const seasons = { 1578628800000: 10 } +/** +* League of Legends all support item ids +*/ +const supportItems = [3850, 3851, 3853, 3854, 3855, 3857, 3858, 3859, 3860, 3862, 3863, 3864] + module.exports = { queuesWithRole, seasons, + supportItems, /** * Get season number for a match */