Search in sources :

Example 11 with CardType

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

the class RiteOfRuinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<String> choices = new HashSet<>();
    choices.add("Artifacts");
    choices.add("Creatures");
    choices.add("Lands");
    LinkedList<CardType> order = new LinkedList<>();
    ChoiceImpl choice = new ChoiceImpl(true);
    choice.setMessage("Choose a card type");
    choice.setChoices(choices);
    while (choices.size() > 1) {
        if (!controller.choose(Outcome.Sacrifice, choice, game)) {
            return false;
        }
        order.add(getCardType(choice.getChoice()));
        choices.remove(choice.getChoice());
        choice.clearChoice();
    }
    order.add(getCardType(choices.iterator().next()));
    int count = 1;
    for (CardType cardType : order) {
        FilterControlledPermanent filter = new FilterControlledPermanent(cardType + " you control");
        filter.add(cardType.getPredicate());
        new SacrificeAllEffect(count, filter).apply(game, source);
        count++;
    }
    return true;
}
Also used : Player(mage.players.Player) CardType(mage.constants.CardType) SacrificeAllEffect(mage.abilities.effects.common.SacrificeAllEffect) ChoiceImpl(mage.choices.ChoiceImpl) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 12 with CardType

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

the class HolisticWisdomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(source.getFirstTarget());
    if (card != null && game.getState().getZone(card.getId()) == Zone.GRAVEYARD) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof ExileFromHandCost) {
                List<CardType> cardtypes = new ArrayList<>();
                ExileFromHandCost exileCost = (ExileFromHandCost) cost;
                for (CardType cardtype : exileCost.getCards().get(0).getCardType(game)) {
                    cardtypes.add(cardtype);
                }
                for (CardType cardtype : card.getCardType(game)) {
                    if (cardtypes.contains(cardtype)) {
                        Effect effect = new ReturnToHandTargetEffect();
                        effect.setTargetPointer(new FixedTarget(card.getId(), game));
                        return effect.apply(game, source);
                    }
                }
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) CardType(mage.constants.CardType) ArrayList(java.util.ArrayList) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ExileFromHandCost(mage.abilities.costs.common.ExileFromHandCost) Cost(mage.abilities.costs.Cost) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 13 with CardType

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

the class RowdyCrewEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(source.getSourceId());
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        player.drawCards(3, source, game);
        Cards cards = new CardsImpl();
        int cardsInHand = player.getHand().size();
        switch(cardsInHand) {
            case 0:
                break;
            case 1:
                player.discard(1, true, false, source, game);
                break;
            default:
                cards = player.discard(2, true, false, source, game);
        }
        if (creature != null && cardsInHand > 1) {
            for (CardType type : CardType.values()) {
                int count = 0;
                for (UUID cardId : cards) {
                    if (game.getCard(cardId).getCardType(game).contains(type)) {
                        count++;
                        if (count > 1) {
                            creature.addCounters(CounterType.P1P1.createInstance(2), source.getControllerId(), source, game);
                            return true;
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 14 with CardType

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

the class CopyTokenFunction method apply.

@Override
public Token apply(Card source, Game game) {
    if (target == null) {
        throw new IllegalArgumentException("Target can't be null");
    }
    // A copy contains only the attributes of the basic card or basic Token that's the base of the permanent
    // else gained abililies would be copied too.
    MageObject sourceObj = source;
    if (source instanceof PermanentToken) {
        sourceObj = ((PermanentToken) source).getToken();
        // to show the source image, the original values have to be used
        target.setOriginalExpansionSetCode(((Token) sourceObj).getOriginalExpansionSetCode());
        target.setOriginalCardNumber(((Token) sourceObj).getOriginalCardNumber());
        target.setCopySourceCard(((PermanentToken) source).getToken().getCopySourceCard());
    } else if (source instanceof PermanentCard) {
        if (((PermanentCard) source).isMorphed() || ((PermanentCard) source).isManifested()) {
            MorphAbility.setPermanentToFaceDownCreature(target, game);
            return target;
        } else {
            if (((PermanentCard) source).isTransformed() && source.getSecondCardFace() != null) {
                sourceObj = ((PermanentCard) source).getSecondCardFace();
            } else {
                sourceObj = ((PermanentCard) source).getCard();
            }
            target.setOriginalExpansionSetCode(source.getExpansionSetCode());
            target.setOriginalCardNumber(source.getCardNumber());
            target.setCopySourceCard((Card) sourceObj);
        }
    } else {
        target.setOriginalExpansionSetCode(source.getExpansionSetCode());
        target.setOriginalCardNumber(source.getCardNumber());
        target.setCopySourceCard(source);
    }
    // modify all attributes permanently (without game usage)
    target.setName(sourceObj.getName());
    target.getColor().setColor(sourceObj.getColor());
    target.getManaCost().clear();
    target.getManaCost().add(sourceObj.getManaCost().copy());
    target.removeAllCardTypes();
    for (CardType type : sourceObj.getCardType()) {
        target.addCardType(type);
    }
    target.getSubtype().copyFrom(sourceObj.getSubtype());
    target.getSuperType().clear();
    for (SuperType type : sourceObj.getSuperType()) {
        target.addSuperType(type);
    }
    target.getAbilities().clear();
    for (Ability ability0 : sourceObj.getAbilities()) {
        Ability ability = ability0.copy();
        // The token is independant from the copy from object so it need a new original Id,
        // otherwise there are problems to check for created continuous effects to check if
        // the source (the Token) has still this ability
        ability.newOriginalId();
        target.addAbility(ability);
    }
    target.getPower().modifyBaseValue(sourceObj.getPower().getBaseValueModified());
    target.getToughness().modifyBaseValue(sourceObj.getToughness().getBaseValueModified());
    target.setStartingLoyalty(sourceObj.getStartingLoyalty());
    return target;
}
Also used : MorphAbility(mage.abilities.keyword.MorphAbility) Ability(mage.abilities.Ability) CardType(mage.constants.CardType) MageObject(mage.MageObject) PermanentToken(mage.game.permanent.PermanentToken) SuperType(mage.constants.SuperType) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card)

Example 15 with CardType

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

the class RealityScrambleEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent == null || controller == null) {
        return false;
    }
    Set<CardType> types = EnumSet.noneOf(CardType.class);
    types.addAll(permanent.getCardType(game));
    controller.putCardsOnBottomOfLibrary(new CardsImpl(permanent), game, source, false);
    Cards toReveal = new CardsImpl();
    Card cardToPlay = null;
    for (Card card : controller.getLibrary().getCards(game)) {
        toReveal.add(card);
        for (CardType type : types) {
            if (card.getCardType(game).contains(type)) {
                cardToPlay = card;
                break;
            }
        }
        if (cardToPlay != null) {
            break;
        }
    }
    controller.revealCards(source, toReveal, game);
    if (cardToPlay != null) {
        controller.moveCards(cardToPlay, Zone.BATTLEFIELD, source, game);
        toReveal.remove(cardToPlay);
    }
    controller.putCardsOnBottomOfLibrary(toReveal, game, source, false);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CardType(mage.constants.CardType) CardsImpl(mage.cards.CardsImpl) Cards(mage.cards.Cards) Card(mage.cards.Card)

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