use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class EloHandler method update.
private void update(@Nonnull Game game, @Nonnull Map<IPlayer, Rating> newRatings) {
for (IPlayer iPlayer : newRatings.keySet()) {
if (!(iPlayer instanceof User)) {
log.warning("WTF");
continue;
}
User user = (User) iPlayer;
user.saveRating(game.getGameMode(), newRatings.get(iPlayer));
// TODO fixme
log.info("New Rating for " + user.getRawDisplayName() + " is " + newRatings.get(iPlayer).getMean() + "(" + newRatings.get(iPlayer).getStandardDeviation() + ")");
}
}
use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class AbstractPhase method checkEnd.
private void checkEnd() {
// check all victory conditions
User winner = null;
Team winnerTeam = null;
for (VictoryCondition victoryCondition : victoryConditions) {
if (!victoryCondition.completed()) {
return;
}
if (victoryCondition.getWinner() != null) {
if (!victoryCondition.getWinner().equals(winner)) {
if (winner == null) {
if (winnerTeam != null && !winnerTeam.contains(victoryCondition.getWinner())) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winner even tho we already have a winning team!");
}
winner = victoryCondition.getWinner();
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winner than one of the conditions before it!");
}
}
}
if (victoryCondition.getWinnerTeam() != null) {
if (!victoryCondition.getWinnerTeam().equals(winnerTeam)) {
if (winnerTeam == null) {
if (winner != null && !victoryCondition.getWinnerTeam().contains(winner)) {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a winning team even tho we already have a winning user!");
} else {
winnerTeam = victoryCondition.getWinnerTeam();
}
} else {
throw new VoxelGameLibException(victoryCondition.getName() + " defined a different winning team than one of the conditions before it!");
}
}
}
}
// all done, end this game
getGame().endGame(winnerTeam, winner);
}
use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class TeamSelectFeature method balance.
private void balance() {
// TODO Balancing by rating
Map<String, Integer> sizes = calcSizes();
String large = findLargest(sizes);
if (large == null || large.equals("")) {
log.finer("no balancing");
teams.stream().map(t -> t.getName() + ": " + t.getPlayers().size()).forEach(log::finer);
return;
}
int largeCount = sizes.get(large);
String small = findSmallest(sizes);
int smallCount = sizes.get(small);
log.finer("LARGE: " + large + " : " + largeCount);
log.finer("SMALL: " + small + " : " + smallCount);
if (!(largeCount == smallCount || largeCount == smallCount + 1)) {
Team largeT = getTeam(large).orElseThrow(() -> new RuntimeException("Null team encountered"));
Team smallT = getTeam(small).orElseThrow(() -> new RuntimeException("Null team encountered"));
boolean switched = false;
for (int i = largeT.getPlayers().size() - 1; i > 0; i--) {
User player = largeT.getPlayers().get(i);
// if(playerIsInParty) {TODO party handling for team select
log.finer("SWITCH: " + player + " from " + large + " to " + small);
largeT.leave(player);
smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
switched = true;
break;
// }
}
if (!switched) {
log.finer(largeT.getName());
log.finer(largeT.getPlayers().size() + "");
User player = largeT.getPlayers().get(largeT.getPlayers().size() - 1);
largeT.leave(player);
smallT.join(player, player.getRating(getPhase().getGame().getGameMode()));
Lang.msg(player, LangKey.TEAM_AUTO_BALANCED, largeT.getName(), smallT.getName());
}
balance();
}
}
use of com.voxelgameslib.voxelgameslib.components.user.User in project VoxelGamesLibv2 by VoxelGamesLib.
the class DuelFeature method enable.
@Override
public void enable() {
if (getPhase().getGame().getPlayers().size() != 2) {
getPhase().getGame().broadcastMessage(LangKey.DUEL_WRONG_PLAYER_COUNT, getPhase().getGame().getPlayers().size());
getPhase().getGame().abortGame();
return;
}
one = getPhase().getGame().getPlayers().get(0);
two = getPhase().getGame().getPlayers().get(1);
if (ThreadLocalRandom.current().nextBoolean()) {
User temp = one;
one = two;
two = temp;
}
}
Aggregations