HUGE update to the GUI refactoring, fixing most known bugs and making everything run a lot faster and smoother.

Fixed: exceptions during combat, display of face-down cards, searching libraries, mindslaver effects, and more.
This commit is contained in:
elcnesh
2014-09-11 15:46:33 +00:00
parent fbcc8dbf1c
commit 1ba2cb498b
25 changed files with 308 additions and 175 deletions

View File

@@ -43,8 +43,8 @@ public class LobbyPlayerAi extends LobbyPlayer implements IGameEntitiesFactory {
} }
@Override @Override
public Player createIngamePlayer(Game game) { public Player createIngamePlayer(Game game, final int id) {
Player ai = new Player(getName(), game); Player ai = new Player(getName(), game, id);
ai.setFirstController(createControllerFor(ai)); ai.setFirstController(createControllerFor(ai));
if( rotateProfileEachGame ) { if( rotateProfileEachGame ) {

View File

@@ -168,9 +168,10 @@ public class Game implements IGameStateObject {
} }
} }
int plId = 0;
for (RegisteredPlayer psc : players0) { for (RegisteredPlayer psc : players0) {
IGameEntitiesFactory factory = (IGameEntitiesFactory)psc.getPlayer(); IGameEntitiesFactory factory = (IGameEntitiesFactory)psc.getPlayer();
Player pl = factory.createIngamePlayer(this); Player pl = factory.createIngamePlayer(this, plId++);
players.add(pl); players.add(pl);
ingamePlayers.add(pl); ingamePlayers.add(pl);

View File

@@ -8859,6 +8859,7 @@ public class Card extends GameEntity implements Comparable<Card> {
Zone zone = this.getZone(); Zone zone = this.getZone();
if (zone == null) { return true; } //cards outside any zone are visible to all if (zone == null) { return true; } //cards outside any zone are visible to all
final Player controller = this.getController();
switch (zone.getZoneType()) { switch (zone.getZoneType()) {
case Ante: case Ante:
case Command: case Command:
@@ -8869,23 +8870,23 @@ public class Card extends GameEntity implements Comparable<Card> {
//cards in these zones are visible to all //cards in these zones are visible to all
return true; return true;
case Hand: case Hand:
if (getController().hasKeyword("Play with your hand revealed.")) { if (controller.hasKeyword("Play with your hand revealed.")) {
return true; return true;
} }
//fall through //fall through
case Sideboard: case Sideboard:
//face-up cards in these zones are hidden to opponents unless they specify otherwise //face-up cards in these zones are hidden to opponents unless they specify otherwise
if (getController().isOpponentOf(viewer) && !hasKeyword("Your opponent may look at this card.")) { if (controller.isOpponentOf(viewer) && !hasKeyword("Your opponent may look at this card.")) {
break; break;
} }
return true; return true;
case Library: case Library:
case PlanarDeck: case PlanarDeck:
//cards in these zones are hidden to all unless they specify otherwise //cards in these zones are hidden to all unless they specify otherwise
if (getController() == viewer && hasKeyword("You may look at this card.")) { if (controller == viewer && hasKeyword("You may look at this card.")) {
return true; return true;
} }
if (getController().isOpponentOf(viewer) && hasKeyword("Your opponent may look at this card.")) { if (controller.isOpponentOf(viewer) && hasKeyword("Your opponent may look at this card.")) {
return true; return true;
} }
break; break;
@@ -8906,8 +8907,8 @@ public class Card extends GameEntity implements Comparable<Card> {
} }
//if viewer is controlled by another player, also check if card can be shown to that player //if viewer is controlled by another player, also check if card can be shown to that player
if (viewer.isMindSlaved()) { if (controller.isMindSlaved() && viewer == controller.getMindSlaveMaster()) {
return canBeShownTo(viewer.getMindSlaveMaster()); return canBeShownTo(controller);
} }
return false; return false;

View File

@@ -2,10 +2,8 @@ package forge.game.player;
import forge.game.Game; import forge.game.Game;
public interface IGameEntitiesFactory public interface IGameEntitiesFactory
{ {
PlayerController createControllerFor(Player p); PlayerController createControllerFor(Player p);
Player createIngamePlayer(Game game); Player createIngamePlayer(Game game, int id);
} }

View File

@@ -71,6 +71,8 @@ import java.util.concurrent.ConcurrentSkipListMap;
* @version $Id$ * @version $Id$
*/ */
public class Player extends GameEntity implements Comparable<Player> { public class Player extends GameEntity implements Comparable<Player> {
private final int id;
private final Map<Card,Integer> commanderDamage = new HashMap<Card,Integer>(); private final Map<Card,Integer> commanderDamage = new HashMap<Card,Integer>();
/** The poison counters. */ /** The poison counters. */
@@ -206,7 +208,7 @@ public class Player extends GameEntity implements Comparable<Player> {
* @param myPoisonCounters * @param myPoisonCounters
* a int. * a int.
*/ */
public Player(String name, Game game0) { public Player(String name, Game game0, final int id) {
game = game0; game = game0;
for (final ZoneType z : Player.ALL_ZONES) { for (final ZoneType z : Player.ALL_ZONES) {
final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this); final PlayerZone toPut = z == ZoneType.Battlefield ? new PlayerZoneBattlefield(z, this) : new PlayerZone(z, this);
@@ -214,6 +216,7 @@ public class Player extends GameEntity implements Comparable<Player> {
} }
this.setName(chooseName(name)); this.setName(chooseName(name));
this.id = id;
} }
private String chooseName(String originalName) { private String chooseName(String originalName) {
@@ -234,6 +237,10 @@ public class Player extends GameEntity implements Comparable<Player> {
return nameCandidate; return nameCandidate;
} }
public int getId() {
return this.id;
}
@Override @Override
public Game getGame() { // I'll probably regret about this public Game getGame() { // I'll probably regret about this
return game; return game;

View File

@@ -182,7 +182,7 @@ public class CardDetailPanel extends SkinnedPanel {
final CardStateView state = card.getState(isInAltState); final CardStateView state = card.getState(isInAltState);
if (state.getManaCost().isNoCost()) { if (state.getManaCost().isNoCost()) {
this.nameCostLabel.setText(state.getName()); this.nameCostLabel.setText(CardDetailUtil.formatCardName(state));
} else { } else {
final String manaCost; final String manaCost;
if (card.isSplitCard() && card.hasAltState()) { if (card.isSplitCard() && card.hasAltState()) {
@@ -190,7 +190,7 @@ public class CardDetailPanel extends SkinnedPanel {
} else { } else {
manaCost = state.getManaCost().toString(); manaCost = state.getManaCost().toString();
} }
this.nameCostLabel.setText(FSkin.encodeSymbols(state.getName() + " - " + manaCost, true)); this.nameCostLabel.setText(FSkin.encodeSymbols(CardDetailUtil.formatCardName(state) + " - " + manaCost, true));
} }
this.typeLabel.setText(CardDetailUtil.formatCardType(state)); this.typeLabel.setText(CardDetailUtil.formatCardType(state));

View File

@@ -208,8 +208,15 @@ public class GuiChoose {
@Override @Override
public void valueChanged(final ListSelectionEvent ev) { public void valueChanged(final ListSelectionEvent ev) {
final T sel = list.getSelectedValue(); final T sel = list.getSelectedValue();
final CardView card;
if (sel instanceof CardStateView) { if (sel instanceof CardStateView) {
final CardView card = ((CardStateView) sel).getCard(); card = ((CardStateView) sel).getCard();
} else if (sel instanceof CardView) {
card = (CardView) sel;
} else {
card = null;
}
if (card != null) {
CMatchUI.SINGLETON_INSTANCE.setCard(card); CMatchUI.SINGLETON_INSTANCE.setCard(card);
GuiUtils.clearPanelSelections(); GuiUtils.clearPanelSelections();

View File

@@ -168,7 +168,7 @@ public enum CMatchUI implements ICDoc, IMenuProvider {
int i = 0; int i = 0;
for (final PlayerView p : sortedPlayers) { for (final PlayerView p : sortedPlayers) {
if (localPlayer == null || p.getLobbyPlayer() == localPlayer) { if (p.getLobbyPlayer().equals(localPlayer) || !p.getHandCards().isEmpty()) {
VHand newHand = new VHand(EDocID.Hands[i], p); VHand newHand = new VHand(EDocID.Hands[i], p);
newHand.getLayoutControl().initialize(); newHand.getLayoutControl().initialize();
hands.add(newHand); hands.add(newHand);

View File

@@ -158,6 +158,7 @@ public enum CDock implements ICDoc {
/** Attack with everyone. */ /** Attack with everyone. */
public void alphaStrike() { public void alphaStrike() {
game.alphaStrike();
/* TODO: rewrite this! /* TODO: rewrite this!
final Player p = this.findAffectedPlayer(); final Player p = this.findAffectedPlayer();
final Combat combat = FControl.instance.getObservedGame().getCombat(); final Combat combat = FControl.instance.getObservedGame().getCombat();

View File

@@ -119,12 +119,12 @@ public class PlayerDetailsPanel extends JPanel {
* @param p0 &emsp; {@link forge.game.player.Player} * @param p0 &emsp; {@link forge.game.player.Player}
*/ */
public void updateZones() { public void updateZones() {
this.getLblHand().setText("" + player.getHandCards().size()); this.getLblHand().setText("" + player.getnHandCards());
final String handMaxToolTip = player.hasUnlimitedHandSize() final String handMaxToolTip = player.hasUnlimitedHandSize()
? "no maximum hand size" : String.valueOf(player.getMaxHandSize()); ? "no maximum hand size" : String.valueOf(player.getMaxHandSize());
this.getLblHand().setToolTipText("Cards in hand (max: " + handMaxToolTip + ")"); this.getLblHand().setToolTipText("Cards in hand (max: " + handMaxToolTip + ")");
this.getLblGraveyard().setText("" + player.getGraveCards().size()); this.getLblGraveyard().setText("" + player.getGraveCards().size());
this.getLblLibrary().setText("" + player.getLibraryCards().size()); this.getLblLibrary().setText("" + player.getnLibraryCards());
this.getLblFlashback().setText("" + player.getFlashbackCards().size()); this.getLblFlashback().setText("" + player.getFlashbackCards().size());
this.getLblExile().setText("" + player.getExileCards().size()); this.getLblExile().setText("" + player.getExileCards().size());
} }

View File

@@ -609,22 +609,19 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
for (final CardPanel cpa : getCardPanels()) { for (final CardPanel cpa : getCardPanels()) {
oldCards.add(cpa.getCard()); oldCards.add(cpa.getCard());
} }
final List<CardView> toDelete = Lists.newArrayList(oldCards);
final List<CardView> toReplace = Lists.newArrayList();
// delete all cards that differ in timestamp (they have been blinked) final List<CardView> toDelete = Lists.newArrayList(oldCards);
final List<CardView> notToDelete = Lists.newLinkedList();
for (final CardView c : modelCopy) { for (final CardView c : modelCopy) {
for (int i = 0; i < toDelete.size(); i++) { for (int i = 0; i < toDelete.size(); i++) {
final CardView c2 = toDelete.get(i); final CardView c2 = toDelete.get(i);
if (c.getId() == c2.getId()) { if (c.getId() == c2.getId()) {
if (c.getTimestamp() == c2.getTimestamp()) { notToDelete.add(c2);
toDelete.remove(c2);
} else {
toReplace.add(c);
}
} }
} }
} }
toDelete.removeAll(notToDelete);
if (toDelete.size() == getCardPanels().size()) { if (toDelete.size() == getCardPanels().size()) {
clear(); clear();
} else { } else {
@@ -635,7 +632,6 @@ public class PlayArea extends CardPanelContainer implements CardPanelMouseListen
final List<CardView> toAdd = new ArrayList<CardView>(modelCopy); final List<CardView> toAdd = new ArrayList<CardView>(modelCopy);
toAdd.removeAll(oldCards); toAdd.removeAll(oldCards);
toAdd.addAll(toReplace);
final List<CardPanel> newPanels = new ArrayList<CardPanel>(); final List<CardPanel> newPanels = new ArrayList<CardPanel>();
for (final CardView card : toAdd) { for (final CardView card : toAdd) {

View File

@@ -28,8 +28,8 @@ public class LobbyPlayerForTests extends LobbyPlayer implements IGameEntitiesFac
@Override @Override
public Player createIngamePlayer( Game gameState ) { public Player createIngamePlayer(Game gameState, final int id) {
Player dummyPlayer = new Player( getName(), gameState ); Player dummyPlayer = new Player(getName(), gameState, id);
dummyPlayer.setFirstController( createControllerFor( dummyPlayer ) ); dummyPlayer.setFirstController( createControllerFor( dummyPlayer ) );
return dummyPlayer; return dummyPlayer;
} }

View File

@@ -40,12 +40,7 @@ import forge.game.GameRules;
import forge.game.GameType; import forge.game.GameType;
import forge.game.Match; import forge.game.Match;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardLists;
import forge.game.card.CounterType; import forge.game.card.CounterType;
import forge.game.card.CardPredicates.Presets;
import forge.game.combat.Combat;
import forge.game.combat.CombatUtil;
import forge.game.phase.PhaseHandler;
import forge.game.phase.PhaseType; import forge.game.phase.PhaseType;
import forge.game.player.Player; import forge.game.player.Player;
import forge.game.player.RegisteredPlayer; import forge.game.player.RegisteredPlayer;
@@ -324,29 +319,7 @@ public class FControl {
} }
public static void alphaStrike() { public static void alphaStrike() {
final PhaseHandler ph = game.getPhaseHandler(); gameView.alphaStrike();
final Player p = getCurrentPlayer();
final Game game = p.getGame();
Combat combat = game.getCombat();
if (combat == null) { return; }
if (ph.is(PhaseType.COMBAT_DECLARE_ATTACKERS, p)) {
List<Player> defenders = p.getOpponents();
for (Card c : CardLists.filter(p.getCardsIn(ZoneType.Battlefield), Presets.CREATURES)) {
if (combat.isAttacking(c)) {
continue;
}
for (Player defender : defenders) {
if (CombatUtil.canAttack(c, defender, combat)) {
combat.addAttacker(c, defender);
break;
}
}
}
}
} }
public static void showCombat(CombatView combat) { public static void showCombat(CombatView combat) {
@@ -421,6 +394,9 @@ public class FControl {
for (Pair<PlayerView, ZoneType> kv : zonesToUpdate) { for (Pair<PlayerView, ZoneType> kv : zonesToUpdate) {
PlayerView owner = kv.getKey(); PlayerView owner = kv.getKey();
ZoneType zt = kv.getValue(); ZoneType zt = kv.getValue();
if (owner == null || zt == null) {
continue;
}
getPlayerPanel(owner).updateZone(zt); getPlayerPanel(owner).updateZone(zt);
} }
} }

View File

@@ -14,8 +14,6 @@ import forge.assets.TextRenderer;
import forge.assets.FSkinColor.Colors; import forge.assets.FSkinColor.Colors;
import forge.card.CardRenderer; import forge.card.CardRenderer;
import forge.card.CardZoom; import forge.card.CardZoom;
import forge.game.card.Card;
import forge.game.player.Player;
import forge.game.spellability.SpellAbility; import forge.game.spellability.SpellAbility;
import forge.item.PaperCard; import forge.item.PaperCard;
import forge.screens.match.FControl; import forge.screens.match.FControl;
@@ -60,13 +58,13 @@ public class FChoiceList<T> extends FList<T> {
if (item instanceof PaperCard) { if (item instanceof PaperCard) {
renderer = new PaperCardItemRenderer(); renderer = new PaperCardItemRenderer();
} }
else if (item instanceof Card) { else if (item instanceof CardView) {
renderer = new CardItemRenderer(); renderer = new CardItemRenderer();
} }
else if (item instanceof SpellAbility) { else if (item instanceof SpellAbility) {
renderer = new SpellAbilityItemRenderer(); renderer = new SpellAbilityItemRenderer();
} }
else if (item instanceof Player) { else if (item instanceof PlayerView) {
renderer = new PlayerItemRenderer(); renderer = new PlayerItemRenderer();
} }
else { else {

View File

@@ -6,6 +6,8 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import org.apache.commons.lang3.StringUtils;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import forge.game.card.CardUtil; import forge.game.card.CardUtil;
@@ -159,6 +161,11 @@ public class CardDetailUtil {
return item.getName(); return item.getName();
} }
public static String formatCardName(final CardStateView card) {
final String name = card.getName();
return StringUtils.isEmpty(name) ? "(no name)" : name.trim();
}
public static String formatCardType(final CardStateView card) { public static String formatCardType(final CardStateView card) {
final List<String> list = card.getType(); final List<String> list = card.getType();
final StringBuilder sb = new StringBuilder(); final StringBuilder sb = new StringBuilder();
@@ -199,7 +206,7 @@ public class CardDetailUtil {
sb.append(type).append(" "); sb.append(type).append(" ");
} }
return sb.toString(); return sb.toString().trim();
} }
public static String formatPowerToughness(final CardStateView card) { public static String formatPowerToughness(final CardStateView card) {

View File

@@ -355,8 +355,12 @@ public class FControlGameEventHandler extends IGameEventVisitor.Base<Void> {
@Override @Override
public Void visit(GameEventCardChangeZone event) { public Void visit(GameEventCardChangeZone event) {
if (event.from != null) {
updateZone(event.from); updateZone(event.from);
}
if (event.to != null) {
updateZone(event.to); updateZone(event.to);
}
return null; return null;
} }

View File

@@ -25,8 +25,8 @@ public class LobbyPlayerHuman extends LobbyPlayer implements IGameEntitiesFactor
} }
@Override @Override
public Player createIngamePlayer(Game game) { public Player createIngamePlayer(Game game, final int id) {
Player player = new Player(GuiDisplayUtil.personalizeHuman(getName()), game); Player player = new Player(GuiDisplayUtil.personalizeHuman(getName()), game, id);
player.setFirstController(new PlayerControllerHuman(game, player, this, gui)); player.setFirstController(new PlayerControllerHuman(game, player, this, gui));
if (ForgePreferences.DEV_MODE && FModel.getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) { if (ForgePreferences.DEV_MODE && FModel.getPreferences().getPrefBoolean(FPref.DEV_UNLIMITED_LAND)) {

View File

@@ -7,6 +7,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang3.Range; import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@@ -20,6 +21,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import com.google.common.collect.Sets;
import forge.LobbyPlayer; import forge.LobbyPlayer;
import forge.card.ColorSet; import forge.card.ColorSet;
@@ -39,6 +41,8 @@ import forge.game.GameOutcome;
import forge.game.GameType; import forge.game.GameType;
import forge.game.ability.effects.CharmEffect; import forge.game.ability.effects.CharmEffect;
import forge.game.card.Card; import forge.game.card.Card;
import forge.game.card.CardLists;
import forge.game.card.CardPredicates.Presets;
import forge.game.card.CardShields; import forge.game.card.CardShields;
import forge.game.card.CounterType; import forge.game.card.CounterType;
import forge.game.combat.Combat; import forge.game.combat.Combat;
@@ -101,9 +105,14 @@ import forge.view.StackItemView;
*/ */
public class PlayerControllerHuman extends PlayerController { public class PlayerControllerHuman extends PlayerController {
private final IGuiBase gui; private IGuiBase gui;
private final InputProxy inputProxy; private final InputProxy inputProxy;
private final GameView gameView; private final GameView gameView;
/**
* Cards this player may look at right now, for example when searching a
* library.
*/
private final Set<Card> mayLookAt = Sets.newHashSet();
public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) { public PlayerControllerHuman(final Game game0, final Player p, final LobbyPlayer lp, final IGuiBase gui) {
super(game0, p, lp); super(game0, p, lp);
@@ -304,9 +313,11 @@ public class PlayerControllerHuman extends PlayerController {
return Lists.newArrayList(sc.getSelected()); return Lists.newArrayList(sc.getSelected());
} }
return SGuiChoose.many(getGui(), title, "Chosen Cards", min, max, sourceList, gameView.getCardView(sa.getHostCard())); final List<CardView> choices = SGuiChoose.many(getGui(), title, "Chosen Cards", min, max, gameView.getCardViews(sourceList), gameView.getCardView(sa.getHostCard()));
return getCards(choices);
} }
@SuppressWarnings("unchecked")
@Override @Override
public <T extends GameEntity> T chooseSingleEntityForEffect(Collection<T> options, SpellAbility sa, String title, boolean isOptional, Player targetedPlayer) { public <T extends GameEntity> T chooseSingleEntityForEffect(Collection<T> options, SpellAbility sa, String title, boolean isOptional, Player targetedPlayer) {
// Human is supposed to read the message and understand from it what to choose // Human is supposed to read the message and understand from it what to choose
@@ -338,7 +349,15 @@ public class PlayerControllerHuman extends PlayerController {
return Iterables.getFirst(input.getSelected(), null); return Iterables.getFirst(input.getSelected(), null);
} }
return isOptional ? SGuiChoose.oneOrNone(getGui(), title, options) : SGuiChoose.one(getGui(), title, options); for (final T t : options) {
if (t instanceof Card) {
// assume you may see any card passed through here
mayLookAt.add((Card) t);
}
}
final GameEntityView result = isOptional ? SGuiChoose.oneOrNone(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options)) : SGuiChoose.one(getGui(), title, gameView.getGameEntityViews((Iterable<GameEntity>) options));
mayLookAt.clear();
return (T) gameView.getGameEntity(result);
} }
@Override @Override
@@ -357,8 +376,13 @@ public class PlayerControllerHuman extends PlayerController {
@Override @Override
public SpellAbility chooseSingleSpellForEffect(java.util.List<SpellAbility> spells, SpellAbility sa, String title) { public SpellAbility chooseSingleSpellForEffect(java.util.List<SpellAbility> spells, SpellAbility sa, String title) {
if (spells.size() < 2) {
return spells.get(0);
}
// Human is supposed to read the message and understand from it what to choose // Human is supposed to read the message and understand from it what to choose
return spells.size() < 2 ? spells.get(0) : SGuiChoose.one(getGui(), title, spells); final SpellAbilityView choice = SGuiChoose.one(getGui(), title, gameView.getSpellAbilityViews(spells));
return gameView.getSpellAbility(choice);
} }
/* (non-Javadoc) /* (non-Javadoc)
@@ -469,7 +493,9 @@ public class PlayerControllerHuman extends PlayerController {
} }
String fm = formatMessage(message, owner); String fm = formatMessage(message, owner);
if (!cards.isEmpty()) { if (!cards.isEmpty()) {
SGuiChoose.reveal(getGui(), fm, cards); mayLookAt.addAll(cards);
SGuiChoose.reveal(getGui(), fm, gameView.getCardViews(cards));
mayLookAt.clear();
} }
else { else {
SGuiDialog.message(getGui(), formatMessage("There are no cards in {player's} " + SGuiDialog.message(getGui(), formatMessage("There are no cards in {player's} " +
@@ -539,8 +565,9 @@ public class PlayerControllerHuman extends PlayerController {
@Override @Override
public List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> valid, int min, int max) { public List<Card> chooseCardsToDiscardFrom(Player p, SpellAbility sa, List<Card> valid, int min, int max) {
if (p != player) { if (p != player) {
return SGuiChoose.many(getGui(), "Choose " + min + " card" + (min != 1 ? "s" : "") + " to discard", final List<CardView> choices = SGuiChoose.many(getGui(), "Choose " + min + " card" + (min != 1 ? "s" : "") + " to discard",
"Discarded", min, min, valid, null); "Discarded", min, min, gameView.getCardViews(valid), null);
return getCards(choices);
} }
InputSelectCardsFromList inp = new InputSelectCardsFromList(this, min, max, valid); InputSelectCardsFromList inp = new InputSelectCardsFromList(this, min, max, valid);
@@ -570,7 +597,7 @@ public class PlayerControllerHuman extends PlayerController {
System.out.println("Delve for " + chosenAmount); System.out.println("Delve for " + chosenAmount);
for (int i = 0; i < chosenAmount; i++) { for (int i = 0; i < chosenAmount; i++) {
final Card nowChosen = SGuiChoose.oneOrNone(getGui(), "Exile which card?", grave); final CardView nowChosen = SGuiChoose.oneOrNone(getGui(), "Exile which card?", gameView.getCardViews(grave));
if (nowChosen == null) { if (nowChosen == null) {
// User canceled,abort delving. // User canceled,abort delving.
@@ -579,7 +606,7 @@ public class PlayerControllerHuman extends PlayerController {
} }
grave.remove(nowChosen); grave.remove(nowChosen);
toExile.add(nowChosen); toExile.add(gameView.getCard(nowChosen));
} }
return toExile; return toExile;
} }
@@ -849,8 +876,9 @@ public class PlayerControllerHuman extends PlayerController {
if (srcCards.isEmpty()) { if (srcCards.isEmpty()) {
return result; return result;
} }
List<Card> chosen = SGuiChoose.many(getGui(), "Choose cards to activate from opening hand and their order", "Activate first", -1, srcCards, null); final List<CardView> chosen = SGuiChoose.many(getGui(), "Choose cards to activate from opening hand and their order", "Activate first", -1, gameView.getCardViews(srcCards), null);
for (Card c : chosen) { for (final CardView view : chosen) {
final Card c = getCard(view);
for (SpellAbility sa : usableFromOpeningHand) { for (SpellAbility sa : usableFromOpeningHand) {
if (sa.getHostCard() == c) { if (sa.getHostCard() == c) {
result.add(sa); result.add(sa);
@@ -939,7 +967,7 @@ public class PlayerControllerHuman extends PlayerController {
if (sa.isManaAbility()) { if (sa.isManaAbility()) {
game.getGameLog().add(GameLogEntryType.LAND, message); game.getGameLog().add(GameLogEntryType.LAND, message);
} else { } else {
SGuiDialog.message(getGui(), message, sa.getHostCard() == null ? "" : sa.getHostCard().getName()); SGuiDialog.message(getGui(), message, sa.getHostCard() == null ? "" : getCardView(sa.getHostCard()).toString());
} }
} }
@@ -1098,7 +1126,8 @@ public class PlayerControllerHuman extends PlayerController {
public void orderAndPlaySimultaneousSa(List<SpellAbility> activePlayerSAs) { public void orderAndPlaySimultaneousSa(List<SpellAbility> activePlayerSAs) {
List<SpellAbility> orderedSAs = activePlayerSAs; List<SpellAbility> orderedSAs = activePlayerSAs;
if (activePlayerSAs.size() > 1) { // give a dual list form to create instead of needing to do it one at a time if (activePlayerSAs.size() > 1) { // give a dual list form to create instead of needing to do it one at a time
orderedSAs = SGuiChoose.order(getGui(), "Select order for Simultaneous Spell Abilities", "Resolve first", activePlayerSAs, null); final List<SpellAbilityView> orderedSAViews = SGuiChoose.order(getGui(), "Select order for Simultaneous Spell Abilities", "Resolve first", gameView.getSpellAbilityViews(activePlayerSAs), null);
orderedSAs = getSpellAbilities(orderedSAViews);
} }
int size = orderedSAs.size(); int size = orderedSAs.size();
for (int i = size - 1; i >= 0; i--) { for (int i = size - 1; i >= 0; i--) {
@@ -1319,10 +1348,35 @@ public class PlayerControllerHuman extends PlayerController {
getInputProxy().selectAbility(sa); getInputProxy().selectAbility(sa);
} }
@Override
public void alphaStrike() {
final Combat combat = game.getCombat();
if (!game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS)
|| combat == null
|| game.getPhaseHandler().getPlayerTurn() != player
|| !(getGui().getInputQueue().getInput() instanceof InputAttack)) {
return;
}
final List<Player> defenders = player.getOpponents();
for (final Card c : CardLists.filter(player.getCardsIn(ZoneType.Battlefield), Presets.CREATURES)) {
if (combat.isAttacking(c))
continue;
for (final Player defender : defenders) {
if (CombatUtil.canAttack(c, defender, combat)) {
combat.addAttacker(c, defender);
break;
}
}
}
}
@Override @Override
public boolean mayShowCard(final CardView c) { public boolean mayShowCard(final CardView c) {
final Card card = getCard(c); final Card card = getCard(c);
return card == null || card.canBeShownTo(player); return card == null || mayLookAt.contains(card) || card.canBeShownTo(player);
} }
@Override @Override
@@ -1457,21 +1511,12 @@ public class PlayerControllerHuman extends PlayerController {
return gameView.getGameEntityView(e); return gameView.getGameEntityView(e);
} }
/**
* @param players
* @return
* @see forge.view.LocalGameView#getPlayerViews(java.util.List)
*/
public final List<PlayerView> getPlayerViews(List<Player> players) {
return gameView.getPlayerViews(players);
}
/** /**
* @param players * @param players
* @return * @return
* @see forge.view.LocalGameView#getPlayerViews(java.lang.Iterable) * @see forge.view.LocalGameView#getPlayerViews(java.lang.Iterable)
*/ */
public final Iterable<PlayerView> getPlayerViews(Iterable<Player> players) { public final List<PlayerView> getPlayerViews(Iterable<Player> players) {
return gameView.getPlayerViews(players); return gameView.getPlayerViews(players);
} }
@@ -1516,7 +1561,7 @@ public class PlayerControllerHuman extends PlayerController {
* @return * @return
* @see forge.view.LocalGameView#getCardViews(java.lang.Iterable) * @see forge.view.LocalGameView#getCardViews(java.lang.Iterable)
*/ */
public final Iterable<CardView> getCardViews(Iterable<Card> cards) { public final List<CardView> getCardViews(Iterable<Card> cards) {
return gameView.getCardViews(cards); return gameView.getCardViews(cards);
} }

View File

@@ -117,6 +117,17 @@ public class CardView extends GameEntityView {
this.id = id; this.id = id;
} }
@Override
public boolean equals(final Object obj) {
return obj instanceof CardView && this.getId() == ((CardView) obj).getId()
&& (this.getId() > 0 || this == obj);
}
@Override
public int hashCode() {
return id > 0 ? id : super.hashCode();
}
public boolean isUiDisplayable() { public boolean isUiDisplayable() {
return isUiDisplayable; return isUiDisplayable;
} }

View File

@@ -1,18 +1,20 @@
package forge.view; package forge.view;
import java.util.List;
import java.util.Map; import java.util.Map;
import com.google.common.base.Predicates; import com.google.common.base.Predicates;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
public class CombatView { public class CombatView {
private Map<CardView, GameEntityView> attackersWithDefenders; private Map<CardView, GameEntityView> attackersWithDefenders = Maps.newHashMap();
private Map<CardView, Iterable<CardView>> attackersWithBlockers; private Map<CardView, Iterable<CardView>> attackersWithBlockers = Maps.newHashMap();
private Map<Iterable<CardView>, GameEntityView> bandsWithDefenders; private Map<Iterable<CardView>, GameEntityView> bandsWithDefenders = Maps.newHashMap();
private Map<Iterable<CardView>, Iterable<CardView>> bandsWithBlockers; private Map<Iterable<CardView>, Iterable<CardView>> bandsWithBlockers = Maps.newHashMap();
public CombatView() { public CombatView() {
} }
@@ -39,6 +41,9 @@ public class CombatView {
public boolean isBlocking(final CardView card) { public boolean isBlocking(final CardView card) {
for (final Iterable<CardView> blockers : attackersWithBlockers.values()) { for (final Iterable<CardView> blockers : attackersWithBlockers.values()) {
if (blockers == null) {
continue;
}
if (Iterables.contains(blockers, card)) { if (Iterables.contains(blockers, card)) {
return true; return true;
} }
@@ -69,18 +74,20 @@ public class CombatView {
} }
public void addAttackingBand(final Iterable<CardView> attackingBand, final GameEntityView defender, final Iterable<CardView> blockers) { public void addAttackingBand(final Iterable<CardView> attackingBand, final GameEntityView defender, final Iterable<CardView> blockers) {
for (final CardView attacker : attackingBand) { final List<CardView> attackingBandCopy = Lists.newArrayList(attackingBand),
this.attackersWithDefenders.put(attacker, defender); blockersCopy;
this.attackersWithBlockers.put(attacker, blockers); if (blockers == null) {
} blockersCopy = null;
this.bandsWithDefenders.put(attackingBand, defender); } else {
this.bandsWithBlockers.put(attackingBand, blockers); blockersCopy = Lists.newArrayList(blockers);
} }
public void reset() { for (final CardView attacker : attackingBandCopy) {
this.attackersWithDefenders = Maps.newHashMap(); this.attackersWithDefenders.put(attacker, defender);
this.attackersWithBlockers = Maps.newHashMap(); this.attackersWithBlockers.put(attacker, blockersCopy);
this.bandsWithDefenders = Maps.newHashMap();
this.bandsWithBlockers = Maps.newHashMap();
} }
this.bandsWithDefenders.put(attackingBandCopy, defender);
this.bandsWithBlockers.put(attackingBandCopy, blockersCopy);
}
} }

View File

@@ -35,8 +35,6 @@ public interface IGameView {
public abstract int getGamesWonBy(LobbyPlayer p); public abstract int getGamesWonBy(LobbyPlayer p);
public abstract GameOutcome.AnteResult getAnteResult(); public abstract GameOutcome.AnteResult getAnteResult();
public abstract boolean isCombatDeclareAttackers();
public abstract boolean isGameOver(); public abstract boolean isGameOver();
public abstract int getPoisonCountersToLose(); public abstract int getPoisonCountersToLose();
@@ -61,6 +59,7 @@ public interface IGameView {
public abstract void selectPlayer(PlayerView player, ITriggerEvent triggerEvent); public abstract void selectPlayer(PlayerView player, ITriggerEvent triggerEvent);
public abstract boolean selectCard(CardView card, ITriggerEvent triggerEvent); public abstract boolean selectCard(CardView card, ITriggerEvent triggerEvent);
public abstract void selectAbility(SpellAbilityView sa); public abstract void selectAbility(SpellAbilityView sa);
public abstract void alphaStrike();
// the following method should eventually be replaced by methods returning // the following method should eventually be replaced by methods returning
// View classes // View classes

View File

@@ -47,8 +47,6 @@ public class LocalGameView implements IGameView {
private final Cache<SpellAbility, SpellAbilityView> spabs = new Cache<>(); private final Cache<SpellAbility, SpellAbilityView> spabs = new Cache<>();
/** Cache of stack items. */ /** Cache of stack items. */
private final Cache<SpellAbilityStackInstance, StackItemView> stackItems = new Cache<>(); private final Cache<SpellAbilityStackInstance, StackItemView> stackItems = new Cache<>();
/** Combat view. */
private final CombatView combatView = new CombatView();
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#isCommander() * @see forge.view.IGameView#isCommander()
@@ -133,15 +131,6 @@ public class LocalGameView implements IGameView {
return null; return null;
} }
/* (non-Javadoc)
* @see forge.view.IGameView#isCombatDeclareAttackers()
*/
@Override
public boolean isCombatDeclareAttackers() {
return game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_ATTACKERS)
&& game.getCombat() != null;
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#isGameOver() * @see forge.view.IGameView#isGameOver()
*/ */
@@ -171,22 +160,19 @@ public class LocalGameView implements IGameView {
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#getCombat() * @see forge.view.IGameView#getCombat()
*/ */
public CombatView getCombat(final Combat c) { public CombatView getCombat(final Combat combat) {
if (c == null) { if (combat == null) {
return null; return null;
} }
updateCombatView(c);
return combatView;
}
private final void updateCombatView(final Combat combat) { final CombatView combatView = new CombatView();
combatView.reset();
for (final AttackingBand b : combat.getAttackingBands()) { for (final AttackingBand b : combat.getAttackingBands()) {
if (b == null) continue; if (b == null) continue;
final GameEntity defender = combat.getDefenderByAttacker(b); final GameEntity defender = combat.getDefenderByAttacker(b);
final List<Card> blockers = b.isBlocked() == null ? null : combat.getBlockers(b); final List<Card> blockers = (b.isBlocked() != null && b.isBlocked()) ? combat.getBlockers(b) : null;
combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), blockers == null ? null : getCardViews(blockers)); combatView.addAttackingBand(getCardViews(b.getAttackers()), getGameEntityView(defender), blockers == null ? null : getCardViews(blockers));
} }
return combatView;
} }
@Override @Override
@@ -256,6 +242,10 @@ public class LocalGameView implements IGameView {
public void selectAbility(final SpellAbilityView sa) { public void selectAbility(final SpellAbilityView sa) {
} }
@Override
public void alphaStrike() {
}
/* (non-Javadoc) /* (non-Javadoc)
* @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer) * @see forge.view.IGameView#getGuiRegisteredPlayer(forge.LobbyPlayer)
*/ */
@@ -351,6 +341,26 @@ public class LocalGameView implements IGameView {
return null; return null;
} }
private final Function<GameEntity, GameEntityView> FN_GET_GAME_ENTITY_VIEW = new Function<GameEntity, GameEntityView>() {
@Override
public GameEntityView apply(GameEntity input) {
return getGameEntityView(input);
}
};
public final List<GameEntityView> getGameEntityViews(final Iterable<GameEntity> entities) {
return ViewUtil.transformIfNotNull(entities, FN_GET_GAME_ENTITY_VIEW);
}
public final GameEntity getGameEntity(final GameEntityView view) {
if (view instanceof CardView) {
return getCard((CardView) view);
} else if (view instanceof PlayerView) {
return getPlayer((PlayerView) view);
}
return null;
}
private final Function<Player, PlayerView> FN_GET_PLAYER_VIEW = new Function<Player, PlayerView>() { private final Function<Player, PlayerView> FN_GET_PLAYER_VIEW = new Function<Player, PlayerView>() {
@Override @Override
public PlayerView apply(final Player input) { public PlayerView apply(final Player input) {
@@ -358,12 +368,8 @@ public class LocalGameView implements IGameView {
} }
}; };
public final List<PlayerView> getPlayerViews(final List<Player> players) { public final List<PlayerView> getPlayerViews(final Iterable<Player> players) {
return Lists.transform(players, FN_GET_PLAYER_VIEW); return ViewUtil.transformIfNotNull(players, FN_GET_PLAYER_VIEW);
}
public final Iterable<PlayerView> getPlayerViews(final Iterable<Player> players) {
return Iterables.transform(players, FN_GET_PLAYER_VIEW);
} }
public PlayerView getPlayerView(final Player p) { public PlayerView getPlayerView(final Player p) {
@@ -376,7 +382,7 @@ public class LocalGameView implements IGameView {
view = players.get(p); view = players.get(p);
getPlayerView(p, view); getPlayerView(p, view);
} else { } else {
view = new PlayerView(p.getLobbyPlayer(), p.getController()); view = new PlayerView(p.getLobbyPlayer(), p.getId());
players.put(p, view); players.put(p, view);
getPlayerView(p, view); getPlayerView(p, view);
view.setOpponents(getPlayerViews(p.getOpponents())); view.setOpponents(getPlayerViews(p.getOpponents()));
@@ -407,8 +413,12 @@ public class LocalGameView implements IGameView {
view.setExileCards(getCardViews(p.getCardsIn(ZoneType.Exile))); view.setExileCards(getCardViews(p.getCardsIn(ZoneType.Exile)));
view.setFlashbackCards(getCardViews(p.getCardsActivableInExternalZones(false))); view.setFlashbackCards(getCardViews(p.getCardsActivableInExternalZones(false)));
view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard))); view.setGraveCards(getCardViews(p.getCardsIn(ZoneType.Graveyard)));
view.setHandCards(getCardViews(p.getCardsIn(ZoneType.Hand))); final List<Card> handCards = p.getCardsIn(ZoneType.Hand),
view.setLibraryCards(getCardViews(p.getCardsIn(ZoneType.Library))); libraryCards = p.getCardsIn(ZoneType.Library);
view.setHandCards(getCardViews(handCards));
view.setLibraryCards(getCardViews(libraryCards));
view.setnHandCards(handCards.size());
view.setnLibraryCards(libraryCards.size());
for (final byte b : MagicColor.WUBRGC) { for (final byte b : MagicColor.WUBRGC) {
view.setMana(b, p.getManaPool().getAmountOfColor(b)); view.setMana(b, p.getManaPool().getAmountOfColor(b));
@@ -421,7 +431,8 @@ public class LocalGameView implements IGameView {
} }
final Card cUi = c.getCardForUi(); final Card cUi = c.getCardForUi();
final boolean isDisplayable = cUi == c; final boolean isDisplayable = cUi == c &&
!(c.isInZone(ZoneType.Hand) || c.isInZone(ZoneType.Library));
CardView view = cards.get(c); CardView view = cards.get(c);
final boolean mayShow; final boolean mayShow;
@@ -438,10 +449,12 @@ public class LocalGameView implements IGameView {
} }
} }
if (isDisplayable && mayShow) { if (mayShow) {
writeCardToView(cUi, view); writeCardToView(cUi, view);
} else { } else if (isDisplayable) {
view.reset(); view.reset();
} else {
return null;
} }
return view; return view;
@@ -454,11 +467,8 @@ public class LocalGameView implements IGameView {
} }
}; };
public final List<CardView> getCardViews(final List<Card> cards) { public final List<CardView> getCardViews(final Iterable<Card> cards) {
return Lists.transform(cards, FN_GET_CARD_VIEW); return ViewUtil.transformIfNotNull(cards, FN_GET_CARD_VIEW);
}
public final Iterable<CardView> getCardViews(final Iterable<Card> cards) {
return Iterables.transform(cards, FN_GET_CARD_VIEW);
} }
private CardView getCardViewFast(final Card c) { private CardView getCardViewFast(final Card c) {
@@ -467,10 +477,14 @@ public class LocalGameView implements IGameView {
} }
final CardView view = cards.get(c); final CardView view = cards.get(c);
if (!mayShowCard(view)) { if (mayShowCard(view)) {
view.reset();
}
return view; return view;
} else if (view.isUiDisplayable()) {
view.reset();
return view;
}
return null;
} }
private final Function<Card, CardView> FN_GET_CARDVIEW_FAST = new Function<Card, CardView>() { private final Function<Card, CardView> FN_GET_CARDVIEW_FAST = new Function<Card, CardView>() {
@@ -480,8 +494,8 @@ public class LocalGameView implements IGameView {
} }
}; };
private Iterable<CardView> getCardViewsFast(final Iterable<Card> cards) { private List<CardView> getCardViewsFast(final Iterable<Card> cards) {
return Iterables.transform(cards, FN_GET_CARDVIEW_FAST); return ViewUtil.transformIfNotNull(cards, FN_GET_CARDVIEW_FAST);
} }
public Card getCard(final CardView c) { public Card getCard(final CardView c) {
@@ -496,7 +510,7 @@ public class LocalGameView implements IGameView {
}; };
public final List<Card> getCards(final List<CardView> cards) { public final List<Card> getCards(final List<CardView> cards) {
return Lists.transform(cards, FN_GET_CARD); return ViewUtil.transformIfNotNull(cards, FN_GET_CARD);
} }
private void writeCardToView(final Card c, final CardView view) { private void writeCardToView(final Card c, final CardView view) {
@@ -558,7 +572,7 @@ public class LocalGameView implements IGameView {
}; };
public final List<SpellAbilityView> getSpellAbilityViews(final List<SpellAbility> cards) { public final List<SpellAbilityView> getSpellAbilityViews(final List<SpellAbility> cards) {
return Lists.transform(cards, FN_GET_SPAB_VIEW); return ViewUtil.transformIfNotNull(cards, FN_GET_SPAB_VIEW);
} }
public SpellAbility getSpellAbility(final SpellAbilityView c) { public SpellAbility getSpellAbility(final SpellAbilityView c) {
@@ -573,7 +587,7 @@ public class LocalGameView implements IGameView {
}; };
public final List<SpellAbility> getSpellAbilities(final List<SpellAbilityView> cards) { public final List<SpellAbility> getSpellAbilities(final List<SpellAbilityView> cards) {
return Lists.transform(cards, FN_GET_SPAB); return ViewUtil.transformIfNotNull(cards, FN_GET_SPAB);
} }
private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) { private void writeSpellAbilityToView(final SpellAbility sa, final SpellAbilityView view) {

View File

@@ -11,19 +11,19 @@ import com.google.common.collect.Sets;
import forge.LobbyPlayer; import forge.LobbyPlayer;
import forge.card.MagicColor; import forge.card.MagicColor;
import forge.game.player.PlayerController;
import forge.game.zone.ZoneType; import forge.game.zone.ZoneType;
public class PlayerView extends GameEntityView { public class PlayerView extends GameEntityView {
private final LobbyPlayer lobbyPlayer; private final LobbyPlayer lobbyPlayer;
private final PlayerController controller; private final int id;
private Set<PlayerView> opponents; private Set<PlayerView> opponents;
private int life, poisonCounters, maxHandSize, numDrawnThisTurn, preventNextDamage; private int life, poisonCounters, maxHandSize, numDrawnThisTurn, preventNextDamage;
private List<String> keywords; private List<String> keywords;
private String commanderInfo; private String commanderInfo;
private List<CardView> anteCards = Lists.newArrayList(), private List<CardView>
anteCards = Lists.newArrayList(),
bfCards = Lists.newArrayList(), bfCards = Lists.newArrayList(),
commandCards = Lists.newArrayList(), commandCards = Lists.newArrayList(),
exileCards = Lists.newArrayList(), exileCards = Lists.newArrayList(),
@@ -31,12 +31,15 @@ public class PlayerView extends GameEntityView {
graveCards = Lists.newArrayList(), graveCards = Lists.newArrayList(),
handCards = Lists.newArrayList(), handCards = Lists.newArrayList(),
libraryCards = Lists.newArrayList(); libraryCards = Lists.newArrayList();
private int
nHandCards,
nLibraryCards;
private boolean hasUnlimitedHandSize; private boolean hasUnlimitedHandSize;
private Map<Byte, Integer> mana = Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1); private Map<Byte, Integer> mana = Maps.newHashMapWithExpectedSize(MagicColor.NUMBER_OR_COLORS + 1);
public PlayerView(final LobbyPlayer lobbyPlayer, final PlayerController controller) { public PlayerView(final LobbyPlayer lobbyPlayer, final int id) {
this.lobbyPlayer = lobbyPlayer; this.lobbyPlayer = lobbyPlayer;
this.controller = controller; this.id = id;
} }
/** /**
@@ -46,6 +49,20 @@ public class PlayerView extends GameEntityView {
return lobbyPlayer; return lobbyPlayer;
} }
public int getId() {
return id;
}
@Override
public boolean equals(final Object obj) {
return obj instanceof PlayerView && this.getId() == ((PlayerView) obj).getId();
}
@Override
public int hashCode() {
return id;
}
public void setOpponents(final Iterable<PlayerView> opponents) { public void setOpponents(final Iterable<PlayerView> opponents) {
this.opponents = Sets.newHashSet(opponents); this.opponents = Sets.newHashSet(opponents);
} }
@@ -54,14 +71,6 @@ public class PlayerView extends GameEntityView {
return opponents.contains(other); return opponents.contains(other);
} }
/**
* @return the controller
*/
@Deprecated
public PlayerController getController() {
return controller;
}
public String getName() { public String getName() {
return this.getLobbyPlayer().getName(); return this.getLobbyPlayer().getName();
} }
@@ -302,6 +311,34 @@ public class PlayerView extends GameEntityView {
} }
} }
/**
* @return the nHandCards
*/
public int getnHandCards() {
return nHandCards;
}
/**
* @param nHandCards the nHandCards to set
*/
public void setnHandCards(int nHandCards) {
this.nHandCards = nHandCards;
}
/**
* @return the nLibraryCards
*/
public int getnLibraryCards() {
return nLibraryCards;
}
/**
* @param nLibraryCards the nLibraryCards to set
*/
public void setnLibraryCards(int nLibraryCards) {
this.nLibraryCards = nLibraryCards;
}
/** /**
* @return the hasUnlimitedHandSize * @return the hasUnlimitedHandSize
*/ */

View File

@@ -1,6 +1,10 @@
package forge.view; package forge.view;
import java.util.Collections; import java.util.Collections;
import java.util.List;
import com.google.common.base.Function;
import com.google.common.collect.Lists;
import forge.card.CardCharacteristicName; import forge.card.CardCharacteristicName;
import forge.game.card.Card; import forge.game.card.Card;
@@ -51,8 +55,17 @@ public final class ViewUtil {
view.setNamedCard(c.getNamedCard()); view.setNamedCard(c.getNamedCard());
if (c.isSplitCard()) { if (c.isSplitCard()) {
writeCardStateViewProperties(c, view.getOriginal(), CardCharacteristicName.LeftSplit); final CardCharacteristicName orig, alt;
writeCardStateViewProperties(c, view.getAlternate(), CardCharacteristicName.RightSplit); if (c.getCurState() == CardCharacteristicName.RightSplit) {
// If right half on stack, place it first
orig = CardCharacteristicName.RightSplit;
alt = CardCharacteristicName.LeftSplit;
} else {
orig = CardCharacteristicName.LeftSplit;
alt = CardCharacteristicName.RightSplit;
}
writeCardStateViewProperties(c, view.getOriginal(), orig);
writeCardStateViewProperties(c, view.getAlternate(), alt);
return; return;
} }
@@ -114,4 +127,15 @@ public final class ViewUtil {
writeNonDependentCardViewProperties(c, view, c.getCardForUi() == c); writeNonDependentCardViewProperties(c, view, c.getCardForUi() == c);
return view; return view;
} }
public static <T,V> List<V> transformIfNotNull(final Iterable<T> input, final Function<T, V> transformation) {
final List<V> ret = Lists.newLinkedList();
for (final T t : input) {
final V v = transformation.apply(t);
if (v != null) {
ret.add(v);
}
}
return ret;
}
} }

View File

@@ -21,7 +21,7 @@ public class LobbyPlayerRemote extends LobbyPlayer implements IGameEntitiesFacto
* @see forge.game.player.LobbyPlayer#getPlayer(forge.game.GameState) * @see forge.game.player.LobbyPlayer#getPlayer(forge.game.GameState)
*/ */
@Override @Override
public Player createIngamePlayer(Game gameState) { public Player createIngamePlayer(Game gameState, final int id) {
// Cannot create remote players yet // Cannot create remote players yet
throw new UnsupportedOperationException("method is not implemented"); throw new UnsupportedOperationException("method is not implemented");
} }