mirror of
https://github.com/correl/mage.git
synced 2024-12-24 03:00:14 +00:00
Mage.Server/config/init.txt for adding cards to any zone in testMode. Fix for icon being null. Temporary fix for expansionSetCode being null for BasicLands.
This commit is contained in:
parent
17f2e7dab5
commit
c82d3c6dd9
8 changed files with 155 additions and 9 deletions
|
@ -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
|
||||
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
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
14
Mage.Server/config/init.txt
Normal file
14
Mage.Server/config/init.txt
Normal file
|
@ -0,0 +1,14 @@
|
|||
# You may add any card to any zone here
|
||||
#
|
||||
# Format: <zone>:<nickname>:<card name>:<amount>
|
||||
#
|
||||
# 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
|
|
@ -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.<br/>
|
||||
* <br/>
|
||||
* <b>Implementation note:</b><br/>
|
||||
* 1. Read init.txt line by line<br/>
|
||||
* 2. Parse line using the following format: line ::= <zone>:<nickname>:<card name>:<amount><br/>
|
||||
* 3. If zone equals to 'hand', add card to player's library<br/>
|
||||
* 3a. Then swap added card with any card in player's hand<br/>
|
||||
* 3b. Parse next line (go to 2.), If EOF go to 4.<br/>
|
||||
* 4. Log message to all players that cards were added (to prevent unfair play).<br/>
|
||||
* 5. Exit<br/>
|
||||
*/
|
||||
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<Card> cards = new HashSet<Card>();
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Reference in a new issue