forked from External/mage
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:
parent
c449a9b2fd
commit
0c03ce3727
4 changed files with 67 additions and 66 deletions
|
|
@ -174,15 +174,17 @@ public class SessionManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser(String sessionId) {
|
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 UserManager.getInstance().getUser(sessions.get(sessionId).getUserId());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean extendUserSession(String sessionId) {
|
public boolean extendUserSession(String sessionId) {
|
||||||
if (sessions.containsKey(sessionId)) {
|
Session session = sessions.get(sessionId);
|
||||||
return UserManager.getInstance().extendUserSession(sessions.get(sessionId).getUserId());
|
if (session != null) {
|
||||||
|
return UserManager.getInstance().extendUserSession(session.getUserId());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -276,8 +276,10 @@ public class GameSession extends GameWatcher {
|
||||||
|
|
||||||
public void kill() {
|
public void kill() {
|
||||||
if (game != null) {
|
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);
|
game.quit(playerId);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
logger.error("game object missing playerId: " + (playerId == null ? "[null]":playerId));
|
logger.error("game object missing playerId: " + (playerId == null ? "[null]":playerId));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -912,14 +912,14 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
int deduction = 1;
|
int deduction = 1;
|
||||||
if (freeMulligans > 0) {
|
if (freeMulligans > 0) {
|
||||||
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
|
if (usedFreeMulligans != null && usedFreeMulligans.containsKey(player.getId())) {
|
||||||
int used = usedFreeMulligans.get(player.getId()).intValue();
|
int used = usedFreeMulligans.get(player.getId());
|
||||||
if (used < freeMulligans ) {
|
if (used < freeMulligans ) {
|
||||||
deduction = 0;
|
deduction = 0;
|
||||||
usedFreeMulligans.put(player.getId(), new Integer(used+1));
|
usedFreeMulligans.put(player.getId(), used+1);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deduction = 0;
|
deduction = 0;
|
||||||
usedFreeMulligans.put(player.getId(), new Integer(1));
|
usedFreeMulligans.put(player.getId(), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fireInformEvent(new StringBuilder(player.getName())
|
fireInformEvent(new StringBuilder(player.getName())
|
||||||
|
|
@ -931,20 +931,13 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void quit(UUID playerId) {
|
public void quit(UUID playerId) {
|
||||||
logger.debug("GameImpl.quit start " + playerId);
|
|
||||||
if (state != null) {
|
if (state != null) {
|
||||||
Player player = state.getPlayer(playerId);
|
Player player = state.getPlayer(playerId);
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
logger.debug("GameImpl.quit " + player.getName() + " quits the game");
|
|
||||||
player.quit(this);
|
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
|
@Override
|
||||||
|
|
@ -1294,7 +1287,12 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
}
|
}
|
||||||
return somethingHappened;
|
return somethingHappened;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Sets the waiting triggered abilities (if there are any)
|
||||||
|
* to the stack in the choosen order by player
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
public boolean checkTriggered() {
|
public boolean checkTriggered() {
|
||||||
boolean played = false;
|
boolean played = false;
|
||||||
for (UUID playerId: state.getPlayerList(state.getActivePlayerId())) {
|
for (UUID playerId: state.getPlayerList(state.getActivePlayerId())) {
|
||||||
|
|
@ -1868,10 +1866,10 @@ public abstract class GameImpl implements Game, Serializable {
|
||||||
|
|
||||||
Player player = getPlayer(playerId);
|
Player player = getPlayer(playerId);
|
||||||
if (player == null || player.hasLeft()) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
logger.debug("game.leave -> start player: " + player.getName());
|
logger.debug("Start leave game: " + player.getName());
|
||||||
player.leave();
|
player.leave();
|
||||||
if (checkIfGameIsOver()) {
|
if (checkIfGameIsOver()) {
|
||||||
// no need to remove objects if only one player is left so the game is over
|
// no need to remove objects if only one player is left so the game is over
|
||||||
|
|
|
||||||
|
|
@ -747,6 +747,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
castSourceIdWithoutMana = sourceId;
|
castSourceIdWithoutMana = sourceId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public UUID getCastSourceIdWithoutMana() {
|
public UUID getCastSourceIdWithoutMana() {
|
||||||
return castSourceIdWithoutMana;
|
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
|
// create list of all "notMoreThan" effects to track which one are consumed
|
||||||
HashMap<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffectsUsage = new HashMap<>();
|
HashMap<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffectsUsage = new HashMap<>();
|
||||||
for (Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>> restrictionEffect: game.getContinuousEffects().getApplicableRestrictionUntapNotMoreThanEffects(this, game).entrySet()) {
|
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()) {
|
if (!notMoreThanEffectsUsage.isEmpty()) {
|
||||||
|
|
@ -1141,7 +1142,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
// select permanents to untap to consume the "notMoreThan" effects
|
// select permanents to untap to consume the "notMoreThan" effects
|
||||||
for(Map.Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> handledEntry: notMoreThanEffectsUsage.entrySet()) {
|
for(Map.Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> handledEntry: notMoreThanEffectsUsage.entrySet()) {
|
||||||
// select a permanent to untap for this entry
|
// select a permanent to untap for this entry
|
||||||
int numberToUntap = handledEntry.getValue().intValue();
|
int numberToUntap = handledEntry.getValue();
|
||||||
if (numberToUntap > 0) {
|
if (numberToUntap > 0) {
|
||||||
|
|
||||||
List<Permanent> leftForUntap = getPermanentsThatCanBeUntapped(game, canBeUntapped, handledEntry.getKey().getKey(), notMoreThanEffectsUsage);
|
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())));
|
filter.add(Predicates.not(new PermanentIdPredicate(selectedPermanent.getId())));
|
||||||
// reduce available untap numbers from other "UntapNotMoreThan" effects if selected permanent applies to their filter too
|
// 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()) {
|
for (Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffect : notMoreThanEffectsUsage.entrySet()) {
|
||||||
if (notMoreThanEffect.getValue().intValue() > 0 && notMoreThanEffect.getKey().getKey().getFilter().match(selectedPermanent, game)) {
|
if (notMoreThanEffect.getValue() > 0 && notMoreThanEffect.getKey().getKey().getFilter().match(selectedPermanent, game)) {
|
||||||
notMoreThanEffect.setValue(new Integer(notMoreThanEffect.getValue().intValue() - 1));
|
notMoreThanEffect.setValue(notMoreThanEffect.getValue() - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// update the left for untap list
|
// update the left for untap list
|
||||||
|
|
@ -1250,7 +1251,7 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
boolean canBeSelected = true;
|
boolean canBeSelected = true;
|
||||||
// check if the permanent is restriced by another restriction that has left no permanent
|
// check if the permanent is restriced by another restriction that has left no permanent
|
||||||
for (Entry<Entry<RestrictionUntapNotMoreThanEffect, HashSet<Ability>>, Integer> notMoreThanEffect : notMoreThanEffectsUsage.entrySet()) {
|
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;
|
canBeSelected = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -1540,10 +1541,8 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void quit(Game game) {
|
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());
|
game.informPlayers(new StringBuilder(getName()).append(" quits the match.").toString());
|
||||||
quit = true;
|
quit = true;
|
||||||
log.debug("PlayerImpl.quit before concede" + getName() + " quits game " + game.getId());
|
|
||||||
this.concede(game);
|
this.concede(game);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1614,21 +1613,21 @@ public abstract class PlayerImpl implements Player, Serializable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lost(Game game) {
|
public void lost(Game game) {
|
||||||
log.debug("player lost -> start: " + this.getName());
|
log.debug(this.getName() + " has lost gameId: " + game.getId());
|
||||||
if (canLose(game)) {
|
if (canLose(game)) {
|
||||||
this.loses = true;
|
|
||||||
//20100423 - 603.9
|
//20100423 - 603.9
|
||||||
if (!this.wins) {
|
if (!this.wins) {
|
||||||
|
this.loses = true;
|
||||||
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
|
game.fireEvent(GameEvent.getEvent(GameEvent.EventType.LOST, null, null, playerId));
|
||||||
game.informPlayers(new StringBuilder(this.getName()).append(" has lost the game.").toString());
|
game.informPlayers(new StringBuilder(this.getName()).append(" has lost the game.").toString());
|
||||||
} else {
|
} 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);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue