SteamWar/FightSystem
Archiviert
13
1

Implementing ranked computation and setting

Signed-off-by: Lixfel <agga-games@gmx.de>
Dieser Commit ist enthalten in:
Lixfel 2020-07-07 19:07:11 +02:00
Ursprung c1261a4fa2
Commit 8ebf509b4e
2 geänderte Dateien mit 24 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -211,19 +211,15 @@ public class FightSystem extends JavaPlugin {
Bukkit.broadcastMessage(PREFIX + "§aKein Team hat gewonnen!");
}
if(Config.event()){
if(winFightTeam == null)
if(Config.event()) {
if (winFightTeam == null)
getEventFight().setErgebnis(0);
else if(winFightTeam.isBlue())
else if (winFightTeam.isBlue())
getEventFight().setErgebnis(1);
else
getEventFight().setErgebnis(2);
}
if(Config.Ranked){
//TODO
}
if(!Config.test()){
new SpectateOverCountdown();
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.FightPlayer;
import de.steamwar.fightsystem.fight.FightTeam;
import de.steamwar.sql.Elo;
import de.steamwar.sql.SteamwarUser;
import org.bukkit.Bukkit;
@ -17,26 +18,43 @@ public class FightStatistics {
private FightStatistics(){}
private static Timestamp starttime = Timestamp.from(Instant.now());
private static int K = 20;
public static void start(){
starttime = Timestamp.from(Instant.now());
}
public static void saveStats(FightTeam winner, String windescription){
String gameMode = Config.SchematicType.toDB();
SteamwarUser blueLeader = SteamwarUser.get(Fight.getBlueTeam().getLeader().getPlayer().getUniqueId());
SteamwarUser redLeader = SteamwarUser.get(Fight.getRedTeam().getLeader().getPlayer().getUniqueId());
int win = 0;
if(winner == Fight.getBlueTeam())
double blueResult;
if(winner == Fight.getBlueTeam()) {
win = 1;
else if(winner == Fight.getRedTeam())
blueResult = 1;
}else if(winner == Fight.getRedTeam()) {
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);
for(FightPlayer fp : Fight.getBlueTeam().getPlayers())
savePlayerStats(fp, fightId);
for(FightPlayer fp : Fight.getRedTeam().getPlayers())
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){