This commit is contained in:
maurer.it 2010-12-29 15:14:47 -05:00
commit 88627d5606
17 changed files with 46 additions and 40 deletions

View file

@ -79,14 +79,17 @@ public class GamePane extends MagePane {
public void showGame(UUID gameId, UUID playerId) { public void showGame(UUID gameId, UUID playerId) {
gamePanel.showGame(gameId, playerId); gamePanel.showGame(gameId, playerId);
this.toFront();
} }
public void watchGame(UUID gameId) { public void watchGame(UUID gameId) {
gamePanel.watchGame(gameId); gamePanel.watchGame(gameId);
this.toFront();
} }
public void replayGame() { public void replayGame() {
gamePanel.replayGame(); gamePanel.replayGame();
this.toFront();
} }
/** This method is called from within the constructor to /** This method is called from within the constructor to

View file

@ -117,8 +117,8 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
private transient List<Card> playableInstant = new ArrayList<Card>(); private transient List<Card> playableInstant = new ArrayList<Card>();
private transient List<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>(); private transient List<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>();
public ComputerPlayer(String name, Deck deck, RangeOfInfluence range) { public ComputerPlayer(String name, RangeOfInfluence range) {
super(name, deck, range); super(name, range);
human = false; human = false;
} }
@ -768,7 +768,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
} }
@Override @Override
public void sideboard(Table table) { public void sideboard(Table table, Deck deck) {
//TODO: improve this //TODO: improve this
table.fireSubmitDeckEvent(playerId, deck); table.fireSubmitDeckEvent(playerId, deck);
} }

View file

@ -99,8 +99,8 @@ public class ComputerPlayer2 extends ComputerPlayer<ComputerPlayer2> implements
protected int currentScore; protected int currentScore;
protected SimulationNode root; protected SimulationNode root;
public ComputerPlayer2(String name, Deck deck, RangeOfInfluence range) { public ComputerPlayer2(String name, RangeOfInfluence range) {
super(name, deck, range); super(name, range);
maxDepth = Config.maxDepth; maxDepth = Config.maxDepth;
maxNodes = Config.maxNodes; maxNodes = Config.maxNodes;
} }

View file

@ -83,8 +83,8 @@ public class ComputerPlayer3 extends ComputerPlayer2 implements Player {
} }
public ComputerPlayer3(String name, Deck deck, RangeOfInfluence range) { public ComputerPlayer3(String name, RangeOfInfluence range) {
super(name, deck, range); super(name, range);
maxDepth = Config.maxDepth; maxDepth = Config.maxDepth;
maxNodes = Config.maxNodes; maxNodes = Config.maxNodes;
} }

View file

@ -81,8 +81,8 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
} }
protected transient TargetCreaturePermanent targetCombat = new TargetCreaturePermanent(filter); protected transient TargetCreaturePermanent targetCombat = new TargetCreaturePermanent(filter);
public HumanPlayer(String name, Deck deck, RangeOfInfluence range) { public HumanPlayer(String name, RangeOfInfluence range) {
super(name, deck, range); super(name, range);
human = true; human = true;
} }
@ -473,8 +473,8 @@ public class HumanPlayer extends PlayerImpl<HumanPlayer> {
} }
@Override @Override
public void sideboard(Table table) { public void sideboard(Table table, Deck deck) {
table.fireSideboardEvent(playerId); table.fireSideboardEvent(playerId, deck);
} }
protected void specialAction(Game game) { protected void specialAction(Game game) {

View file

@ -57,12 +57,12 @@ public class PlayerFactory {
private PlayerFactory() {} private PlayerFactory() {}
public Player createPlayer(String playerType, String name, Deck deck, RangeOfInfluence range) { public Player createPlayer(String playerType, String name, RangeOfInfluence range) {
Player player; Player player;
Constructor<?> con; Constructor<?> con;
try { try {
con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, Deck.class, RangeOfInfluence.class}); con = playerTypes.get(playerType).getConstructor(new Class[]{String.class, RangeOfInfluence.class});
player = (Player)con.newInstance(new Object[] {name, deck, range}); player = (Player)con.newInstance(new Object[] {name, range});
} catch (Exception ex) { } catch (Exception ex) {
logger.log(Level.SEVERE, null, ex); logger.log(Level.SEVERE, null, ex);
return null; return null;

View file

@ -96,7 +96,7 @@ public class TableController {
public void event(TableEvent event) { public void event(TableEvent event) {
switch (event.getEventType()) { switch (event.getEventType()) {
case SIDEBOARD: case SIDEBOARD:
sideboard(event.getPlayerId()); sideboard(event.getPlayerId(), event.getDeck());
break; break;
case SUBMIT_DECK: case SUBMIT_DECK:
submitDeck(event.getPlayerId(), event.getDeck()); submitDeck(event.getPlayerId(), event.getDeck());
@ -120,7 +120,7 @@ public class TableController {
throw new GameException(name + " has an invalid deck for this format"); throw new GameException(name + " has an invalid deck for this format");
} }
Player player = createPlayer(name, deck, seat.getPlayerType()); Player player = createPlayer(name, seat.getPlayerType());
match.addPlayer(player, deck); match.addPlayer(player, deck);
table.joinTable(player, seat); table.joinTable(player, seat);
logger.info("player joined " + player.getId()); logger.info("player joined " + player.getId());
@ -178,8 +178,8 @@ public class TableController {
return table.getValidator().validate(deck); return table.getValidator().validate(deck);
} }
private Player createPlayer(String name, Deck deck, String playerType) { private Player createPlayer(String name, String playerType) {
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, deck, options.getRange()); Player player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange());
logger.info("Player created " + player.getId()); logger.info("Player created " + player.getId());
return player; return player;
} }
@ -214,17 +214,16 @@ public class TableController {
table.sideboard(); table.sideboard();
for (MatchPlayer player: match.getPlayers()) { for (MatchPlayer player: match.getPlayers()) {
player.setSideboarding(); player.setSideboarding();
player.getPlayer().sideboard(table); player.getPlayer().sideboard(table, player.getDeck());
} }
while (!match.isDoneSideboarding()){} while (!match.isDoneSideboarding()){}
} }
private void sideboard(UUID playerId) { private void sideboard(UUID playerId, Deck deck) {
SessionManager sessionManager = SessionManager.getInstance(); SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) { for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
if (entry.getValue().equals(playerId)) { if (entry.getValue().equals(playerId)) {
MatchPlayer player = match.getPlayer(entry.getValue()); sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId());
sessionManager.getSession(entry.getKey()).sideboard(player.getDeck(), table.getId());
break; break;
} }
} }
@ -244,11 +243,6 @@ public class TableController {
} catch (GameException ex) { } catch (GameException ex) {
logger.log(Level.SEVERE, null, ex); logger.log(Level.SEVERE, null, ex);
} }
endMatch();
}
public void endMatch() {
match = null;
} }
public void swapSeats(int seatNum1, int seatNum2) { public void swapSeats(int seatNum1, int seatNum2) {

View file

@ -48,6 +48,7 @@ import mage.abilities.TriggeredAbility;
import mage.abilities.effects.ContinuousEffect; import mage.abilities.effects.ContinuousEffect;
import mage.abilities.effects.ContinuousEffects; import mage.abilities.effects.ContinuousEffects;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.choices.Choice; import mage.choices.Choice;
import mage.game.combat.Combat; import mage.game.combat.Combat;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
@ -81,7 +82,7 @@ public interface Game extends MageItem, Serializable {
public Card getCard(UUID cardId); public Card getCard(UUID cardId);
public Zone getZone(UUID objectId); public Zone getZone(UUID objectId);
public void setZone(UUID objectId, Zone zone); public void setZone(UUID objectId, Zone zone);
public void addPlayer(Player player) throws GameException; public void addPlayer(Player player, Deck deck) throws GameException;
public Player getPlayer(UUID playerId); public Player getPlayer(UUID playerId);
public Players getPlayers(); public Players getPlayers();
public PlayerList getPlayerList(); public PlayerList getPlayerList();

View file

@ -59,6 +59,7 @@ import mage.abilities.effects.ContinuousEffects;
import mage.abilities.keyword.LeylineAbility; import mage.abilities.keyword.LeylineAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.choices.Choice; import mage.choices.Choice;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.Filter.ComparisonScope; import mage.filter.Filter.ComparisonScope;
@ -110,7 +111,6 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
protected Map<UUID, Card> gameCards = new HashMap<UUID, Card>(); protected Map<UUID, Card> gameCards = new HashMap<UUID, Card>();
protected GameState state; protected GameState state;
protected UUID startingPlayerId; protected UUID startingPlayerId;
// protected UUID choosingPlayerId;
protected UUID winnerId; protected UUID winnerId;
protected transient GameStates gameStates = new GameStates(); protected transient GameStates gameStates = new GameStates();
@ -131,7 +131,6 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
this.id = game.id; this.id = game.id;
this.ready = game.ready; this.ready = game.ready;
this.startingPlayerId = game.startingPlayerId; this.startingPlayerId = game.startingPlayerId;
// this.choosingPlayerId = game.choosingPlayerId;
this.winnerId = game.winnerId; this.winnerId = game.winnerId;
this.range = game.range; this.range = game.range;
this.attackOption = game.attackOption; this.attackOption = game.attackOption;
@ -161,6 +160,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
for (Card card: cards) { for (Card card: cards) {
card.setOwnerId(ownerId); card.setOwnerId(ownerId);
gameCards.put(card.getId(), card); gameCards.put(card.getId(), card);
state.setZone(card.getId(), Zone.OUTSIDE);
for (Watcher watcher: card.getWatchers()) { for (Watcher watcher: card.getWatchers()) {
watcher.setControllerId(ownerId); watcher.setControllerId(ownerId);
state.getWatchers().add(watcher); state.getWatchers().add(watcher);
@ -174,7 +174,8 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
} }
@Override @Override
public void addPlayer(Player player) throws GameException { public void addPlayer(Player player, Deck deck) throws GameException {
player.useDeck(deck, this);
state.addPlayer(player); state.addPlayer(player);
} }

View file

@ -147,8 +147,8 @@ public class Table implements Serializable {
return this.name; return this.name;
} }
public void fireSideboardEvent(UUID playerId) { public void fireSideboardEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, null); tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, deck);
} }
public void fireSubmitDeckEvent(UUID playerId, Deck deck) { public void fireSubmitDeckEvent(UUID playerId, Deck deck) {

View file

@ -103,9 +103,9 @@ public abstract class MatchImpl<T extends Game> implements Match {
protected void initGame(Game game) throws GameException { protected void initGame(Game game) throws GameException {
for (MatchPlayer matchPlayer: this.players) { for (MatchPlayer matchPlayer: this.players) {
game.addPlayer(matchPlayer.getPlayer());
game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getCards(), matchPlayer.getPlayer().getId());
game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId()); game.loadCards(matchPlayer.getDeck().getSideboard(), matchPlayer.getPlayer().getId());
game.addPlayer(matchPlayer.getPlayer(), matchPlayer.getDeck());
} }
} }

View file

@ -94,7 +94,8 @@ public class Library implements Serializable {
* @see Card * @see Card
*/ */
public Card removeFromTop(Game game) { public Card removeFromTop(Game game) {
Card card = game.getCard(library.pollFirst()); UUID cardId = library.pollFirst();
Card card = game.getCard(cardId);
if (card == null) { if (card == null) {
emptyDraw = true; emptyDraw = true;
} }

View file

@ -90,6 +90,7 @@ public interface Player extends MageItem, Copyable<Player> {
public Set<UUID> getInRange(); public Set<UUID> getInRange();
public void init(Game game); public void init(Game game);
public void useDeck(Deck deck, Game game);
public void reset(); public void reset();
public void shuffleLibrary(Game game); public void shuffleLibrary(Game game);
public int drawCards(int num, Game game); public int drawCards(int num, Game game);
@ -146,7 +147,7 @@ public interface Player extends MageItem, Copyable<Player> {
public abstract void selectBlockers(Game game); public abstract void selectBlockers(Game game);
public abstract void assignDamage(int damage, List<UUID> targets, UUID sourceId, Game game); public abstract void assignDamage(int damage, List<UUID> targets, UUID sourceId, Game game);
public abstract int getAmount(int min, int max, String message, Game game); public abstract int getAmount(int min, int max, String message, Game game);
public abstract void sideboard(Table table); public abstract void sideboard(Table table, Deck deck);
public void declareAttacker(UUID attackerId, UUID defenderId, Game game); public void declareAttacker(UUID attackerId, UUID defenderId, Game game);
public void declareBlocker(UUID blockerId, UUID attackerId, Game game); public void declareBlocker(UUID blockerId, UUID attackerId, Game game);

View file

@ -98,16 +98,16 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
protected boolean left; protected boolean left;
protected RangeOfInfluence range; protected RangeOfInfluence range;
protected Set<UUID> inRange = new HashSet<UUID>(); protected Set<UUID> inRange = new HashSet<UUID>();
protected Deck deck; // protected Deck deck;
@Override @Override
public abstract T copy(); public abstract T copy();
public PlayerImpl(String name, Deck deck, RangeOfInfluence range) { public PlayerImpl(String name, RangeOfInfluence range) {
this(UUID.randomUUID()); this(UUID.randomUUID());
this.name = name; this.name = name;
this.range = range; this.range = range;
this.deck = deck; // this.deck = deck;
hand = new CardsImpl(Zone.HAND); hand = new CardsImpl(Zone.HAND);
graveyard = new CardsImpl(Zone.GRAVEYARD); graveyard = new CardsImpl(Zone.GRAVEYARD);
abilities = new AbilitiesImpl<Ability>(); abilities = new AbilitiesImpl<Ability>();
@ -146,10 +146,15 @@ public abstract class PlayerImpl<T extends PlayerImpl<T>> implements Player, Ser
} }
} }
@Override
public void useDeck(Deck deck, Game game) {
library.clear();
library.addAll(deck.getCards(), game);
}
@Override @Override
public void init(Game game) { public void init(Game game) {
this.abort = false; this.abort = false;
library.addAll(deck.getCards(), game);
this.hand.clear(); this.hand.clear();
this.graveyard.clear(); this.graveyard.clear();
this.abilities.clear(); this.abilities.clear();