mirror of
https://github.com/correl/mage.git
synced 2024-11-28 11:09:54 +00:00
Fixed weird errors with server lost of player priority on lagged games (see #4448)
This commit is contained in:
parent
1b191a5f93
commit
ba4fee11f6
2 changed files with 80 additions and 7 deletions
|
@ -74,6 +74,7 @@ import mage.target.common.TargetDefender;
|
||||||
import mage.util.GameLog;
|
import mage.util.GameLog;
|
||||||
import mage.util.ManaUtil;
|
import mage.util.ManaUtil;
|
||||||
import mage.util.MessageToClient;
|
import mage.util.MessageToClient;
|
||||||
|
import mage.util.RandomUtil;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,6 +83,7 @@ import org.apache.log4j.Logger;
|
||||||
*/
|
*/
|
||||||
public class HumanPlayer extends PlayerImpl {
|
public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
|
private transient Boolean responseOpenedForAnswer = false; // can't get response until prepared target (e.g. until send all fire events to all players)
|
||||||
private final transient PlayerResponse response = new PlayerResponse();
|
private final transient PlayerResponse response = new PlayerResponse();
|
||||||
|
|
||||||
protected static FilterCreatureForCombatBlock filterCreatureForCombatBlock = new FilterCreatureForCombatBlock();
|
protected static FilterCreatureForCombatBlock filterCreatureForCombatBlock = new FilterCreatureForCombatBlock();
|
||||||
|
@ -148,6 +150,17 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|| (actionIterations > 0 && !actionQueueSaved.isEmpty()));
|
|| (actionIterations > 0 && !actionQueueSaved.isEmpty()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void waitResponseOpen() {
|
||||||
|
// wait response open for answer process
|
||||||
|
while(!responseOpenedForAnswer && canRespond()) {
|
||||||
|
try {
|
||||||
|
Thread.sleep(100);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.warn("Response waiting interrapted for " + getId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean pullResponseFromQueue(Game game) {
|
protected boolean pullResponseFromQueue(Game game) {
|
||||||
if (actionQueue.isEmpty() && actionIterations > 0 && !actionQueueSaved.isEmpty()) {
|
if (actionQueue.isEmpty() && actionIterations > 0 && !actionQueueSaved.isEmpty()) {
|
||||||
actionQueue = new LinkedList(actionQueueSaved);
|
actionQueue = new LinkedList(actionQueueSaved);
|
||||||
|
@ -164,6 +177,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, game, null);
|
sendPlayerAction(PlayerAction.PASS_PRIORITY_UNTIL_STACK_RESOLVED, game, null);
|
||||||
}
|
}
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.copy(action);
|
response.copy(action);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
@ -174,6 +188,11 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void prepareForResponse(Game game) {
|
||||||
|
//logger.info("Prepare waiting " + getId());
|
||||||
|
responseOpenedForAnswer = false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void waitForResponse(Game game) {
|
protected void waitForResponse(Game game) {
|
||||||
if (isExecutingMacro()) {
|
if (isExecutingMacro()) {
|
||||||
pullResponseFromQueue(game);
|
pullResponseFromQueue(game);
|
||||||
|
@ -184,21 +203,27 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
// }
|
// }
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
response.clear();
|
response.clear(); // TODO: only one response for all games (can play only one game per session)?!
|
||||||
logger.debug("Waiting response from player: " + getId());
|
//logger.info("Waiting response from player: " + getId());
|
||||||
game.resumeTimer(getTurnControlledBy());
|
game.resumeTimer(getTurnControlledBy());
|
||||||
|
responseOpenedForAnswer = true; // start waiting for next response
|
||||||
boolean loop = true;
|
boolean loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
loop = false;
|
loop = false;
|
||||||
|
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
try {
|
try {
|
||||||
|
//logger.info("wait start: " + getId());
|
||||||
response.wait();
|
response.wait();
|
||||||
|
//logger.info("wait end: " + getId());
|
||||||
} catch (InterruptedException ex) {
|
} catch (InterruptedException ex) {
|
||||||
logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex);
|
logger.error("Response error for player " + getName() + " gameId: " + game.getId(), ex);
|
||||||
} finally {
|
} finally {
|
||||||
|
responseOpenedForAnswer = false;
|
||||||
game.pauseTimer(getTurnControlledBy());
|
game.pauseTimer(getTurnControlledBy());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.getResponseConcedeCheck()) {
|
if (response.getResponseConcedeCheck()) {
|
||||||
((GameImpl) game).checkConcede();
|
((GameImpl) game).checkConcede();
|
||||||
if (game.hasEnded()) {
|
if (game.hasEnded()) {
|
||||||
|
@ -210,6 +235,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//logger.info("Waiting response DONE (res queue " + actionQueueSaved.size() + "): " + getId() + ", res: " + response.toString());
|
||||||
if (recordingMacro && !macroTriggeredSelectionFlag) {
|
if (recordingMacro && !macroTriggeredSelectionFlag) {
|
||||||
// logger.info("Adding an action " + response);
|
// logger.info("Adding an action " + response);
|
||||||
actionQueueSaved.add(new PlayerResponse(response));
|
actionQueueSaved.add(new PlayerResponse(response));
|
||||||
|
@ -227,6 +253,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
Map<String, Serializable> options = new HashMap<>();
|
Map<String, Serializable> options = new HashMap<>();
|
||||||
options.put("UI.left.btn.text", "Mulligan");
|
options.put("UI.left.btn.text", "Mulligan");
|
||||||
options.put("UI.right.btn.text", "Keep");
|
options.put("UI.right.btn.text", "Keep");
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireAskPlayerEvent(playerId, new MessageToClient(message), null, options);
|
game.fireAskPlayerEvent(playerId, new MessageToClient(message), null, options);
|
||||||
}
|
}
|
||||||
|
@ -269,6 +296,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (messageToClient.getSecondMessage() == null) {
|
if (messageToClient.getSecondMessage() == null) {
|
||||||
messageToClient.setSecondMessage(getRelatedObjectName(source, game));
|
messageToClient.setSecondMessage(getRelatedObjectName(source, game));
|
||||||
}
|
}
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireAskPlayerEvent(playerId, messageToClient, source, options);
|
game.fireAskPlayerEvent(playerId, messageToClient, source, options);
|
||||||
}
|
}
|
||||||
|
@ -330,10 +358,11 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
replacementEffectChoice.setKeyChoices(rEffects);
|
replacementEffectChoice.setKeyChoices(rEffects);
|
||||||
|
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
updateGameStatePriority("chooseEffect", game);
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireChooseChoiceEvent(playerId, replacementEffectChoice);
|
game.fireChooseChoiceEvent(playerId, replacementEffectChoice);
|
||||||
}
|
}
|
||||||
updateGameStatePriority("chooseEffect", game);
|
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
logger.debug("Choose effect: " + response.getString());
|
logger.debug("Choose effect: " + response.getString());
|
||||||
if (response.getString() != null) {
|
if (response.getString() != null) {
|
||||||
|
@ -367,6 +396,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
updateGameStatePriority("choose(3)", game);
|
updateGameStatePriority("choose(3)", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireChooseChoiceEvent(playerId, choice);
|
game.fireChooseChoiceEvent(playerId, choice);
|
||||||
}
|
}
|
||||||
|
@ -416,6 +446,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
List<UUID> chosen = target.getTargets();
|
List<UUID> chosen = target.getTargets();
|
||||||
options.put("chosen", (Serializable) chosen);
|
options.put("chosen", (Serializable) chosen);
|
||||||
|
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(getId(), new MessageToClient(target.getMessage(), getRelatedObjectName(sourceId, game)), targetIds, required, getOptions(target, options));
|
game.fireSelectTargetEvent(getId(), new MessageToClient(target.getMessage(), getRelatedObjectName(sourceId, game)), targetIds, required, getOptions(target, options));
|
||||||
}
|
}
|
||||||
|
@ -483,6 +514,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
required = false;
|
required = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(getId(), new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), possibleTargets, required, getOptions(target, null));
|
game.fireSelectTargetEvent(getId(), new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), possibleTargets, required, getOptions(target, null));
|
||||||
}
|
}
|
||||||
|
@ -553,6 +585,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
options.put("choosable", (Serializable) choosable);
|
options.put("choosable", (Serializable) choosable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage()), cards, required, options);
|
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage()), cards, required, options);
|
||||||
}
|
}
|
||||||
|
@ -617,6 +650,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), cards, required, options);
|
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage(), getRelatedObjectName(source, game)), cards, required, options);
|
||||||
}
|
}
|
||||||
|
prepareForResponse(game);
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
if (response.getUUID() != null) {
|
if (response.getUUID() != null) {
|
||||||
if (target.getTargets().contains(response.getUUID())) { // if already included remove it
|
if (target.getTargets().contains(response.getUUID())) { // if already included remove it
|
||||||
|
@ -643,6 +677,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
public boolean chooseTargetAmount(Outcome outcome, TargetAmount target, Ability source, Game game) {
|
||||||
updateGameStatePriority("chooseTargetAmount", game);
|
updateGameStatePriority("chooseTargetAmount", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), getRelatedObjectName(source, game)),
|
game.fireSelectTargetEvent(playerId, new MessageToClient(target.getMessage() + "\n Amount remaining:" + target.getAmountRemaining(), getRelatedObjectName(source, game)),
|
||||||
target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game),
|
target.possibleTargets(source == null ? null : source.getSourceId(), playerId, game),
|
||||||
|
@ -786,6 +821,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
while (canRespond()) {
|
while (canRespond()) {
|
||||||
updateGameStatePriority("priority", game);
|
updateGameStatePriority("priority", game);
|
||||||
holdingPriority = false;
|
holdingPriority = false;
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.firePriorityEvent(playerId);
|
game.firePriorityEvent(playerId);
|
||||||
}
|
}
|
||||||
|
@ -920,6 +956,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
macroTriggeredSelectionFlag = true;
|
macroTriggeredSelectionFlag = true;
|
||||||
updateGameStatePriority("chooseTriggeredAbility", game);
|
updateGameStatePriority("chooseTriggeredAbility", game);
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetTriggeredAbilityEvent(playerId, "Pick triggered ability (goes to the stack first)", abilitiesWithNoOrderSet);
|
game.fireSelectTargetTriggeredAbilityEvent(playerId, "Pick triggered ability (goes to the stack first)", abilitiesWithNoOrderSet);
|
||||||
}
|
}
|
||||||
|
@ -956,6 +993,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
protected boolean playManaHandling(Ability abilityToCast, ManaCost unpaid, String promptText, Game game) {
|
protected boolean playManaHandling(Ability abilityToCast, ManaCost unpaid, String promptText, Game game) {
|
||||||
updateGameStatePriority("playMana", game);
|
updateGameStatePriority("playMana", game);
|
||||||
Map<String, Serializable> options = new HashMap<>();
|
Map<String, Serializable> options = new HashMap<>();
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.firePlayManaEvent(playerId, "Pay " + promptText, options);
|
game.firePlayManaEvent(playerId, "Pay " + promptText, options);
|
||||||
}
|
}
|
||||||
|
@ -992,6 +1030,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
int xValue = 0;
|
int xValue = 0;
|
||||||
updateGameStatePriority("announceRepetitions", game);
|
updateGameStatePriority("announceRepetitions", game);
|
||||||
do {
|
do {
|
||||||
|
prepareForResponse(game);
|
||||||
game.fireGetAmountEvent(playerId, "How many times do you want to repeat your shortcut?", 0, 999);
|
game.fireGetAmountEvent(playerId, "How many times do you want to repeat your shortcut?", 0, 999);
|
||||||
waitForResponse(game);
|
waitForResponse(game);
|
||||||
} while (response.getInteger() == null
|
} while (response.getInteger() == null
|
||||||
|
@ -1018,6 +1057,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
int xValue = 0;
|
int xValue = 0;
|
||||||
updateGameStatePriority("announceXMana", game);
|
updateGameStatePriority("announceXMana", game);
|
||||||
do {
|
do {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetAmountEvent(playerId, message, min, max);
|
game.fireGetAmountEvent(playerId, message, min, max);
|
||||||
}
|
}
|
||||||
|
@ -1036,6 +1076,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
int xValue = 0;
|
int xValue = 0;
|
||||||
updateGameStatePriority("announceXCost", game);
|
updateGameStatePriority("announceXCost", game);
|
||||||
do {
|
do {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetAmountEvent(playerId, message, min, max);
|
game.fireGetAmountEvent(playerId, message, min, max);
|
||||||
}
|
}
|
||||||
|
@ -1107,6 +1148,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
options.put(Constants.Option.SPECIAL_BUTTON, (Serializable) "All attack");
|
options.put(Constants.Option.SPECIAL_BUTTON, (Serializable) "All attack");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectEvent(playerId, "Select attackers", options);
|
game.fireSelectEvent(playerId, "Select attackers", options);
|
||||||
}
|
}
|
||||||
|
@ -1326,6 +1368,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectEvent(playerId, "Select blockers");
|
game.fireSelectEvent(playerId, "Select blockers");
|
||||||
}
|
}
|
||||||
|
@ -1358,6 +1401,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public UUID chooseAttackerOrder(List<Permanent> attackers, Game game) {
|
public UUID chooseAttackerOrder(List<Permanent> attackers, Game game) {
|
||||||
updateGameStatePriority("chooseAttackerOrder", game);
|
updateGameStatePriority("chooseAttackerOrder", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, "Pick attacker", attackers, true);
|
game.fireSelectTargetEvent(playerId, "Pick attacker", attackers, true);
|
||||||
}
|
}
|
||||||
|
@ -1377,6 +1421,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, List<UUID> blockerOrder, Game game) {
|
public UUID chooseBlockerOrder(List<Permanent> blockers, CombatGroup combatGroup, List<UUID> blockerOrder, Game game) {
|
||||||
updateGameStatePriority("chooseBlockerOrder", game);
|
updateGameStatePriority("chooseBlockerOrder", game);
|
||||||
while (!abort) {
|
while (!abort) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, "Pick blocker", blockers, true);
|
game.fireSelectTargetEvent(playerId, "Pick blocker", blockers, true);
|
||||||
}
|
}
|
||||||
|
@ -1395,6 +1440,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
protected void selectCombatGroup(UUID defenderId, UUID blockerId, Game game) {
|
protected void selectCombatGroup(UUID defenderId, UUID blockerId, Game game) {
|
||||||
updateGameStatePriority("selectCombatGroup", game);
|
updateGameStatePriority("selectCombatGroup", game);
|
||||||
TargetAttackingCreature target = new TargetAttackingCreature();
|
TargetAttackingCreature target = new TargetAttackingCreature();
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireSelectTargetEvent(playerId, new MessageToClient("Select attacker to block", getRelatedObjectName(blockerId, game)),
|
game.fireSelectTargetEvent(playerId, new MessageToClient("Select attacker to block", getRelatedObjectName(blockerId, game)),
|
||||||
target.possibleTargets(null, playerId, game), false, getOptions(target, null));
|
target.possibleTargets(null, playerId, game), false, getOptions(target, null));
|
||||||
|
@ -1447,6 +1493,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public int getAmount(int min, int max, String message, Game game) {
|
public int getAmount(int min, int max, String message, Game game) {
|
||||||
updateGameStatePriority("getAmount", game);
|
updateGameStatePriority("getAmount", game);
|
||||||
do {
|
do {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetAmountEvent(playerId, message, min, max);
|
game.fireGetAmountEvent(playerId, message, min, max);
|
||||||
}
|
}
|
||||||
|
@ -1478,6 +1525,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
LinkedHashMap<UUID, SpecialAction> specialActions = game.getState().getSpecialActions().getControlledBy(playerId, false);
|
LinkedHashMap<UUID, SpecialAction> specialActions = game.getState().getSpecialActions().getControlledBy(playerId, false);
|
||||||
if (!specialActions.isEmpty()) {
|
if (!specialActions.isEmpty()) {
|
||||||
updateGameStatePriority("specialAction", game);
|
updateGameStatePriority("specialAction", game);
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetChoiceEvent(playerId, name, null, new ArrayList<>(specialActions.values()));
|
game.fireGetChoiceEvent(playerId, name, null, new ArrayList<>(specialActions.values()));
|
||||||
}
|
}
|
||||||
|
@ -1494,6 +1542,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
LinkedHashMap<UUID, SpecialAction> specialActions = game.getState().getSpecialActions().getControlledBy(playerId, true);
|
LinkedHashMap<UUID, SpecialAction> specialActions = game.getState().getSpecialActions().getControlledBy(playerId, true);
|
||||||
if (!specialActions.isEmpty()) {
|
if (!specialActions.isEmpty()) {
|
||||||
updateGameStatePriority("specialAction", game);
|
updateGameStatePriority("specialAction", game);
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetChoiceEvent(playerId, name, null, new ArrayList<>(specialActions.values()));
|
game.fireGetChoiceEvent(playerId, name, null, new ArrayList<>(specialActions.values()));
|
||||||
}
|
}
|
||||||
|
@ -1539,6 +1588,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values()));
|
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(abilities.values()));
|
||||||
}
|
}
|
||||||
|
@ -1579,6 +1629,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
return (SpellAbility) useableAbilities.values().iterator().next();
|
return (SpellAbility) useableAbilities.values().iterator().next();
|
||||||
} else if (useableAbilities != null
|
} else if (useableAbilities != null
|
||||||
&& !useableAbilities.isEmpty()) {
|
&& !useableAbilities.isEmpty()) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values()));
|
game.fireGetChoiceEvent(playerId, name, object, new ArrayList<>(useableAbilities.values()));
|
||||||
}
|
}
|
||||||
|
@ -1631,6 +1682,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
if (!modeMap.isEmpty()) {
|
if (!modeMap.isEmpty()) {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireGetModeEvent(playerId, "Choose Mode", modeMap);
|
game.fireGetModeEvent(playerId, "Choose Mode", modeMap);
|
||||||
}
|
}
|
||||||
|
@ -1660,6 +1712,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
public boolean choosePile(Outcome outcome, String message, List<? extends Card> pile1, List<? extends Card> pile2, Game game) {
|
public boolean choosePile(Outcome outcome, String message, List<? extends Card> pile1, List<? extends Card> pile2, Game game) {
|
||||||
updateGameStatePriority("choosePile", game);
|
updateGameStatePriority("choosePile", game);
|
||||||
do {
|
do {
|
||||||
|
prepareForResponse(game);
|
||||||
if (!isExecutingMacro()) {
|
if (!isExecutingMacro()) {
|
||||||
game.fireChoosePileEvent(playerId, message, pile1, pile2);
|
game.fireChoosePileEvent(playerId, message, pile1, pile2);
|
||||||
}
|
}
|
||||||
|
@ -1673,6 +1726,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResponseString(String responseString) {
|
public void setResponseString(String responseString) {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setString(responseString);
|
response.setString(responseString);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
@ -1682,6 +1736,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResponseManaType(UUID manaTypePlayerId, ManaType manaType) {
|
public void setResponseManaType(UUID manaTypePlayerId, ManaType manaType) {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setManaType(manaType);
|
response.setManaType(manaType);
|
||||||
response.setResponseManaTypePlayerId(manaTypePlayerId);
|
response.setResponseManaTypePlayerId(manaTypePlayerId);
|
||||||
|
@ -1692,6 +1747,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResponseUUID(UUID responseUUID) {
|
public void setResponseUUID(UUID responseUUID) {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setUUID(responseUUID);
|
response.setUUID(responseUUID);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
@ -1701,15 +1757,17 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResponseBoolean(Boolean responseBoolean) {
|
public void setResponseBoolean(Boolean responseBoolean) {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setBoolean(responseBoolean);
|
response.setBoolean(responseBoolean);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
logger.debug("Got response boolean from player: " + getId());
|
logger.info("Got response boolean from player: " + getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setResponseInteger(Integer responseInteger) {
|
public void setResponseInteger(Integer responseInteger) {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setInteger(responseInteger);
|
response.setInteger(responseInteger);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
@ -1720,6 +1778,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
@Override
|
@Override
|
||||||
public void abort() {
|
public void abort() {
|
||||||
abort = true;
|
abort = true;
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
logger.debug("Got cancel action from player: " + getId());
|
logger.debug("Got cancel action from player: " + getId());
|
||||||
|
@ -1728,6 +1787,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void signalPlayerConcede() {
|
public void signalPlayerConcede() {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setResponseConcedeCheck();
|
response.setResponseConcedeCheck();
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
@ -1737,6 +1797,7 @@ public class HumanPlayer extends PlayerImpl {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void skip() {
|
public void skip() {
|
||||||
|
waitResponseOpen();
|
||||||
synchronized (response) {
|
synchronized (response) {
|
||||||
response.setInteger(0);
|
response.setInteger(0);
|
||||||
response.notifyAll();
|
response.notifyAll();
|
||||||
|
|
|
@ -11,7 +11,7 @@ import org.apache.log4j.Logger;
|
||||||
/**
|
/**
|
||||||
* For tests only
|
* For tests only
|
||||||
*
|
*
|
||||||
* @author noxx
|
* @author noxx, JayDi85
|
||||||
*/
|
*/
|
||||||
public class SimpleMageClient implements MageClient {
|
public class SimpleMageClient implements MageClient {
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ public class SimpleMageClient implements MageClient {
|
||||||
|
|
||||||
private static final Logger log = Logger.getLogger(SimpleMageClient.class);
|
private static final Logger log = Logger.getLogger(SimpleMageClient.class);
|
||||||
|
|
||||||
private final CallbackClient callbackClient;
|
private final LoadCallbackClient callbackClient;
|
||||||
|
|
||||||
public SimpleMageClient() {
|
public SimpleMageClient() {
|
||||||
clientId = UUID.randomUUID();
|
clientId = UUID.randomUUID();
|
||||||
|
@ -54,7 +54,11 @@ public class SimpleMageClient implements MageClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void processCallback(ClientCallback callback) {
|
public void processCallback(ClientCallback callback) {
|
||||||
|
try {
|
||||||
callbackClient.processCallback(callback);
|
callbackClient.processCallback(callback);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSession(Session session) {
|
public void setSession(Session session) {
|
||||||
|
@ -64,4 +68,12 @@ public class SimpleMageClient implements MageClient {
|
||||||
public boolean isGameOver() {
|
public boolean isGameOver() {
|
||||||
return ((LoadCallbackClient)callbackClient).isGameOver();
|
return ((LoadCallbackClient)callbackClient).isGameOver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setConcede(boolean needToConcede) {
|
||||||
|
this.callbackClient.setConcede(needToConcede);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastGameResult() {
|
||||||
|
return this.callbackClient.getLastGameResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue