use of mage.cards.Cards in project mage by magefree.
the class GameSessionPlayer method prepareGameView.
/**
* Prepare client-server data. Can be used in real games or in unit tests
*
* @param game
* @param playerId
* @param userId can be null for tests
* @return
*/
public static GameView prepareGameView(Game game, UUID playerId, UUID userId) {
Player player = game.getPlayer(playerId);
GameView gameView = new GameView(game.getState(), game, playerId, null);
gameView.setHand(new CardsView(game, player.getHand().getCards(game)));
if (gameView.getPriorityPlayerName().equals(player.getName())) {
gameView.setCanPlayObjects(player.getPlayableObjects(game, Zone.ALL));
}
processControlledPlayers(game, player, gameView);
processWatchedHands(game, userId, gameView);
// TODO: should player who controls another player's turn be able to look at all these cards?
List<LookedAtView> list = new ArrayList<>();
for (Entry<String, Cards> entry : game.getState().getLookedAt(playerId).entrySet()) {
list.add(new LookedAtView(entry.getKey(), entry.getValue(), game));
}
gameView.setLookedAt(list);
return gameView;
}
use of mage.cards.Cards in project mage by magefree.
the class BenefactionOfRhonasEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
boolean creatureCardFound = false;
boolean enchantmentCardFound = false;
for (UUID cardId : cards) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
if (card.isCreature(game)) {
creatureCardFound = true;
}
if (card.isEnchantment(game)) {
enchantmentCardFound = true;
}
}
}
if (!cards.isEmpty()) {
controller.revealCards(sourceObject.getName(), cards, game);
if ((creatureCardFound || enchantmentCardFound) && controller.chooseUse(Outcome.DrawCard, "Put a creature card and/or enchantment card into your hand?", source, game)) {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
if (creatureCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
target = new TargetCard(Zone.LIBRARY, new FilterEnchantmentCard("enchantment card to put into your hand"));
if (enchantmentCardFound && controller.chooseTarget(Outcome.DrawCard, cards, target, source, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
}
}
controller.moveCards(cards, Zone.GRAVEYARD, source, game);
return true;
}
return false;
}
use of mage.cards.Cards in project mage by magefree.
the class CryOfTheCarnariumReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
CardsPutIntoGraveyardWatcher watcher = game.getState().getWatcher(CardsPutIntoGraveyardWatcher.class);
if (controller == null || watcher == null) {
return false;
}
Cards cards = new CardsImpl(watcher.getCardsPutIntoGraveyardFromBattlefield(game));
cards.removeIf(uuid -> !game.getCard(uuid).isCreature(game));
return controller.moveCards(cards, Zone.EXILED, source, game);
}
use of mage.cards.Cards in project mage by magefree.
the class CryptIncursionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Player targetPlayer = game.getPlayer(source.getFirstTarget());
Cards cards = new CardsImpl(targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game));
player.moveCards(cards, Zone.EXILED, source, game);
int count = cards.stream().map(game.getState()::getZone).map(Zone.EXILED::equals).mapToInt(x -> x ? 1 : 0).sum();
player.gainLife(3 * count, game, source);
return true;
}
use of mage.cards.Cards in project mage by magefree.
the class CulminationOfStudiesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()));
player.moveCards(cards, Zone.EXILED, source, game);
cards.removeIf(uuid -> game.getState().getZone(uuid) != Zone.EXILED);
int landCards = cards.count(StaticFilters.FILTER_CARD_LAND, game);
int blueCards = cards.count(filterBlue, game);
int redCards = cards.count(filterRed, game);
if (landCards > 0) {
new TreasureToken().putOntoBattlefield(landCards, game, source, source.getControllerId());
}
if (blueCards > 0) {
player.drawCards(blueCards, source, game);
}
if (redCards > 0) {
new DamagePlayersEffect(redCards, TargetController.OPPONENT).apply(game, source);
}
return true;
}
Aggregations