use of mage.abilities.common.PassAbility 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.abilities.common.PassAbility in project mage by magefree.
the class ComputerPlayer6 method act.
protected void act(Game game) {
if (actions == null || actions.isEmpty()) {
pass(game);
} else {
boolean usedStack = false;
while (actions.peek() != null) {
Ability ability = actions.poll();
// example: ===> SELECTED ACTION for PlayerA: Play Swamp
logger.info(String.format("===> SELECTED ACTION for %s: %s", getName(), ability.toString() + listTargets(game, ability.getTargets(), " (targeting %s)", "")));
if (!ability.getTargets().isEmpty()) {
for (Target target : ability.getTargets()) {
for (UUID id : target.getTargets()) {
target.updateTarget(id, game);
if (!target.isNotTarget()) {
game.addSimultaneousEvent(GameEvent.getEvent(GameEvent.EventType.TARGETED, id, ability, ability.getControllerId()));
}
}
}
Player player = game.getPlayer(ability.getFirstTarget());
if (player != null) {
logger.info("targets = " + player.getName());
}
}
this.activateAbility((ActivatedAbility) ability, game);
if (ability.isUsesStack()) {
usedStack = true;
}
if (!suggestedActions.isEmpty() && !(ability instanceof PassAbility)) {
Iterator<String> it = suggestedActions.iterator();
while (it.hasNext()) {
String action = it.next();
Card card = game.getCard(ability.getSourceId());
if (card != null && action.equals(card.getName())) {
logger.info("-> removed from suggested=" + action);
it.remove();
}
}
}
}
if (usedStack) {
pass(game);
}
}
}
use of mage.abilities.common.PassAbility in project mage by magefree.
the class ComputerPlayer6 method checkForRepeatedAction.
private boolean checkForRepeatedAction(Game sim, SimulationNode2 node, Ability action, UUID playerId) {
// pass or casting two times a spell multiple times on hand is ok
if (action instanceof PassAbility || action instanceof SpellAbility || action.getAbilityType() == AbilityType.MANA) {
return false;
}
int newVal = GameStateEvaluator2.evaluate(playerId, sim).getTotalScore();
SimulationNode2 test = node.getParent();
while (test != null) {
if (test.getPlayerId().equals(playerId)) {
if (test.getAbilities() != null && test.getAbilities().size() == 1) {
if (action.toString().equals(test.getAbilities().get(0).toString())) {
if (test.getParent() != null) {
Game prevGame = node.getGame();
if (prevGame != null) {
int oldVal = GameStateEvaluator2.evaluate(playerId, prevGame).getTotalScore();
if (oldVal >= newVal) {
return true;
}
}
}
}
}
}
test = test.getParent();
}
return false;
}
use of mage.abilities.common.PassAbility in project mage by magefree.
the class RandomPlayer method priority.
@Override
public boolean priority(Game game) {
boolean didSomething = false;
Ability ability = getAction(game);
if (!(ability instanceof PassAbility)) {
didSomething = true;
}
activateAbility((ActivatedAbility) ability, game);
actionCount++;
return didSomething;
}
use of mage.abilities.common.PassAbility in project mage by magefree.
the class PlayerImpl method activateAbility.
@Override
public boolean activateAbility(ActivatedAbility ability, Game game) {
if (ability == null) {
return false;
}
boolean result;
if (ability instanceof PassAbility) {
pass(game);
return true;
}
Card card = game.getCard(ability.getSourceId());
if (ability instanceof PlayLandAsCommanderAbility) {
// LAND as commander: play land with cost, but without stack
ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
if (!activationStatus.canActivate() || !this.canPlayLand()) {
return false;
}
if (card == null) {
return false;
}
// as copy, tries to applie cost effects and pays
Ability activatingAbility = ability.copy();
if (activatingAbility.activate(game, false)) {
result = playLand(card, game, false);
} else {
result = false;
}
} else if (ability instanceof PlayLandAbility) {
// LAND as normal card: without cost and stack
result = playLand(card, game, false);
} else {
// ABILITY
ActivationStatus activationStatus = ability.canActivate(this.playerId, game);
if (!activationStatus.canActivate()) {
return false;
}
switch(ability.getAbilityType()) {
case SPECIAL_ACTION:
result = specialAction((SpecialAction) ability.copy(), game);
break;
case SPECIAL_MANA_PAYMENT:
result = specialManaPayment((SpecialAction) ability.copy(), game);
break;
case MANA:
result = playManaAbility((ActivatedManaAbilityImpl) ability.copy(), game);
break;
case SPELL:
result = cast((SpellAbility) ability, game, false, activationStatus.getApprovingObject());
break;
default:
result = playAbility(ability.copy(), game);
break;
}
}
// if player has taken an action then reset all player passed flags
justActivatedType = null;
if (result) {
if (isHuman() && (ability.getAbilityType() == AbilityType.SPELL || ability.getAbilityType() == AbilityType.ACTIVATED)) {
if (ability.isUsesStack()) {
// if the ability does not use the stack (e.g. Suspend) auto pass would go to next phase unintended
setJustActivatedType(ability.getAbilityType());
}
}
game.getPlayers().resetPassed();
}
return result;
}
Aggregations