SteamWar/FightSystem
Archiviert
13
1

Add ranked rework #336

Zusammengeführt
Lixfel hat 6 Commits von Ranked nach master 2022-03-10 12:07:24 +01:00 zusammengeführt
Nur Änderungen aus Commit 94d15aab1d werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -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<FightPlayer> bluePlayers = Fight.getBlueTeam().getPlayers();
Collection<FightPlayer> 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<FightPlayer, Integer> blueElos = new HashMap<>();
Map<FightPlayer, Integer> 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);
}
}