Added context menu to switch between manual and automatic usage of the mana in mana pool. Manual usage is done by clicking on the mana symbol in the player panel. Still some fine tuning to do.

This commit is contained in:
LevelX2 2014-05-24 02:56:35 +02:00
parent eeead4a8b4
commit 71fb7bf25b
26 changed files with 415 additions and 100 deletions

View file

@ -65,6 +65,7 @@ import java.util.List;
import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import mage.constants.ManaType;
/**
*
@ -568,6 +569,21 @@ public class MageServerImpl implements MageServer {
});
}
@Override
public void sendPlayerManaType(final UUID gameId, final String sessionId, final ManaType data) throws MageException {
execute("sendPlayerManaType", sessionId, new Action() {
@Override
public void execute() {
User user = SessionManager.getInstance().getUser(sessionId);
if (user != null) {
user.sendPlayerManaType(gameId, data);
} else {
logger.warn("Your session expired: gameId=" + gameId + ", sessionId=" + sessionId);
}
}
});
}
@Override
public void sendPlayerBoolean(final UUID gameId, final String sessionId, final Boolean data) throws MageException {
execute("sendPlayerBoolean", sessionId, new Action() {
@ -609,6 +625,17 @@ public class MageServerImpl implements MageServer {
});
}
@Override
public void setManaPoolMode(final UUID gameId, final String sessionId, final boolean autoPayment) throws MageException {
execute("setManaPoolMode", sessionId, new Action() {
@Override
public void execute() {
UUID userId = SessionManager.getInstance().getSession(sessionId).getUserId();
GameManager.getInstance().setManaPoolMode(gameId, userId, autoPayment);
}
});
}
@Override
public void concedeGame(final UUID gameId, final String sessionId) throws MageException {
execute("concedeGame", sessionId, new Action() {

View file

@ -36,6 +36,7 @@ import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import mage.cards.decks.Deck;
import mage.constants.ManaType;
import mage.game.Table;
import mage.interfaces.callback.ClientCallback;
import mage.players.net.UserData;
@ -137,7 +138,7 @@ public class User {
public String getDisconnectDuration() {
long secondsDisconnected = SystemUtil.getDateDiff(lastActivity, new Date(), TimeUnit.SECONDS);
long secondsLeft = 0;
long secondsLeft;
String sign = "";
if (secondsDisconnected > (3 * 60)) {
sign="-";
@ -222,6 +223,11 @@ public class User {
GameManager.getInstance().sendPlayerString(gameId, userId, data);
}
public void sendPlayerManaType(final UUID gameId, final ManaType data) {
lastActivity = new Date();
GameManager.getInstance().sendPlayerManaType(gameId, userId, data);
}
public void sendPlayerBoolean(final UUID gameId, final Boolean data) {
lastActivity = new Date();
GameManager.getInstance().sendPlayerBoolean(gameId, userId, data);

View file

@ -54,6 +54,7 @@ import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.constants.ManaType;
import mage.constants.Zone;
import mage.game.Game;
import mage.game.GameException;
@ -356,6 +357,10 @@ public class GameController implements GameCallback {
game.concede(getPlayerId(userId));
}
public void setManaPoolMode(UUID userId, boolean autoPayment) {
game.setManaPoolMode(getPlayerId(userId), autoPayment);
}
public void quit(UUID userId) {
game.quit(getPlayerId(userId));
}
@ -470,6 +475,15 @@ public class GameController implements GameCallback {
});
}
public void sendPlayerManaType(UUID userId, final ManaType data) {
sendMessage(userId, new Command() {
@Override
public void execute(UUID playerId) {
getGameSession(playerId).sendPlayerManaType(data);
}
});
}
public void sendPlayerBoolean(UUID userId, final Boolean data) {
sendMessage(userId, new Command() {
@Override

View file

@ -28,12 +28,12 @@
package mage.server.game;
import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.view.GameView;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.cards.decks.DeckCardLists;
import mage.constants.ManaType;
import mage.game.Game;
import mage.view.GameView;
/**
*
@ -85,6 +85,12 @@ public class GameManager {
}
}
public void sendPlayerManaType(UUID gameId, UUID userId, ManaType data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerManaType(userId, data);
}
}
public void sendPlayerBoolean(UUID gameId, UUID userId, Boolean data) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).sendPlayerBoolean(userId, data);
@ -97,6 +103,12 @@ public class GameManager {
}
}
public void setManaPoolMode(UUID gameId, UUID userId, boolean autoPayment) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).setManaPoolMode(userId, autoPayment);
}
}
public void concedeGame(UUID gameId, UUID userId) {
if (gameControllers.containsKey(gameId)) {
gameControllers.get(gameId).concede(userId);

View file

@ -29,12 +29,18 @@
package mage.server.game;
import java.io.Serializable;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.cards.Cards;
import mage.constants.ManaType;
import mage.game.Game;
import mage.game.match.Match;
import mage.interfaces.callback.ClientCallback;
@ -215,6 +221,11 @@ public class GameSession extends GameWatcher {
game.getPlayer(playerId).setResponseString(data);
}
public void sendPlayerManaType(ManaType manaType) {
cancelTimeout();
game.getPlayer(playerId).setResponseManaType(manaType);
}
public void sendPlayerBoolean(Boolean data) {
cancelTimeout();
game.getPlayer(playerId).setResponseBoolean(data);