From f4ffd17c5578a7408cba3953fa99d0c14c2b3529 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 9 Mar 2022 15:30:19 +0100 Subject: [PATCH 1/6] Add ranked rework --- .../de/steamwar/fightsystem/ArenaMode.java | 8 +- .../src/de/steamwar/fightsystem/Config.java | 9 +- .../de/steamwar/fightsystem/FightSystem.java | 2 - .../fightsystem/FightSystem.properties | 3 +- .../fightsystem/countdown/Countdown.java | 6 + .../fightsystem/listener/RankedJoin.java | 52 -------- .../fightsystem/utils/FightStatistics.java | 116 +++++++++++++----- .../RankedPlayerLeftWincondition.java | 50 -------- 8 files changed, 101 insertions(+), 145 deletions(-) delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java delete mode 100644 FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java b/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java index 94d3d2b..e291fd7 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/ArenaMode.java @@ -25,7 +25,6 @@ import java.util.Set; public enum ArenaMode { NORMAL, - RANKED, EVENT, TEST, CHECK, @@ -38,7 +37,6 @@ public enum ArenaMode { public static final Set Check = Collections.unmodifiableSet(EnumSet.of(CHECK)); public static final Set Event = Collections.unmodifiableSet(EnumSet.of(EVENT)); public static final Set Test = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK)); - public static final Set Ranked = Collections.unmodifiableSet(EnumSet.of(RANKED)); public static final Set Prepare = Collections.unmodifiableSet(EnumSet.of(PREPARE)); public static final Set Replay = Collections.unmodifiableSet(EnumSet.of(REPLAY, TEST)); @@ -46,9 +44,9 @@ public enum ArenaMode { public static final Set AntiTest = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK))); public static final Set AntiEvent = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT))); public static final Set AntiPrepare = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(PREPARE))); - public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(RANKED, EVENT, REPLAY))); - public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(RANKED, EVENT, REPLAY)); - public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL, RANKED)); + public static final Set VariableTeams = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(EVENT, REPLAY))); + public static final Set RankedEvent = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY)); + public static final Set Restartable = Collections.unmodifiableSet(EnumSet.of(NORMAL)); public static final Set NotRestartable = Collections.unmodifiableSet(EnumSet.of(EVENT, REPLAY)); public static final Set SoloLeader = Collections.unmodifiableSet(EnumSet.of(TEST, CHECK, PREPARE)); public static final Set NotOnBau = Collections.unmodifiableSet(EnumSet.complementOf(EnumSet.of(TEST, CHECK, PREPARE, REPLAY))); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 9e1dd53..6dab0a9 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -92,7 +92,7 @@ public class Config { public static final String TeamChatDetection; public static final UUID BlueLeader; public static final UUID RedLeader; - public static final boolean Ranked; + public static final boolean RankedEnabled; //Active win conditions public static final Set ActiveWinconditions; @@ -150,6 +150,8 @@ public class Config { } FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); + RankedEnabled = config.getBoolean("Server.Ranked", false); + NoPlayerOnlineDuration = config.getInt("Times.NoPlayersOnlineDuration", 30); PreSchemPasteDuration = config.getInt("Times.PreSchemPasteDuration", 120); SetupDuration = config.getInt("Times.SetupDuration", 300); @@ -370,12 +372,9 @@ public class Config { CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); PrepareSchemID = Integer.parseInt(System.getProperty("prepareSchemID", "0")); - Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false")); ReplayID = Integer.parseInt(System.getProperty("replay", "0")); - if(Ranked){ - mode = ArenaMode.RANKED; - }else if(CheckSchemID != 0){ + if(CheckSchemID != 0){ mode = ArenaMode.CHECK; }else if(PrepareSchemID != 0){ mode = ArenaMode.PREPARE; diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java index 892edd1..5088d1c 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.java @@ -87,7 +87,6 @@ public class FightSystem extends JavaPlugin { new PrepareSchem(); new TestJoin(); new NormalJoin(); - new RankedJoin(); new RunningWorldInteraction(); new PersonalKitCreator(); new ArrowStopper(); @@ -114,7 +113,6 @@ public class FightSystem extends JavaPlugin { new WinconditionHeartRatioTimeout(); new WinconditionTimeTechKO(); new EventTeamOffWincondition(); - new RankedPlayerLeftWincondition(); new WinconditionPercentTimeout(); new HellsBells(); diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index cdd7e40..3ddde23 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -180,7 +180,7 @@ UI_PLAYER_LEAVES= UI_LEADER_JOINS=§a§l» {0}Leader {1} UI_PLAYER_DEATH={0}{1} §7ist gestorben UI_PLAYER_LEAVE={0}{1} §7hat den Kampf verlassen -UI_ELO=§7ELO von {0}{1}§8: §7{2}§8»§e{3} +UI_ELO_PLAYER=§7Elo§8: §7{0}§8»§7{1} UI_WIN={0}Sieg {1} UI_DRAW=§7Unentschieden @@ -232,7 +232,6 @@ WIN_FIGHTLEADER= WIN_PERCENT={0} §7zu beschädigt WIN_OFFLINE_BOTH=§7Beide Teams offline WIN_OFFLINE={0} §7offline -WIN_RANKED_LEFT={0} §7hat den Kampf verlassen WIN_ALL_DEAD={0}Alle Spieler kampfunfähig WIN_LEADER_DEAD={0} kampfunfähig WIN_TIME_OVER=§7Zeit abgelaufen diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java index 46c8ace..d575287 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -45,6 +45,7 @@ public abstract class Countdown { private final boolean level; protected int time; + protected int timeElapsed; private BukkitTask task = null; public abstract void countdownFinished(); @@ -110,8 +111,13 @@ public abstract class Countdown { return time; } + public int getTimeElapsed(){ + return timeElapsed; + } + private void count() { time--; + timeElapsed++; show(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java b/FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java deleted file mode 100644 index 49ec963..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/listener/RankedJoin.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.listener; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.Config; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerJoinEvent; - -public class RankedJoin implements Listener { - - public RankedJoin() { - new StateDependentListener(ArenaMode.Ranked, FightState.PreLeaderSetup, this); - } - - @EventHandler - public void handlePlayerJoin(PlayerJoinEvent event) { - Player player = event.getPlayer(); - FightTeam fightTeam = Fight.getPlayerTeam(player); - - if (fightTeam == null) { - if(!player.getUniqueId().equals(Config.RedLeader) && Fight.getBlueTeam().canbeLeader(player)) { - Fight.getBlueTeam().addMember(player); - }else if(Fight.getRedTeam().canbeLeader(player)) { - Fight.getRedTeam().addMember(player); - } - } - } -} diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 22c9891..1b245dc 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -39,6 +39,9 @@ import java.io.FileInputStream; import java.sql.Timestamp; import java.time.Instant; import java.time.temporal.ChronoUnit; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; import java.util.logging.Level; import static de.steamwar.sql.Fight.create; @@ -61,7 +64,7 @@ public class FightStatistics { new OneShotStateDependent(ArenaMode.SeriousFight, FightState.Spectate, () -> Bukkit.getScheduler().runTask(FightSystem.getPlugin(), this::disable)); } - private void enable(){ + private void enable() { starttime = Timestamp.from(Instant.now()); } @@ -84,33 +87,43 @@ public class FightStatistics { int win = 0; double blueResult; - if(winner == Fight.getBlueTeam()) { + if (winner == Fight.getBlueTeam()) { win = 1; blueResult = 1; - }else if(winner == Fight.getRedTeam()) { + } else if (winner == Fight.getRedTeam()) { win = 2; blueResult = 0; - }else{ + } else { blueResult = 0.5; } Integer blueSchem; + Integer blueSchemRank; Integer redSchem; - try{ - blueSchem = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()).getId(); - }catch(SecurityException e){ + Integer redSchemRank; + try { + SchematicNode schematicNode = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()); + blueSchem = schematicNode.getId(); + blueSchemRank = schematicNode.getRank(); + } catch (SecurityException e) { blueSchem = null; + blueSchemRank = null; } - try{ - redSchem = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()).getId(); - }catch(SecurityException e){ + try { + SchematicNode schematicNode = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()); + redSchem = schematicNode.getId(); + redSchemRank = schematicNode.getRank(); + } catch (SecurityException e) { redSchem = null; + redSchemRank = null; } int remainingTime = 0; + int timeElapsed = 0; Countdown timeOverCountdown = Wincondition.getTimeOverCountdown(); - if(timeOverCountdown != null){ + if (timeOverCountdown != null) { remainingTime = timeOverCountdown.getTimeLeft(); + timeElapsed = timeOverCountdown.getTimeElapsed(); } try { @@ -122,43 +135,88 @@ public class FightStatistics { for (FightPlayer fp : Fight.getRedTeam().getPlayers()) savePlayerStats(fp, fightId); - if(ArenaMode.Event.contains(Config.mode)) { + if (ArenaMode.Event.contains(Config.mode)) { FightSystem.getEventFight().setFight(fightId); } try { setReplay(fightId, new FileInputStream(FileRecorder.getFile())); - }catch(Exception e){ + } catch (Exception e) { Bukkit.getLogger().log(Level.INFO, "Failed to save replay", e); } - }catch(Exception e){ + } catch (Exception e) { Bukkit.getLogger().log(Level.SEVERE, "Failed to save statistics", e); } replayLock = false; - if(Config.Ranked){ - int blueElo = Elo.getElo(blueLeader, gameMode); - int redElo = Elo.getElo(redLeader, gameMode); - double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f)); - double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f)); - int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation)); - int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)); - Elo.setElo(blueLeader, gameMode, newBlueElo); - Elo.setElo(redLeader, gameMode, newRedElo); - FightSystem.broadcast("UI_ELO", Fight.getBlueTeam().getPrefix(), SteamwarUser.get(blueLeader).getUserName(), blueElo, newBlueElo); - FightSystem.broadcast("UI_ELO", Fight.getRedTeam().getPrefix(), SteamwarUser.get(redLeader).getUserName(), redElo, newRedElo); + calculateEloIfNeeded(timeElapsed, blueSchemRank, redSchemRank, blueResult, gameMode); + } + + private void calculateEloIfNeeded(int timeElapsed, Integer blueSchemRank, Integer redSchemRank, double blueResult, String gameMode) { + if (!Config.RankedEnabled) { + return; + } + + if (timeElapsed < 30) { // Too short fights are not worth elo change + return; + } + + if (blueSchemRank == null || redSchemRank == null) { // Schematics are not ranked + return; + } + + if (blueSchemRank != redSchemRank) { // Different schematics ranks are not worth elo change + return; + } + + Collection bluePlayers = Fight.getBlueTeam().getPlayers(); + Collection redPlayers = Fight.getRedTeam().getPlayers(); + double playerDiff = 1 - (Math.min(bluePlayers.size(), redPlayers.size()) / (double) Math.max(bluePlayers.size(), redPlayers.size())); + if (playerDiff >= 0.4) { // Too many players, not worth elo change + return; + } + + int blueElo = 0; + int redElo = 0; + Map blueElos = new HashMap<>(); + Map redElos = new HashMap<>(); + for (FightPlayer fp : bluePlayers) { + int elo = Elo.getElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode); + blueElo += elo; + blueElos.put(fp, elo); + } + for (FightPlayer fp : redPlayers) { + int elo = Elo.getElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode); + redElo += elo; + redElos.put(fp, elo); + } + + double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 600f)); + double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 600f)); + double diffBlueElo = K * (blueResult - blueWinExpectation); + double diffRedElo = K * (1 - blueResult - redWinExpectation); + + for (FightPlayer fp : bluePlayers) { + int nElo = (int) Math.round(blueElos.get(fp) + diffBlueElo / bluePlayers.size()); + Elo.setElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode, nElo); + FightSystem.getMessage().send("UI_ELO_PLAYER", fp.getPlayer(), redElos.get(fp), nElo); + } + for (FightPlayer fp : redPlayers) { + int nElo = (int) Math.round(redElos.get(fp) + diffRedElo / redPlayers.size()); + Elo.setElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode, nElo); + FightSystem.getMessage().send("UI_ELO_PLAYER", fp.getPlayer(), redElos.get(fp), nElo); } } - private int getLeader(FightTeam team){ - if(team.getLeader() != null) + private int getLeader(FightTeam team) { + if (team.getLeader() != null) return SteamwarUser.get(team.getLeader().getPlayer().getUniqueId()).getId(); - else if(team.getDesignatedLeader() != null) + else if (team.getDesignatedLeader() != null) return SteamwarUser.get(team.getDesignatedLeader()).getId(); return 0; } - private void savePlayerStats(FightPlayer fp, int fightId){ + private void savePlayerStats(FightPlayer fp, int fightId) { SteamwarUser user = SteamwarUser.get(fp.getPlayer().getUniqueId()); de.steamwar.sql.FightPlayer.create(fightId, user.getId(), fp.getTeam().isBlue(), fp.getKit().getName(), fp.getKills(), !fp.isLiving()); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java b/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java deleted file mode 100644 index 33f3045..0000000 --- a/FightSystem_Core/src/de/steamwar/fightsystem/winconditions/RankedPlayerLeftWincondition.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - This file is a part of the SteamWar software. - - Copyright (C) 2020 SteamWar.de-Serverteam - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -package de.steamwar.fightsystem.winconditions; - -import de.steamwar.fightsystem.ArenaMode; -import de.steamwar.fightsystem.fight.Fight; -import de.steamwar.fightsystem.fight.FightTeam; -import de.steamwar.fightsystem.states.FightState; -import de.steamwar.fightsystem.states.StateDependentListener; -import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; -import org.bukkit.event.Listener; -import org.bukkit.event.player.PlayerQuitEvent; - -public class RankedPlayerLeftWincondition extends Wincondition implements Listener { - - public RankedPlayerLeftWincondition(){ - super("LeaderQuit"); - new StateDependentListener(ArenaMode.Ranked, FightState.Setup, this); - } - - @EventHandler - public void handlePlayerQuit(PlayerQuitEvent event) { - Player player = event.getPlayer(); - FightTeam team = isTarget(player); - if(team == null) - return; - - if(team.isPlayerLeader(player)) { - win(Fight.getOpposite(team), "WIN_RANKED_LEFT", team.getPrefix() + team.getLeader().getPlayer().getName()); - } - } -} -- 2.39.2 From 14e64c39473a29057ff1c52a0a1bd2d42ee3489d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 9 Mar 2022 18:01:37 +0100 Subject: [PATCH 2/6] Add ranked rework --- .../de/steamwar/fightsystem/countdown/Countdown.java | 6 ------ .../de/steamwar/fightsystem/utils/FightStatistics.java | 10 ++-------- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java index d575287..46c8ace 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/countdown/Countdown.java @@ -45,7 +45,6 @@ public abstract class Countdown { private final boolean level; protected int time; - protected int timeElapsed; private BukkitTask task = null; public abstract void countdownFinished(); @@ -111,13 +110,8 @@ public abstract class Countdown { return time; } - public int getTimeElapsed(){ - return timeElapsed; - } - private void count() { time--; - timeElapsed++; show(); } diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 1b245dc..c79bd0f 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -119,11 +119,9 @@ public class FightStatistics { } int remainingTime = 0; - int timeElapsed = 0; Countdown timeOverCountdown = Wincondition.getTimeOverCountdown(); if (timeOverCountdown != null) { remainingTime = timeOverCountdown.getTimeLeft(); - timeElapsed = timeOverCountdown.getTimeElapsed(); } try { @@ -149,18 +147,14 @@ public class FightStatistics { } replayLock = false; - calculateEloIfNeeded(timeElapsed, blueSchemRank, redSchemRank, blueResult, gameMode); + calculateEloIfNeeded(blueSchemRank, redSchemRank, blueResult, gameMode); } - private void calculateEloIfNeeded(int timeElapsed, Integer blueSchemRank, Integer redSchemRank, double blueResult, String gameMode) { + private void calculateEloIfNeeded(Integer blueSchemRank, Integer redSchemRank, double blueResult, String gameMode) { if (!Config.RankedEnabled) { return; } - if (timeElapsed < 30) { // Too short fights are not worth elo change - return; - } - if (blueSchemRank == null || redSchemRank == null) { // Schematics are not ranked return; } -- 2.39.2 From 94d15aab1d445ad10cd7acd872887d0a6cc10bb5 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 9 Mar 2022 20:53:50 +0100 Subject: [PATCH 3/6] Update FightStatistics --- .../fightsystem/utils/FightStatistics.java | 74 ++----------------- 1 file changed, 8 insertions(+), 66 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index c79bd0f..1948970 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -19,6 +19,7 @@ package de.steamwar.fightsystem.utils; +import de.steamwar.comms.packets.FightEndsPacket; import de.steamwar.fightsystem.ArenaMode; import de.steamwar.fightsystem.Config; import de.steamwar.fightsystem.FightSystem; @@ -30,19 +31,17 @@ import de.steamwar.fightsystem.record.FileRecorder; import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.OneShotStateDependent; import de.steamwar.fightsystem.winconditions.Wincondition; -import de.steamwar.sql.Elo; import de.steamwar.sql.SchematicNode; import de.steamwar.sql.SteamwarUser; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import java.io.FileInputStream; import java.sql.Timestamp; import java.time.Instant; import java.time.temporal.ChronoUnit; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; import java.util.logging.Level; +import java.util.stream.Collectors; import static de.steamwar.sql.Fight.create; import static de.steamwar.sql.Fight.setReplay; @@ -98,24 +97,16 @@ public class FightStatistics { } Integer blueSchem; - Integer blueSchemRank; Integer redSchem; - Integer redSchemRank; try { - SchematicNode schematicNode = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()); - blueSchem = schematicNode.getId(); - blueSchemRank = schematicNode.getRank(); + blueSchem = SchematicNode.getSchematicNode(Fight.getBlueTeam().getSchematic()).getId(); } catch (SecurityException e) { blueSchem = null; - blueSchemRank = null; } try { - SchematicNode schematicNode = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()); - redSchem = schematicNode.getId(); - redSchemRank = schematicNode.getRank(); + redSchem = SchematicNode.getSchematicNode(Fight.getRedTeam().getSchematic()).getId(); } catch (SecurityException e) { redSchem = null; - redSchemRank = null; } int remainingTime = 0; @@ -147,58 +138,9 @@ public class FightStatistics { } replayLock = false; - calculateEloIfNeeded(blueSchemRank, redSchemRank, blueResult, gameMode); - } - - private void calculateEloIfNeeded(Integer blueSchemRank, Integer redSchemRank, double blueResult, String gameMode) { - if (!Config.RankedEnabled) { - return; - } - - if (blueSchemRank == null || redSchemRank == null) { // Schematics are not ranked - return; - } - - if (blueSchemRank != redSchemRank) { // Different schematics ranks are not worth elo change - return; - } - - Collection bluePlayers = Fight.getBlueTeam().getPlayers(); - Collection redPlayers = Fight.getRedTeam().getPlayers(); - double playerDiff = 1 - (Math.min(bluePlayers.size(), redPlayers.size()) / (double) Math.max(bluePlayers.size(), redPlayers.size())); - if (playerDiff >= 0.4) { // Too many players, not worth elo change - return; - } - - int blueElo = 0; - int redElo = 0; - Map blueElos = new HashMap<>(); - Map redElos = new HashMap<>(); - for (FightPlayer fp : bluePlayers) { - int elo = Elo.getElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode); - blueElo += elo; - blueElos.put(fp, elo); - } - for (FightPlayer fp : redPlayers) { - int elo = Elo.getElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode); - redElo += elo; - redElos.put(fp, elo); - } - - double redWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 600f)); - double blueWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 600f)); - double diffBlueElo = K * (blueResult - blueWinExpectation); - double diffRedElo = K * (1 - blueResult - redWinExpectation); - - for (FightPlayer fp : bluePlayers) { - int nElo = (int) Math.round(blueElos.get(fp) + diffBlueElo / bluePlayers.size()); - Elo.setElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode, nElo); - FightSystem.getMessage().send("UI_ELO_PLAYER", fp.getPlayer(), redElos.get(fp), nElo); - } - for (FightPlayer fp : redPlayers) { - int nElo = (int) Math.round(redElos.get(fp) + diffRedElo / redPlayers.size()); - Elo.setElo(SteamwarUser.get(fp.getPlayer()).getId(), gameMode, nElo); - FightSystem.getMessage().send("UI_ELO_PLAYER", fp.getPlayer(), redElos.get(fp), nElo); + if (Bukkit.getOnlinePlayers().isEmpty()) { + Player p = Bukkit.getOnlinePlayers().iterator().next(); + new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList())).send(p); } } -- 2.39.2 From 0617fd8d6bf7bca90cb2695e2c77d5996e12a796 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 9 Mar 2022 20:54:31 +0100 Subject: [PATCH 4/6] Update FightSystem.properties --- .../src/de/steamwar/fightsystem/FightSystem.properties | 1 - 1 file changed, 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties index 3ddde23..bff5b59 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties +++ b/FightSystem_Core/src/de/steamwar/fightsystem/FightSystem.properties @@ -180,7 +180,6 @@ UI_PLAYER_LEAVES= UI_LEADER_JOINS=§a§l» {0}Leader {1} UI_PLAYER_DEATH={0}{1} §7ist gestorben UI_PLAYER_LEAVE={0}{1} §7hat den Kampf verlassen -UI_ELO_PLAYER=§7Elo§8: §7{0}§8»§7{1} UI_WIN={0}Sieg {1} UI_DRAW=§7Unentschieden -- 2.39.2 From 25f492e1d13108b43205c37a784569ce870b3e2c Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 12:00:44 +0100 Subject: [PATCH 5/6] Update Config --- FightSystem_Core/src/de/steamwar/fightsystem/Config.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java index 6dab0a9..a97493d 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/Config.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/Config.java @@ -92,7 +92,6 @@ public class Config { public static final String TeamChatDetection; public static final UUID BlueLeader; public static final UUID RedLeader; - public static final boolean RankedEnabled; //Active win conditions public static final Set ActiveWinconditions; @@ -150,8 +149,6 @@ public class Config { } FileConfiguration worldconfig = YamlConfiguration.loadConfiguration(worldConfigFile); - RankedEnabled = config.getBoolean("Server.Ranked", false); - NoPlayerOnlineDuration = config.getInt("Times.NoPlayersOnlineDuration", 30); PreSchemPasteDuration = config.getInt("Times.PreSchemPasteDuration", 120); SetupDuration = config.getInt("Times.SetupDuration", 300); -- 2.39.2 From 1de78548bbf8ae32ec93b61d1ca764de7b4c3c47 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 10 Mar 2022 12:05:30 +0100 Subject: [PATCH 6/6] Fix logic error --- .../src/de/steamwar/fightsystem/utils/FightStatistics.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java index 1948970..73bbe7e 100644 --- a/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java +++ b/FightSystem_Core/src/de/steamwar/fightsystem/utils/FightStatistics.java @@ -138,7 +138,7 @@ public class FightStatistics { } replayLock = false; - if (Bukkit.getOnlinePlayers().isEmpty()) { + if (!Bukkit.getOnlinePlayers().isEmpty()) { Player p = Bukkit.getOnlinePlayers().iterator().next(); new FightEndsPacket((byte) win, blueSchem == null ? 0 : blueSchem, redSchem == null ? 0 : redSchem, Fight.getBlueTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList()), Fight.getRedTeam().getPlayers().stream().map(FightPlayer::getPlayer).map(SteamwarUser::get).map(SteamwarUser::getId).collect(Collectors.toList())).send(p); } -- 2.39.2