use of mage.cards.repository.ExpansionInfo in project mage by magefree.
the class NewTournamentDialog method getTournamentOptions.
private TournamentOptions getTournamentOptions() {
TournamentTypeView tournamentType = (TournamentTypeView) cbTournamentType.getSelectedItem();
int numSeats = (Integer) this.spnNumSeats.getValue();
TournamentOptions tOptions = new TournamentOptions(this.txtName.getText(), "", numSeats);
tOptions.setTournamentType(tournamentType.getName());
tOptions.setPassword(txtPassword.getText());
tOptions.getPlayerTypes().add(PlayerType.HUMAN);
tOptions.setWatchingAllowed(cbAllowSpectators.isSelected());
tOptions.setPlaneChase(cbPlaneChase.isSelected());
tOptions.setQuitRatio((Integer) spnQuitRatio.getValue());
tOptions.setMinimumRating((Integer) spnMinimumRating.getValue());
for (TournamentPlayerPanel player : players) {
tOptions.getPlayerTypes().add((PlayerType) player.getPlayerType().getSelectedItem());
}
if (!tournamentType.isElimination()) {
tOptions.setNumberRounds((Integer) spnNumRounds.getValue());
}
if (tournamentType.isDraft()) {
DraftOptions options = new DraftOptions();
options.setTiming((TimingOption) this.cbDraftTiming.getSelectedItem());
tOptions.setLimitedOptions(options);
}
if (tOptions.getLimitedOptions() == null) {
tOptions.setLimitedOptions(new LimitedOptions());
}
if (tournamentType.isLimited()) {
tOptions.getLimitedOptions().setConstructionTime((Integer) this.spnConstructTime.getValue() * 60);
tOptions.getLimitedOptions().setIsRandom(tournamentType.isRandom());
tOptions.getLimitedOptions().setIsRichMan(tournamentType.isRichMan());
tOptions.getLimitedOptions().setIsJumpstart(tournamentType.isJumpstart());
if (tournamentType.isJumpstart()) {
if (!(jumpstartPacksFilename.isEmpty())) {
String jumpstartPacksData = "";
try {
jumpstartPacksData = new String(Files.readAllBytes(Paths.get(jumpstartPacksFilename)));
if (jumpstartPacksData.length() > 300000) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), "Chosen file too big", "Jumpstart Packs data is too long. Please trim or choose another file.", JOptionPane.ERROR_MESSAGE);
jumpstartPacksData = "";
}
} catch (IOException e2) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e2.getMessage(), "Error loading Jumpstart Packs data", JOptionPane.ERROR_MESSAGE);
}
tOptions.getLimitedOptions().setJumpstartPacks(jumpstartPacksData);
}
}
if (tournamentType.isCubeBooster()) {
tOptions.getLimitedOptions().setDraftCubeName(this.cbDraftCube.getSelectedItem().toString());
if (!(cubeFromDeckFilename.isEmpty())) {
Deck cubeFromDeck = new Deck();
try {
cubeFromDeck = Deck.load(DeckImporter.importDeckFromFile(cubeFromDeckFilename, true), true, true);
} catch (GameException e1) {
JOptionPane.showMessageDialog(MageFrame.getDesktop(), e1.getMessage(), "Error loading deck", JOptionPane.ERROR_MESSAGE);
}
if (cubeFromDeck != null) {
cubeFromDeck.clearLayouts();
tOptions.getLimitedOptions().setCubeFromDeck(cubeFromDeck);
}
}
} else if (tournamentType.isRandom() || tournamentType.isRichMan()) {
this.isRandom = tournamentType.isRandom();
this.isRichMan = tournamentType.isRichMan();
tOptions.getLimitedOptions().getSetCodes().clear();
java.util.List<String> selected = randomPackSelector.getSelectedPacks();
Collections.shuffle(selected);
int maxPacks = 3 * (players.size() + 1);
if (tournamentType.isRichMan()) {
maxPacks = 36;
}
if (selected.size() > maxPacks) {
StringBuilder infoString = new StringBuilder("More sets were selected than needed. ");
infoString.append(maxPacks);
infoString.append(" sets will be randomly chosen.");
JOptionPane.showMessageDialog(MageFrame.getDesktop(), infoString, "Information", JOptionPane.INFORMATION_MESSAGE);
tOptions.getLimitedOptions().getSetCodes().addAll(selected.subList(0, maxPacks));
} else {
tOptions.getLimitedOptions().getSetCodes().addAll(selected);
}
} else {
for (JPanel panel : packPanels) {
JComboBox combo = findComboInComponent(panel);
if (combo != null) {
tOptions.getLimitedOptions().getSetCodes().add(((ExpansionInfo) combo.getSelectedItem()).getCode());
} else {
logger.error("Can't find combo component in " + panel.toString());
}
}
}
tOptions.getMatchOptions().setDeckType("Limited");
tOptions.getMatchOptions().setGameType("Two Player Duel");
tOptions.getMatchOptions().setLimited(true);
} else {
tOptions.getLimitedOptions().setConstructionTime(0);
tOptions.getLimitedOptions().setNumberBoosters(0);
tOptions.getLimitedOptions().setDraftCube(null);
tOptions.getLimitedOptions().setDraftCubeName("");
tOptions.getMatchOptions().setDeckType((String) this.cbDeckType.getSelectedItem());
tOptions.getMatchOptions().setGameType(((GameTypeView) this.cbGameType.getSelectedItem()).getName());
tOptions.getMatchOptions().setLimited(false);
}
String serverAddress = SessionHandler.getSession().getServerHostname().orElse("");
tOptions.getMatchOptions().setBannedUsers(IgnoreList.getIgnoredUsers(serverAddress));
tOptions.getMatchOptions().setMatchTimeLimit((MatchTimeLimit) this.cbTimeLimit.getSelectedItem());
tOptions.getMatchOptions().setSkillLevel((SkillLevel) this.cbSkillLevel.getSelectedItem());
tOptions.getMatchOptions().setWinsNeeded((Integer) this.spnNumWins.getValue());
tOptions.getMatchOptions().setFreeMulligans((Integer) this.spnFreeMulligans.getValue());
tOptions.getMatchOptions().setMullgianType((MulliganType) this.cbMulligan.getSelectedItem());
tOptions.getMatchOptions().setAttackOption(MultiplayerAttackOption.LEFT);
tOptions.getMatchOptions().setRange(RangeOfInfluence.ALL);
tOptions.getMatchOptions().setRollbackTurnsAllowed(this.chkRollbackTurnsAllowed.isSelected());
tOptions.getMatchOptions().setRated(this.chkRated.isSelected());
return tOptions;
}
use of mage.cards.repository.ExpansionInfo in project mage by magefree.
the class ConstructedFormats method buildLists.
public static void buildLists() {
underlyingSetCodesPerFormat.put(STANDARD, new ArrayList<>());
underlyingSetCodesPerFormat.put(EXTENDED, new ArrayList<>());
underlyingSetCodesPerFormat.put(FRONTIER, new ArrayList<>());
underlyingSetCodesPerFormat.put(PIONEER, new ArrayList<>());
underlyingSetCodesPerFormat.put(MODERN, new ArrayList<>());
underlyingSetCodesPerFormat.put(VINTAGE_LEGACY, new ArrayList<>());
underlyingSetCodesPerFormat.put(HISTORIC, new ArrayList<>());
underlyingSetCodesPerFormat.put(JOKE, new ArrayList<>());
underlyingSetCodesPerFormat.put(CUSTOM, new ArrayList<>());
final Map<String, ExpansionInfo> expansionInfo = new HashMap<>();
// prevent NPE on sorting if this is not the first try
formats.clear();
// we have to return here to prevent exception in design view. (Does not hurt at design time)
if (!ExpansionRepository.instance.instanceInitialized) {
return;
}
// build formats list for deck validators
for (ExpansionInfo set : ExpansionRepository.instance.getAll()) {
expansionInfo.put(set.getName(), set);
formats.add(set.getName());
// full list
underlyingSetCodesPerFormat.put(set.getName(), new ArrayList<>());
underlyingSetCodesPerFormat.get(set.getName()).add(set.getCode());
// custom
if (set.getType().isCustomSet()) {
underlyingSetCodesPerFormat.get(CUSTOM).add(set.getCode());
continue;
}
// joke
if (set.getType().isJokeSet()) {
underlyingSetCodesPerFormat.get(JOKE).add(set.getCode());
continue;
}
// vintage/legacy (any set, TODO: even ?custom set?)
underlyingSetCodesPerFormat.get(VINTAGE_LEGACY).add(set.getCode());
// historic
if (set.getType().isHistoricLegal() && set.getReleaseDate().after(historicDate)) {
underlyingSetCodesPerFormat.get(HISTORIC).add(set.getCode());
}
// standard (dependent on current date)
if (STANDARD_CARDS.getSetCodes().contains(set.getCode())) {
underlyingSetCodesPerFormat.get(STANDARD).add(set.getCode());
}
// extended
if (set.getType().isStandardLegal() && set.getReleaseDate().after(extendedDate)) {
underlyingSetCodesPerFormat.get(EXTENDED).add(set.getCode());
}
// frontier
if (set.getType().isStandardLegal() && set.getReleaseDate().after(frontierDate)) {
underlyingSetCodesPerFormat.get(FRONTIER).add(set.getCode());
}
// pioneer
if (set.getType().isStandardLegal() && set.getReleaseDate().after(pioneerDate)) {
underlyingSetCodesPerFormat.get(PIONEER).add(set.getCode());
}
// modern
if (set.getType().isModernLegal() && set.getReleaseDate().after(modernDate)) {
underlyingSetCodesPerFormat.get(MODERN).add(set.getCode());
}
if (set.getType() == SetType.EXPANSION && set.getBlockName() != null) {
String blockDisplayName = getBlockDisplayName(set.getBlockName());
underlyingSetCodesPerFormat.computeIfAbsent(blockDisplayName, k -> new ArrayList<>());
underlyingSetCodesPerFormat.get(blockDisplayName).add(set.getCode());
if (expansionInfo.get(blockDisplayName) == null) {
expansionInfo.put(blockDisplayName, set);
formats.add(blockDisplayName);
}
if (expansionInfo.get(blockDisplayName).getReleaseDate().after(set.getReleaseDate())) {
expansionInfo.put(blockDisplayName, set);
}
}
if (set.getType() == SetType.SUPPLEMENTAL && set.getBlockName() != null) {
expansionInfo.putIfAbsent(set.getBlockName(), set);
if (expansionInfo.get(set.getBlockName()).getReleaseDate().before(set.getReleaseDate())) {
expansionInfo.put(set.getBlockName(), set);
}
}
}
formats.sort((name1, name2) -> {
ExpansionInfo expansionInfo1 = expansionInfo.get(name1);
ExpansionInfo expansionInfo2 = expansionInfo.get(name2);
if (expansionInfo1.getType().compareTo(expansionInfo2.getType()) == 0) {
SetType setType = expansionInfo1.getType();
switch(setType) {
case EXPANSION:
if (expansionInfo1.getBlockName() == null) {
if (expansionInfo2.getBlockName() == null) {
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
}
return 1;
}
if (expansionInfo2.getBlockName() == null) {
return -1;
}
// Block comparison
if (name1.endsWith("Block") && name2.endsWith("Block")) {
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
}
if (name1.endsWith("Block")) {
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
return -1;
}
}
if (name2.endsWith("Block")) {
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
return 1;
}
}
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
case SUPPLEMENTAL:
if (expansionInfo1.getBlockName() == null) {
if (expansionInfo2.getBlockName() == null) {
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
}
return -1;
}
if (expansionInfo2.getBlockName() == null) {
return 1;
}
if (expansionInfo1.getBlockName().equals(expansionInfo2.getBlockName())) {
// If release date is the same, sort alphabetically.
if (expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate()) == 0) {
return name1.compareTo(name2);
}
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
}
if (expansionInfo1.getBlockName().startsWith("Duel Decks")) {
if (expansionInfo1.getBlockName().startsWith("Duel Decks: Anthology")) {
return 1;
}
return 1;
}
if (expansionInfo2.getBlockName().startsWith("Duel Decks")) {
return -1;
}
ExpansionInfo blockInfo1 = expansionInfo.get(expansionInfo1.getBlockName());
ExpansionInfo blockInfo2 = expansionInfo.get(expansionInfo2.getBlockName());
return blockInfo2.getReleaseDate().compareTo(blockInfo1.getReleaseDate());
default:
return expansionInfo2.getReleaseDate().compareTo(expansionInfo1.getReleaseDate());
}
}
return expansionInfo1.getType().compareTo(expansionInfo2.getType());
});
if (!formats.isEmpty()) {
formats.add(0, CUSTOM);
formats.add(0, JOKE);
formats.add(0, HISTORIC);
formats.add(0, VINTAGE_LEGACY);
formats.add(0, MODERN);
formats.add(0, PIONEER);
formats.add(0, FRONTIER);
formats.add(0, EXTENDED);
formats.add(0, STANDARD);
}
formats.add(0, ALL_SETS);
}
use of mage.cards.repository.ExpansionInfo in project mage by magefree.
the class TestGameType method createHandCard.
private CardView createHandCard(Game game, UUID controllerId, String code, String cardNumber) {
CardInfo cardInfo = CardRepository.instance.findCard(code, cardNumber);
ExpansionInfo setInfo = ExpansionRepository.instance.getSetByCode(code);
CardSetInfo testSet = new CardSetInfo(cardInfo.getName(), setInfo.getCode(), cardNumber, cardInfo.getRarity(), new CardGraphicInfo(cardInfo.getFrameStyle(), cardInfo.usesVariousArt()));
Card card = CardImpl.createCard(cardInfo.getClassName(), testSet);
Set<Card> cardsList = new HashSet<>();
cardsList.add(card);
game.loadCards(cardsList, controllerId);
CardView cardView = new CardView(card);
return cardView;
}
Aggregations