Search in sources :

Example 1 with TargetCardInHand

use of mage.target.common.TargetCardInHand in project mage by magefree.

the class BoonweaverGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("Aura card");
    filter.add(CardType.ENCHANTMENT.getPredicate());
    filter.add(SubType.AURA.getPredicate());
    Card card = null;
    Zone zone = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for an Aura card?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.GRAVEYARD;
            }
        }
    }
    if (card == null && controller.chooseUse(Outcome.Neutral, "Search your Hand for an Aura card?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.HAND;
            }
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.LIBRARY;
            }
        }
        controller.shuffleLibrary(source, game);
    }
    // aura card found - attach it
    if (card != null) {
        Permanent permanent = game.getPermanent(source.getSourceId());
        if (permanent != null) {
            game.getState().setValue("attachTo:" + card.getId(), permanent);
        }
        controller.moveCards(card, Zone.BATTLEFIELD, source, game);
        if (permanent != null) {
            return permanent.addAttachment(card.getId(), source, game);
        }
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Zone(mage.constants.Zone) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 2 with TargetCardInHand

use of mage.target.common.TargetCardInHand in project mage by magefree.

the class ChecksAndBalancesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (player.getHand().isEmpty()) {
                    game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
                    return true;
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null) {
                if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
                    game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
                    return true;
                } else {
                    game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
                }
            }
        }
        for (UUID uuid : game.getOpponents(spell.getControllerId())) {
            Player player = game.getPlayer(uuid);
            if (player != null && !player.getHand().isEmpty()) {
                TargetCardInHand target = new TargetCardInHand();
                if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
                    Card card = game.getCard(target.getFirstTarget());
                    player.discard(card, false, source, game);
                }
            }
        }
        game.getStack().counter(spell.getId(), source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 3 with TargetCardInHand

use of mage.target.common.TargetCardInHand in project mage by magefree.

the class CounterlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (stackObject != null && controller != null) {
        game.getStack().counter(source.getFirstTarget(), source, game);
        if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
            FilterCard filter = new FilterCard();
            List<Predicate<MageObject>> types = new ArrayList<>();
            for (CardType type : stackObject.getCardType(game)) {
                if (type != CardType.LAND) {
                    types.add(type.getPredicate());
                }
            }
            filter.add(Predicates.or(types));
            TargetCardInHand target = new TargetCardInHand(filter);
            if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
                Card card = controller.getHand().get(target.getFirstTarget(), game);
                if (card != null) {
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                    controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                    game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CardType(mage.constants.CardType) StackObject(mage.game.stack.StackObject) ArrayList(java.util.ArrayList) Predicate(mage.filter.predicate.Predicate) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 4 with TargetCardInHand

use of mage.target.common.TargetCardInHand in project mage by magefree.

the class DiscipleOfDeceitEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (player != null && mageObject != null) {
        Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
        String message = "Discard a nonland card to search your library?";
        if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
            if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
                Card card = game.getCard(cost.getTargets().getFirstTarget());
                if (card == null) {
                    return false;
                }
                String targetName = "card with mana value of " + card.getManaValue();
                FilterCard filter = new FilterCard(targetName);
                filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
                return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterNonlandCard(mage.filter.common.FilterNonlandCard) TargetCardInHand(mage.target.common.TargetCardInHand) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) MageObject(mage.MageObject) SearchLibraryPutInHandEffect(mage.abilities.effects.common.search.SearchLibraryPutInHandEffect) DiscardTargetCost(mage.abilities.costs.common.DiscardTargetCost) Cost(mage.abilities.costs.Cost) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) FilterNonlandCard(mage.filter.common.FilterNonlandCard) Card(mage.cards.Card)

Example 5 with TargetCardInHand

use of mage.target.common.TargetCardInHand in project mage by magefree.

the class ElevenTheMageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    player.drawCards(1, source, game);
    player.loseLife(1, game, source, false);
    if (player.getHand().size() < 11) {
        return true;
    }
    // TODO: change this to fit with changes made in https://github.com/magefree/mage/pull/8136 when merged
    Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
    if (!target.canChoose(source.getSourceId(), player.getId(), game) || !player.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery spell " + "from your hand without paying its mana cost?", source, game)) {
        return true;
    }
    Card cardToCast = null;
    boolean cancel = false;
    while (player.canRespond() && !cancel) {
        if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
            cardToCast = game.getCard(target.getFirstTarget());
            if (cardToCast != null) {
                if (cardToCast.getSpellAbility() == null) {
                    Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
                    cancel = true;
                }
                if (cardToCast.getSpellAbility().canChooseTarget(game, player.getId())) {
                    cancel = true;
                }
            }
        } else {
            cancel = true;
        }
    }
    if (cardToCast != null) {
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
        player.cast(player.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
        game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) CastWithoutPayingManaCostEffect(mage.abilities.effects.common.cost.CastWithoutPayingManaCostEffect) Card(mage.cards.Card)

Aggregations

TargetCardInHand (mage.target.common.TargetCardInHand)148 Player (mage.players.Player)133 Card (mage.cards.Card)96 FilterCard (mage.filter.FilterCard)61 Permanent (mage.game.permanent.Permanent)45 CardsImpl (mage.cards.CardsImpl)41 UUID (java.util.UUID)39 Cards (mage.cards.Cards)24 Target (mage.target.Target)21 TargetCard (mage.target.TargetCard)21 MageObject (mage.MageObject)17 FixedTarget (mage.target.targetpointer.FixedTarget)14 ApprovingObject (mage.ApprovingObject)13 FilterCreatureCard (mage.filter.common.FilterCreatureCard)12 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)10 RevealTargetFromHandCost (mage.abilities.costs.common.RevealTargetFromHandCost)10 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)10 ContinuousEffect (mage.abilities.effects.ContinuousEffect)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)9 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)9