SteamWar/FightSystem
Archiviert
13
1

Merge pull request 'Implementation of ELO-Based 1 vs 1 ranked games' (#172) from firstRanked into master

Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2020-07-11 07:17:45 +02:00
Commit 4de9f5a8e8
6 geänderte Dateien mit 54 neuen und 15 gelöschten Zeilen

Datei anzeigen

@ -81,6 +81,7 @@ public class Config {
public static final String TeamChatDetection; public static final String TeamChatDetection;
public static final UUID BlueLeader; public static final UUID BlueLeader;
public static final UUID RedLeader; public static final UUID RedLeader;
public static final boolean Ranked;
//Active win conditions //Active win conditions
public static final boolean Timeout; public static final boolean Timeout;
@ -372,6 +373,7 @@ public class Config {
RedLeader = null; RedLeader = null;
CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0")); CheckSchemID = Integer.parseInt(System.getProperty("checkSchemID", "0"));
Ranked = Boolean.parseBoolean(System.getProperty("ranked", "false"));
} }
public static boolean event(){ public static boolean event(){

Datei anzeigen

@ -101,7 +101,7 @@ public class FightSystem extends JavaPlugin {
mainCountdown = new NoPlayersOnlineCountdown(); mainCountdown = new NoPlayersOnlineCountdown();
if(Config.event()) { if(Config.event() || Config.Ranked) {
Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("invite")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ready")).setExecutor(new EventDummyCommand());
Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand()); Objects.requireNonNull(getCommand("ak")).setExecutor(new EventDummyCommand());
@ -196,8 +196,8 @@ public class FightSystem extends JavaPlugin {
} }
public static void setSpectateState(FightTeam winFightTeam, String windescription) { public static void setSpectateState(FightTeam winFightTeam, String windescription) {
if(!fightState.ingame()) if(fightState == FightState.SPECTATE)
throw new SecurityException(fightState.name()); return;
setFightState(FightState.SPECTATE); setFightState(FightState.SPECTATE);
setAllPlayersGM(GameMode.SPECTATOR); setAllPlayersGM(GameMode.SPECTATOR);

Datei anzeigen

@ -122,7 +122,7 @@ public class Fight {
return; return;
} }
if(Config.IgnorePublicOnly || Config.event()){ if(Config.IgnorePublicOnly || Config.event() || Config.Ranked){
schemRank = 1000; schemRank = 1000;
return; return;
} }

Datei anzeigen

@ -8,6 +8,7 @@ import de.steamwar.fightsystem.IFightSystem;
import de.steamwar.fightsystem.kit.KitManager; import de.steamwar.fightsystem.kit.KitManager;
import de.steamwar.fightsystem.states.FightState; import de.steamwar.fightsystem.states.FightState;
import de.steamwar.fightsystem.utils.*; import de.steamwar.fightsystem.utils.*;
import de.steamwar.fightsystem.winconditions.RankedPlayerLeftWincondition;
import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWItem;
import de.steamwar.sql.NoClipboardException; import de.steamwar.sql.NoClipboardException;
import de.steamwar.sql.PersonalKit; import de.steamwar.sql.PersonalKit;
@ -186,19 +187,20 @@ public class FightTeam implements IFightTeam{
} }
public void setLeader(FightPlayer leader) { public void setLeader(FightPlayer leader) {
this.leader = leader;
if(ready && leader != null)
setReady(false);
if (leader == null){ if (leader == null){
if(!players.isEmpty()) { if(!players.isEmpty()) {
setLeader(players.iterator().next()); setLeader(players.iterator().next());
Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!"); Bukkit.broadcastMessage(FightSystem.PREFIX + "§aDer Spieler §e" + this.leader.getPlayer().getName() + " §aist nun Leader von Team " + getColoredName() + "§a!");
}else if(Config.Ranked){
RankedPlayerLeftWincondition.leaderQuit(this);
}else if(!Config.event()){ }else if(!Config.event()){
FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt..."); FightSystem.shutdown(FightSystem.PREFIX + "§cTeam " + getColoredName() + " §chat keine Spieler mehr.\n Arena schließt...");
} }
return; return;
} }
this.leader = leader;
if(ready)
setReady(false);
leader.setKit(KitManager.getKitByName(Config.LeaderDefault)); leader.setKit(KitManager.getKitByName(Config.LeaderDefault));
Inventory inventory = leader.getPlayer().getInventory(); Inventory inventory = leader.getPlayer().getInventory();
@ -209,7 +211,7 @@ public class FightTeam implements IFightTeam{
else else
inventory.setItem(1, new ItemBuilder(Material.AIR).build()); inventory.setItem(1, new ItemBuilder(Material.AIR).build());
if(!Config.event()){ if(!Config.event() && !Config.Ranked){
inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build()); inventory.setItem(2, new ItemBuilder(Material.PAPER).removeAllAttributs().setDisplayName("§eSpieler einladen").build());
inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build()); inventory.setItem(3, new ItemBuilder(SWItem.getMaterial("FIREWORK_CHARGE")).removeAllAttributs().setDisplayName("§cSpieler rauswerfen").build());
} }

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,47 @@ 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));
int newBlueElo = (int) Math.round(blueElo + K * (blueResult - blueWinExpectation));
int newRedElo = (int) Math.round(redElo + K * (1 - blueResult - redWinExpectation));
Elo.setElo(blueLeader.getId(), gameMode, newBlueElo);
Elo.setElo(redLeader.getId(), gameMode, newRedElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getBlueTeam().getPrefix() + blueLeader.getUserName() + "§8: §7" + blueElo + "§8»§e" + newBlueElo);
Bukkit.broadcastMessage(FightSystem.PREFIX + "§7ELO von " + Fight.getRedTeam().getPrefix() + redLeader.getUserName() + "§8: §7" + redElo + "§8»§e" + newRedElo);
}
} }
private static void savePlayerStats(FightPlayer fp, int fightId){ private static void savePlayerStats(FightPlayer fp, int fightId){

Datei anzeigen

@ -0,0 +1,13 @@
package de.steamwar.fightsystem.winconditions;
import de.steamwar.fightsystem.FightSystem;
import de.steamwar.fightsystem.fight.Fight;
import de.steamwar.fightsystem.fight.FightTeam;
public class RankedPlayerLeftWincondition {
private RankedPlayerLeftWincondition(){}
public static void leaderQuit(FightTeam leaderlessTeam){
FightSystem.setSpectateState(Fight.getOpposite(leaderlessTeam), "LeaderQuit");
}
}