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) {
gamePanel.showGame(gameId, playerId);
this.toFront();
}
public void watchGame(UUID gameId) {
gamePanel.watchGame(gameId);
this.toFront();
}
public void replayGame() {
gamePanel.replayGame();
this.toFront();
}
/** 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<ActivatedAbility> playableAbilities = new ArrayList<ActivatedAbility>();
public ComputerPlayer(String name, Deck deck, RangeOfInfluence range) {
super(name, deck, range);
public ComputerPlayer(String name, RangeOfInfluence range) {
super(name, range);
human = false;
}
@ -768,7 +768,7 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
}
@Override
public void sideboard(Table table) {
public void sideboard(Table table, Deck deck) {
//TODO: improve this
table.fireSubmitDeckEvent(playerId, deck);
}

View file

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

View file

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

View file

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

View file

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

View file

@ -96,7 +96,7 @@ public class TableController {
public void event(TableEvent event) {
switch (event.getEventType()) {
case SIDEBOARD:
sideboard(event.getPlayerId());
sideboard(event.getPlayerId(), event.getDeck());
break;
case SUBMIT_DECK:
submitDeck(event.getPlayerId(), event.getDeck());
@ -120,7 +120,7 @@ public class TableController {
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);
table.joinTable(player, seat);
logger.info("player joined " + player.getId());
@ -178,8 +178,8 @@ public class TableController {
return table.getValidator().validate(deck);
}
private Player createPlayer(String name, Deck deck, String playerType) {
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, deck, options.getRange());
private Player createPlayer(String name, String playerType) {
Player player = PlayerFactory.getInstance().createPlayer(playerType, name, options.getRange());
logger.info("Player created " + player.getId());
return player;
}
@ -214,17 +214,16 @@ public class TableController {
table.sideboard();
for (MatchPlayer player: match.getPlayers()) {
player.setSideboarding();
player.getPlayer().sideboard(table);
player.getPlayer().sideboard(table, player.getDeck());
}
while (!match.isDoneSideboarding()){}
}
private void sideboard(UUID playerId) {
private void sideboard(UUID playerId, Deck deck) {
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
if (entry.getValue().equals(playerId)) {
MatchPlayer player = match.getPlayer(entry.getValue());
sessionManager.getSession(entry.getKey()).sideboard(player.getDeck(), table.getId());
sessionManager.getSession(entry.getKey()).sideboard(deck, table.getId());
break;
}
}
@ -244,11 +243,6 @@ public class TableController {
} catch (GameException ex) {
logger.log(Level.SEVERE, null, ex);
}
endMatch();
}
public void endMatch() {
match = null;
}
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.ContinuousEffects;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.game.combat.Combat;
import mage.game.events.GameEvent;
@ -81,7 +82,7 @@ public interface Game extends MageItem, Serializable {
public Card getCard(UUID cardId);
public Zone getZone(UUID objectId);
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 Players getPlayers();
public PlayerList getPlayerList();

View file

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

View file

@ -147,8 +147,8 @@ public class Table implements Serializable {
return this.name;
}
public void fireSideboardEvent(UUID playerId) {
tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, null);
public void fireSideboardEvent(UUID playerId, Deck deck) {
tableEventSource.fireTableEvent(EventType.SIDEBOARD, playerId, 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 {
for (MatchPlayer matchPlayer: this.players) {
game.addPlayer(matchPlayer.getPlayer());
game.loadCards(matchPlayer.getDeck().getCards(), 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
*/
public Card removeFromTop(Game game) {
Card card = game.getCard(library.pollFirst());
UUID cardId = library.pollFirst();
Card card = game.getCard(cardId);
if (card == null) {
emptyDraw = true;
}

View file

@ -90,6 +90,7 @@ public interface Player extends MageItem, Copyable<Player> {
public Set<UUID> getInRange();
public void init(Game game);
public void useDeck(Deck deck, Game game);
public void reset();
public void shuffleLibrary(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 assignDamage(int damage, List<UUID> targets, UUID sourceId, 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 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 RangeOfInfluence range;
protected Set<UUID> inRange = new HashSet<UUID>();
protected Deck deck;
// protected Deck deck;
@Override
public abstract T copy();
public PlayerImpl(String name, Deck deck, RangeOfInfluence range) {
public PlayerImpl(String name, RangeOfInfluence range) {
this(UUID.randomUUID());
this.name = name;
this.range = range;
this.deck = deck;
// this.deck = deck;
hand = new CardsImpl(Zone.HAND);
graveyard = new CardsImpl(Zone.GRAVEYARD);
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
public void init(Game game) {
this.abort = false;
library.addAll(deck.getCards(), game);
this.hand.clear();
this.graveyard.clear();
this.abilities.clear();