use of mage.cards.repository.CardInfo in project mage by magefree.
the class CardsViewUtil method convertSimple.
public static CardsView convertSimple(SimpleCardsView view, Map<String, Card> loadedCards) {
CardsView cards = new CardsView();
for (SimpleCardView simple : view.values()) {
String key = simple.getExpansionSetCode() + '_' + simple.getCardNumber();
Card card = loadedCards.get(key);
if (card == null) {
CardInfo cardInfo = CardRepository.instance.findCard(simple.getExpansionSetCode(), simple.getCardNumber());
card = cardInfo != null ? cardInfo.getMockCard() : null;
loadedCards.put(key, card);
}
if (card != null) {
cards.put(simple.getId(), new CardView(card, simple));
}
}
return cards;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class NaturalOrderCardNumberComparator method compare.
@Override
public int compare(Object o1, Object o2) {
CardInfo cardInfo1 = (CardInfo) o1;
CardInfo cardInfo2 = (CardInfo) o2;
return super.compare(cardInfo1.getCardNumber(), cardInfo2.getCardNumber());
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class ChatManagerImpl method performUserCommand.
private boolean performUserCommand(User user, String message, UUID chatId, boolean doError) {
String command = message.substring(1).trim().toUpperCase(Locale.ENGLISH);
if (doError) {
message += new StringBuilder("<br/>Invalid User Command '" + message + "'.").append(COMMANDS_LIST).toString();
message += "<br/>Type <font color=green>\\w " + user.getName() + " profanity 0 (or 1 or 2)</font> to use/not use the profanity filter";
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
if (command.startsWith("H ") || command.startsWith("HISTORY ")) {
message += "<br/>" + managerFactory.userManager().getUserHistory(message.substring(command.startsWith("H ") ? 3 : 9));
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
if (command.equals("ME")) {
message += "<br/>" + managerFactory.userManager().getUserHistory(user.getName());
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
if (command.startsWith("GAME")) {
message += "<br/>";
ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) {
String gameId = session.getInfo();
if (gameId.startsWith("Game ")) {
UUID id = java.util.UUID.fromString(gameId.substring(5));
for (Entry<UUID, GameController> entry : managerFactory.gameManager().getGameController().entrySet()) {
if (entry.getKey().equals(id)) {
GameController controller = entry.getValue();
if (controller != null) {
message += controller.getGameStateDebugMessage();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
}
}
}
}
return true;
}
if (command.startsWith("FIX")) {
message += "<br/>";
ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) {
String gameId = session.getInfo();
if (gameId.startsWith("Game ")) {
UUID id = java.util.UUID.fromString(gameId.substring(5));
for (Entry<UUID, GameController> entry : managerFactory.gameManager().getGameController().entrySet()) {
if (entry.getKey().equals(id)) {
GameController controller = entry.getValue();
if (controller != null) {
message += controller.attemptToFixGame(user);
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
}
}
}
}
return true;
}
if (command.equals("PINGS")) {
message += "<br/>";
ChatSession session = chatSessions.get(chatId);
if (session != null && session.getInfo() != null) {
String gameId = session.getInfo();
if (gameId.startsWith("Game ")) {
UUID id = java.util.UUID.fromString(gameId.substring(5));
for (Entry<UUID, GameController> entry : managerFactory.gameManager().getGameController().entrySet()) {
if (entry.getKey().equals(id)) {
GameController controller = entry.getValue();
if (controller != null) {
message += controller.getPingsInfo();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
}
}
}
}
return true;
}
if (command.startsWith("CARD ")) {
Matcher matchPattern = getCardTextPattern.matcher(message.toLowerCase(Locale.ENGLISH));
if (matchPattern.find()) {
String cardName = matchPattern.group(1);
CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
if (cardInfo != null) {
cardInfo.getRules();
message = "<font color=orange>" + cardInfo.getName() + "</font>: Cost:" + cardInfo.getManaCosts(CardInfo.ManaCostSide.ALL).toString() + ", Types:" + cardInfo.getTypes().toString() + ", ";
for (String rule : cardInfo.getRules()) {
message = message + rule;
}
} else {
message = "Couldn't find: " + cardName;
}
}
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
if (command.startsWith("W ") || command.startsWith("WHISPER ")) {
String rest = message.substring(command.startsWith("W ") ? 3 : 9);
int first = rest.indexOf(' ');
if (first > 1) {
String userToName = rest.substring(0, first);
rest = rest.substring(first + 1).trim();
Optional<User> userTo = managerFactory.userManager().getUserByName(userToName);
if (userTo.isPresent()) {
if (!chatSessions.get(chatId).broadcastWhisperToUser(user, userTo.get(), rest)) {
message += new StringBuilder("<br/>User ").append(userToName).append(" not found").toString();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
} else {
message += new StringBuilder("<br/>User ").append(userToName).append(" not found").toString();
chatSessions.get(chatId).broadcastInfoToUser(user, message);
}
return true;
}
}
if (command.equals("L") || command.equals("LIST")) {
message += COMMANDS_LIST;
message += "<br/>Type <font color=green>\\w " + user.getName() + " profanity 0 (or 1 or 2)</font> to use/not use the profanity filter";
chatSessions.get(chatId).broadcastInfoToUser(user, message);
return true;
}
return false;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class DominariaCollator method findSpecialCardsByRarity.
@Override
protected List<CardInfo> findSpecialCardsByRarity(Rarity rarity) {
List<CardInfo> cardInfos = super.findSpecialCardsByRarity(rarity);
cardInfos.addAll(CardRepository.instance.findCards(new CardCriteria().setCodes(this.code).rarities(rarity).supertypes(SuperType.LEGENDARY).types(CardType.CREATURE).maxCardNumber(maxCardNumberInBooster)));
cardInfos.removeIf(cardInfo -> nonSpecialLegends.contains(cardInfo.getName()));
return cardInfos;
}
use of mage.cards.repository.CardInfo in project mage by magefree.
the class ModernHorizons2Collator method addSpecialCards.
@Override
protected void addSpecialCards(List<Card> booster, int number) {
// number is here always 1
Rarity rarity;
int rarityKey = RandomUtil.nextInt(120);
if (rarityKey < 4) {
rarity = Rarity.MYTHIC;
} else if (rarityKey < 40) {
rarity = Rarity.RARE;
} else {
rarity = Rarity.UNCOMMON;
}
List<CardInfo> reprintCards = getSpecialCardsByRarity(rarity);
addToBooster(booster, reprintCards);
}
Aggregations