mirror of
https://github.com/magefree/mage.git
synced 2025-12-23 03:51:58 -08:00
[CardRepository] Replaced findCard methods from Sets and ExpansionSet
This commit is contained in:
parent
042e4baa1f
commit
08815ffb88
12 changed files with 165 additions and 129 deletions
|
|
@ -43,7 +43,6 @@ public class DeckGenerator {
|
||||||
private static final int DECK_LANDS = 16;
|
private static final int DECK_LANDS = 16;
|
||||||
private static final int MAX_NON_BASIC_SOURCE = DECK_LANDS / 2;
|
private static final int MAX_NON_BASIC_SOURCE = DECK_LANDS / 2;
|
||||||
|
|
||||||
private static final boolean GENERATE_RANDOM_BASIC_LAND = true;
|
|
||||||
private static final int MAX_TRIES = 4096;
|
private static final int MAX_TRIES = 4096;
|
||||||
|
|
||||||
private static Deck deck = new Deck();
|
private static Deck deck = new Deck();
|
||||||
|
|
@ -341,19 +340,24 @@ public class DeckGenerator {
|
||||||
*/
|
*/
|
||||||
private static Card getBestBasicLand(ColoredManaSymbol color) {
|
private static Card getBestBasicLand(ColoredManaSymbol color) {
|
||||||
if (color.equals(ColoredManaSymbol.G)) {
|
if (color.equals(ColoredManaSymbol.G)) {
|
||||||
return Sets.findCard("Forest", GENERATE_RANDOM_BASIC_LAND);
|
CardInfo cardInfo = CardRepository.instance.findCard("Forest");
|
||||||
|
return cardInfo != null ? cardInfo.getCard() : null;
|
||||||
}
|
}
|
||||||
if (color.equals(ColoredManaSymbol.R)) {
|
if (color.equals(ColoredManaSymbol.R)) {
|
||||||
return Sets.findCard("Mountain", GENERATE_RANDOM_BASIC_LAND);
|
CardInfo cardInfo = CardRepository.instance.findCard("Mountain");
|
||||||
|
return cardInfo != null ? cardInfo.getCard() : null;
|
||||||
}
|
}
|
||||||
if (color.equals(ColoredManaSymbol.B)) {
|
if (color.equals(ColoredManaSymbol.B)) {
|
||||||
return Sets.findCard("Swamp", GENERATE_RANDOM_BASIC_LAND);
|
CardInfo cardInfo = CardRepository.instance.findCard("Swamp");
|
||||||
|
return cardInfo != null ? cardInfo.getCard() : null;
|
||||||
}
|
}
|
||||||
if (color.equals(ColoredManaSymbol.U)) {
|
if (color.equals(ColoredManaSymbol.U)) {
|
||||||
return Sets.findCard("Island", GENERATE_RANDOM_BASIC_LAND);
|
CardInfo cardInfo = CardRepository.instance.findCard("Island");
|
||||||
|
return cardInfo != null ? cardInfo.getCard() : null;
|
||||||
}
|
}
|
||||||
if (color.equals(ColoredManaSymbol.W)) {
|
if (color.equals(ColoredManaSymbol.W)) {
|
||||||
return Sets.findCard("Plains", GENERATE_RANDOM_BASIC_LAND);
|
CardInfo cardInfo = CardRepository.instance.findCard("Plains");
|
||||||
|
return cardInfo != null ? cardInfo.getCard() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,14 @@
|
||||||
|
|
||||||
package mage.client.dialog;
|
package mage.client.dialog;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import javax.swing.JLayeredPane;
|
import javax.swing.JLayeredPane;
|
||||||
|
import mage.cards.Card;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.sets.Sets;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
@ -59,6 +63,19 @@ public class AddLandDialog extends MageDialog {
|
||||||
this.setVisible(true);
|
this.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addLands(String landName, int number) {
|
||||||
|
Random random = new Random();
|
||||||
|
List<CardInfo> cards = CardRepository.instance.findCards(landName);
|
||||||
|
if (cards.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < number; i++) {
|
||||||
|
Card land = cards.get(random.nextInt(cards.size())).getCard();
|
||||||
|
deck.getCards().add(land);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** This method is called from within the constructor to
|
/** This method is called from within the constructor to
|
||||||
* initialize the form.
|
* initialize the form.
|
||||||
* WARNING: Do NOT modify this code. The content of this method is
|
* WARNING: Do NOT modify this code. The content of this method is
|
||||||
|
|
@ -194,25 +211,16 @@ public class AddLandDialog extends MageDialog {
|
||||||
|
|
||||||
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
|
private void btnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAddActionPerformed
|
||||||
int nForest = ((Number)spnForest.getValue()).intValue();
|
int nForest = ((Number)spnForest.getValue()).intValue();
|
||||||
for (int i = 0; i < nForest; i++) {
|
|
||||||
deck.getCards().add(Sets.findCard("Forest", true));
|
|
||||||
}
|
|
||||||
int nIsland = ((Number)spnIsland.getValue()).intValue();
|
int nIsland = ((Number)spnIsland.getValue()).intValue();
|
||||||
for (int i = 0; i < nIsland; i++) {
|
|
||||||
deck.getCards().add(Sets.findCard("Island", true));
|
|
||||||
}
|
|
||||||
int nMountain = ((Number)spnMountain.getValue()).intValue();
|
int nMountain = ((Number)spnMountain.getValue()).intValue();
|
||||||
for (int i = 0; i < nMountain; i++) {
|
|
||||||
deck.getCards().add(Sets.findCard("Mountain", true));
|
|
||||||
}
|
|
||||||
int nPlains = ((Number)spnPlains.getValue()).intValue();
|
int nPlains = ((Number)spnPlains.getValue()).intValue();
|
||||||
for (int i = 0; i < nPlains; i++) {
|
|
||||||
deck.getCards().add(Sets.findCard("Plains", true));
|
|
||||||
}
|
|
||||||
int nSwamp = ((Number)spnSwamp.getValue()).intValue();
|
int nSwamp = ((Number)spnSwamp.getValue()).intValue();
|
||||||
for (int i = 0; i < nSwamp; i++) {
|
|
||||||
deck.getCards().add(Sets.findCard("Swamp", true));
|
addLands("Forest", nForest);
|
||||||
}
|
addLands("Island", nIsland);
|
||||||
|
addLands("Mountain", nMountain);
|
||||||
|
addLands("Plains", nPlains);
|
||||||
|
addLands("Swamp", nSwamp);
|
||||||
this.hideDialog();
|
this.hideDialog();
|
||||||
}//GEN-LAST:event_btnAddActionPerformed
|
}//GEN-LAST:event_btnAddActionPerformed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,7 @@ package mage.client.game;
|
||||||
import mage.cards.MageCard;
|
import mage.cards.MageCard;
|
||||||
import mage.cards.action.ActionCallback;
|
import mage.cards.action.ActionCallback;
|
||||||
import mage.cards.decks.importer.DckDeckImporter;
|
import mage.cards.decks.importer.DckDeckImporter;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.cards.BigCard;
|
import mage.client.cards.BigCard;
|
||||||
import mage.client.components.HoverButton;
|
import mage.client.components.HoverButton;
|
||||||
|
|
@ -50,7 +51,6 @@ import mage.client.util.ImageHelper;
|
||||||
import mage.client.util.gui.BufferedImageBuilder;
|
import mage.client.util.gui.BufferedImageBuilder;
|
||||||
import mage.components.ImagePanel;
|
import mage.components.ImagePanel;
|
||||||
import mage.remote.Session;
|
import mage.remote.Session;
|
||||||
import mage.sets.Sets;
|
|
||||||
import mage.view.CardView;
|
import mage.view.CardView;
|
||||||
import mage.view.ManaPoolView;
|
import mage.view.ManaPoolView;
|
||||||
import mage.view.PlayerView;
|
import mage.view.PlayerView;
|
||||||
|
|
@ -202,7 +202,7 @@ public class PlayerPanelExt extends javax.swing.JPanel {
|
||||||
// Avatar
|
// Avatar
|
||||||
Image image = ImageHelper.getImageFromResources("/avatars/unknown.jpg");
|
Image image = ImageHelper.getImageFromResources("/avatars/unknown.jpg");
|
||||||
|
|
||||||
topCardPanel = Plugins.getInstance().getMageCard(new CardView(Sets.findCard("Forest")), bigCard, topCardDimension, gameId, true);
|
topCardPanel = Plugins.getInstance().getMageCard(new CardView(CardRepository.instance.findCard("Forest").getCard()), bigCard, topCardDimension, gameId, true);
|
||||||
topCardPanel.setVisible(false);
|
topCardPanel.setVisible(false);
|
||||||
panelBackground.add(topCardPanel);
|
panelBackground.add(topCardPanel);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,9 @@
|
||||||
package mage.client.util;
|
package mage.client.util;
|
||||||
|
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.ExpansionSet;
|
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.sets.Sets;
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.view.DeckView;
|
import mage.view.DeckView;
|
||||||
import mage.view.SimpleCardView;
|
import mage.view.SimpleCardView;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
@ -51,27 +51,23 @@ public class DeckUtil {
|
||||||
public static Deck construct(DeckView view) {
|
public static Deck construct(DeckView view) {
|
||||||
Deck deck = new Deck();
|
Deck deck = new Deck();
|
||||||
for (SimpleCardView cardView : view.getCards().values()) {
|
for (SimpleCardView cardView : view.getCards().values()) {
|
||||||
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
|
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
|
||||||
if (set != null) {
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
Card card = set.findCard(cardView.getCardNumber());
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
deck.getCards().add(card);
|
deck.getCards().add(card);
|
||||||
} else {
|
} else {
|
||||||
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
|
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
for (SimpleCardView cardView : view.getSideboard().values()) {
|
for (SimpleCardView cardView : view.getSideboard().values()) {
|
||||||
ExpansionSet set = Sets.findSet(cardView.getExpansionSetCode());
|
CardInfo cardInfo = CardRepository.instance.findCard(cardView.getExpansionSetCode(), cardView.getCardNumber());
|
||||||
if (set != null) {
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
Card card = set.findCard(cardView.getCardNumber());
|
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
deck.getSideboard().add(card);
|
deck.getSideboard().add(card);
|
||||||
} else {
|
} else {
|
||||||
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
|
log.fatal("(Deck constructing) Couldn't find card: set=" + cardView.getExpansionSetCode() + ", cid=" + Integer.valueOf(cardView.getCardNumber()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,8 @@ import mage.abilities.mana.ManaOptions;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.choices.Choice;
|
import mage.choices.Choice;
|
||||||
import mage.filter.FilterPermanent;
|
import mage.filter.FilterPermanent;
|
||||||
import mage.filter.common.*;
|
import mage.filter.common.*;
|
||||||
|
|
@ -72,7 +74,6 @@ import mage.players.Player;
|
||||||
import mage.players.PlayerImpl;
|
import mage.players.PlayerImpl;
|
||||||
import mage.players.net.UserData;
|
import mage.players.net.UserData;
|
||||||
import mage.players.net.UserGroup;
|
import mage.players.net.UserGroup;
|
||||||
import mage.sets.Sets;
|
|
||||||
import mage.target.*;
|
import mage.target.*;
|
||||||
import mage.target.common.*;
|
import mage.target.common.*;
|
||||||
import mage.util.Copier;
|
import mage.util.Copier;
|
||||||
|
|
@ -1096,6 +1097,19 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
match.submitDeck(playerId, deck);
|
match.submitDeck(playerId, deck);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void addBasicLands(Deck deck, String landName, int number) {
|
||||||
|
Random random = new Random();
|
||||||
|
List<CardInfo> cards = CardRepository.instance.findCards(landName);
|
||||||
|
if (cards.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < number; i++) {
|
||||||
|
Card land = cards.get(random.nextInt(cards.size())).getCard();
|
||||||
|
deck.getCards().add(land);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Deck buildDeck(List<Card> cardPool, final List<Constants.ColoredManaSymbol> colors) {
|
public static Deck buildDeck(List<Card> cardPool, final List<Constants.ColoredManaSymbol> colors) {
|
||||||
Deck deck = new Deck();
|
Deck deck = new Deck();
|
||||||
List<Card> sortedCards = new ArrayList<Card>(cardPool);
|
List<Card> sortedCards = new ArrayList<Card>(cardPool);
|
||||||
|
|
@ -1124,45 +1138,28 @@ public class ComputerPlayer<T extends ComputerPlayer<T>> extends PlayerImpl<T> i
|
||||||
}
|
}
|
||||||
double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
|
double total = mana.getBlack() + mana.getBlue() + mana.getGreen() + mana.getRed() + mana.getWhite();
|
||||||
if (mana.getGreen() > 0) {
|
if (mana.getGreen() > 0) {
|
||||||
int numGreen = (int) Math.round(mana.getGreen() / total * 17);
|
int number = (int) Math.round(mana.getGreen() / total * 17);
|
||||||
for (int i = 0; i < numGreen; i++) {
|
addBasicLands(deck, "Forest", number);
|
||||||
Card land = Sets.findCard("Forest", true);
|
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mana.getBlack() > 0) {
|
if (mana.getBlack() > 0) {
|
||||||
int numBlack = (int) Math.round(mana.getBlack() / total * 17);
|
int number = (int) Math.round(mana.getBlack() / total * 17);
|
||||||
for (int i = 0; i < numBlack; i++) {
|
addBasicLands(deck, "Swamp", number);
|
||||||
Card land = Sets.findCard("Swamp", true);
|
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mana.getBlue() > 0) {
|
if (mana.getBlue() > 0) {
|
||||||
int numBlue = (int) Math.round(mana.getBlue() / total * 17);
|
int number = (int) Math.round(mana.getBlue() / total * 17);
|
||||||
for (int i = 0; i < numBlue; i++) {
|
addBasicLands(deck, "Island", number);
|
||||||
Card land = Sets.findCard("Island", true);
|
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mana.getWhite() > 0) {
|
if (mana.getWhite() > 0) {
|
||||||
int numWhite = (int) Math.round(mana.getWhite() / total * 17);
|
int number = (int) Math.round(mana.getWhite() / total * 17);
|
||||||
for (int i = 0; i < numWhite; i++) {
|
addBasicLands(deck, "Plains", number);
|
||||||
Card land = Sets.findCard("Plains", true);
|
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (mana.getRed() > 0) {
|
if (mana.getRed() > 0) {
|
||||||
int numRed = (int) Math.round(mana.getRed() / total * 17);
|
int number = (int) Math.round(mana.getRed() / total * 17);
|
||||||
for (int i = 0; i < numRed; i++) {
|
addBasicLands(deck, "Mountain", number);
|
||||||
Card land = Sets.findCard("Mountain", true);
|
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
while (deck.getCards().size() < 40) {
|
|
||||||
//TODO: improve this
|
//TODO: improve this
|
||||||
Card land = Sets.findCard("Forest", true);
|
addBasicLands(deck, "Forest", 40 - deck.getCards().size());
|
||||||
deck.getCards().add(land);
|
|
||||||
}
|
|
||||||
|
|
||||||
return deck;
|
return deck;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ import mage.cards.Card;
|
||||||
import mage.cards.Cards;
|
import mage.cards.Cards;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
import mage.game.events.Listener;
|
import mage.game.events.Listener;
|
||||||
|
|
@ -46,7 +48,6 @@ import mage.server.*;
|
||||||
import mage.server.util.Splitter;
|
import mage.server.util.Splitter;
|
||||||
import mage.server.util.SystemUtil;
|
import mage.server.util.SystemUtil;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.sets.Sets;
|
|
||||||
import mage.view.AbilityPickerView;
|
import mage.view.AbilityPickerView;
|
||||||
import mage.view.CardsView;
|
import mage.view.CardsView;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
import mage.view.ChatMessage.MessageColor;
|
||||||
|
|
@ -273,7 +274,8 @@ public class GameController implements GameCallback {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean cheat(UUID userId, UUID playerId, String cardName) {
|
public boolean cheat(UUID userId, UUID playerId, String cardName) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
Set<Card> cards = new HashSet<Card>();
|
Set<Card> cards = new HashSet<Card>();
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,15 @@ package mage.server.util;
|
||||||
|
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.sets.Sets;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
|
@ -48,15 +51,25 @@ public class SystemUtil {
|
||||||
try {
|
try {
|
||||||
while (scanner.hasNextLine()) {
|
while (scanner.hasNextLine()) {
|
||||||
String line = scanner.nextLine().trim();
|
String line = scanner.nextLine().trim();
|
||||||
if (line.trim().length() == 0 || line.startsWith("#")) continue;
|
if (line.trim().length() == 0 || line.startsWith("#")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Matcher m = pattern.matcher(line);
|
Matcher m = pattern.matcher(line);
|
||||||
if (m.matches()) {
|
if (!m.matches()) {
|
||||||
|
logger.warn("Init string wasn't parsed: " + line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
String zone = m.group(1);
|
String zone = m.group(1);
|
||||||
String nickname = m.group(2);
|
String nickname = m.group(2);
|
||||||
|
|
||||||
Player player = findPlayer(game, nickname);
|
Player player = findPlayer(game, nickname);
|
||||||
if (player != null) {
|
if (player == null) {
|
||||||
|
logger.warn("Was skipped: " + line);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
Constants.Zone gameZone;
|
Constants.Zone gameZone;
|
||||||
if ("hand".equalsIgnoreCase(zone)) {
|
if ("hand".equalsIgnoreCase(zone)) {
|
||||||
gameZone = Constants.Zone.HAND;
|
gameZone = Constants.Zone.HAND;
|
||||||
|
|
@ -72,22 +85,25 @@ public class SystemUtil {
|
||||||
|
|
||||||
String cardName = m.group(3);
|
String cardName = m.group(3);
|
||||||
Integer amount = Integer.parseInt(m.group(4));
|
Integer amount = Integer.parseInt(m.group(4));
|
||||||
|
|
||||||
|
List<CardInfo> cards = CardRepository.instance.findCards(cardName);
|
||||||
|
if (cards.isEmpty()) {
|
||||||
|
logger.warn("Couldn't find a card: " + cardName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Random random = new Random();
|
||||||
|
Set<Card> cardsToLoad = new HashSet<Card>();
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = cards.get(random.nextInt(cards.size()));
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
Set<Card> cards = new HashSet<Card>();
|
cardsToLoad.add(card);
|
||||||
cards.add(card);
|
}
|
||||||
game.loadCards(cards, player.getId());
|
}
|
||||||
|
game.loadCards(cardsToLoad, player.getId());
|
||||||
|
for (Card card : cardsToLoad) {
|
||||||
swapWithAnyCard(game, player, card, gameZone);
|
swapWithAnyCard(game, player, card, gameZone);
|
||||||
} else {
|
|
||||||
logger.fatal("Couldn't find a card: " + cardName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.warn("Was skipped: " + line);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
logger.warn("Init string wasn't parsed: " + line);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -126,9 +142,10 @@ public class SystemUtil {
|
||||||
*/
|
*/
|
||||||
private static Player findPlayer(Game game, String name) {
|
private static Player findPlayer(Game game, String name) {
|
||||||
for (Player player: game.getPlayers().values()) {
|
for (Player player: game.getPlayers().values()) {
|
||||||
if (player.getName().equals(name))
|
if (player.getName().equals(name)) {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,10 @@ package org.mage.test.load;
|
||||||
|
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.ExpansionSet;
|
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.game.match.MatchOptions;
|
import mage.game.match.MatchOptions;
|
||||||
import mage.player.ai.ComputerPlayer;
|
import mage.player.ai.ComputerPlayer;
|
||||||
import mage.remote.Connection;
|
import mage.remote.Connection;
|
||||||
|
|
@ -247,9 +248,10 @@ public class LoadTest {
|
||||||
DeckCardLists deckList = new DeckCardLists();
|
DeckCardLists deckList = new DeckCardLists();
|
||||||
Deck deck = generateRandomDeck();
|
Deck deck = generateRandomDeck();
|
||||||
for (Card card : deck.getCards()) {
|
for (Card card : deck.getCards()) {
|
||||||
ExpansionSet set = Sets.findSet(card.getExpansionSetCode());
|
CardInfo cardInfo = CardRepository.instance.findCard(card.getExpansionSetCode(), card.getCardNumber());
|
||||||
String cardName = set.findCardName(card.getCardNumber());
|
if (cardInfo != null) {
|
||||||
deckList.getCards().add(cardName);
|
deckList.getCards().add(cardInfo.getClassName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return deckList;
|
return deckList;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package org.mage.test.serverside.base;
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.Constants.PhaseStep;
|
import mage.Constants.PhaseStep;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.match.MatchType;
|
import mage.game.match.MatchType;
|
||||||
import mage.game.permanent.PermanentCard;
|
import mage.game.permanent.PermanentCard;
|
||||||
|
|
@ -15,7 +17,6 @@ import mage.server.util.ConfigSettings;
|
||||||
import mage.server.util.PluginClassLoader;
|
import mage.server.util.PluginClassLoader;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.server.util.config.Plugin;
|
import mage.server.util.config.Plugin;
|
||||||
import mage.sets.Sets;
|
|
||||||
import mage.util.Copier;
|
import mage.util.Copier;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
@ -253,7 +254,8 @@ public abstract class MageTestBase {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||||
PermanentCard p = new PermanentCard(card, null);
|
PermanentCard p = new PermanentCard(card, null);
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,8 @@ package org.mage.test.serverside.base;
|
||||||
import mage.Constants;
|
import mage.Constants;
|
||||||
import mage.Constants.PhaseStep;
|
import mage.Constants.PhaseStep;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.game.Game;
|
import mage.game.Game;
|
||||||
import mage.game.match.MatchType;
|
import mage.game.match.MatchType;
|
||||||
import mage.game.permanent.PermanentCard;
|
import mage.game.permanent.PermanentCard;
|
||||||
|
|
@ -13,7 +15,6 @@ import mage.server.util.ConfigSettings;
|
||||||
import mage.server.util.PluginClassLoader;
|
import mage.server.util.PluginClassLoader;
|
||||||
import mage.server.util.config.GamePlugin;
|
import mage.server.util.config.GamePlugin;
|
||||||
import mage.server.util.config.Plugin;
|
import mage.server.util.config.Plugin;
|
||||||
import mage.sets.Sets;
|
|
||||||
import mage.util.Copier;
|
import mage.util.Copier;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
@ -230,7 +231,8 @@ public abstract class MageTestPlayerBase {
|
||||||
getCommands(getPlayer(nickname)).put(gameZone, "clear");
|
getCommands(getPlayer(nickname)).put(gameZone, "clear");
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < amount; i++) {
|
for (int i = 0; i < amount; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card != null) {
|
if (card != null) {
|
||||||
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||||
PermanentCard p = new PermanentCard(card, null);
|
PermanentCard p = new PermanentCard(card, null);
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,12 @@ import mage.Constants;
|
||||||
import mage.Constants.PhaseStep;
|
import mage.Constants.PhaseStep;
|
||||||
import mage.abilities.Ability;
|
import mage.abilities.Ability;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.permanent.PermanentCard;
|
import mage.game.permanent.PermanentCard;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.sets.Sets;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.mage.test.player.TestPlayer;
|
import org.mage.test.player.TestPlayer;
|
||||||
import org.mage.test.serverside.base.CardTestAPI;
|
import org.mage.test.serverside.base.CardTestAPI;
|
||||||
|
|
@ -118,7 +119,8 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
||||||
|
|
||||||
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
|
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
|
||||||
}
|
}
|
||||||
|
|
@ -136,7 +138,8 @@ public abstract class CardTestAPIImpl extends MageTestBase implements CardTestAP
|
||||||
}
|
}
|
||||||
List<Card> cards = getCardList(gameZone, player);
|
List<Card> cards = getCardList(gameZone, player);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
cards.add(card);
|
cards.add(card);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ import mage.abilities.Ability;
|
||||||
import mage.cards.Card;
|
import mage.cards.Card;
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.cards.decks.importer.DeckImporterUtil;
|
import mage.cards.decks.importer.DeckImporterUtil;
|
||||||
|
import mage.cards.repository.CardInfo;
|
||||||
|
import mage.cards.repository.CardRepository;
|
||||||
import mage.counters.CounterType;
|
import mage.counters.CounterType;
|
||||||
import mage.filter.Filter;
|
import mage.filter.Filter;
|
||||||
import mage.game.ExileZone;
|
import mage.game.ExileZone;
|
||||||
|
|
@ -16,7 +18,6 @@ import mage.game.command.CommandObject;
|
||||||
import mage.game.permanent.Permanent;
|
import mage.game.permanent.Permanent;
|
||||||
import mage.game.permanent.PermanentCard;
|
import mage.game.permanent.PermanentCard;
|
||||||
import mage.players.Player;
|
import mage.players.Player;
|
||||||
import mage.sets.Sets;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.mage.test.player.TestPlayer;
|
import org.mage.test.player.TestPlayer;
|
||||||
import org.mage.test.serverside.base.CardTestAPI;
|
import org.mage.test.serverside.base.CardTestAPI;
|
||||||
|
|
@ -150,7 +151,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
|
|
||||||
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
if (gameZone.equals(Constants.Zone.BATTLEFIELD)) {
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
|
throw new IllegalArgumentException("[TEST] Couldn't find a card: " + cardName);
|
||||||
}
|
}
|
||||||
|
|
@ -164,7 +166,8 @@ public abstract class CardTestPlayerAPIImpl extends MageTestPlayerBase implement
|
||||||
}
|
}
|
||||||
List<Card> cards = getCardList(gameZone, player);
|
List<Card> cards = getCardList(gameZone, player);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
Card card = Sets.findCard(cardName, true);
|
CardInfo cardInfo = CardRepository.instance.findCard(cardName);
|
||||||
|
Card card = cardInfo != null ? cardInfo.getCard() : null;
|
||||||
if (card == null) {
|
if (card == null) {
|
||||||
throw new AssertionError("Couldn't find a card: " + cardName);
|
throw new AssertionError("Couldn't find a card: " + cardName);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue