|
| 1 | +/// <reference path="../src/electron/typings/EndGame.d.ts" /> |
| 2 | + |
| 3 | +class Honor { |
| 4 | + constructor() { |
| 5 | + this.name = 'Auto Honor'; |
| 6 | + this.description = 'Automatically honors'; |
| 7 | + this.active = true; |
| 8 | + this.endpoint = '/lol-gameflow/v1/gameflow-phase'; |
| 9 | + } |
| 10 | + |
| 11 | + setup() { |
| 12 | + console.log('Honor.js loaded.'); |
| 13 | + |
| 14 | + const configuration = [ |
| 15 | + { id: 'honor.system', type: 'radio', value: 'Shotcalling', options: ['Cool', 'Shotcalling', 'GG', 'Skip'] }, |
| 16 | + { id: 'honor.player.type', type: 'radio', value: 'Best Player', options: ['Best Player', 'Random', 'Custom'] }, |
| 17 | + { id: 'honor.player.name', type: 'text', value: 'GR0236621563#EUW' }, // temp |
| 18 | + ]; |
| 19 | + |
| 20 | + return configuration; |
| 21 | + } |
| 22 | + |
| 23 | + async execute(getSetting, lcu, event) { |
| 24 | + if (event.data !== 'PreEndOfGame') return; |
| 25 | + |
| 26 | + const response = await lcu.request({ method: 'GET', url: '/lol-honor-v2/v1/ballot' }); |
| 27 | + const honorList = await response.json(); |
| 28 | + |
| 29 | + if (!honorList.eligiblePlayers.length) return; |
| 30 | + |
| 31 | + const honorsTypes = { |
| 32 | + Cool: 'COOL', |
| 33 | + Shotcalling: 'SHOTCALLER', |
| 34 | + GG: 'HEART', |
| 35 | + Skip: 'OPT_OUT', |
| 36 | + }; |
| 37 | + |
| 38 | + const honorSystem = getSetting('honor.system'); |
| 39 | + const honorType = getSetting('honor.player.type'); |
| 40 | + |
| 41 | + if (honorSystem.value === 'Skip') { |
| 42 | + const honor = { |
| 43 | + gameId: honorList.gameId, |
| 44 | + honorType: honorsTypes[honorSystem.value], |
| 45 | + puuid: '', |
| 46 | + summonerId: 0, |
| 47 | + }; |
| 48 | + |
| 49 | + const isHonored = await lcu.request({ method: 'POST', url: '/lol-honor-v2/v1/honor-player', body: honor }); |
| 50 | + const data = await isHonored.json(); |
| 51 | + console.log('Skiped.', JSON.parse(data)); |
| 52 | + return; |
| 53 | + } |
| 54 | + |
| 55 | + let player; |
| 56 | + switch (honorType.value) { |
| 57 | + case 'Random': |
| 58 | + player = this.random(honorList.eligiblePlayers); |
| 59 | + break; |
| 60 | + |
| 61 | + case 'Custom': |
| 62 | + const customPlayer = getSetting('honor.player.name'); |
| 63 | + const [customName, customTag] = customPlayer.value.split('#'); |
| 64 | + const response = await lcu.request({ method: 'GET', url: `/lol-summoner/v1/summoners?name=${customName}%23${customTag}` }); |
| 65 | + player = await response.json(); |
| 66 | + break; |
| 67 | + |
| 68 | + default: |
| 69 | + const gameResponse = await lcu.request({ method: 'GET', url: '/lol-end-of-game/v1/eog-stats-block' }); |
| 70 | + const gameStats = await gameResponse.json(); |
| 71 | + player = this.bestPlayer(gameStats.teams); |
| 72 | + break; |
| 73 | + } |
| 74 | + |
| 75 | + const honor = { |
| 76 | + gameId: honorList.gameId, |
| 77 | + honorType: honorsTypes[honorSystem.value], |
| 78 | + puuid: player.puuid, |
| 79 | + summonerId: player.summonerId, |
| 80 | + }; |
| 81 | + |
| 82 | + const isHonored = await lcu.request({ method: 'POST', url: '/lol-honor-v2/v1/honor-player', body: honor }); |
| 83 | + const data = await isHonored.json(); |
| 84 | + console.log('Done.', JSON.parse(data)); |
| 85 | + } |
| 86 | + |
| 87 | + bestPlayer(teams) { |
| 88 | + let bestPlayer = null; |
| 89 | + let highestScore = -Infinity; |
| 90 | + |
| 91 | + for (const team of teams) { |
| 92 | + if (!team.isPlayerTeam) continue; |
| 93 | + |
| 94 | + for (const player of team.players) { |
| 95 | + if (player.isLocalPlayer) continue; |
| 96 | + |
| 97 | + const score = this.score(player); |
| 98 | + console.log(`${player.summonerName} (${player.championName}) has a score: ${score}`); |
| 99 | + if (score <= highestScore) continue; |
| 100 | + |
| 101 | + highestScore = score; |
| 102 | + bestPlayer = player; |
| 103 | + } |
| 104 | + } |
| 105 | + |
| 106 | + return bestPlayer; |
| 107 | + } |
| 108 | + |
| 109 | + random(array) { |
| 110 | + const randomIndex = Math.floor(Math.random() * array.length); |
| 111 | + return array[randomIndex]; |
| 112 | + } |
| 113 | + |
| 114 | + score(player) { |
| 115 | + const WEIGHT_KDA = 0.35; |
| 116 | + const WEIGHT_VISION = 0.15; |
| 117 | + const WEIGHT_DAMAGES_DEAL = 0.3; |
| 118 | + const WEIGHT_DAMAGES_TAKEN = 0.2; |
| 119 | + |
| 120 | + const SCORE_KILLS_AND_ASSISTS = player.stats.ASSISTS + player.stats.CHAMPIONS_KILLED; |
| 121 | + const SCORE_KDA = player.stats.NUM_DEATHS ? SCORE_KILLS_AND_ASSISTS / player.stats.NUM_DEATHS : SCORE_KILLS_AND_ASSISTS; |
| 122 | + const SCORE_VISION = player.stats.VISION_WARDS_BOUGHT_IN_GAME; |
| 123 | + const SCORE_DAMAGES_DEAL = player.stats.TOTAL_DAMAGE_DEALT; |
| 124 | + const SCORE_DAMAGES_TAKEN = player.stats.TOTAL_DAMAGE_TAKEN; |
| 125 | + |
| 126 | + const CONTRIBUTION_KDA = SCORE_KDA * WEIGHT_KDA; |
| 127 | + const CONTRIBUTION_VISION = SCORE_VISION * WEIGHT_VISION; |
| 128 | + const CONTRIBUTION_DAMAGES_DEAL = SCORE_DAMAGES_DEAL * WEIGHT_DAMAGES_DEAL; |
| 129 | + const CONTRIBUTION_DAMAGES_TAKEN = SCORE_DAMAGES_TAKEN * WEIGHT_DAMAGES_TAKEN; |
| 130 | + |
| 131 | + const TOTAL = CONTRIBUTION_KDA + CONTRIBUTION_VISION + CONTRIBUTION_DAMAGES_DEAL + CONTRIBUTION_DAMAGES_TAKEN; |
| 132 | + return TOTAL; |
| 133 | + } |
| 134 | +} |
| 135 | + |
| 136 | +module.exports = Honor; |
0 commit comments