use of mage.game.turn.Phase in project mage by magefree.
the class GameController method attemptToFixGame.
public String attemptToFixGame(User user) {
if (game == null) {
return "";
}
GameState state = game.getState();
if (state == null) {
return "";
}
logger.warn("FIX command was called by " + user.getName() + " for game " + game.getId() + " - players: " + game.getPlayerList().stream().map(game::getPlayer).filter(Objects::nonNull).map(p -> p.getName() + (p.isInGame() ? " (play)" : " (out)")).collect(Collectors.joining(", ")));
StringBuilder sb = new StringBuilder();
sb.append("<font color='red'>FIX command called by ").append(user.getName()).append("</font>");
// font resize start for all next logs
sb.append("<font size='-2'>");
sb.append("<br>Game ID: ").append(game.getId());
if (game.getTurn().getPhaseType() == null) {
sb.append("<br>Phase: not started").append(" Step: not started");
} else {
sb.append("<br>Phase: ").append(game.getTurn().getPhaseType().toString()).append(" Step: ").append(game.getTurn().getStepType().toString());
}
// pings info
sb.append("<br>");
sb.append(getPingsInfo());
boolean fixedAlready = false;
// for logs info
List<String> fixActions = new ArrayList<>();
// fix active
Player playerActive = game.getPlayer(state.getActivePlayerId());
sb.append("<br>Fixing active player: ").append(getName(playerActive));
if (playerActive != null && !playerActive.canRespond()) {
fixActions.add("active player fix");
sb.append("<br><font color='red'>WARNING, active player can't respond.</font>");
sb.append("<br>Try to concede...");
playerActive.concede(game);
// abort any wait response actions
playerActive.leave();
sb.append(" (").append(asWarning("OK")).append(", concede done)");
sb.append("<br>Try to skip step...");
Phase currentPhase = game.getPhase();
if (currentPhase != null) {
currentPhase.getStep().skipStep(game, state.getActivePlayerId());
fixedAlready = true;
sb.append(" (").append(asWarning("OK")).append(", skip step done)");
} else {
sb.append(" (").append(asBad("FAIL")).append(", step is null)");
}
} else {
sb.append(playerActive != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
}
// fix lost choosing dialog
Player choosingPlayer = game.getPlayer(state.getChoosingPlayerId());
sb.append("<br>Fixing choosing player: ").append(getName(choosingPlayer));
if (choosingPlayer != null && !choosingPlayer.canRespond()) {
fixActions.add("choosing player fix");
sb.append("<br><font color='red'>WARNING, choosing player can't respond.</font>");
sb.append("<br>Try to concede...");
choosingPlayer.concede(game);
// abort any wait response actions
choosingPlayer.leave();
sb.append(" (").append(asWarning("OK")).append(", concede done)");
sb.append("<br>Try to skip step...");
if (fixedAlready) {
sb.append(" (OK, already skipped before)");
} else {
Phase currentPhase = game.getPhase();
if (currentPhase != null) {
currentPhase.getStep().skipStep(game, state.getActivePlayerId());
fixedAlready = true;
sb.append(" (").append(asWarning("OK")).append(", skip step done)");
} else {
sb.append(" (").append(asBad("FAIL")).append(", step is null)");
}
}
} else {
sb.append(choosingPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
}
// fix lost priority
Player priorityPlayer = game.getPlayer(state.getPriorityPlayerId());
sb.append("<br>Fixing priority player: ").append(getName(priorityPlayer));
if (priorityPlayer != null && !priorityPlayer.canRespond()) {
fixActions.add("priority player fix");
sb.append("<br><font color='red'>WARNING, priority player can't respond.</font>");
sb.append("<br>Try to concede...");
priorityPlayer.concede(game);
// abort any wait response actions
priorityPlayer.leave();
sb.append(" (").append(asWarning("OK")).append(", concede done)");
sb.append("<br>Try to skip step...");
if (fixedAlready) {
sb.append(" (").append(asWarning("OK")).append(", already skipped before)");
} else {
Phase currentPhase = game.getPhase();
if (currentPhase != null) {
currentPhase.getStep().skipStep(game, state.getActivePlayerId());
fixedAlready = true;
sb.append(" (").append(asWarning("OK")).append(", skip step done)");
} else {
sb.append(" (").append(asBad("FAIL")).append(", step is null)");
}
}
} else {
sb.append(priorityPlayer != null ? " (" + asGood("OK") + ", can respond)" : " (" + asGood("OK") + ", no player)");
}
// fix timeout
sb.append("<br>Fixing future timeout: ");
if (futureTimeout != null) {
sb.append("cancelled?=").append(futureTimeout.isCancelled());
sb.append("...done?=").append(futureTimeout.isDone());
int delay = (int) futureTimeout.getDelay(TimeUnit.SECONDS);
sb.append("...getDelay?=").append(delay);
if (delay < 25) {
fixActions.add("future timeout fix");
sb.append("<br><font color='red'>WARNING, future timeout delay < 25</font>");
sb.append("<br>Try to pass...");
PassAbility pass = new PassAbility();
game.endTurn(pass);
sb.append(" (").append(asWarning("OK")).append(", pass done)");
} else {
sb.append(" (").append(asGood("OK")).append(", delay > 25)");
}
} else {
sb.append(" (").append(asGood("OK")).append(", timeout is not using)");
}
// ALL DONE
if (fixActions.isEmpty()) {
fixActions.add("none");
}
String appliedFixes = fixActions.stream().collect(Collectors.joining(", "));
sb.append("<br>Applied fixes: ").append(appliedFixes);
// font resize end
sb.append("</font>");
sb.append("<br>");
logger.warn("FIX command result for game " + game.getId() + ": " + appliedFixes);
return sb.toString();
}
use of mage.game.turn.Phase in project mage by magefree.
the class IllusionistsGambitRestrictionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<UUID> attackers = game.getCombat().getAttackers();
for (UUID attackerId : attackers) {
Permanent creature = game.getPermanent(attackerId);
if (creature != null) {
creature.removeFromCombat(game);
creature.untap(game);
}
}
if (!attackers.isEmpty()) {
Phase phase = game.getTurn().getPhase();
game.getState().getTurnMods().add(new TurnMod(game.getActivePlayerId(), TurnPhase.COMBAT, null, false));
ContinuousEffect effect = new IllusionistsGambitRequirementEffect(attackers, phase);
game.addEffect(effect, source);
effect = new IllusionistsGambitRestrictionEffect(attackers, phase);
game.addEffect(effect, source);
}
return true;
}
Aggregations