From e99f24b01b71b8c2224f7d70917fc7643379fa73 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 18 Jul 2023 18:21:31 +0200 Subject: [PATCH] Fix another elo related thing --- .../network/handlers/EloPlayerHandler.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java b/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java index 70f5752..febb04b 100644 --- a/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java +++ b/src/de/steamwar/bungeecore/network/handlers/EloPlayerHandler.java @@ -49,6 +49,10 @@ public class EloPlayerHandler extends PacketHandler { private Map> gameModeGames = new HashMap<>(); + /** + * {@link FightEndsPacket#getWin()} == 1 -> Blue won + * {@link FightEndsPacket#getWin()} == 2 -> Red won + */ @Handler public void handle(FightEndsPacket fightEndsPacket) { if (!ArenaMode.getBySchemType(SchematicType.fromDB(fightEndsPacket.getGameMode())).isRanked()) { @@ -86,6 +90,20 @@ public class EloPlayerHandler extends PacketHandler { int blueTeamElo = fightEndsPacket.getBluePlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum(); int redTeamElo = fightEndsPacket.getRedPlayers().stream().mapToInt(player -> UserElo.getEloOrDefault(player, fightEndsPacket.getGameMode())).sum(); + // Adaptive elo bonus + int blueTeamEloBonus = 0; + int redTeamEloBonus = 0; + if (Math.abs(blueTeamElo / (double) fightEndsPacket.getBluePlayers().size() - redTeamElo / (double) fightEndsPacket.getRedPlayers().size()) > 400) { + int outlivedDuration = Math.max(fightEndsPacket.getDuration() - 60, 0); + if (fightEndsPacket.getWin() == 1 && blueTeamElo < redTeamElo) { + blueTeamEloBonus = outlivedDuration / 20; + redTeamEloBonus = -(blueTeamEloBonus / 2); + } else if (fightEndsPacket.getWin() == 2 && redTeamElo < blueTeamElo) { + redTeamEloBonus = outlivedDuration / 20; + blueTeamEloBonus = -(redTeamEloBonus / 2); + } + } + // Calculate the elo factor double blueEloFactor = ((fightEndsPacket.getWin() == 1 ? 1 : 0) - 1 / (1 + Math.pow(10, (redTeamElo - blueTeamElo) / 600.0))) * (1 / (1 + Math.exp(-Math.abs(blueTeamElo - redTeamElo) / 1200))) * 4; double redEloFactor = blueEloFactor * -1; @@ -125,8 +143,8 @@ public class EloPlayerHandler extends PacketHandler { double redFactor = redPlayerFactor * timeFactor * redEloFactor * rematchFactor * redWinFactor * divisionFactor; // Calculate the elo gain for each player - int blueEloGain = (int) Math.round((blueFactor < 0 ? MEDIAN_ELO_LOSE : MEDIAN_ELO_GAIN) * blueFactor); - int redEloGain = (int) Math.round((redFactor < 0 ? MEDIAN_ELO_LOSE : MEDIAN_ELO_GAIN) * redFactor); + int blueEloGain = (int) Math.round((blueFactor < 0 ? MEDIAN_ELO_LOSE : MEDIAN_ELO_GAIN) * blueFactor) + blueTeamEloBonus; + int redEloGain = (int) Math.round((redFactor < 0 ? MEDIAN_ELO_LOSE : MEDIAN_ELO_GAIN) * redFactor) + redTeamEloBonus; // BungeeCore.get().getLogger().info("Blue: " + fightEndsPacket.getBluePlayers() + " " + blueTeamSize + " " + bluePlayerFactor + " " + timeFactor + " " + blueEloFactor + " " + rematchFactor + " " + blueWinFactor + " " + divisionFactor + " " + blueEloGain); // BungeeCore.get().getLogger().info("Red: " + fightEndsPacket.getRedPlayers() + " " + redTeamSize + " " + redPlayerFactor + " " + timeFactor + " " + redEloFactor + " " + rematchFactor + " " + redWinFactor + " " + divisionFactor + " " + redEloGain);