Some changes to game end handling (in hope to fix/improve server handling of games). Some chanmges to log messages.

This commit is contained in:
LevelX2 2014-08-17 02:49:21 +02:00
parent c449a9b2fd
commit 0c03ce3727
4 changed files with 67 additions and 66 deletions

View file

@ -174,15 +174,17 @@ public class SessionManager {
}
public User getUser(String sessionId) {
if (sessions.containsKey(sessionId)) {
Session session = sessions.get(sessionId);
if (session != null) {
return UserManager.getInstance().getUser(sessions.get(sessionId).getUserId());
}
return null;
}
public boolean extendUserSession(String sessionId) {
if (sessions.containsKey(sessionId)) {
return UserManager.getInstance().extendUserSession(sessions.get(sessionId).getUserId());
Session session = sessions.get(sessionId);
if (session != null) {
return UserManager.getInstance().extendUserSession(session.getUserId());
}
return false;
}

View file

@ -276,8 +276,10 @@ public class GameSession extends GameWatcher {
public void kill() {
if (game != null) {
logger.debug("before game.quit playerId:" + playerId);
if (game.getPlayer(playerId).isInGame()) {
logger.debug("QUIT game playerId: " + playerId + " gameId: " + game.getId());
game.quit(playerId);
}
} else {
logger.error("game object missing playerId: " + (playerId == null ? "[null]":playerId));
}

View file

@ -912,14 +912,14 @@ public abstract class GameImpl implements Game, Serializable {
int deduction = 1;
if (freeMulligans > 0) {
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
int used = usedFreeMulligans.get(player.getId()).intValue();
int used = usedFreeMulligans.get(player.getId());
if (used < freeMulligans ) {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(used+1));
usedFreeMulligans.put(player.getId(), used+1);
}
} else {
deduction = 0;
usedFreeMulligans.put(player.getId(), new Integer(1));
usedFreeMulligans.put(player.getId(), 1);
}
}
fireInformEvent(new StringBuilder(player.getName())
@ -931,20 +931,13 @@ public abstract class GameImpl implements Game, Serializable {
}
@Override
public synchronized void quit(UUID playerId) {
logger.debug("GameImpl.quit start " + playerId);
public void quit(UUID playerId) {
if (state != null) {
Player player = state.getPlayer(playerId);
if (player != null) {
logger.debug("GameImpl.quit " + player.getName() + " quits the game");
player.quit(this);
}else {
logger.error(new StringBuilder("GameImpl.quit - player not found - playerId: ").append(playerId));
}
} else {
logger.error(new StringBuilder("GameImpl.quit - state not found - playerId: ").append(playerId));
}
logger.debug("GameImpl.quit end " + playerId);
}
@Override
@ -1294,7 +1287,12 @@ public abstract class GameImpl implements Game, Serializable {
}
return somethingHappened;
}
/**
* Sets the waiting triggered abilities (if there are any)
* to the stack in the choosen order by player
*
* @return
*/
public boolean checkTriggered() {
boolean played = false;
for (UUID playerId: state.getPlayerList(state.getActivePlayerId())) {
@ -1868,10 +1866,10 @@ public abstract class GameImpl implements Game, Serializable {
Player player = getPlayer(playerId);
if (player == null || player.hasLeft()) {
logger.debug("game.leave -> player already left " + (player != null ? player.getName():playerId));
logger.debug("Player already left " + (player != null ? player.getName():playerId));
return;
}
logger.debug("game.leave -> start player: " + player.getName());
logger.debug("Start leave game: " + player.getName());
player.leave();
if (checkIfGameIsOver()) {
// no need to remove objects if only one player is left so the game is over

View file

@ -747,6 +747,7 @@ public abstract class PlayerImpl implements Player, Serializable {
castSourceIdWithoutMana = sourceId;
}
@Override
public UUID getCastSourceIdWithoutMana() {
return castSourceIdWithoutMana;
}
@ -1116,7 +1117,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// create list of all "notMoreThan" effects to track which one are consumed
HashMap<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffectsUsage = new HashMap<>();
for (Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>> restrictionEffect: game.getContinuousEffects().getApplicableRestrictionUntapNotMoreThanEffects(this, game).entrySet()) {
notMoreThanEffectsUsage.put(restrictionEffect, new Integer(restrictionEffect.getKey().getNumber()));
notMoreThanEffectsUsage.put(restrictionEffect, restrictionEffect.getKey().getNumber());
}
if (!notMoreThanEffectsUsage.isEmpty()) {
@ -1141,7 +1142,7 @@ public abstract class PlayerImpl implements Player, Serializable {
// select permanents to untap to consume the "notMoreThan" effects
for(Map.Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> handledEntry: notMoreThanEffectsUsage.entrySet()) {
// select a permanent to untap for this entry
int numberToUntap = handledEntry.getValue().intValue();
int numberToUntap = handledEntry.getValue();
if (numberToUntap > 0) {
List<Permanent> leftForUntap = getPermanentsThatCanBeUntapped(game, canBeUntapped, handledEntry.getKey().getKey(), notMoreThanEffectsUsage);
@ -1178,8 +1179,8 @@ public abstract class PlayerImpl implements Player, Serializable {
filter.add(Predicates.not(new PermanentIdPredicate(selectedPermanent.getId())));
// reduce available untap numbers from other "UntapNotMoreThan" effects if selected permanent applies to their filter too
for (Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffect : notMoreThanEffectsUsage.entrySet()) {
if (notMoreThanEffect.getValue().intValue() > 0 && notMoreThanEffect.getKey().getKey().getFilter().match(selectedPermanent, game)) {
notMoreThanEffect.setValue(new Integer(notMoreThanEffect.getValue().intValue() - 1));
if (notMoreThanEffect.getValue() > 0 && notMoreThanEffect.getKey().getKey().getFilter().match(selectedPermanent, game)) {
notMoreThanEffect.setValue(notMoreThanEffect.getValue() - 1);
}
}
// update the left for untap list
@ -1250,7 +1251,7 @@ public abstract class PlayerImpl implements Player, Serializable {
boolean canBeSelected = true;
// check if the permanent is restriced by another restriction that has left no permanent
for (Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffect : notMoreThanEffectsUsage.entrySet()) {
if (notMoreThanEffect.getKey().getKey().getFilter().match(permanent, game) && notMoreThanEffect.getValue().intValue() == 0) {
if (notMoreThanEffect.getKey().getKey().getFilter().match(permanent, game) && notMoreThanEffect.getValue() == 0) {
canBeSelected = false;
break;
}
@ -1540,10 +1541,8 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public void quit(Game game) {
log.debug("PlayerImpl.quit start " + getName() + " quits game " + game.getId());
game.informPlayers(new StringBuilder(getName()).append(" quits the match.").toString());
quit = true;
log.debug("PlayerImpl.quit before concede" + getName() + " quits game " + game.getId());
this.concede(game);
}
@ -1614,21 +1613,21 @@ public abstract class PlayerImpl implements Player, Serializable {
@Override
public void lost(Game game) {
log.debug("player lost -> start: " + this.getName());
log.debug(this.getName() + " has lost gameId: " + game.getId());
if (canLose(game)) {
this.loses = true;
//20100423 - 603.9
if (!this.wins) {
this.loses = true;
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
game.informPlayers(new StringBuilder(this.getName()).append(" has lost the game.").toString());
} else {
log.debug("player.lost -> stop setting lost because he already has won!: " + this.getName());
log.debug(this.getName() + " has already won - stop lost");
}
// for draw - first all players that have lost have to be set to lost
if (!hasLeft()) {
log.debug("Game over playerId: " + playerId);
game.gameOver(playerId);
}
// for draw first all players that have lost have to be set to lost
// if (!hasLeft()) {
// log.debug("player.lost -> calling leave");
// game.gameOver(playerId);
// }
}
}