Search in sources :

Example 61 with Cards

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;
}
Also used : Player(mage.players.Player) Cards(mage.cards.Cards)

Example 62 with Cards

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;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterEnchantmentCard(mage.filter.common.FilterEnchantmentCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 63 with Cards

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);
}
Also used : Player(mage.players.Player) CardsPutIntoGraveyardWatcher(mage.watchers.common.CardsPutIntoGraveyardWatcher) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 64 with Cards

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;
}
Also used : StaticFilters(mage.filter.StaticFilters) Zone(mage.constants.Zone) Cards(mage.cards.Cards) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) TargetPlayer(mage.target.TargetPlayer) UUID(java.util.UUID) CardsImpl(mage.cards.CardsImpl) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Ability(mage.abilities.Ability) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 65 with Cards

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;
}
Also used : Player(mage.players.Player) TreasureToken(mage.game.permanent.token.TreasureToken) DamagePlayersEffect(mage.abilities.effects.common.DamagePlayersEffect) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Aggregations

Cards (mage.cards.Cards)354 Player (mage.players.Player)342 CardsImpl (mage.cards.CardsImpl)328 Card (mage.cards.Card)157 UUID (java.util.UUID)104 FilterCard (mage.filter.FilterCard)86 TargetCard (mage.target.TargetCard)84 MageObject (mage.MageObject)73 Permanent (mage.game.permanent.Permanent)71 TargetPlayer (mage.target.TargetPlayer)35 OneShotEffect (mage.abilities.effects.OneShotEffect)27 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)27 Ability (mage.abilities.Ability)25 Target (mage.target.Target)24 TargetCardInHand (mage.target.common.TargetCardInHand)24 Game (mage.game.Game)23 CardSetInfo (mage.cards.CardSetInfo)22 CardImpl (mage.cards.CardImpl)21 CardType (mage.constants.CardType)21 FilterPermanent (mage.filter.FilterPermanent)19