personal game messages

This commit is contained in:
magenoxx 2012-07-23 01:29:56 +04:00
parent 6a70d1ee6d
commit c783cbc41f
8 changed files with 71 additions and 14 deletions

View file

@ -220,6 +220,14 @@ public class CallbackClientImpl implements CallbackClient {
logger.warn("message out of sequence - ignoring");
}
}
else if (callback.getMethod().equals("gameInformPersonal")) {
GameClientMessage message = (GameClientMessage) callback.getData();
GamePanel panel = frame.getGame(callback.getObjectId());
if (panel != null) {
JOptionPane.showMessageDialog(panel, message.getMessage(), "Game message",
JOptionPane.INFORMATION_MESSAGE);
}
}
else if (callback.getMethod().equals("sideboard")) {
TableClientMessage message = (TableClientMessage) callback.getData();
DeckView deckView = message.getDeck();

View file

@ -168,6 +168,9 @@ public class GameController implements GameCallback {
case LOOK:
lookAtCards(event.getPlayerId(), event.getMessage(), event.getCards());
break;
case PERSONAL_MESSAGE:
informPersonal(event.getPlayerId(), event.getMessage());
break;
}
} catch (MageException ex) {
logger.fatal("Player event listener error ", ex);
@ -519,6 +522,14 @@ public class GameController implements GameCallback {
}
}
private synchronized void informPersonal(UUID playerId, final String message) throws MageException {
perform(playerId, new Command() {
public void execute(UUID playerId) {
gameSessions.get(playerId).informPersonal(message);
}
});
}
private void error(String message, Exception ex) {
StringBuilder sb = new StringBuilder();
sb.append(message).append(ex.toString());

View file

@ -28,8 +28,6 @@
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import mage.game.Game;
import mage.interfaces.callback.ClientCallback;
import mage.server.User;
@ -38,6 +36,9 @@ import mage.view.GameClientMessage;
import mage.view.GameView;
import org.apache.log4j.Logger;
import java.rmi.RemoteException;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -84,6 +85,15 @@ public class GameWatcher {
}
}
public void informPersonal(final String message) {
if (!killed) {
User user = UserManager.getInstance().getUser(userId);
if (user != null) {
user.fireCallback(new ClientCallback("gameInformPersonal", game.getId(), new GameClientMessage(getGameView(), message)));
}
}
}
public void gameOver(final String message) {
if (!killed) {
User user = UserManager.getInstance().getUser(userId);

View file

@ -109,6 +109,7 @@ public class DamageTargetEffect extends OneShotEffect<DamageTargetEffect> {
}
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player != null) {
game.informPlayer(player, "You were dealt 3 damage");
player.damage(amount.calculate(game, source), source.getSourceId(), game, false, preventable);
return true;
}

View file

@ -28,8 +28,6 @@
package mage.game.events;
import java.io.Serializable;
import java.util.*;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbility;
@ -37,6 +35,9 @@ import mage.cards.Card;
import mage.cards.Cards;
import mage.game.permanent.Permanent;
import java.io.Serializable;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -44,7 +45,7 @@ import mage.game.permanent.Permanent;
public class PlayerQueryEvent extends EventObject implements ExternalEvent, Serializable {
public enum QueryType {
ASK, CHOOSE, CHOOSE_ABILITY, CHOOSE_MODE, PICK_TARGET, PICK_ABILITY, SELECT, PLAY_MANA, PLAY_X_MANA, AMOUNT, LOOK, PICK_CARD, CONSTRUCT, CHOOSE_PILE
ASK, CHOOSE, CHOOSE_ABILITY, CHOOSE_MODE, PICK_TARGET, PICK_ABILITY, SELECT, PLAY_MANA, PLAY_X_MANA, AMOUNT, LOOK, PICK_CARD, CONSTRUCT, CHOOSE_PILE, PERSONAL_MESSAGE
}
private String message;
@ -127,6 +128,13 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
this.pile2 = pile2;
}
private PlayerQueryEvent(UUID playerId, String message) {
super(playerId);
this.queryType = QueryType.PERSONAL_MESSAGE;
this.message = message;
this.playerId = playerId;
}
public static PlayerQueryEvent askEvent(UUID playerId, String message) {
return new PlayerQueryEvent(playerId, message, null, null, null, null, QueryType.ASK, 0, 0, false);
}
@ -195,6 +203,9 @@ public class PlayerQueryEvent extends EventObject implements ExternalEvent, Seri
return new PlayerQueryEvent(playerId, message, QueryType.CONSTRUCT, time);
}
public static PlayerQueryEvent informPersonal(UUID playerId, String message) {
return new PlayerQueryEvent(playerId, message);
}
public String getMessage() {
return message;

View file

@ -28,14 +28,15 @@
package mage.game.events;
import java.io.Serializable;
import java.util.*;
import mage.abilities.*;
import mage.abilities.ActivatedAbility;
import mage.abilities.TriggeredAbility;
import mage.cards.Card;
import mage.cards.Cards;
import mage.game.permanent.Permanent;
import java.io.Serializable;
import java.util.*;
/**
*
* @author BetaSteward_at_googlemail.com
@ -117,4 +118,8 @@ public class PlayerQueryEventSource implements EventSource<PlayerQueryEvent>, Se
dispatcher.fireEvent(PlayerQueryEvent.construct(playerId, message, time));
}
public void informPlayer(UUID playerId, String message) {
dispatcher.fireEvent(PlayerQueryEvent.informPersonal(playerId, message));
}
}

View file

@ -28,9 +28,6 @@
package mage.game.events;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.game.Game;
@ -38,6 +35,10 @@ import mage.game.draft.Draft;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.EventObject;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -82,6 +83,11 @@ public class TableEvent extends EventObject implements ExternalEvent, Serializab
this.ex = ex;
}
public TableEvent(EventType eventType, UUID playerId, String message, Game game) {
this(eventType, message, game);
this.playerId = playerId;
}
public TableEvent(EventType eventType, UUID playerId, Deck deck, int timeout) {
super(playerId);
this.playerId = playerId;

View file

@ -28,8 +28,6 @@
package mage.game.events;
import java.io.Serializable;
import java.util.UUID;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.game.Game;
@ -38,6 +36,9 @@ import mage.game.events.TableEvent.EventType;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentPairing;
import java.io.Serializable;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -59,6 +60,10 @@ public class TableEventSource implements EventSource<TableEvent>, Serializable {
dispatcher.fireEvent(new TableEvent(eventType, message, game));
}
public void fireTableEvent(EventType eventType, UUID playerId, String message, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, playerId, message, game));
}
public void fireTableEvent(EventType eventType, String message, Exception ex, Game game) {
dispatcher.fireEvent(new TableEvent(eventType, message, ex, game));
}