diff --git a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java index 63cbd799..97e263c0 100644 --- a/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java +++ b/src/de/steamwar/bungeecore/comms/handlers/FightEndsHandler.java @@ -69,22 +69,16 @@ public class FightEndsHandler implements SpigotHandler { int blueSchemElo = SchemElo.getElo(fightEndsPacket.getBlueSchem()); int redSchemElo = SchemElo.getElo(fightEndsPacket.getRedSchem()); - double blueWinExpectation = 1 / (1 + Math.pow(10, (redSchemElo - blueSchemElo) / 600f)); - double redWinExpectation = 1 / (1 + Math.pow(10, (blueSchemElo - redSchemElo) / 600f)); - - SchemElo.setElo(fightEndsPacket.getBlueSchem(), (int) Math.round(blueSchemElo + K * (blueResult - blueWinExpectation))); - SchemElo.setElo(fightEndsPacket.getRedSchem(), (int) Math.round(redSchemElo + K * (1 - blueResult - redWinExpectation))); - - if (!bluePublic) { - calculateEloOfTeam(fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode(), blueResult - blueWinExpectation); - calculateEloOfTeam(fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode(), 1 - blueResult - blueWinExpectation); - } + calculateEloOfTeam(fightEndsPacket.getBlueSchem(), blueSchemElo, redSchemElo, blueResult, fightEndsPacket.getBluePlayers(), fightEndsPacket.getGameMode()); + calculateEloOfTeam(fightEndsPacket.getRedSchem(), redSchemElo, blueSchemElo, 1 - blueResult, fightEndsPacket.getRedPlayers(), fightEndsPacket.getGameMode()); } - private void calculateEloOfTeam(List team, String gameMode, double factor) { - for (int player : team) { + private void calculateEloOfTeam(int schemId, int elo1, int elo2, double result, List players, String gameMode) { + double winExpectation = 1 / (1 + Math.pow(10, (elo1 - elo2) / 600f)); + SchemElo.setElo(schemId, (int) Math.round(elo1 + K * (result - winExpectation))); + for (int player : players) { int playerElo = UserElo.getEloOrDefault(player, gameMode); - UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * factor)); + UserElo.setElo(player, gameMode, (int) Math.round(playerElo + K * (result - winExpectation))); } } }