SteamWar/FightSystem
Archiviert
13
1

Implementation of ELO-Based 1 vs 1 ranked games #172

Manuell gemergt
Lixfel hat 4 Commits von firstRanked nach master 2020-07-11 07:17:45 +02:00 zusammengeführt
2 geänderte Dateien mit 24 neuen und 10 gelöschten Zeilen
Nur Änderungen aus Commit 8ebf509b4e werden angezeigt - Alle Commits anzeigen

Datei anzeigen

@ -220,10 +220,6 @@ public class FightSystem extends JavaPlugin {
getEventFight().setErgebnis(2); getEventFight().setErgebnis(2);
} }
if(Config.Ranked){
//TODO
}
if(!Config.test()){ if(!Config.test()){
new SpectateOverCountdown(); new SpectateOverCountdown();
FightStatistics.saveStats(winFightTeam, windescription); FightStatistics.saveStats(winFightTeam, windescription);

Datei anzeigen

@ -5,6 +5,7 @@ import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight; import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightPlayer; import de.steamwar.fightsystem.fight.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam; import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.sql.Elo;
import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -17,26 +18,43 @@ public class FightStatistics {
private FightStatistics(){} private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now()); private static Timestamp starttime = Timestamp.from(Instant.now());
private static int K = 20;
public static void start(){ public static void start(){
starttime = Timestamp.from(Instant.now()); starttime = Timestamp.from(Instant.now());
} }
public static void saveStats(FightTeam winner, String windescription){ public static void saveStats(FightTeam winner, String windescription){
String gameMode = Config.SchematicType.toDB();
SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId());
SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId()); SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId());
int win = 0; int win = 0;
if(winner == Fight.getBlueTeam()) double blueResult;
if(winner == Fight.getBlueTeam()) {
win = 1; win = 1;
else if(winner == Fight.getRedTeam()) blueResult = 1;
}else if(winner == Fight.getRedTeam()) {
win = 2; win = 2;
int fightId = create(Config.SchematicType.toDB(), Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(), blueResult = 0;
}else{
blueResult = 0.5;
}
int fightId = create(gameMode, Bukkit.getWorlds().get(0).getName(), starttime, Config.TimeoutTime - FightSystem.getFightTime(),
blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription); blueLeader.getId(), redLeader.getId(), Fight.getBlueTeam().getSchematic().getSchemID(), Fight.getRedTeam().getSchematic().getSchemID(), win, windescription);
for(FightPlayer fp : Fight.getBlueTeam().getPlayers()) for(FightPlayer fp : Fight.getBlueTeam().getPlayers())
savePlayerStats(fp, fightId); savePlayerStats(fp, fightId);
for(FightPlayer fp : Fight.getRedTeam().getPlayers()) for(FightPlayer fp : Fight.getRedTeam().getPlayers())
savePlayerStats(fp, fightId); savePlayerStats(fp, fightId);
if(Config.Ranked && !Config.event()){
int blueElo = Elo.getElo(blueLeader.getId(), gameMode);
int redElo = Elo.getElo(redLeader.getId(), gameMode);
double blueWinExpectation = 1 / (1 + Math.pow(10, (blueElo - redElo) / 400f));
double redWinExpectation = 1 / (1 + Math.pow(10, (redElo - blueElo) / 400f));
Elo.setElo(blueLeader.getId(), gameMode, (int) Math.round(blueElo + K * (blueResult - blueWinExpectation)));
Elo.setElo(redLeader.getId(), gameMode, (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation)));
}
} }
private static void savePlayerStats(FightPlayer fp, int fightId){ private static void savePlayerStats(FightPlayer fp, int fightId){