Add allowed quit ratio option to match option and tourney option.

This commit is contained in:
Me Car 2016-01-30 23:17:32 +09:00
parent ef3fbffe11
commit 284c36b756
16 changed files with 292 additions and 74 deletions

View file

@ -238,9 +238,21 @@ public class MageServerImpl implements MageServer {
@Override
public TableView execute() throws MageException {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
User user = UserManager.getInstance().getUser(userId);
// check if the user satisfies the quitRatio requirement.
if (user != null) {
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getMatchQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
user.showUserMessage("Create table", message);
throw new MageException("No message");
}
}
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(userId, options);
if (logger.isDebugEnabled()) {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
logger.debug("TABLE created - tableId: " + table.getTableId() + " " + table.getTableName());
logger.debug("- " + user.getName() + " userId: " + user.getId());
@ -260,6 +272,7 @@ public class MageServerImpl implements MageServer {
public TableView execute() throws MageException {
try {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
User user = UserManager.getInstance().getUser(userId);
// check AI players max
String maxAiOpponents = ConfigSettings.getInstance().getMaxAiOpponents();
if (maxAiOpponents != null) {
@ -271,13 +284,22 @@ public class MageServerImpl implements MageServer {
}
}
if (aiPlayers > max) {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.showUserMessage("Create tournament", "It's only allowed to use a maximum of " + max + " AI players.");
}
throw new MageException("No message");
}
}
// check if the user satisfies the quitRatio requirement.
if (user != null) {
int quitRatio = options.getQuitRatio();
if (quitRatio < user.getTourneyQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
user.showUserMessage("Create tournament", message);
throw new MageException("No message");
}
}
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTournamentTable(userId, options);
logger.debug("Tournament table " + table.getTableId() + " created");
LogServiceImpl.instance.log(LogKeys.KEY_TOURNAMENT_TABLE_CREATED, sessionId, userId.toString(), table.getTableId().toString());

View file

@ -170,7 +170,7 @@ public class TableController {
}
}
if (userPlayerMap.containsKey(userId) && playerType.equals("Human")) {
user.showUserMessage("Join Table", new StringBuilder("You can join a table only one time.").toString());
user.showUserMessage("Join Table", "You can join a table only one time.");
return false;
}
Deck deck = null;
@ -195,6 +195,14 @@ public class TableController {
return false;
}
}
// Check quit ratio.
int quitRatio = table.getTournament().getOptions().getQuitRatio();
if (quitRatio < user.getTourneyQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getTourneyQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
user.showUserMessage("Join Table", message);
return false;
}
Player player = createPlayer(name, seat.getPlayerType(), skill);
if (player != null) {
@ -284,6 +292,15 @@ public class TableController {
}
return false;
}
// Check quit ratio.
int quitRatio = table.getMatch().getOptions().getQuitRatio();
if (quitRatio < user.getMatchQuitRatio()) {
String message = new StringBuilder("Your quit ratio ").append(user.getMatchQuitRatio())
.append("% is higher than the table requirement ").append(quitRatio).append("%").toString();
user.showUserMessage("Join Table", message);
return false;
}
Player player = createPlayer(name, seat.getPlayerType(), skill);
if (player == null) {
String message = new StringBuilder("Could not create player ").append(name).append(" of type ").append(seat.getPlayerType()).toString();

View file

@ -530,10 +530,14 @@ public class User {
userStats = UserStatsRepository.instance.getUser(this.userName);
if (userStats != null) {
userData.setMatchHistory(userStatsToMatchHistory(userStats.getProto()));
userData.setMatchQuitRatio(userStatsToMatchQuitRatio(userStats.getProto()));
userData.setTourneyHistory(userStatsToTourneyHistory(userStats.getProto()));
userData.setTourneyQuitRatio(userStatsToTourneyQuitRatio(userStats.getProto()));
} else {
userData.setMatchHistory("0");
userData.setMatchQuitRatio(0);
userData.setTourneyHistory("0");
userData.setTourneyQuitRatio(0);
}
}
@ -544,6 +548,13 @@ public class User {
return "<not available>";
}
public int getMatchQuitRatio() {
if (userData != null) {
return userData.getMatchQuitRatio();
}
return 0;
}
public String getTourneyHistory() {
if (userData != null) {
return userData.getTourneyHistory();
@ -556,6 +567,13 @@ public class User {
" Tourneys: " + userStatsToTourneyHistory(proto);
}
public int getTourneyQuitRatio() {
if (userData != null) {
return userData.getTourneyQuitRatio();
}
return 0;
}
public static String userStatsToMatchHistory(ResultProtos.UserStatsProto proto) {
StringBuilder builder = new StringBuilder();
builder.append(proto.getMatches());
@ -577,6 +595,17 @@ public class User {
return builder.toString();
}
public static int userStatsToMatchQuitRatio(ResultProtos.UserStatsProto proto) {
int matches = proto.getMatches();
if (matches == 0) {
return 0;
}
int quits = proto.getMatchesIdleTimeout() +
proto.getMatchesTimerTimeout() +
proto.getMatchesQuit();
return 100 * quits / matches;
}
public static String userStatsToTourneyHistory(ResultProtos.UserStatsProto proto) {
StringBuilder builder = new StringBuilder();
builder.append(proto.getTourneys());
@ -598,6 +627,17 @@ public class User {
return builder.toString();
}
public static int userStatsToTourneyQuitRatio(ResultProtos.UserStatsProto proto) {
int tourneys = proto.getTourneys();
if (tourneys == 0) {
return 0;
}
int quits = proto.getTourneysQuitDuringDrafting() +
proto.getTourneysQuitDuringConstruction() +
proto.getTourneysQuitDuringRound();
return 100 * quits / tourneys;
}
private static void joinStrings(StringBuilder joined, List<String> strings, String separator) {
for (int i = 0; i < strings.size(); ++i) {
if (i > 0) {

View file

@ -114,14 +114,18 @@ public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
List<UsersView> users = new ArrayList<>();
for (User user : UserManager.getInstance().getUsers()) {
try {
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(), user.getMatchHistory(), user.getTourneyHistory(), user.getGameInfo(), user.getPingInfo()));
users.add(new UsersView(user.getUserData().getFlagName(), user.getName(),
user.getMatchHistory(), user.getMatchQuitRatio(), user.getTourneyHistory(),
user.getTourneyQuitRatio(), user.getGameInfo(), user.getPingInfo()));
} catch (Exception ex) {
logger.fatal("User update exception: " + user.getName() + " - " + ex.toString(), ex);
users.add(new UsersView(
(user.getUserData() != null && user.getUserData().getFlagName() != null) ? user.getUserData().getFlagName() : "world",
user.getName() != null ? user.getName() : "<no name>",
user.getMatchHistory() != null ? user.getMatchHistory() : "<no match history>",
user.getMatchQuitRatio(),
user.getTourneyHistory() != null ? user.getTourneyHistory() : "<no tourney history>",
user.getTourneyQuitRatio(),
"[exception]",
user.getPingInfo() != null ? user.getPingInfo() : "<no ping>"));
}