diff --git a/Mage.Client/config/config.properties b/Mage.Client/config/config.properties index 5b4f8d43b44..9fb6435889d 100644 --- a/Mage.Client/config/config.properties +++ b/Mage.Client/config/config.properties @@ -7,4 +7,10 @@ resource-path=C:\\Program Files (x86)\\Wizards of the Coast\\Magic Online III\\G #cards-resource-path=resources/images/cards/ #symbols-resource-path=resources/images/symbols/ #resource-path=resources/images/ -card-scaling-factor=0.4 \ No newline at end of file +card-scaling-factor=0.4 + +# parameters for debugging and testing faster +default-deck-path=C:\\UW Control.dck +# 0: Human, 1: Computer - default, 2: Computer - minimax, 3: Computer - minimax hybrid +default-other-player-index=1 +default-computer-name=computer \ No newline at end of file diff --git a/Mage.Client/src/mage/client/table/NewPlayerPanel.java b/Mage.Client/src/mage/client/table/NewPlayerPanel.java index 75c64da58df..73792a8fe28 100644 --- a/Mage.Client/src/mage/client/table/NewPlayerPanel.java +++ b/Mage.Client/src/mage/client/table/NewPlayerPanel.java @@ -39,6 +39,7 @@ import java.io.IOException; import javax.swing.JFileChooser; import javax.swing.filechooser.FileFilter; import mage.client.MageFrame; +import mage.client.util.Config; /** * @@ -54,6 +55,8 @@ public class NewPlayerPanel extends javax.swing.JPanel { fcSelectDeck = new JFileChooser(); fcSelectDeck.setAcceptAllFileFilterUsed(false); fcSelectDeck.addChoosableFileFilter(new DeckFilter()); + if (Config.defaultDeckPath != null) this.txtPlayerDeck.setText(Config.defaultDeckPath); + if (Config.defaultComputerName != null) this.txtPlayerName.setText(Config.defaultComputerName); } public void setPlayerName(String playerName) { diff --git a/Mage.Client/src/mage/client/table/TablePlayerPanel.java b/Mage.Client/src/mage/client/table/TablePlayerPanel.java index 0d2cd254d18..d1a3bbc7926 100644 --- a/Mage.Client/src/mage/client/table/TablePlayerPanel.java +++ b/Mage.Client/src/mage/client/table/TablePlayerPanel.java @@ -37,13 +37,14 @@ package mage.client.table; import java.io.FileNotFoundException; import java.io.IOException; import java.util.UUID; -import java.util.logging.Level; import java.util.logging.Logger; + import javax.swing.DefaultComboBoxModel; -import javax.swing.JOptionPane; + import mage.cards.decks.DeckCardLists; import mage.client.MageFrame; import mage.client.remote.Session; +import mage.client.util.Config; import mage.client.util.Event; import mage.client.util.Listener; import mage.util.Logging; @@ -70,6 +71,12 @@ public class TablePlayerPanel extends javax.swing.JPanel { session = MageFrame.getSession(); cbPlayerType.setModel(new DefaultComboBoxModel(session.getPlayerTypes())); this.lblPlayerNum.setText("Player " + playerNum); + if (Config.defaultOtherPlayerIndex != null) { + try { + Integer index = Integer.parseInt(Config.defaultOtherPlayerIndex); + cbPlayerType.setSelectedIndex(index); + } catch (NumberFormatException e) {} + } } public boolean joinTable(UUID roomId, UUID tableId) throws FileNotFoundException, IOException, ClassNotFoundException { diff --git a/Mage.Client/src/mage/client/util/Config.java b/Mage.Client/src/mage/client/util/Config.java index cad90461904..6afa3364874 100644 --- a/Mage.Client/src/mage/client/util/Config.java +++ b/Mage.Client/src/mage/client/util/Config.java @@ -34,6 +34,9 @@ import java.io.IOException; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; + +import com.sun.xml.internal.ws.api.streaming.XMLStreamReaderFactory.Default; + import mage.client.cards.CardDimensions; import mage.util.Logging; @@ -58,6 +61,11 @@ public class Config { public static final double cardScalingFactor; public static final boolean useResource; public static final CardDimensions dimensions; + + public static final String defaultGameType; + public static final String defaultDeckPath; + public static final String defaultOtherPlayerIndex; + public static final String defaultComputerName; static { Properties p = new Properties(); @@ -72,6 +80,11 @@ public class Config { cardsResourcePath = p.getProperty("cards-resource-path"); resourcePath = p.getProperty("resource-path"); cardScalingFactor = Double.valueOf(p.getProperty("card-scaling-factor")); + defaultGameType = p.getProperty("default-game-type", "Human"); + defaultDeckPath = p.getProperty("default-deck-path"); + defaultOtherPlayerIndex = p.getProperty("default-other-player-index"); + defaultComputerName = p.getProperty("default-computer-name"); + dimensions = new CardDimensions(cardScalingFactor); File test = new File(cardsResourcePath); if (test.isDirectory()) { diff --git a/Mage.Client/src/mage/client/util/ImageHelper.java b/Mage.Client/src/mage/client/util/ImageHelper.java index 972ad5e7399..65611edb78f 100644 --- a/Mage.Client/src/mage/client/util/ImageHelper.java +++ b/Mage.Client/src/mage/client/util/ImageHelper.java @@ -117,7 +117,8 @@ public class ImageHelper { StringBuilder sb = new StringBuilder(); sb.append(Config.setIconsResourcePath).append("graphic_").append(symbolCode).append("_").append(card.getRarity().getSymbolCode()).append(".png"); BufferedImage icon = loadImage(sb.toString(), ICON_MAX_HEIGHT); - g.drawImage(icon, ICON_MAX_XOFFSET - icon.getWidth(), ICON_MAX_YOFFSET, null); + if (icon != null) + g.drawImage(icon, ICON_MAX_XOFFSET - icon.getWidth(), ICON_MAX_YOFFSET, null); } } diff --git a/Mage.Server/config/init.txt b/Mage.Server/config/init.txt new file mode 100644 index 00000000000..74cdea018a5 --- /dev/null +++ b/Mage.Server/config/init.txt @@ -0,0 +1,14 @@ +# You may add any card to any zone here +# +# Format: ::: +# +# zone ::= hand | battlefield | graveyard +# nickname - Player's name you connect to the game with +# +# +hand:player:mage.sets.magic2010.LightningBolt:1 +hand:player:mage.sets.magic2011.Fireball:2 +battlefield:player:mage.sets.magic2011.BrindleBoar:2 +graveyard:player:mage.sets.magic2011.BrindleBoar:1 +hand:player:mage.sets.magic2011.DoomBlade:1 +battlefield:player:mage.cards.basiclands.Swamp:2 diff --git a/Mage.Server/src/mage/server/game/GameController.java b/Mage.Server/src/mage/server/game/GameController.java index 90470779718..c6f9e394f10 100644 --- a/Mage.Server/src/mage/server/game/GameController.java +++ b/Mage.Server/src/mage/server/game/GameController.java @@ -28,31 +28,40 @@ package mage.server.game; +import java.io.File; import java.util.Collection; -import java.util.Map.Entry; +import java.util.HashSet; +import java.util.Scanner; +import java.util.Set; import java.util.UUID; +import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import mage.Constants; import mage.Constants.Zone; import mage.abilities.Ability; import mage.cards.Card; +import mage.cards.CardImpl; import mage.cards.Cards; import mage.cards.decks.Deck; import mage.cards.decks.DeckCardLists; import mage.game.Game; -import mage.game.events.TableEvent; -import mage.server.ChatManager; -import mage.server.util.ThreadExecutor; import mage.game.events.Listener; import mage.game.events.PlayerQueryEvent; +import mage.game.events.TableEvent; import mage.players.Player; +import mage.server.ChatManager; +import mage.server.util.ThreadExecutor; import mage.util.Logging; import mage.view.AbilityPickerView; import mage.view.CardsView; -import mage.view.ChatMessage.MessageColor; import mage.view.GameView; +import mage.view.ChatMessage.MessageColor; /** * @@ -205,6 +214,7 @@ public class GameController implements GameCallback { for (Card card: deck.getCards()) { card.putOntoBattlefield(game, Zone.OUTSIDE, playerId); } + addCardsForTesting(game, game.getPlayer(playerId)); updateGame(); } @@ -368,4 +378,93 @@ public class GameController implements GameCallback { endGame(result); } + /** + * Replaces cards in player's hands by specified in config/init.txt.
+ *
+ * Implementation note:
+ * 1. Read init.txt line by line
+ * 2. Parse line using the following format: line ::= :::
+ * 3. If zone equals to 'hand', add card to player's library
+ * 3a. Then swap added card with any card in player's hand
+ * 3b. Parse next line (go to 2.), If EOF go to 4.
+ * 4. Log message to all players that cards were added (to prevent unfair play).
+ * 5. Exit
+ */ + private void addCardsForTesting(Game game, Player player) { + try { + File f = new File(Constants.INIT_FILE_PATH); + Pattern pattern = Pattern.compile("([a-zA-Z]*):([\\w]*):([a-zA-Z ,.!\\d]*):([\\d]*)"); + if (!f.exists()) { + //TODO: log warning with Logger + System.err.println("WARN! Couldn't find init file: " + Constants.INIT_FILE_PATH); + return; + } + + System.err.println("Parsing init.txt for player : " + player.getName()); + + Scanner scanner = new Scanner(f); + while (scanner.hasNextLine()) { + String line = scanner.nextLine().trim(); + if (line.startsWith("#")) continue; + Matcher m = pattern.matcher(line); + if (m.matches()) { + + String zone = m.group(1); + String nickname = m.group(2); + + if (nickname.equals(player.getName())) { + Zone gameZone; + if ("hand".equalsIgnoreCase(zone)) { + gameZone = Zone.HAND; + } else if ("battlefield".equalsIgnoreCase(zone)) { + gameZone = Zone.BATTLEFIELD; + } else if ("graveyard".equalsIgnoreCase(zone)) { + gameZone = Zone.GRAVEYARD; + } else { + continue; // go parse next line + } + + String cardName = m.group(3); + Integer amount = Integer.parseInt(m.group(4)); + for (int i = 0; i < amount; i++) { + Card card = CardImpl.createCard(cardName); + if (card != null) { + Set cards = new HashSet(); + cards.add(card); + game.loadCards(cards, player.getId()); + swapWithAnyCard(game, player, card, gameZone); + } else { + //TODO: log warning with Logger + System.err.println("ERROR! Couldn't create a card: " + cardName); + } + } + } else { + //TODO: log warning with Logger + System.err.println("WARN! Was skipped: " + line); + } + } else { + //TODO: log warning with Logger + System.err.println("WARN! Init string wasn't parsed: " + line); + } + } + } catch (Exception e) { + //TODO: add logger + e.printStackTrace(); + } + } + + /** + * Swap cards between specified card from library and any hand card. + * + * @param game + * @param card Card to put to player's hand + */ + private void swapWithAnyCard(Game game, Player player, Card card, Zone zone) { + if (zone.equals(Zone.BATTLEFIELD)) { + card.putOntoBattlefield(game, Zone.OUTSIDE, player.getId()); + } else { + card.moveToZone(zone, game, false); + } + System.out.println("Added card to player's " + zone.toString() + ": " + card.getName() +", player = " + player.getName()); + } } diff --git a/Mage/src/mage/Constants.java b/Mage/src/mage/Constants.java index ce24f9116b3..2751c05da80 100644 --- a/Mage/src/mage/Constants.java +++ b/Mage/src/mage/Constants.java @@ -28,10 +28,13 @@ package mage; +import java.io.File; import java.util.ArrayList; import java.util.List; public final class Constants { + + public static final String INIT_FILE_PATH = "config" + File.separator + "init.txt"; public enum ColoredManaSymbol { W("W"), U("U"), B("B"), R("R"), G("G");