Search in sources :

Example 76 with TargetCardInHand

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

the class MaximumHandSizeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetCardInHand target = new TargetCardInHand();
        controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
        Card card = controller.getHand().get(target.getFirstTarget(), game);
        if (card != null) {
            controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetCardInHand(mage.target.common.TargetCardInHand) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

Example 77 with TargetCardInHand

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

the class FlashEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
        return false;
    }
    TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
    if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
        Card card = game.getCard(target.getFirstTarget());
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            ManaCosts<ManaCost> reducedCost = ManaCosts.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2));
            if (controller.chooseUse(Outcome.Benefit, String.valueOf("Pay " + reducedCost.getText()) + Character.toString('?'), source, game)) {
                reducedCost.clearPaid();
                if (reducedCost.pay(source, game, source, source.getControllerId(), false, null)) {
                    return true;
                }
            }
            Permanent permanent = game.getPermanent(card.getId());
            if (permanent != null) {
                permanent.sacrifice(source, game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) ManaCost(mage.abilities.costs.mana.ManaCost) Card(mage.cards.Card)

Example 78 with TargetCardInHand

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

the class InSearchOfGreatnessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int cmc = 0;
    UUID permId = source.getSourceId();
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
        if (permanent != null && !permanent.getId().equals(permId)) {
            int permCmc = permanent.getManaValue();
            if (permCmc > cmc) {
                cmc = permCmc;
            }
        }
    }
    if (controller.chooseUse(outcome, "Cast a permanent spell from your hand with CMC equal to " + ++cmc + "?", source, game)) {
        FilterPermanentCard filter = new FilterPermanentCard("permanent spell from your hand");
        filter.add(Predicates.not(CardType.LAND.getPredicate()));
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc));
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                if (cardWasCast) {
                    return true;
                }
            }
        }
    }
    return controller.scry(1, source, game);
}
Also used : Player(mage.players.Player) FilterPermanentCard(mage.filter.common.FilterPermanentCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) ApprovingObject(mage.ApprovingObject) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) UUID(java.util.UUID) FilterPermanentCard(mage.filter.common.FilterPermanentCard) Card(mage.cards.Card)

Example 79 with TargetCardInHand

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

the class MercadianLiftEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int numberOfCounters = 0;
        for (Cost cost : source.getCosts()) {
            if (cost instanceof RemoveVariableCountersSourceCost) {
                numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
            }
        }
        System.out.println("The number is " + numberOfCounters);
        FilterCreatureCard filter = new FilterCreatureCard();
        filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
        filter.setMessage("creature card with mana value " + numberOfCounters);
        TargetCardInHand target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
            target.setRequired(false);
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) TargetCardInHand(mage.target.common.TargetCardInHand) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) RemoveVariableCountersSourceCost(mage.abilities.costs.common.RemoveVariableCountersSourceCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 80 with TargetCardInHand

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

the class MetalworkerManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Player controller = getPlayer(game, source);
    if (controller == null) {
        return mana;
    }
    int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game);
    if (artifacts > 0) {
        TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_ARTIFACT);
        if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
            Cards cards = new CardsImpl(target.getTargets());
            controller.revealCards(source, cards, game);
            return Mana.ColorlessMana(target.getTargets().size() * 2);
        }
    }
    return mana;
}
Also used : Player(mage.players.Player) Mana(mage.Mana) TargetCardInHand(mage.target.common.TargetCardInHand) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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