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;
}
}
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);
}
}
Aggregations