Search in sources :

Example 26 with CardType

use of mage.constants.CardType in project mage by magefree.

the class CreepingDreadEffect method apply.

/*
    * When a spell or ability instructs each player to discard a card, 
    starting with the player whose turn it is and proceeding in turn order, 
    each player selects a card from their hand without revealing it,
    sets it aside, and then all of those cards are revealed and discarded at once.
    
    https://gatherer.wizards.com/Pages/Card/Details.aspx?multiverseid=409851
    */
@Override
public boolean apply(Game game, Ability source) {
    // controller discards a card - store info on card type
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<CardType> typesChosen = new HashSet<>();
        Map<Player, Card> cardsChosen = new HashMap<>();
        if (!controller.getHand().isEmpty()) {
            TargetCard controllerTarget = new TargetCard(Zone.HAND, new FilterCard());
            if (controller.choose(Outcome.Discard, controller.getHand(), controllerTarget, game)) {
                Card card = controller.getHand().get(controllerTarget.getFirstTarget(), game);
                if (card != null) {
                    typesChosen = new HashSet<>(card.getCardType(game));
                    cardsChosen.put(controller, card);
                }
            }
        }
        Set<Player> opponentsAffected = new HashSet<>();
        for (UUID playerId : game.getOpponents(source.getControllerId())) {
            Player opponent = game.getPlayer(playerId);
            // opponent discards a card - if it is same card type as controller, add to opponentsAffected
            if (opponent != null && !opponent.getHand().isEmpty()) {
                TargetCard target = new TargetCard(Zone.HAND, new FilterCard());
                if (opponent.choose(Outcome.Discard, opponent.getHand(), target, game)) {
                    Card card = opponent.getHand().get(target.getFirstTarget(), game);
                    if (card != null) {
                        if (!typesChosen.isEmpty()) {
                            for (CardType cType : typesChosen) {
                                for (CardType oType : card.getCardType(game)) {
                                    if (cType == oType) {
                                        opponentsAffected.add(opponent);
                                        break;
                                    }
                                }
                            }
                        }
                        cardsChosen.put(opponent, card);
                    }
                }
            }
        }
        // everyone discards the card at the same time
        if (!cardsChosen.isEmpty()) {
            for (Map.Entry<Player, Card> entry : cardsChosen.entrySet()) {
                Player player = entry.getKey();
                Card cardChosen = entry.getValue();
                if (player != null) {
                    player.discard(cardChosen, false, source, game);
                }
            }
        }
        // each opponent who discarded a card of the same type loses 3 life
        if (!opponentsAffected.isEmpty()) {
            for (Player opponent : opponentsAffected) {
                opponent.loseLife(3, game, source, false);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) CardType(mage.constants.CardType)

Example 27 with CardType

use of mage.constants.CardType in project mage by magefree.

the class PlayerPanelExt method qtyCardTypes.

private int qtyCardTypes(mage.view.CardsView cardsView) {
    Set<String> cardTypesPresent = new LinkedHashSet<String>() {
    };
    for (CardView card : cardsView.values()) {
        Set<CardType> cardTypes = EnumSet.noneOf(CardType.class);
        cardTypes.addAll(card.getCardTypes());
        for (CardType cardType : cardTypes) {
            cardTypesPresent.add(cardType.toString());
        }
    }
    if (cardTypesPresent.isEmpty()) {
        return 0;
    } else {
        return cardTypesPresent.size();
    }
}
Also used : CardType(mage.constants.CardType)

Example 28 with CardType

use of mage.constants.CardType in project mage by magefree.

the class DaringThiefSecondTarget method possibleTargets.

@Override
public Set<UUID> possibleTargets(UUID sourceId, UUID sourceControllerId, Game game) {
    // get all cardtypes from opponents permanents
    Set<CardType> cardTypes = getOpponentPermanentCardTypes(sourceId, sourceControllerId, game);
    Set<UUID> possibleTargets = new HashSet<>();
    MageObject targetSource = game.getObject(sourceId);
    if (targetSource != null) {
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, sourceControllerId, sourceId, game)) {
            if (!targets.containsKey(permanent.getId()) && permanent.canBeTargetedBy(targetSource, sourceControllerId, game)) {
                for (CardType type : permanent.getCardType(game)) {
                    if (cardTypes.contains(type)) {
                        possibleTargets.add(permanent.getId());
                        break;
                    }
                }
            }
        }
    }
    return possibleTargets;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) MageObject(mage.MageObject) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 29 with CardType

use of mage.constants.CardType in project mage by magefree.

the class DaringThiefSecondTarget method getOpponentPermanentCardTypes.

private EnumSet<CardType> getOpponentPermanentCardTypes(UUID sourceId, UUID sourceControllerId, Game game) {
    Player controller = game.getPlayer(sourceControllerId);
    EnumSet<CardType> cardTypes = EnumSet.noneOf(CardType.class);
    if (controller != null) {
        for (Permanent permanent : game.getBattlefield().getActivePermanents(sourceControllerId, game)) {
            if (controller.hasOpponent(permanent.getControllerId(), game)) {
                cardTypes.addAll(permanent.getCardType(game));
            }
        }
    }
    return cardTypes;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType)

Aggregations

CardType (mage.constants.CardType)29 Player (mage.players.Player)16 Permanent (mage.game.permanent.Permanent)11 MageObject (mage.MageObject)9 Card (mage.cards.Card)9 TargetPermanent (mage.target.TargetPermanent)8 Choice (mage.choices.Choice)7 ChoiceImpl (mage.choices.ChoiceImpl)7 UUID (java.util.UUID)4 Cards (mage.cards.Cards)4 SuperType (mage.constants.SuperType)4 FilterCard (mage.filter.FilterCard)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)3 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)3 Ability (mage.abilities.Ability)2 Effect (mage.abilities.effects.Effect)2 Rarity (mage.constants.Rarity)2 SubType (mage.constants.SubType)2