mirror of
https://github.com/correl/mage.git
synced 2024-11-14 19:19:32 +00:00
Attempt to allow players to fix the game if the active/choosing/person with priority has left or has run down the clock
This commit is contained in:
parent
7698856d29
commit
471d49892f
2 changed files with 101 additions and 2 deletions
|
@ -244,6 +244,27 @@ public enum ChatManager {
|
|||
}
|
||||
return true;
|
||||
}
|
||||
if (command.startsWith("FIX")) {
|
||||
message += "<br/>" + GameManager.instance.getChatId(chatId);
|
||||
ChatSession session = chatSessions.get(chatId);
|
||||
if (session != null && session.getInfo() != null) {
|
||||
String gameId = session.getInfo();
|
||||
if (gameId.startsWith("Game ")) {
|
||||
UUID id = java.util.UUID.fromString(gameId.substring(5, gameId.length()));
|
||||
for (Entry<UUID, GameController> entry : GameManager.instance.getGameController().entrySet()) {
|
||||
if (entry.getKey().equals(id)) {
|
||||
GameController controller = entry.getValue();
|
||||
if (controller != null) {
|
||||
message += controller.attemptToFixGame();
|
||||
chatSessions.get(chatId).broadcastInfoToUser(user, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (command.startsWith("CARD ")) {
|
||||
Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase(Locale.ENGLISH));
|
||||
if (matchPattern.find()) {
|
||||
|
|
|
@ -37,6 +37,7 @@ import java.util.concurrent.locks.ReentrantReadWriteLock;
|
|||
import java.util.zip.GZIPOutputStream;
|
||||
import mage.MageException;
|
||||
import mage.abilities.Ability;
|
||||
import mage.abilities.common.PassAbility;
|
||||
import mage.cards.Card;
|
||||
import mage.cards.Cards;
|
||||
import mage.cards.decks.Deck;
|
||||
|
@ -57,6 +58,7 @@ import mage.game.events.PlayerQueryEvent;
|
|||
import mage.game.events.TableEvent;
|
||||
import mage.game.match.MatchPlayer;
|
||||
import mage.game.permanent.Permanent;
|
||||
import mage.game.turn.Phase;
|
||||
import mage.interfaces.Action;
|
||||
import mage.players.Player;
|
||||
import mage.server.*;
|
||||
|
@ -1150,13 +1152,13 @@ public class GameController implements GameCallback {
|
|||
sb.append(state.getPlayerList());
|
||||
sb.append("<br>getPlayers: ");
|
||||
sb.append(state.getPlayers());
|
||||
sb.append("<br>Player with Priority is: ");
|
||||
sb.append("<br><font color=orange>Player with Priority is: ");
|
||||
if (state.getPriorityPlayerId() != null) {
|
||||
sb.append(game.getPlayer(state.getPriorityPlayerId()).getName());
|
||||
} else {
|
||||
sb.append("noone!");
|
||||
}
|
||||
sb.append("<br>getRevealed: ");
|
||||
sb.append("</font><br>getRevealed: ");
|
||||
sb.append(state.getRevealed());
|
||||
sb.append("<br>getSpecialActions: ");
|
||||
sb.append(state.getSpecialActions());
|
||||
|
@ -1187,4 +1189,80 @@ public class GameController implements GameCallback {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public String attemptToFixGame() {
|
||||
if (game == null) {
|
||||
return "";
|
||||
}
|
||||
GameState state = game.getState();
|
||||
if (state == null) {
|
||||
return "";
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("<br/>Game State:<br/><font size=-2>");
|
||||
sb.append(state);
|
||||
boolean fixedAlready = false;
|
||||
|
||||
sb.append("<br>Active player is: ");
|
||||
sb.append(game.getPlayer(state.getActivePlayerId()).getName());
|
||||
PassAbility pass = new PassAbility();
|
||||
if (game.getPlayer(state.getActivePlayerId()).hasLeft()) {
|
||||
Phase currentPhase = game.getPhase();
|
||||
if (currentPhase != null) {
|
||||
currentPhase.getStep().skipStep(game, state.getActivePlayerId());
|
||||
sb.append("<br>Forcibly passing the phase!");
|
||||
fixedAlready = true;
|
||||
} else {
|
||||
sb.append("<br>Current phase null");
|
||||
}
|
||||
sb.append("<br>Active player has left");
|
||||
}
|
||||
|
||||
sb.append("<br>getChoosingPlayerId: ");
|
||||
if (state.getChoosingPlayerId() != null) {
|
||||
if (game.getPlayer(state.getChoosingPlayerId()).hasLeft()) {
|
||||
Phase currentPhase = game.getPhase();
|
||||
if (currentPhase != null && !fixedAlready) {
|
||||
currentPhase.getStep().endStep(game, state.getActivePlayerId());
|
||||
fixedAlready = true;
|
||||
sb.append("<br>Forcibly passing the phase!");
|
||||
} else if (currentPhase == null) {
|
||||
sb.append("<br>Current phase null");
|
||||
}
|
||||
sb.append("<br>Choosing player has left");
|
||||
}
|
||||
}
|
||||
|
||||
sb.append("<br><font color=orange>Player with Priority is: ");
|
||||
if (state.getPriorityPlayerId() != null) {
|
||||
if (game.getPlayer(state.getPriorityPlayerId()).hasLeft()) {
|
||||
Phase currentPhase = game.getPhase();
|
||||
if (currentPhase != null && !fixedAlready) {
|
||||
currentPhase.getStep().skipStep(game, state.getActivePlayerId());
|
||||
fixedAlready = true;
|
||||
sb.append("<br>Forcibly passing the phase!");
|
||||
}
|
||||
}
|
||||
sb.append(game.getPlayer(state.getPriorityPlayerId()).getName());
|
||||
sb.append("</font>");
|
||||
}
|
||||
|
||||
sb.append("<br>Future Timeout:");
|
||||
if (futureTimeout != null) {
|
||||
sb.append("Cancelled?=");
|
||||
sb.append(futureTimeout.isCancelled());
|
||||
sb.append(",,,Done?=");
|
||||
sb.append(futureTimeout.isDone());
|
||||
sb.append(",,,GetDelay?=");
|
||||
sb.append((int) futureTimeout.getDelay(TimeUnit.SECONDS));
|
||||
if ((int) futureTimeout.getDelay(TimeUnit.SECONDS) < 25) {
|
||||
game.endTurn(pass);
|
||||
sb.append("<br>Forcibly passing the turn!");
|
||||
}
|
||||
} else {
|
||||
sb.append("Not using future Timeout!");
|
||||
}
|
||||
sb.append("</font>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue