Fixed that to allow watchers of a game to see the hand cards of players did not work correctly.

This commit is contained in:
LevelX2 2015-04-10 12:36:22 +02:00
parent c0db6dfdc8
commit c65adebc57
14 changed files with 129 additions and 68 deletions

View file

@ -712,6 +712,8 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
String proxyPassword = prefs.get("proxyPassword", "");
int avatarId = PreferencesDialog.getSelectedAvatar();
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
try {
setCursor(new Cursor(Cursor.WAIT_CURSOR));
Connection connection = new Connection();
@ -725,6 +727,7 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
connection.setProxyPassword(proxyPassword);
connection.setAvatarId(avatarId);
connection.setShowAbilityPickerForced(showAbilityPickerForced);
connection.setAllowRequestShowHandCards(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"));
connection.setUserSkipPrioritySteps(PreferencesDialog.getUserSkipPrioritySteps());
logger.debug("connecting (auto): " + proxyType + " " + proxyServer + " " + proxyPort + " " + proxyUsername);
if (MageFrame.connect(connection)) {

View file

@ -332,6 +332,7 @@ public class ConnectDialog extends MageDialog {
int avatarId = PreferencesDialog.getSelectedAvatar();
connection.setAvatarId(avatarId);
boolean showAbilityPickerForced = PreferencesDialog.getCachedValue(PreferencesDialog.KEY_SHOW_ABILITY_PICKER_FORCED, "true").equals("true");
connection.setAllowRequestShowHandCards(PreferencesDialog.getCachedValue(PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true").equals("true"));
connection.setShowAbilityPickerForced(showAbilityPickerForced);
connection.setUserSkipPrioritySteps(PreferencesDialog.getUserSkipPrioritySteps());
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());

View file

@ -1681,9 +1681,9 @@ public class PreferencesDialog extends javax.swing.JDialog {
try {
MageFrame.getSession().updatePreferencesForServer(
getSelectedAvatar(),
dialog.cbAllowRequestToShowHandCards.isSelected(),
getSelectedAvatar(),
dialog.showAbilityPickerForced.isSelected(),
dialog.cbAllowRequestToShowHandCards.isSelected(),
getUserSkipPrioritySteps());
prefs.flush();
@ -2235,6 +2235,14 @@ public class PreferencesDialog extends javax.swing.JDialog {
save(prefs, checkBox, propName, PHASE_ON, PHASE_OFF, false);
}
public static void setPrefValue(String key, boolean value) {
switch(key) {
case KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS:
dialog.cbAllowRequestToShowHandCards.setSelected(value);
save(MageFrame.getPreferences(), dialog.cbAllowRequestToShowHandCards, KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, "true", "false", UPDATE_CACHE_POLICY);
break;
}
}
private static void save(Preferences prefs, JCheckBox checkBox, String propName, String yesValue, String noValue, boolean updateCache) {
prefs.put(propName, checkBox.isSelected() ? yesValue : noValue);
if (updateCache) {

View file

@ -37,6 +37,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.lang.reflect.Field;
import java.util.UUID;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
@ -50,6 +51,8 @@ import javax.swing.event.ChangeListener;
import mage.cards.decks.importer.DeckImporterUtil;
import mage.client.MageFrame;
import mage.client.cards.BigCard;
import mage.client.dialog.PreferencesDialog;
import static mage.client.dialog.PreferencesDialog.KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS;
import mage.constants.PlayerAction;
import mage.view.PlayerView;
@ -68,6 +71,7 @@ public class PlayAreaPanel extends javax.swing.JPanel {
private final boolean playerItself;
private JCheckBoxMenuItem manaPoolMenuItem;
private JCheckBoxMenuItem allowViewHandCardsMenuItem;
public static final int PANEL_HEIGHT = 242;
public static final int PANEL_HEIGHT_SMALL = 190;
@ -248,16 +252,17 @@ public class PlayAreaPanel extends javax.swing.JPanel {
}
});
} else {
menuItem = new JCheckBoxMenuItem("Allow requests to show your hand cards", allowRequestToShowHandCards);
menuItem.setMnemonic(KeyEvent.VK_A);
menuItem.setToolTipText("If activated watchers or other players can request to see your hand cards. If you grant this to a user, it's valid for the complete match.");
popupMenu.add(menuItem);
allowViewHandCardsMenuItem = new JCheckBoxMenuItem("Allow requests to show your hand cards", allowRequestToShowHandCards);
allowViewHandCardsMenuItem.setMnemonic(KeyEvent.VK_A);
allowViewHandCardsMenuItem.setToolTipText("If activated watchers or other players can request to see your hand cards. If you grant this to a user, it's valid for the complete match.");
popupMenu.add(allowViewHandCardsMenuItem);
// Requests allowed
menuItem.addActionListener(new ActionListener() {
allowViewHandCardsMenuItem.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
boolean requestsAllowed = ((JCheckBoxMenuItem)e.getSource()).getState();
PreferencesDialog.setPrefValue(KEY_GAME_ALLOW_REQUEST_SHOW_HAND_CARDS, requestsAllowed);
gamePanel.getSession().sendPlayerAction(requestsAllowed ? PlayerAction.PERMISSION_REQUESTS_ALLOWED_ON: PlayerAction.PERMISSION_REQUESTS_ALLOWED_OFF, gameId, null);
}
});
@ -391,6 +396,9 @@ public class PlayAreaPanel extends javax.swing.JPanel {
public final void update(PlayerView player) {
this.playerPanel.update(player);
this.battlefieldPanel.update(player.getBattlefield());
if (this.allowViewHandCardsMenuItem != null) {
this.allowViewHandCardsMenuItem.setSelected(player.getUserData().allowRequestShowHandCards());
}
}
public mage.client.game.BattlefieldPanel getBattlefieldPanel() {

View file

@ -27,6 +27,9 @@ public class UserDataView implements Serializable {
public UserDataView(UserData userData) {
this.avatarId = userData.getAvatarId();
this.userGroup = userData.getGroupId();
this.allowRequestShowHandCards = userData.isAllowRequestShowHandCards();
this.showAbilityPickerForced = userData.isShowAbilityPickerForced();
this.userSkipPrioritySteps = userData.getUserSkipPrioritySteps();
}
public int getAvatarId() {

View file

@ -28,25 +28,84 @@
package mage.player.ai;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;
import mage.MageObject;
import mage.Mana;
import mage.abilities.*;
import mage.abilities.Ability;
import mage.abilities.ActivatedAbility;
import mage.abilities.Mode;
import mage.abilities.Modes;
import mage.abilities.SpellAbility;
import mage.abilities.TriggeredAbility;
import mage.abilities.costs.VariableCost;
import mage.abilities.costs.mana.*;
import mage.abilities.costs.mana.ColoredManaCost;
import mage.abilities.costs.mana.GenericManaCost;
import mage.abilities.costs.mana.HybridManaCost;
import mage.abilities.costs.mana.ManaCost;
import mage.abilities.costs.mana.ManaCosts;
import mage.abilities.costs.mana.MonoHybridManaCost;
import mage.abilities.costs.mana.PhyrexianManaCost;
import mage.abilities.effects.Effect;
import mage.abilities.effects.common.DamageTargetEffect;
import mage.abilities.effects.common.continuous.BecomesCreatureSourceEffect;
import mage.abilities.keyword.*;
import mage.abilities.keyword.DoubleStrikeAbility;
import mage.abilities.keyword.EquipAbility;
import mage.abilities.keyword.FirstStrikeAbility;
import mage.abilities.keyword.FlashAbility;
import mage.abilities.keyword.TrampleAbility;
import mage.abilities.mana.ManaAbility;
import mage.abilities.mana.ManaOptions;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.cards.repository.*;
import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.cards.repository.ExpansionInfo;
import mage.cards.repository.ExpansionRepository;
import mage.choices.Choice;
import mage.constants.*;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome;
import static mage.constants.PhaseStep.DECLARE_ATTACKERS;
import static mage.constants.PhaseStep.DECLARE_BLOCKERS;
import static mage.constants.PhaseStep.DRAW;
import static mage.constants.PhaseStep.END_COMBAT;
import static mage.constants.PhaseStep.POSTCOMBAT_MAIN;
import static mage.constants.PhaseStep.PRECOMBAT_MAIN;
import static mage.constants.PhaseStep.UPKEEP;
import mage.constants.RangeOfInfluence;
import mage.constants.Rarity;
import static mage.constants.SpellAbilityType.SPLIT;
import static mage.constants.SpellAbilityType.SPLIT_FUSED;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
import mage.filter.common.*;
import mage.filter.common.FilterCreatureForCombatBlock;
import mage.filter.common.FilterCreatureOrPlayer;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.common.FilterLandCard;
import mage.filter.common.FilterNonlandCard;
import mage.filter.common.FilterPermanentOrPlayer;
import mage.filter.common.FilterPlaneswalkerPermanent;
import mage.filter.predicate.permanent.ControllerIdPredicate;
import mage.game.Game;
import mage.game.combat.CombatGroup;
import mage.game.draft.Draft;
@ -65,20 +124,31 @@ import mage.players.Player;
import mage.players.PlayerImpl;
import mage.players.net.UserData;
import mage.players.net.UserGroup;
import mage.target.*;
import mage.target.common.*;
import mage.target.Target;
import mage.target.TargetAmount;
import mage.target.TargetCard;
import mage.target.TargetPermanent;
import mage.target.TargetPlayer;
import mage.target.TargetSource;
import mage.target.TargetSpell;
import mage.target.common.TargetCardInASingleGraveyard;
import mage.target.common.TargetCardInExile;
import mage.target.common.TargetCardInGraveyard;
import mage.target.common.TargetCardInHand;
import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetCardInOpponentsGraveyard;
import mage.target.common.TargetCardInYourGraveyard;
import mage.target.common.TargetControlledPermanent;
import mage.target.common.TargetCreatureOrPlayer;
import mage.target.common.TargetCreatureOrPlayerAmount;
import mage.target.common.TargetDefender;
import mage.target.common.TargetDiscard;
import mage.target.common.TargetPermanentOrPlayer;
import mage.target.common.TargetSpellOrPermanent;
import mage.util.Copier;
import mage.util.TreeNode;
import org.apache.log4j.Logger;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.Map.Entry;
import mage.filter.Filter;
import mage.filter.predicate.other.PlayerIdPredicate;
import mage.filter.predicate.permanent.ControllerIdPredicate;
/**
*
@ -119,10 +189,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
return false;
}
Set<Card> lands = hand.getCards(new FilterLandCard(), game);
if (lands.size() < 2 || lands.size() > hand.size() - 2) {
return true;
}
return false;
return lands.size() < 2 || lands.size() > hand.size() - 2;
}
@Override
@ -1975,7 +2042,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
protected void logState(Game game) {
if (log.isTraceEnabled()) {
logList("Computer player " + name + " hand: ", new ArrayList(hand.getCards(game)));
logList("Computer player " + name + " hand: ", new ArrayList<MageObject>(hand.getCards(game)));
}
}

View file

@ -300,6 +300,7 @@ public class TableController {
logger.trace(player.getName() + " joined tableId: " + table.getId());
//only inform human players and add them to sessionPlayerMap
if (seat.getPlayer().isHuman()) {
seat.getPlayer().setUserData(user.getUserData());
if (!table.isTournamentSubTable()) {
user.addTable(player.getId(), table);
}
@ -552,14 +553,11 @@ public class TableController {
GameManager.getInstance().createGameSession(match.getGame(), userPlayerMap, table.getId(), choosingPlayerId);
String creator = null;
StringBuilder opponent = new StringBuilder();
// int activePlayers = 0;
for (Entry<UUID, UUID> entry: userPlayerMap.entrySet()) { // no AI players
if (!match.getPlayer(entry.getValue()).hasQuit()) {
User user = UserManager.getInstance().getUser(entry.getKey());
if (user != null) {
// activePlayers++;
Player player = match.getPlayer(entry.getValue()).getPlayer();
player.setRequestToShowHandCardsAllowed(user.getUserData().allowRequestShowHandCards());
user.ccGameStarted(match.getGame().getId(), entry.getValue());
if (creator == null) {
@ -582,16 +580,12 @@ public class TableController {
// Append AI opponents to the log file
for (MatchPlayer mPlayer :match.getPlayers()) {
if (!mPlayer.getPlayer().isHuman()) {
// activePlayers++;
if (opponent.length() > 0) {
opponent.append(" - ");
}
opponent.append(mPlayer.getName());
}
}
// if (activePlayers < 2) {
// throw new MageException("Can't start game - Less than two players active - " +activePlayers);
// }
ServerMessagesUtil.getInstance().incGamesStarted();

View file

@ -331,7 +331,6 @@ public class GameController implements GameCallback {
if (gameSession == null) {
gameSession = new GameSessionPlayer(game, userId, playerId);
gameSessions.put(playerId, gameSession);
gameSession.setUserData(user.getUserData());
joinType = "joined";
} else {
joinType = "rejoined";

View file

@ -48,9 +48,9 @@ public class GameFactory {
private static final GameFactory INSTANCE = new GameFactory();
private static final Logger logger = Logger.getLogger(GameFactory.class);
private Map<String, Class<Match>> games = new HashMap<String, Class<Match>>();
private Map<String, MatchType> gameTypes = new HashMap<String, MatchType>();
private List<GameTypeView> gameTypeViews = new ArrayList<GameTypeView>();
private final Map<String, Class<Match>> games = new HashMap<>();
private final Map<String, MatchType> gameTypes = new HashMap<>();
private final List<GameTypeView> gameTypeViews = new ArrayList<>();
public static GameFactory getInstance() {

View file

@ -135,19 +135,6 @@ public class GameManager {
}
}
// public void removeSession(UUID userId) {
// for (GameController controller: gameControllers.values()) {
// controller.kill(userId);
// }
// }
// public void kill(UUID gameId, UUID userId) {
// GameController gameController = gameControllers.get(gameId);
// if (gameController != null) {
// gameController.kill(userId);
// }
// }
public void cheat(UUID gameId, UUID userId, UUID playerId, DeckCardLists deckList) {
GameController gameController = gameControllers.get(gameId);
if (gameController != null) {

View file

@ -70,8 +70,6 @@ public class GameSessionPlayer extends GameSessionWatcher {
private static final ExecutorService callExecutor = ThreadExecutor.getInstance().getCallExecutor();
private UserData userData;
public GameSessionPlayer(Game game, UUID userId, UUID playerId) {
super(userId, game, true);
this.playerId = playerId;
@ -214,7 +212,6 @@ public class GameSessionPlayer extends GameSessionWatcher {
@Override
public GameView getGameView() {
Player player = game.getPlayer(playerId);
player.setUserData(this.userData);
GameView gameView = new GameView(game.getState(), game, playerId, null);
gameView.setHand(new CardsView(player.getHand().getCards(game)));
if (gameView.getPriorityPlayerName().equals(player.getName())) {
@ -298,7 +295,4 @@ public class GameSessionPlayer extends GameSessionWatcher {
}
}
public void setUserData(UserData userData) {
this.userData = userData;
}
}

View file

@ -565,7 +565,6 @@ public interface Player extends MageItem, Copyable<Player> {
void addPermissionToShowHandCards(UUID watcherUserId);
boolean hasUserPermissionToSeeHand(UUID userId);
void revokePermissionToSeeHandCards();
void setRequestToShowHandCardsAllowed(boolean requestAllowed);
boolean isRequestToShowHandCardsAllowed();
Set<UUID> getUsersAllowedToSeeHandCards();

View file

@ -306,7 +306,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.playersUnderYourControl.clear();
this.playersUnderYourControl.addAll(player.playersUnderYourControl);
this.usersAllowedToSeeHandCards.addAll(player.usersAllowedToSeeHandCards);
this.requestsAllowedToSeeHandCards = player.requestsAllowedToSeeHandCards;
this.isTestMode = player.isTestMode;
this.isGameUnderControl = player.isGameUnderControl;
@ -386,7 +385,6 @@ public abstract class PlayerImpl implements Player, Serializable {
this.castSourceIdWithoutMana = player.getCastSourceIdWithoutMana();
this.usersAllowedToSeeHandCards.addAll(player.getUsersAllowedToSeeHandCards());
this.requestsAllowedToSeeHandCards = player.isRequestToShowHandCardsAllowed();
}
@Override
@ -1864,10 +1862,10 @@ public abstract class PlayerImpl implements Player, Serializable {
passedUntilStackResolved = false;
break;
case PERMISSION_REQUESTS_ALLOWED_OFF:
this.setRequestToShowHandCardsAllowed(false);
userData.setAllowRequestShowHandCards(false);
break;
case PERMISSION_REQUESTS_ALLOWED_ON:
this.setRequestToShowHandCardsAllowed(true);
userData.setAllowRequestShowHandCards(true);
break;
}
logger.trace("PASS Priority: " + playerAction.toString());
@ -3007,14 +3005,10 @@ public abstract class PlayerImpl implements Player, Serializable {
usersAllowedToSeeHandCards.add(watcherUserId);
}
@Override
public void setRequestToShowHandCardsAllowed(boolean requestAllowed) {
this.requestsAllowedToSeeHandCards = requestAllowed;
}
@Override
public boolean isRequestToShowHandCardsAllowed() {
return requestsAllowedToSeeHandCards;
return userData.allowRequestShowHandCards();
}
@Override

View file

@ -43,6 +43,10 @@ public class UserData implements Serializable {
return showAbilityPickerForced;
}
public boolean isAllowRequestShowHandCards() {
return allowRequestShowHandCards;
}
public void setShowAbilityPickerForced(boolean showAbilityPickerForced) {
this.showAbilityPickerForced = showAbilityPickerForced;
}