use of mage.cards.ExpansionSet in project mage by magefree.
the class GathererSets method AnalyseSearchResult.
private void AnalyseSearchResult() {
// analyze supported sets and show wrong settings
Date startedDate = new Date();
for (ExpansionSet set : Sets.getInstance().values()) {
CheckResult res = setsToDownload.get(set.getCode());
// 1. not configured at all
if (res == null) {
logger.warn(String.format("Symbols: set is not configured: %s (%s)", set.getCode(), set.getName()));
// can't do other checks
continue;
}
if (logger.isDebugEnabled()) {
// /*
if (!set.getCardsByRarity(Rarity.COMMON).isEmpty() && !res.haveCommon) {
logger.error(String.format("Symbols: set have common cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
}
if (!set.getCardsByRarity(Rarity.UNCOMMON).isEmpty() && !res.haveUncommon) {
logger.error(String.format("Symbols: set have uncommon cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
}
if (!set.getCardsByRarity(Rarity.RARE).isEmpty() && !res.haveRare) {
logger.error(String.format("Symbols: set have rare cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
}
if (!set.getCardsByRarity(Rarity.MYTHIC).isEmpty() && !res.haveMyth) {
logger.error(String.format("Symbols: set have mythic cards, but don't download icon: %s (%s)", set.getCode(), set.getName()));
}
// 3. info: sets with alternative numbers
for (ExpansionSet.SetCardInfo card : set.getSetCardInfo()) {
if (String.valueOf(card.getCardNumberAsInt()).length() != card.getCardNumber().length()) {
logger.info(String.format("Symbols: set have alternative card but do not config to it: %s (%s)", set.getCode(), set.getName()));
break;
}
}
// 4. info: sets with missing cards for boosters
if (set.getMaxCardNumberInBooster() != Integer.MAX_VALUE) {
for (ExpansionSet.SetCardInfo card : set.getSetCardInfo()) {
if (card.getCardNumberAsInt() > set.getMaxCardNumberInBooster()) {
if (card.getRarity() == Rarity.LAND) {
logger.info(String.format("Symbols: set's booster have land above max card number: %s (%s), %s - %s", set.getCode(), set.getName(), card.getCardNumber(), card.getName()));
} else {
logger.info(String.format("Symbols: set's booster missing nonland card:: %s (%s), %s - %s", set.getCode(), set.getName(), card.getCardNumber(), card.getName()));
}
}
}
}
}
}
Date endedDate = new Date();
long secs = (endedDate.getTime() - startedDate.getTime()) / 1000;
logger.debug(String.format("Symbols: check completed after %d seconds", secs));
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class GathererSets method iterator.
@Override
public Iterator<DownloadJob> iterator() {
Calendar c = Calendar.getInstance();
c.setTime(new Date());
c.add(Calendar.DATE, DAYS_BEFORE_RELEASE_TO_DOWNLOAD);
Date compareDate = c.getTime();
List<DownloadJob> jobs = new ArrayList<>();
boolean canDownload;
setsToDownload.clear();
for (String symbol : symbolsBasic) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "C", "C"));
jobs.add(generateDownloadJob(symbol, "U", "U"));
jobs.add(generateDownloadJob(symbol, "R", "R"));
}
CheckSearchResult(symbol, exp, canDownload, true, true, true, false);
}
for (String symbol : symbolsBasicWithMyth) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "C", "C"));
jobs.add(generateDownloadJob(symbol, "U", "U"));
jobs.add(generateDownloadJob(symbol, "R", "R"));
jobs.add(generateDownloadJob(symbol, "M", "M"));
}
CheckSearchResult(symbol, exp, canDownload, true, true, true, true);
}
for (String symbol : symbolsOnlyMyth) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "M", "M"));
}
CheckSearchResult(symbol, exp, canDownload, false, false, false, true);
}
for (String symbol : symbolsOnlySpecial) {
ExpansionSet exp = Sets.findSet(symbol);
canDownload = false;
if (exp != null && exp.getReleaseDate().before(compareDate)) {
canDownload = true;
jobs.add(generateDownloadJob(symbol, "M", "S"));
}
CheckSearchResult(symbol, exp, canDownload, false, false, false, true);
}
// check wrong settings
AnalyseSearchResult();
return jobs.iterator();
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class BoosterTutorEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ChooseExpansionSetEffect effect = new ChooseExpansionSetEffect(Outcome.UnboostCreature);
effect.apply(game, source);
Player controller = game.getPlayer(source.getControllerId());
String setChosen = null;
if (effect.getValue("setchosen") != null) {
setChosen = (String) effect.getValue("setchosen");
} else if (game.getState().getValue(this.getId() + "_set") != null) {
setChosen = (String) game.getState().getValue(this.getId() + "_set");
}
if (setChosen != null && controller != null) {
// ExpansionInfo set = ExpansionRepository.instance.getSetByName(setChosen);
ExpansionSet expansionSet = Sets.findSet(setChosen);
if (expansionSet != null) {
List<Card> boosterPack = expansionSet.create15CardBooster();
if (boosterPack != null) {
StringBuilder message = new StringBuilder(controller.getLogName()).append(" opened: ");
for (Card card : boosterPack) {
message.append(card.getName()).append(" ");
}
game.informPlayers(message.toString());
TargetCard targetCard = new TargetCard(Zone.ALL, new FilterCard());
Set<Card> cardsToLoad = new HashSet<Card>(boosterPack);
game.loadCards(cardsToLoad, controller.getId());
CardsImpl cards = new CardsImpl();
cards.addAll(boosterPack);
if (controller.choose(Outcome.Benefit, cards, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.HAND, source, game);
}
}
}
}
return true;
}
return false;
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class Main method main.
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
System.setProperty("java.util.Arrays.useLegacyMergeSort", "true");
logger.info("Starting MAGE server version " + version);
logger.info("Logging level: " + logger.getEffectiveLevel());
logger.info("Default charset: " + Charset.defaultCharset());
String adminPassword = "";
for (String arg : args) {
if (arg.startsWith(testModeArg)) {
testMode = Boolean.valueOf(arg.replace(testModeArg, ""));
} else if (arg.startsWith(adminPasswordArg)) {
adminPassword = arg.replace(adminPasswordArg, "");
adminPassword = SystemUtil.sanitize(adminPassword);
} else if (arg.startsWith(fastDBModeArg)) {
fastDbMode = Boolean.valueOf(arg.replace(fastDBModeArg, ""));
}
}
final String configPath = Optional.ofNullable(System.getProperty(configPathProp)).orElse(defaultConfigPath);
logger.info(String.format("Reading configuration from path=%s", configPath));
final ConfigWrapper config = new ConfigWrapper(ConfigFactory.loadFromFile(configPath));
if (config.isAuthenticationActivated()) {
logger.info("Check authorized user DB version ...");
if (!AuthorizedUserRepository.getInstance().checkAlterAndMigrateAuthorizedUser()) {
logger.fatal("Failed to start server.");
return;
}
logger.info("Done.");
}
// db init and updates checks (e.g. cleanup cards db on new version)
RepositoryUtil.bootstrapLocalDb();
logger.info("Done.");
logger.info("Loading extension packages...");
if (!extensionFolder.exists()) {
if (!extensionFolder.mkdirs()) {
logger.error("Could not create extensions directory.");
}
}
File[] extensionDirectories = extensionFolder.listFiles();
List<ExtensionPackage> extensions = new ArrayList<>();
if (extensionDirectories != null) {
for (File f : extensionDirectories) {
if (f.isDirectory()) {
try {
logger.info(" - Loading extension from " + f);
extensions.add(ExtensionPackageLoader.loadExtension(f));
} catch (IOException e) {
logger.error("Could not load extension in " + f + '!', e);
}
}
}
}
logger.info("Done.");
if (!extensions.isEmpty()) {
logger.info("Registering custom sets...");
for (ExtensionPackage pkg : extensions) {
for (ExpansionSet set : pkg.getSets()) {
logger.info("- Loading " + set.getName() + " (" + set.getCode() + ')');
Sets.getInstance().addSet(set);
}
PluginClassloaderRegistery.registerPluginClassloader(pkg.getClassLoader());
}
logger.info("Done.");
}
logger.info("Loading cards...");
if (fastDbMode) {
CardScanner.scanned = true;
} else {
CardScanner.scan();
}
logger.info("Done.");
// cards preload with ratings
if (RateCard.PRELOAD_CARD_RATINGS_ON_STARTUP) {
RateCard.bootstrapCardsAndRatings();
logger.info("Done.");
}
logger.info("Updating user stats DB...");
UserStatsRepository.instance.updateUserStats();
logger.info("Done.");
deleteSavedGames();
int gameTypes = 0;
for (GamePlugin plugin : config.getGameTypes()) {
gameTypes++;
GameFactory.instance.addGameType(plugin.getName(), loadGameType(plugin), loadPlugin(plugin));
}
int tourneyTypes = 0;
for (GamePlugin plugin : config.getTournamentTypes()) {
tourneyTypes++;
TournamentFactory.instance.addTournamentType(plugin.getName(), loadTournamentType(plugin), loadPlugin(plugin));
}
int playerTypes = 0;
for (Plugin plugin : config.getPlayerTypes()) {
playerTypes++;
PlayerFactory.instance.addPlayerType(plugin.getName(), loadPlugin(plugin));
}
int cubeTypes = 0;
for (Plugin plugin : config.getDraftCubes()) {
cubeTypes++;
CubeFactory.instance.addDraftCube(plugin.getName(), loadPlugin(plugin));
}
int deckTypes = 0;
for (Plugin plugin : config.getDeckTypes()) {
deckTypes++;
DeckValidatorFactory.instance.addDeckType(plugin.getName(), loadPlugin(plugin));
}
for (ExtensionPackage pkg : extensions) {
for (Map.Entry<String, Class> entry : pkg.getDraftCubes().entrySet()) {
logger.info("Loading extension: [" + entry.getKey() + "] " + entry.getValue().toString());
cubeTypes++;
CubeFactory.instance.addDraftCube(entry.getKey(), entry.getValue());
}
for (Map.Entry<String, Class> entry : pkg.getDeckTypes().entrySet()) {
logger.info("Loading extension: [" + entry.getKey() + "] " + entry.getValue().toString());
deckTypes++;
DeckValidatorFactory.instance.addDeckType(entry.getKey(), entry.getValue());
}
}
logger.info("Config - max seconds idle: " + config.getMaxSecondsIdle());
logger.info("Config - max game threads: " + config.getMaxGameThreads());
logger.info("Config - max AI opponents: " + config.getMaxAiOpponents());
logger.info("Config - min usr name le.: " + config.getMinUserNameLength());
logger.info("Config - max usr name le.: " + config.getMaxUserNameLength());
logger.info("Config - min pswrd length: " + config.getMinPasswordLength());
logger.info("Config - max pswrd length: " + config.getMaxPasswordLength());
logger.info("Config - inv.usr name pat: " + config.getInvalidUserNamePattern());
logger.info("Config - save game active: " + (config.isSaveGameActivated() ? "true" : "false"));
logger.info("Config - backlog size : " + config.getBacklogSize());
logger.info("Config - lease period : " + config.getLeasePeriod());
logger.info("Config - sock wrt timeout: " + config.getSocketWriteTimeout());
logger.info("Config - max pool size : " + config.getMaxPoolSize());
logger.info("Config - num accp.threads: " + config.getNumAcceptThreads());
logger.info("Config - second.bind port: " + config.getSecondaryBindPort());
logger.info("Config - auth. activated : " + (config.isAuthenticationActivated() ? "true" : "false"));
logger.info("Config - mailgun api key : " + config.getMailgunApiKey());
logger.info("Config - mailgun domain : " + config.getMailgunDomain());
logger.info("Config - mail smtp Host : " + config.getMailSmtpHost());
logger.info("Config - mail smtpPort : " + config.getMailSmtpPort());
logger.info("Config - mail user : " + config.getMailUser());
logger.info("Config - mail passw. len.: " + config.getMailPassword().length());
logger.info("Config - mail from addre.: " + config.getMailFromAddress());
logger.info("Config - google account : " + config.getGoogleAccount());
logger.info("Loaded game types: " + gameTypes + ", tourneys: " + tourneyTypes + ", players: " + playerTypes + ", cubes: " + cubeTypes + ", decks: " + deckTypes);
if (gameTypes == 0) {
logger.error("ERROR, can't load any game types. Check your config.xml in server's config folder (example: old jar versions after update).");
}
Connection connection = new Connection("&maxPoolSize=" + config.getMaxPoolSize());
connection.setHost(config.getServerAddress());
connection.setPort(config.getPort());
final ManagerFactory managerFactory = new MainManagerFactory(config);
try {
// Parameter: serializationtype => jboss
InvokerLocator serverLocator = new InvokerLocator(connection.getURI());
if (!isAlreadyRunning(config, serverLocator)) {
server = new MageTransporterServer(managerFactory, serverLocator, new MageServerImpl(managerFactory, adminPassword, testMode), MageServer.class.getName(), new MageServerInvocationHandler(managerFactory));
server.start();
logger.info("Started MAGE server - listening on " + connection.toString());
if (testMode) {
logger.info("MAGE server running in test mode");
}
initStatistics();
} else {
logger.fatal("Unable to start MAGE server - another server is already started");
}
} catch (Exception ex) {
logger.fatal("Failed to start server - " + connection.toString(), ex);
}
}
use of mage.cards.ExpansionSet in project mage by magefree.
the class SerializationTest method test_Single_AllCards.
// WARNING, debug only, needs few minutes to execute, so run it manually
@Ignore
@Test
public void test_Single_AllCards() {
// checking FULL cards list for serialization errors
String filterSet = "";
String filterCard = "";
List<String> errorsList = new ArrayList<>();
int checkedCount = 0;
for (ExpansionSet set : Sets.getInstance().values()) {
if (!filterSet.isEmpty() && !set.getCode().equals(filterSet)) {
continue;
}
checkedCount++;
System.out.printf("Checking set %d of %d (%s)%n", checkedCount, Sets.getInstance().size(), set.getName());
for (ExpansionSet.SetCardInfo info : set.getSetCardInfo()) {
if (!filterCard.isEmpty() && !info.getName().equals(filterCard)) {
continue;
}
CardInfo cardInfo = CardRepository.instance.findCardsByClass(info.getCardClass().getCanonicalName()).stream().findFirst().orElse(null);
try {
processSingleCard(cardInfo);
} catch (Throwable e) {
System.out.println("Broken card: " + info.getName());
// e.printStackTrace(); // search exception errors in the logs
errorsList.add(info.getName());
}
}
}
if (!errorsList.isEmpty()) {
Assert.fail("Found broken cards: " + errorsList.size() + "\n" + errorsList.stream().sorted().collect(Collectors.joining("\n")));
}
}
Aggregations