Some changes to manual mana pool handling.

This commit is contained in:
LevelX2 2014-05-27 08:37:16 +02:00
parent 5481841b9f
commit d9e4e99a0f
13 changed files with 33 additions and 24 deletions

View file

@ -414,7 +414,6 @@ public class PlayerPanelExt extends javax.swing.JPanel {
zonesPanel.setSize(100, 20); zonesPanel.setSize(100, 20);
zonesPanel.setLayout(null); zonesPanel.setLayout(null);
//
image = ImageHelper.getImageFromResources("/info/command_zone.png"); image = ImageHelper.getImageFromResources("/info/command_zone.png");
r = new Rectangle(21, 21); r = new Rectangle(21, 21);
resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r); resized = ImageHelper.getResizedImage(BufferedImageBuilder.bufferImage(image, BufferedImage.TYPE_INT_ARGB), r);
@ -735,7 +734,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
} }
private void btnManaActionPerformed(ManaType manaType) { private void btnManaActionPerformed(ManaType manaType) {
session.sendPlayerManaType(gameId, manaType); session.sendPlayerManaType(gameId, player.getPlayerId(), manaType);
} }
private void btnGraveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraveActionPerformed private void btnGraveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGraveActionPerformed
@ -764,10 +763,6 @@ public class PlayerPanelExt extends javax.swing.JPanel {
private ImagePanel life; private ImagePanel life;
private ImagePanel poison; private ImagePanel poison;
private ImagePanel hand; private ImagePanel hand;
// private HoverButton btnWhiteMana;
// private HoverButton btnBlueMana;
private HoverButton grave; private HoverButton grave;
private ImagePanel library; private ImagePanel library;
private CardView topCard; private CardView topCard;

View file

@ -114,7 +114,7 @@ public interface MageServer {
void sendPlayerString(UUID gameId, String sessionId, String data) throws MageException; void sendPlayerString(UUID gameId, String sessionId, String data) throws MageException;
void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException; void sendPlayerBoolean(UUID gameId, String sessionId, Boolean data) throws MageException;
void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException; void sendPlayerInteger(UUID gameId, String sessionId, Integer data) throws MageException;
void sendPlayerManaType(UUID gameId, String sessionId, ManaType data) throws MageException; void sendPlayerManaType(UUID gameId, UUID playerId, String sessionId, ManaType data) throws MageException;
void concedeGame(UUID gameId, String sessionId) throws MageException; void concedeGame(UUID gameId, String sessionId) throws MageException;
void quitMatch(UUID gameId, String sessionId) throws MageException; void quitMatch(UUID gameId, String sessionId) throws MageException;
void undo(UUID gameId, String sessionId) throws MageException; void undo(UUID gameId, String sessionId) throws MageException;

View file

@ -625,10 +625,10 @@ public class SessionImpl implements Session {
} }
@Override @Override
public boolean sendPlayerManaType(UUID gameId, ManaType data) { public boolean sendPlayerManaType(UUID gameId, UUID playerId, ManaType data) {
try { try {
if (isConnected()) { if (isConnected()) {
server.sendPlayerManaType(gameId, sessionId, data); server.sendPlayerManaType(gameId, playerId, sessionId, data);
return true; return true;
} }
} catch (MageException ex) { } catch (MageException ex) {

View file

@ -51,7 +51,7 @@ public interface GamePlay {
boolean sendPlayerString(UUID gameId, String data); boolean sendPlayerString(UUID gameId, String data);
boolean sendPlayerManaType(UUID gameId, ManaType data); boolean sendPlayerManaType(UUID gameId, UUID playerId, ManaType data);
boolean concedeGame(UUID gameId); boolean concedeGame(UUID gameId);

View file

@ -520,7 +520,10 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
} }
} else if (response.getManaType() != null) { } else if (response.getManaType() != null) {
// this mana type can be paid once from pool // this mana type can be paid once from pool
this.getManaPool().unlockManaType(response.getManaType()); if (response.getResponseManaTypePlayerId().equals(this.getId())) {
this.getManaPool().unlockManaType(response.getManaType());
}
// TODO: Handle if mana pool
} }
return true; return true;
} }
@ -965,9 +968,10 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
} }
@Override @Override
public void setResponseManaType(ManaType manaType) { public void setResponseManaType(UUID playerId, ManaType manaType) {
synchronized(response) { synchronized(response) {
response.setManaType(manaType); response.setManaType(manaType);
response.setResponseManaTypePlayerId(playerId);
response.notify(); response.notify();
log.debug("Got response mana type from player: " + getId()); log.debug("Got response mana type from player: " + getId());
} }

View file

@ -43,6 +43,7 @@ public class PlayerResponse implements Serializable {
private Boolean responseBoolean; private Boolean responseBoolean;
private Integer responseInteger; private Integer responseInteger;
private ManaType responseManaType; private ManaType responseManaType;
private UUID responseManaTypePlayerId;
public void clear() { public void clear() {
responseString = null; responseString = null;
@ -50,6 +51,7 @@ public class PlayerResponse implements Serializable {
responseBoolean = null; responseBoolean = null;
responseInteger = null; responseInteger = null;
responseManaType = null; responseManaType = null;
responseManaTypePlayerId = null;
} }
public String getString() { public String getString() {
@ -92,4 +94,12 @@ public class PlayerResponse implements Serializable {
this.responseManaType = responseManaType; this.responseManaType = responseManaType;
} }
public UUID getResponseManaTypePlayerId() {
return responseManaTypePlayerId;
}
public void setResponseManaTypePlayerId(UUID responseManaTypePlayerId) {
this.responseManaTypePlayerId = responseManaTypePlayerId;
}
} }

View file

@ -570,13 +570,13 @@ public class MageServerImpl implements MageServer {
} }
@Override @Override
public void sendPlayerManaType(final UUID gameId, final String sessionId, final ManaType data) throws MageException { public void sendPlayerManaType(final UUID gameId, final UUID playerId, final String sessionId, final ManaType data) throws MageException {
execute("sendPlayerManaType", sessionId, new Action() { execute("sendPlayerManaType", sessionId, new Action() {
@Override @Override
public void execute() { public void execute() {
User user = SessionManager.getInstance().getUser(sessionId); User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) { if (user != null) {
user.sendPlayerManaType(gameId, data); user.sendPlayerManaType(gameId, playerId, data);
} else { } else {
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId); logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
} }

View file

@ -223,9 +223,9 @@ public class User {
GameManager.getInstance().sendPlayerString(gameId, userId, data); GameManager.getInstance().sendPlayerString(gameId, userId, data);
} }
public void sendPlayerManaType(final UUID gameId, final ManaType data) { public void sendPlayerManaType(final UUID gameId, final UUID playerId, final ManaType data) {
lastActivity = new Date(); lastActivity = new Date();
GameManager.getInstance().sendPlayerManaType(gameId, userId, data); GameManager.getInstance().sendPlayerManaType(gameId, playerId, userId, data);
} }
public void sendPlayerBoolean(final UUID gameId, final Boolean data) { public void sendPlayerBoolean(final UUID gameId, final Boolean data) {

View file

@ -475,11 +475,11 @@ public class GameController implements GameCallback {
}); });
} }
public void sendPlayerManaType(UUID userId, final ManaType data) { public void sendPlayerManaType(UUID userId, UUID playerId, final ManaType data) {
sendMessage(userId, new Command() { sendMessage(userId, new Command() {
@Override @Override
public void execute(UUID playerId) { public void execute(UUID playerId) {
getGameSession(playerId).sendPlayerManaType(data); getGameSession(playerId).sendPlayerManaType(data, playerId);
} }
}); });
} }

View file

@ -85,9 +85,9 @@ public class GameManager {
} }
} }
public void sendPlayerManaType(UUID gameId, UUID userId, ManaType data) { public void sendPlayerManaType(UUID gameId, UUID playerId, UUID userId, ManaType data) {
if (gameControllers.containsKey(gameId)) { if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerManaType(userId, data); gameControllers.get(gameId).sendPlayerManaType(userId, playerId, data);
} }
} }

View file

@ -221,9 +221,9 @@ public class GameSession extends GameWatcher {
game.getPlayer(playerId).setResponseString(data); game.getPlayer(playerId).setResponseString(data);
} }
public void sendPlayerManaType(ManaType manaType) { public void sendPlayerManaType(ManaType manaType, UUID playerId) {
cancelTimeout(); cancelTimeout();
game.getPlayer(playerId).setResponseManaType(manaType); game.getPlayer(playerId).setResponseManaType(playerId, manaType);
} }
public void sendPlayerBoolean(Boolean data) { public void sendPlayerBoolean(Boolean data) {

View file

@ -278,7 +278,7 @@ public interface Player extends MageItem, Copyable<Player> {
void setResponseUUID(UUID responseUUID); void setResponseUUID(UUID responseUUID);
void setResponseBoolean(Boolean responseBoolean); void setResponseBoolean(Boolean responseBoolean);
void setResponseInteger(Integer data); void setResponseInteger(Integer data);
void setResponseManaType(ManaType responseManaType); void setResponseManaType(UUID playerId, ManaType responseManaType);
boolean priority(Game game); boolean priority(Game game);
boolean choose(Outcome outcome, Target target, UUID sourceId, Game game); boolean choose(Outcome outcome, Target target, UUID sourceId, Game game);

View file

@ -1473,7 +1473,7 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
public void setResponseString(String responseString) {} public void setResponseString(String responseString) {}
@Override @Override
public void setResponseManaType(ManaType responseManaType) {} public void setResponseManaType(UUID playerId, ManaType responseManaType) {}
@Override @Override
public void setResponseUUID(UUID responseUUID) {} public void setResponseUUID(UUID responseUUID) {}