Search in sources :

Example 66 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class GameController method cheat.

public boolean cheat(UUID userId, UUID playerId, String cardName) {
    CardInfo cardInfo = CardRepository.instance.findCard(cardName);
    Card card = cardInfo != null ? cardInfo.getCard() : null;
    if (card != null) {
        Set<Card> cards = new HashSet<>();
        cards.add(card);
        game.loadCards(cards, playerId);
        card.moveToZone(Zone.HAND, null, game, false);
        return true;
    } else {
        return false;
    }
}
Also used : CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card)

Example 67 with CardInfo

use of mage.cards.repository.CardInfo in project mage by magefree.

the class ChatManagerImpl method broadcast.

@Override
public void broadcast(UUID chatId, String userName, String message, MessageColor color, boolean withTime, Game game, MessageType messageType, SoundToPlay soundToPlay) {
    ChatSession chatSession = chatSessions.get(chatId);
    if (chatSession != null) {
        if (message.startsWith("\\") || message.startsWith("/")) {
            Optional<User> user = managerFactory.userManager().getUserByName(userName);
            if (user.isPresent()) {
                if (!performUserCommand(user.get(), message, chatId, false)) {
                    performUserCommand(user.get(), message, chatId, true);
                }
                return;
            }
        }
        if (messageType != MessageType.GAME && !userName.isEmpty()) {
            Optional<User> u = managerFactory.userManager().getUserByName(userName);
            if (u.isPresent()) {
                User user = u.get();
                String messageId = chatId.toString() + message;
                if (messageId.equals(userMessages.get(userName))) {
                    // prevent identical messages
                    String informUser = "Your message appears to be identical to your last message";
                    chatSessions.get(chatId).broadcastInfoToUser(user, informUser);
                    return;
                }
                if (message.length() > 500) {
                    message = message.replaceFirst("^(.{500}).*", "$1 (rest of message truncated)");
                }
                String messageToCheck = message;
                Matcher matchPattern = cardNamePattern.matcher(message);
                while (matchPattern.find()) {
                    String cardName = matchPattern.group(1);
                    CardInfo cardInfo = CardRepository.instance.findPreferredCoreExpansionCard(cardName, true);
                    if (cardInfo != null) {
                        String colour = "silver";
                        if (cardInfo.getCard().getColor(null).isMulticolored()) {
                            colour = "yellow";
                        } else if (cardInfo.getCard().getColor(null).isWhite()) {
                            colour = "white";
                        } else if (cardInfo.getCard().getColor(null).isBlue()) {
                            colour = "blue";
                        } else if (cardInfo.getCard().getColor(null).isBlack()) {
                            colour = "black";
                        } else if (cardInfo.getCard().getColor(null).isRed()) {
                            colour = "red";
                        } else if (cardInfo.getCard().getColor(null).isGreen()) {
                            colour = "green";
                        }
                        messageToCheck = messageToCheck.replaceFirst("\\[" + cardName + "\\]", "card");
                        String displayCardName = "<font bgcolor=orange color=" + colour + '>' + cardName + "</font>";
                        message = message.replaceFirst("\\[" + cardName + "\\]", displayCardName);
                    }
                }
                userMessages.put(userName, messageId);
                if (messageType == MessageType.TALK) {
                    if (user.getChatLockedUntil() != null) {
                        if (user.getChatLockedUntil().compareTo(Calendar.getInstance().getTime()) > 0) {
                            chatSessions.get(chatId).broadcastInfoToUser(user, "Your chat is muted until " + SystemUtil.dateFormat.format(user.getChatLockedUntil()));
                            return;
                        } else {
                            user.setChatLockedUntil(null);
                        }
                    }
                }
            }
        }
        chatSession.broadcast(userName, message, color, withTime, game, messageType, soundToPlay);
    }
}
Also used : Matcher(java.util.regex.Matcher) CardInfo(mage.cards.repository.CardInfo)

Aggregations

CardInfo (mage.cards.repository.CardInfo)67 Card (mage.cards.Card)25 CardCriteria (mage.cards.repository.CardCriteria)14 DeckCardInfo (mage.cards.decks.DeckCardInfo)13 PermanentCard (mage.game.permanent.PermanentCard)10 Matcher (java.util.regex.Matcher)8 Test (org.junit.Test)8 CardView (mage.view.CardView)7 ArrayList (java.util.ArrayList)6 BigCard (mage.client.cards.BigCard)6 Player (mage.players.Player)5 java.util (java.util)3 List (java.util.List)3 Ability (mage.abilities.Ability)3 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 InfoEffect (mage.abilities.effects.common.InfoEffect)3 ExpansionInfo (mage.cards.repository.ExpansionInfo)3 Rarity (mage.constants.Rarity)3 PermanentImpl (mage.game.permanent.PermanentImpl)3 SimpleCardView (mage.view.SimpleCardView)3