Elo and Division fixed

Elo and Division should be displaying properly

Cleaned the code up a bit

Added endElo() to Game.java to handle team Elo code

Added event listener to check for GameState.End in TDM to call endElo()
This commit is contained in:
Joseph Prezioso Jr. 2016-04-20 14:52:06 -04:00
parent 44263beb87
commit 6a5c8336cf
10 changed files with 330 additions and 294 deletions

View File

@ -41,7 +41,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
public void addToPlayerElos(EloPlayer player, String gameType)
{
NautHashMap<String, Integer> playerInfo = new NautHashMap<String, Integer>();
playerInfo.put(player.getUniqueId(), player.Rating);
playerInfo.put(player.getUniqueId(), player.rating);
_playerElos.put(gameType, playerInfo);
}
@ -66,8 +66,9 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
//If this works, we will never hit the return at the bottom
try
{
elo = _repository.getRepoElo(uuid.toString(), /*gameType*/"Testing");
//Bukkit.broadcastMessage("Fetching Elo...");
//gameType replaced with "Testing" for test purposes
elo = _repository.getRepoElo(uuid.toString(), "Testing" /*gameType*/);
//Bukkit.broadcastMessage("Fetching Elo..." + getElo(uuid, "Testing"));
return elo;
}
catch (SQLException e)
@ -95,6 +96,14 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
System.out.println("Old " + result + " Team Rating:" + teamA.TotalElo);
int teamASize = teamA.getPlayers().size();
int teamBSize = teamB.getPlayers().size();
if(teamASize < 1)
{
teamASize = 1;
}
int newTotal = _ratingSystem.getNewRating(teamA.TotalElo / teamA.getPlayers().size(), teamB.TotalElo / teamB.getPlayers().size(), result) * teamA.getPlayers().size();
System.out.println("New " + result + " Team Rating:" + newTotal);
@ -103,7 +112,7 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
{
EloPlayer newPlayer = new EloPlayer();
newPlayer.setUniqueId(player.getUniqueId());
newPlayer.Rating = (int)(player.Rating + ((double)player.Rating / (double)teamA.TotalElo) * (newTotal - teamA.TotalElo));
newPlayer.rating = (int)(player.rating + ((double)player.rating / (double)teamA.TotalElo) * (newTotal - teamA.TotalElo));
System.out.println("Old:");
player.printInfo();
@ -119,16 +128,12 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
public void saveElo(UUID uuid, String gameType, int elo)
{
//Bukkit.broadcastMessage("SAVE_ELO - EloManager (uuid type) called");
//String playerDiv = getPlayerDivision(uuid, gameType);
saveElo(uuid.toString(), /*gameType*/"Testing", elo);
//saveDivision(uuid.toString(), gameType, playerDiv);
saveElo(uuid.toString(), "Testing" /*gameType*/, elo);
}
public void saveElo(final String uuid, final String gameType, final int elo)
{
//Bukkit.broadcastMessage("SAVE_ELO - EloManager (String type) called");
//Bukkit.broadcastMessage("EloManager saveElo called");
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
@ -136,15 +141,14 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
try {
//it hits this, but doesn't hit the message below.
_repository.saveElo(uuid, gameType, elo);
Bukkit.broadcastMessage("Attempting to save " + elo + " as Elo from repository...");
_repository.saveElo(uuid, "Testing" /*gameType*/, elo);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Bukkit.broadcastMessage("EloManager SaveElo (string) - CATCH hit");
}
//Doesn't hit any of this, to my knowledge - JP
/*
synchronized (_playerEloLock)
{
//Bukkit.broadcastMessage("EloManager SaveElo (string) - _playerEloLock synchronized...");
@ -155,38 +159,11 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
{
//Bukkit.broadcastMessage("EloManager SaveElo (string) - gameType found in _playerElos");
_playerElos.get(uuid).put(gameType, elo);
//Bukkit.broadcastMessage("Attempting to save " + elo + " as Elo from hash map...");
}
}
}
}
});
}
//save divisons the same way that we're saving Elos
public void saveDivision(final String uuid, final String gameType, final String division)
{
Bukkit.getServer().getScheduler().runTaskAsynchronously(getPlugin(), new Runnable()
{
public void run()
{
try {
_repository.saveDivision(uuid, gameType, division);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
synchronized (_playerEloLock)
{
if (_playerDivisions.containsKey(uuid))
{
if (_playerDivisions.get(uuid).containsKey(gameType))
{
_playerDivisions.get(uuid).put(gameType, division);
}
}
}
*/
}
});
}
@ -198,59 +175,109 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
int playerElo = 1000;
try {
playerElo = _repository.getRepoElo(uuid.toString(), gameType);
//gameType replaced with "Testing" for test purposes
playerElo = _repository.getRepoElo(uuid.toString(), "Testing" /*gameType*/);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//this list will be filled with ELO's from other players (but only for the same game type
ArrayList<Integer> allElos = new ArrayList<Integer>();
//gameType replaced with "Testing" for test purposes
String pDivision = CalculateDivision(playerElo, "Testing" /*gameType*/);
for(int i = 0; i < _playerElos.size(); i++)
{
//we're only concerned with this Game Type
if(_playerElos.containsKey(gameType))
{
//add elo's to the list
allElos.add(_playerElos.get(uuid.toString()).get(gameType));
}
}
//sort list of Elos (needed for percentile calculations)
Collections.sort(allElos);
//Calculate how much going up one spot is worth
double individualValue = (100/allElos.size());
/* lastIndexOf gets the last instance of player's Elo
* Consequently, it should be easier for rank to go up than down
* and everyone at the same Elo should be in the same division
*/
double percentile = allElos.lastIndexOf(playerElo) * individualValue;
return CalculateDivision(playerElo, percentile);
return pDivision;
}
public String CalculateDivision(int playerElo, double divPercent)
//calculate percentile into which player falls (above 99 is the top 1%)
public double getEloPercent(int playerElo, String gameType)
{
if (playerElo >= 3500 && divPercent > 99) return "Diamond";
if (playerElo >= 3500) return "Emerald 3";
if (playerElo < 3500 && playerElo >= 3300) return "Emerald 2";
if (playerElo < 3300 && playerElo >= 3100) return "Emerald 1";
if (playerElo < 3100 && playerElo >= 2900) return "Lapis 3";
if (playerElo < 2900 && playerElo >= 2700) return "Lapis 2";
if (playerElo < 2700 && playerElo >= 2500) return "Lapis 1";
if (playerElo < 2500 && playerElo >= 2300) return "Gold 3";
if (playerElo < 2300 && playerElo >= 2100) return "Gold 2";
if (playerElo < 2100 && playerElo >= 1900) return "Gold 1";
if (playerElo < 1900 && playerElo >= 1700) return "Iron 3";
if (playerElo < 1700 && playerElo >= 1500) return "Iron 2";
if (playerElo < 1500 && playerElo >= 1300) return "Iron 1";
if (playerElo < 1300 && playerElo >= 800) return "Coal 3";
if (playerElo < 800 && playerElo >= 600) return "Coal 2";
if (playerElo < 600 && playerElo >= 400) return "Coal 1";
//this list will be filled with ELO's from other players (but only for the same game type
ArrayList<Integer> allElos = new ArrayList<Integer>();
try {
//gameType replaced with "Testing" for test purposes
allElos = _repository.getAllElos( "Testing" /*gameType*/);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "Result not found";
//sort list of Elos (needed for percentile calculations)
Collections.sort(allElos);
double individualValue = 0;
//let's not allow the division of things by 0...
if (allElos.size() != 0)
{
//Calculate how much going up one spot is worth
try
{
individualValue = (100/allElos.size());
}
catch(Error e)
{
e.printStackTrace();
}
}
/* lastIndexOf gets the last instance of player's Elo
* Consequently, it should be easier for rank to go up than down
* and everyone at the same Elo should be in the same division
*/
double percentile = allElos.lastIndexOf(playerElo) * individualValue;
return percentile;
}
//only bother calculating percentile if players actually have above 3500 elo
public String CalculateDiamondPlayers(int playerElo, String gameType)
{
String newDivision = "Emerald 3";
if(getEloPercent(playerElo, gameType) > 99)
{
newDivision = "Diamond";
}
return newDivision;
}
//return a string representing a player's division, based on elo
public String CalculateDivision(int playerElo, String gameType)
{
String pDiv = "Player's division";
if (playerElo >= 3500)
{pDiv = CalculateDiamondPlayers(playerElo, gameType);}
if (playerElo < 3500 && playerElo >= 3300)
{pDiv = "Emerald 2";}
if (playerElo < 3300 && playerElo >= 3100)
{pDiv = "Emerald 1";}
if (playerElo < 3100 && playerElo >= 2900)
{pDiv = "Lapis 3";}
if (playerElo < 2900 && playerElo >= 2700)
{pDiv = "Lapis 2";}
if (playerElo < 2700 && playerElo >= 2500)
{pDiv = "Lapis 1";}
if (playerElo < 2500 && playerElo >= 2300)
{pDiv = "Gold 3";}
if (playerElo < 2300 && playerElo >= 2100)
{pDiv = "Gold 2";}
if (playerElo < 2100 && playerElo >= 1900)
{pDiv = "Gold 1";}
if (playerElo < 1900 && playerElo >= 1700)
{pDiv = "Iron 3";}
if (playerElo < 1700 && playerElo >= 1500)
{pDiv = "Iron 2";}
if (playerElo < 1500 && playerElo >= 1300)
{pDiv = "Iron 1";}
if (playerElo < 1300 && playerElo >= 1100)
{pDiv = "Coal 3";}
if (playerElo < 1100 && playerElo >= 900)
{pDiv = "Coal 2";}
if (playerElo < 900 && playerElo >= 700)
{pDiv = "Coal 1";}
return pDiv;
}
@Override

View File

@ -3,11 +3,13 @@ package mineplex.core.elo;
public class EloPlayer
{
private String _uniqueId;
public int Rating;
public int rating;
private int _killBonus;
private boolean _fullBonus = false;
public void printInfo()
{
System.out.println(_uniqueId + "'s elo is " + Rating);
System.out.println(_uniqueId + "'s elo is " + rating);
}
public String getUniqueId()
@ -20,4 +22,36 @@ public class EloPlayer
_uniqueId = uuid;
}
//bonus points awarded for kills/objectives, but no more than 10
public int getKillBonus()
{
return _killBonus;
}
public void setKillBonus(int bonus)
{
if (_killBonus < 10 && !_fullBonus)
{
_killBonus = bonus;
}
if (_killBonus > 10)
{
_killBonus = 10;
_fullBonus = true;
}
}
public void incrementKillBonus(int toAdd)
{
if (_killBonus < 10 && !_fullBonus)
{
_killBonus += toAdd;
}
if (_killBonus > 10)
{
_killBonus = 10;
_fullBonus = true;
}
}
}

View File

@ -12,18 +12,17 @@ import mineplex.serverdata.database.ResultSetCallable;
import mineplex.serverdata.database.column.ColumnInt;
import mineplex.serverdata.database.column.ColumnVarChar;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
public class EloRepository extends MinecraftRepository
{
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), Testing INT, division VARCHAR(256), PRIMARY KEY (id), UNIQUE INDEX uuid (uuid));";
private static String CREATE_ELO_TABLE = "CREATE TABLE IF NOT EXISTS eloRating (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), Testing INT, PRIMARY KEY (id), UNIQUE INDEX uuid (uuid));";
private static String INSERT_ELO = "INSERT INTO eloRatingTest (uuid, $gameType$) VALUES (?, ?) ON DUPLICATE KEY UPDATE $gameType$=VALUES($gameType$);";
private static String INSERT_DIVISION = "INSERT INTO eloRatingTest (uuid, gameType, division) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE division=VALUES(division);";
//private static String UPDATE_ELO = "UPDATE eloRating SET $gameType$=? WHERE uuid=?;";
private static String SELECT_ELO_BY_UUID = "SELECT $gameType$ FROM eloRatingTest WHERE uuid = ? LIMIT 1";
private static String SELECT_DIVISION_BY_UUID = "SELECT division FROM eloRatingTest WHERE uuid = ? LIMIT 1";
private static String UPDATE_DIVISION = "UPDATE eloRatingTest SET division=? WHERE uuid=?;";
private static String ELO_NEW = "INSERT INTO eloRatingTest (uuid, gameType, elo), values(?, ?, ?);";
private static String GET_ALL_ELOS = "SELECT $gameType$ FROM eloRating;";
public EloRepository(JavaPlugin plugin)
{
@ -37,12 +36,34 @@ public class EloRepository extends MinecraftRepository
//executeUpdate(CREATE_ELO_TABLE);
}
//method to return every Elo from DB
public ArrayList<Integer> getAllElos(String gameType) throws SQLException
{
ArrayList<Integer> allElos = new ArrayList<Integer>();
//gameType replaced with "Testing" for test purposes
String query = GET_ALL_ELOS.replace("$gameType$", /*gameType*/ "Testing");
Connection con = getConnection();
java.sql.Statement stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
//ResultSets start at 1, not 0
while(rs.next())
{
allElos.add(rs.getInt(0));
}
return allElos;
}
//get an elo from the database
public int getRepoElo(String uuid, String gameType) throws SQLException
{
//elo set to 1000 by default
final List<Integer> elo = new ArrayList<Integer>();
String query = SELECT_ELO_BY_UUID.replace("$gameType$", gameType);
//gameType replaced with "Testing" for test purposes
String query = SELECT_ELO_BY_UUID.replace("$gameType$", /*gameType*/ "Testing");
executeQuery(query, new ResultSetCallable()
{
@Override
@ -63,63 +84,10 @@ public class EloRepository extends MinecraftRepository
public void saveElo(String uuid, String gameType, int elo) throws SQLException
{
String query = INSERT_ELO.replace("$gameType$", gameType);
//gameType replaced with "Testing" for test purposes
String query = INSERT_ELO.replace("$gameType$", /*gameType*/ "Testing");
executeUpdate(query, new ColumnVarChar("uuid", 256, uuid), new ColumnInt(gameType, elo));
/*Connection con = getConnection();
java.sql.PreparedStatement stmt = con.prepareStatement(SELECT_ELO_BY_UUID);
stmt.setString(1, uuid.toString());
ResultSet rs = stmt.executeQuery();
boolean contains = false;
Bukkit.broadcastMessage("SAVE_ELO - EloRepository called");
Bukkit.broadcastMessage("Pre-loop - Result Set Boolean:" + rs.toString());
while (rs.next())
{
Bukkit.broadcastMessage("Result Set Boolean:" + rs.toString());
contains = true;
//update elo
java.sql.PreparedStatement updateStatement = con.prepareStatement(UPDATE_ELO);
updateStatement.setInt(1, elo);
updateStatement.setString(2, uuid.toString());
updateStatement.executeUpdate();
//executeUpdate(UPDATE_ELO, new ColumnInt("elo", elo));
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Updating existing elo to " + elo);
}
if(!contains)
{
//insert elo
java.sql.PreparedStatement updateStatement = con.prepareStatement(INSERT_ELO);
updateStatement.setInt(1, elo);
updateStatement.setString(2, uuid.toString());
updateStatement.executeUpdate();
//executeUpdate(INSERT_ELO, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("gameType", 100, gameType), new ColumnInt("elo", elo));
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Adding " + elo + " to " + gameType +" elo database...");
}
Bukkit.broadcastMessage("SAVE_ELO - EloRepository: Adding " + elo + " to " + gameType +" elo database...");*/
}
public void saveDivision(String uuid, String gameType, String division) throws SQLException
{
Connection con = getConnection();
java.sql.Statement stmt = con.createStatement(ResultSet.TYPE_FORWARD_ONLY,ResultSet.CONCUR_UPDATABLE);
String selectQuery = "SELECT gameType, division FROM eloRating WHERE uuid = '" + uuid + "';";
ResultSet rs = stmt.executeQuery(selectQuery);
boolean contains = false;
while(rs.next())
{
String updateQuery = "UPDATE eloRating SET division='" + division + "' WHERE uuid = '" + uuid + "' AND gametype = '" + gameType + "';";
executeUpdate(updateQuery, new ColumnVarChar("elo", 100, uuid));
}
if(!contains)
{
executeUpdate(INSERT_DIVISION, new ColumnVarChar("uuid", 100, uuid), new ColumnVarChar("gameType", 100, gameType), new ColumnVarChar("division", 100, division));
}
//Bukkit.broadcastMessage("EloRepo saveElo called");
}
public EloClientData loadClientInformation(ResultSet resultSet) throws SQLException

View File

@ -11,7 +11,7 @@ public class EloTeam
public void addPlayer(EloPlayer player)
{
TotalElo += player.Rating;
TotalElo += player.rating;
_players.add(player);
}

View File

@ -58,6 +58,7 @@ import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.elo.EloPlayer;
import mineplex.core.elo.EloSettings;
import mineplex.core.elo.EloTeam;
import mineplex.core.elo.GameResult;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.packethandler.IPacketHandler;
import mineplex.core.packethandler.PacketInfo;
@ -313,9 +314,9 @@ public abstract class Game implements Listener
public String Winner = "Nobody";
public GameTeam WinnerTeam = null;
//ELO
//EloSetting - (0 = disabled, 1 = background, 2 = full)
public EloSettings EloSetting = new EloSettings(0);
public boolean EloRanking = false;
public int EloStart = 1000;
@ -1041,7 +1042,6 @@ public abstract class Game implements Listener
@EventHandler
public void eloStart(PlayerLoginEvent event)
{
Bukkit.broadcastMessage("eloStart called in Game. Player's Elo should be saved.");
if (EloRanking)
{
if (Manager.getEloManager().getElo(event.getPlayer().getUniqueId(), GetName()) == -1)
@ -1214,11 +1214,12 @@ public abstract class Game implements Listener
UtilTextMiddle.display(winnerText, subColor + "won the game", 20, 120, 20);
//try to do Elo stuff
handleElo();
//DO SOME ELO STUFF
if (AnnounceSilence)
Manager.GetChat().Silence(5000, false);
}
public void AnnounceEnd(List<Player> places)
@ -1274,11 +1275,11 @@ public abstract class Game implements Listener
UtilTextMiddle.display(winnerText, subColor + "won the game", 20, 120, 20);
//call adjustPlayerElo
adjustPlayerElo(places);
if (AnnounceSilence)
Manager.GetChat().Silence(5000, false);
//call adjustPlayerElo
adjustPlayerElo(places);
}
public void Announce(String message)
@ -1340,7 +1341,7 @@ public abstract class Game implements Listener
return 0;
}
//adjust the elo's of every player, depending on their ranking in the game mode
//INDIVIDUAL ELO -- adjust the elo's of every player, depending on their ranking in the game mode
public void adjustPlayerElo(List<Player> places)
{
int averageElo = 0;
@ -1355,8 +1356,26 @@ public abstract class Game implements Listener
assignEloPoints(places, averageElo);
}
// calculate the average Elos of all players among 2 teams
public int getAverageElos(EloTeam team1, EloTeam team2)
{
EloTeam teamWinner = new EloTeam();
EloTeam teamLoser = new EloTeam();
List<EloPlayer> allPlayers = teamWinner.getPlayers();
allPlayers.addAll(teamLoser.getPlayers());
//method to loop through every player and assign their new Elo
int averageElo = 0;
for (EloPlayer player : allPlayers)
{
averageElo += player.rating;
}
//average Elo of all players
averageElo = averageElo/allPlayers.size();
return averageElo;
}
//INDIVIDUAL ELO -- method to loop through every player and assign their new Elo
public void assignEloPoints(List<Player> places, int averageElo)
{
for (Player player : UtilServer.getPlayers())
@ -1726,6 +1745,7 @@ public abstract class Game implements Listener
public void endGame(GameTeam winningTeam)
{
AnnounceEnd(winningTeam);
for (GameTeam team : GetTeamList())
@ -1741,75 +1761,99 @@ public abstract class Game implements Listener
AddGems(player, 10, "Participation", false, false);
}
handleElo();
//do Elo stuff --
endElo();
// End
SetState(GameState.End);
}
public void handleElo()
//handle Elo at end of game -- method can be overridden in different game modes to meet their individual needs
public void endElo()
{
UtilTextMiddle.display("HandleElo Called", "at Game AnnounceEnd (team)");
//Bukkit.broadcastMessage("handleElo called");
//Bukkit.broadcastMessage("endElo called");
if (EloRanking)
{
Bukkit.broadcastMessage("Game Class EloRanking = True");
//make a list of all players to help find average Elo
EloTeam teamWinner = new EloTeam();
EloTeam teamLoser = new EloTeam();
//EloManager may make most of the code below redundant. leaving inactive, pending testing
//Manager.getEloManager().getNewRatings(teamA, teamB, result)
for (GameTeam team : GetTeamList())
{
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : WinnerTeam.GetPlayers(false))
{
Bukkit.broadcastMessage("Game Class WinnerTeam For Loop Reached");
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
//GetName() replaced with "Testing" for test purposes
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), "Testing" /*GetName()*/);
teamWinner.addPlayer(eloPlayer);
eloPlayer.Rating += 25;
//Bukkit.broadcastMessage(player.getName() + "Old Elo: " + eloPlayer.rating);
Manager.getEloManager().addToPlayerElos(eloPlayer, this.GetName());
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
eloPlayer.rating += 25;
//Bukkit.broadcastMessage(player.getName() + "New Elo: " + Manager.getEloManager().getElo(player.getUniqueId(), "Testing" /*GetName()*/));
}
}
else
{
for (Player player : team.GetPlayers(false))
{
Bukkit.broadcastMessage("Game Class LosingTeam For Loop Reached");
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
//GetName() replaced with "Testing" for test purposes
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), "Testing" /*GetName()*/);
teamLoser.addPlayer(eloPlayer);
eloPlayer.Rating -= 15;
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
eloPlayer.rating -= 15;
}
}
}
//NOT CURRENTLY TRACKING ELO MULTIPLIER -- get averageElo of teams
//int averageElo = getAverageElos(teamWinner, teamLoser);
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
//NOT CURRENTLY TRACKING ELO MULTIPLIER -- calculate Elo Multiplier
//int eloMult = this.calculateEloMultiplier(eloPlayer.rating, averageElo);
//eloPlayer.rating += 20 + (5 * eloMult));
eloPlayer.rating += 25;
//GetName() replaced with "Testing" for test purposes
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), "Testing" /*GetName()*/, eloPlayer.rating);
//Bukkit.broadcastMessage("TDM call to Elomanager.saveElo()");
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
//NOT CURRENTLY TRACKING ELO MULTIPLIER -- calculate Elo Multiplier
/*
int eloMult = this.calculateEloMultiplier(eloPlayer.rating, averageElo);
int eloMod = + (5 * eloMult));
*/
//Bukkit.broadcastMessage("Generic Game End Check Score " + eloPlayer.getUniqueId() + " Old Elo: " + eloPlayer.rating);
//eloPlayer.rating -= 15 + eloMod;
eloPlayer.rating -= 15;
//GetName() replaced with "Testing" for test purposes
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), "Testing" /*GetName()*/, eloPlayer.rating);
//Bukkit.broadcastMessage("Generic Game End Check Score " + eloPlayer.getUniqueId() + " New Elo: " + eloPlayer.rating);
}
}
}
@EventHandler
public void handleInteractEntityPacket(GameStateChangeEvent event)
{

View File

@ -565,7 +565,7 @@ public class CaptureTheFlag extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamWinner.addPlayer(eloPlayer);
}
@ -576,7 +576,7 @@ public class CaptureTheFlag extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamLoser.addPlayer(eloPlayer);
}
@ -585,12 +585,12 @@ public class CaptureTheFlag extends TeamGame
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
}
}

View File

@ -330,10 +330,10 @@ public class Domination extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
//Increment Elo (in case it isn't being incremented already)
eloPlayer.Rating += 20;
eloPlayer.rating += 20;
teamWinner.addPlayer(eloPlayer);
}
@ -344,10 +344,10 @@ public class Domination extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
//Decrement Elo (in case it isn't being decremented already)
eloPlayer.Rating -= 10;
eloPlayer.rating -= 10;
teamLoser.addPlayer(eloPlayer);
}
@ -356,15 +356,15 @@ public class Domination extends TeamGame
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
eloPlayer.Rating += 20;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
eloPlayer.rating += 20;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
eloPlayer.Rating -= 10;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
eloPlayer.rating -= 10;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
}
}

View File

@ -2,6 +2,7 @@ package nautilus.game.arcade.game.games.common;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -82,7 +83,7 @@ public class TeamDeathmatch extends TeamGame
this.EloRanking = true;
this.EloSetting.setEloSetting(2);
this.Manager.getEloManager().generatePlayerElos(this.GetPlayers(false), this.GetName());
//this.Manager.getEloManager().generatePlayerElos(this.GetPlayers(false), this.GetName());
this.Manager.GetDamage().UseSimpleWeaponDamage = false;
@ -339,9 +340,6 @@ public class TeamDeathmatch extends TeamGame
ScoreboardWrite();
//Announce
AnnounceEnd(winner);
for (GameTeam team : GetTeamList())
{
if (WinnerTeam != null && team.equals(WinnerTeam))
@ -355,80 +353,27 @@ public class TeamDeathmatch extends TeamGame
AddGems(player, 10, "Participation", false, false);
}
Bukkit.broadcastMessage("TDM AnnounceEnd Called");
if (EloRanking)
{
Bukkit.broadcastMessage("TDM EloRanking = True");
EloTeam teamWinner = new EloTeam();
EloTeam teamLoser = new EloTeam();
for (GameTeam team : GetTeamList())
{
if (WinnerTeam != null && team.equals(WinnerTeam))
{
for (Player player : WinnerTeam.GetPlayers(false))
{
Bukkit.broadcastMessage("TDM WinnerTeam For Loop Reached");
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamWinner.addPlayer(eloPlayer);
eloPlayer.Rating += 25;
Manager.getEloManager().addToPlayerElos(eloPlayer, this.GetName());
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
}
}
else
{
for (Player player : team.GetPlayers(false))
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamLoser.addPlayer(eloPlayer);
eloPlayer.Rating -= 15;
Bukkit.broadcastMessage(player.getName() + " GetTeamList Elo: " + eloPlayer.Rating);
Manager.getEloManager().saveElo(player.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + " Post-Save Elo: " + eloPlayer.Rating);
}
}
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
eloPlayer.Rating += 25;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "Post-Save Elo: " + eloPlayer.Rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
eloPlayer.Rating -= 15;
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "Post-Save Elo: " + eloPlayer.Rating);
}
}
//Announce End
AnnounceEnd(winner);
//End
SetState(GameState.End);
}
//call endElo (Game.Java) if the game ends
@EventHandler
public void EloCalc(GameStateChangeEvent event)
{
//relevant if we decide to move this to Game.java
if(EloRanking)
{
if (event.GetState() == GameState.End)
{
endElo();
}
}
}
@EventHandler(priority = EventPriority.HIGHEST)
public void UsableInteract(PlayerInteractEvent event)
{

View File

@ -869,10 +869,10 @@ public class TurfForts extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamWinner.addPlayer(eloPlayer);
Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.rating);
}
}
else
@ -881,23 +881,23 @@ public class TurfForts extends TeamGame
{
EloPlayer eloPlayer = new EloPlayer();
eloPlayer.setUniqueId(player.getUniqueId().toString());
eloPlayer.Rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
eloPlayer.rating = Manager.getEloManager().getElo(player.getUniqueId(), GetName());
teamLoser.addPlayer(eloPlayer);
Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.Rating);
Bukkit.broadcastMessage(player.getName() + "'s old Elo: " + eloPlayer.rating);
}
}
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamWinner, teamLoser, GameResult.Win).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "'s new Elo: " + eloPlayer.Rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
Bukkit.broadcastMessage(eloPlayer.getUniqueId() + "'s new Elo: " + eloPlayer.rating);
}
for (EloPlayer eloPlayer : Manager.getEloManager().getNewRatings(teamLoser, teamWinner, GameResult.Loss).getPlayers())
{
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.Rating);
Manager.getEloManager().saveElo(eloPlayer.getUniqueId(), GetName(), eloPlayer.rating);
}
}

View File

@ -106,6 +106,7 @@ public class GameLobbyManager implements Listener
private NautHashMap<Player, Scoreboard> _scoreboardMap = new NautHashMap<Player, Scoreboard>();
private NautHashMap<Player, Integer> _gemMap = new NautHashMap<Player, Integer>();
private NautHashMap<Player, Integer> _eloMap = new NautHashMap<Player, Integer>();
private NautHashMap<Player, String> _divisionMap = new NautHashMap<Player, String>();
private NautHashMap<Player, String> _kitMap = new NautHashMap<Player, String>();
private int _oldPlayerCount = 0;
@ -1135,24 +1136,41 @@ public class GameLobbyManager implements Listener
objective.getScore(Manager.GetDonation().Get(entry.getKey().getName()).GetGems() + " ").setScore(line--);
_gemMap.put(entry.getKey(), Manager.GetDonation().Get(entry.getKey().getName()).GetGems());
objective.getScore(" ").setScore(line--);
//Server
objective.getScore(" ").setScore(line--);
objective.getScore(C.cAqua + C.Bold + "Server").setScore(line--);
objective.getScore(_serverName).setScore(line--);
objective.getScore(" ").setScore(line--);
//ELO
if (Manager.GetGame() != null && Manager.GetGame().EloRanking)
//ELO -- only when full display is set properly
if (Manager.GetGame() != null && Manager.GetGame().EloRanking && Manager.GetGame().EloSetting.getEloSetting() == 2)
{
objective.getScore(" ").setScore(line--);
objective.getScore(C.cPurple + C.Bold + "Elo").setScore(line--);
// Remove old
entry.getValue().resetScores(_eloMap.get(entry.getKey()) + " ");
// Set new
objective.getScore(Manager.getEloManager().getElo(entry.getKey().getUniqueId(), Manager.GetGame().GetName()) + " ").setScore(line--);
// Set new -- GetName() replaced with "Testing" for test purposes
objective.getScore(Manager.getEloManager().getElo(entry.getKey().getUniqueId(), "Testing" /*Manager.GetGame().GetName()*/) + " ").setScore(line--);
objective.getScore(" ").setScore(line--);
}
//ELO DIVISION
if (Manager.GetGame() != null && Manager.GetGame().EloRanking && Manager.GetGame().EloSetting.getEloSetting() >= 1)
{
objective.getScore(" ").setScore(line--);
objective.getScore(C.cDPurpleB + C.Bold + "Division").setScore(line--);
// Remove old
entry.getValue().resetScores(_divisionMap.get(entry.getKey()) + " ");
// Set new
objective.getScore(Manager.getEloManager().getPlayerDivision(entry.getKey().getUniqueId(), "Testing" /* Manager.GetGame().GetName()*/ ) + " ").setScore(line--);
objective.getScore(" ").setScore(line--);
}
}
_oldPlayerCount = UtilServer.getPlayers().length;