mirror of
https://github.com/correl/mage.git
synced 2024-12-24 11:50:45 +00:00
...
This commit is contained in:
parent
69e219c7c6
commit
1f53bb1995
4 changed files with 26 additions and 56 deletions
|
@ -29,7 +29,6 @@
|
|||
package mage.interfaces.callback;
|
||||
|
||||
import java.util.concurrent.locks.Condition;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.logging.Logger;
|
||||
import mage.util.Logging;
|
||||
|
@ -40,56 +39,6 @@ import mage.util.Logging;
|
|||
*/
|
||||
public class CallbackServerSession {
|
||||
|
||||
// private final ClientCallback callback = new ClientCallback();
|
||||
// private Boolean waiting = false;
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * blocks the thread until a callback is requested
|
||||
// *
|
||||
// * @return ClientCallback - the callback requested
|
||||
// */
|
||||
// public ClientCallback callback() {
|
||||
// //TODO: use ReentrantLock instead
|
||||
// do {
|
||||
// callback.clear();
|
||||
// synchronized(callback) {
|
||||
// try {
|
||||
// waiting = true;
|
||||
// callback.wait();
|
||||
// waiting.notify();
|
||||
// waiting = false;
|
||||
// } catch (InterruptedException ex) {}
|
||||
// }
|
||||
// } while (callback.getMethod() == null);
|
||||
// return callback;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// *
|
||||
// * requests a callback
|
||||
// *
|
||||
// * @param call - the callback to request
|
||||
// */
|
||||
// public void setCallback(ClientCallback call) {
|
||||
// //TODO: use ReentrantLock instead - wait until a lock is aquired by another thread before setting method and data
|
||||
// synchronized(waiting) {
|
||||
// if (!waiting) {
|
||||
// try {
|
||||
// waiting.wait();
|
||||
// } catch (InterruptedException ex) {}
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// synchronized(callback) {
|
||||
// callback.setMethod(call.getMethod());
|
||||
// callback.setData(call.getData());
|
||||
// callback.notify();
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private final static Logger logger = Logging.getLogger(CallbackServerSession.class.getName());
|
||||
|
||||
private final ClientCallback callback = new ClientCallback();
|
||||
|
@ -138,6 +87,7 @@ public class CallbackServerSession {
|
|||
}
|
||||
callback.setMethod(call.getMethod());
|
||||
callback.setData(call.getData());
|
||||
callback.setMessageId(call.getMessageId());
|
||||
callbackCalled.signal();
|
||||
}
|
||||
finally {
|
||||
|
|
|
@ -38,6 +38,7 @@ public class ClientCallback implements Serializable {
|
|||
|
||||
private Object data;
|
||||
private String method;
|
||||
private int messageId;
|
||||
|
||||
public ClientCallback() {}
|
||||
|
||||
|
@ -67,4 +68,12 @@ public class ClientCallback implements Serializable {
|
|||
this.method = method;
|
||||
}
|
||||
|
||||
public void setMessageId(int messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
public int getMessageId() {
|
||||
return messageId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ public class GameView implements Serializable {
|
|||
for (ExileZone exileZone: game.getExile().getExileZones()) {
|
||||
exiles.add(new ExileView(exileZone));
|
||||
}
|
||||
this.phase = game.getTurn().getPhase();
|
||||
this.step = game.getTurn().getStep();
|
||||
this.phase = game.getTurn().getPhaseType();
|
||||
this.step = game.getTurn().getStepType();
|
||||
this.turn = game.getTurnNum();
|
||||
if (game.getActivePlayerId() != null)
|
||||
this.activePlayerName = game.getPlayer(game.getActivePlayerId()).getName();
|
||||
|
|
|
@ -66,12 +66,23 @@ public class PlayerView implements Serializable {
|
|||
for (Card card: player.getGraveyard().values()) {
|
||||
graveyard.add(new CardView(card));
|
||||
}
|
||||
for (Permanent permanent: game.getBattlefield().getAllPermanents(player.getId())) {
|
||||
PermanentView view = new PermanentView(permanent);
|
||||
battlefield.put(view.getId(), view);
|
||||
for (Permanent permanent: game.getBattlefield().getAllPermanents()) {
|
||||
if (showInBattlefield(permanent, game)) {
|
||||
PermanentView view = new PermanentView(permanent);
|
||||
battlefield.put(view.getId(), view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean showInBattlefield(Permanent permanent, GameState game) {
|
||||
|
||||
//show permanents controlled by player or attachments to permanents controlled by player
|
||||
if (permanent.getAttachedTo() == null)
|
||||
return permanent.getControllerId().equals(playerId);
|
||||
else
|
||||
return game.getPermanent(permanent.getAttachedTo()).getControllerId().equals(playerId);
|
||||
}
|
||||
|
||||
public int getLife() {
|
||||
return this.life;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue