Search in sources :

Example 26 with TargetCardInYourGraveyard

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

the class StreamOfThoughtEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetCard target = new TargetCardInYourGraveyard(0, 4);
    target.setNotTarget(true);
    if (!player.choose(outcome, player.getGraveyard(), target, game)) {
        return false;
    }
    Cards cards = new CardsImpl(target.getTargets());
    player.putCardsOnTopOfLibrary(cards, game, source, false);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 27 with TargetCardInYourGraveyard

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

the class TemptWithImmortalityEffect method returnCreatureFromGraveToBattlefield.

private boolean returnCreatureFromGraveToBattlefield(Player player, Ability source, Game game) {
    Target target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE);
    target.setNotTarget(false);
    if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
        if (player.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                return player.moveCards(card, Zone.BATTLEFIELD, source, game);
            }
        }
    }
    return false;
}
Also used : Target(mage.target.Target) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) Card(mage.cards.Card)

Example 28 with TargetCardInYourGraveyard

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

the class ExileFromZoneTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    Target target = null;
    switch(zone) {
        case HAND:
            target = new TargetCardInHand(Math.min(player.getHand().count(filter, game), amount), filter);
            break;
        case GRAVEYARD:
            target = new TargetCardInYourGraveyard(Math.min(player.getGraveyard().count(filter, game), amount), filter);
            break;
        default:
    }
    if (target == null || !target.canChoose(source.getSourceId(), player.getId(), game)) {
        return true;
    }
    target.chooseTarget(Outcome.Exile, player.getId(), source, game);
    Cards cards = new CardsImpl(target.getTargets());
    if (withSource) {
        return player.moveCardsToExile(cards.getCards(game), source, game, true, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source));
    }
    return player.moveCards(cards, Zone.EXILED, source, game);
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 29 with TargetCardInYourGraveyard

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

the class DelveEffect method addSpecialAction.

@Override
public void addSpecialAction(Ability source, Game game, ManaCost unpaid) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !controller.getGraveyard().isEmpty()) {
        if (source.getAbilityType() == AbilityType.SPELL && unpaid.getMana().getGeneric() > 0) {
            SpecialAction specialAction = new DelveSpecialAction(this);
            specialAction.setControllerId(source.getControllerId());
            specialAction.setSourceId(source.getSourceId());
            int unpaidAmount = unpaid.getMana().getGeneric();
            if (!controller.getManaPool().isAutoPayment() && unpaidAmount > 1) {
                unpaidAmount = 1;
            }
            specialAction.addCost(new ExileFromGraveCost(new TargetCardInYourGraveyard(0, Math.min(controller.getGraveyard().size(), unpaidAmount), new FilterCard("cards from your graveyard"), true)));
            if (specialAction.canActivate(source.getControllerId(), game).canActivate()) {
                game.getState().getSpecialActions().add(specialAction);
            }
        }
    }
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) SpecialAction(mage.abilities.SpecialAction) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) ValueHint(mage.abilities.hint.ValueHint)

Example 30 with TargetCardInYourGraveyard

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

the class DeadlyBrewEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<Permanent> toSacrifice = new ArrayList<>();
    Permanent yours = null;
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), playerId, game)) {
            continue;
        }
        player.choose(outcome, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null) {
            continue;
        }
        if (permanent.isControlledBy(source.getControllerId())) {
            yours = permanent;
        } else {
            toSacrifice.add(permanent);
        }
    }
    for (Permanent permanent : toSacrifice) {
        if (permanent == null) {
            continue;
        }
        permanent.sacrifice(source, game);
    }
    Cards yourGrave = new CardsImpl(controller.getGraveyard());
    yourGrave.removeIf(uuid -> !game.getCard(uuid).isPermanent(game));
    if (yours == null || !yours.sacrifice(source, game)) {
        return true;
    }
    TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(0, 1, StaticFilters.FILTER_CARD_PERMANENT, true);
    controller.choose(outcome, yourGrave, target, game);
    Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
    if (card != null) {
        controller.moveCards(card, Zone.HAND, source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) TargetPermanent(mage.target.TargetPermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) UUID(java.util.UUID)

Aggregations

TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)88 Player (mage.players.Player)78 Card (mage.cards.Card)47 FilterCard (mage.filter.FilterCard)38 TargetCard (mage.target.TargetCard)29 CardsImpl (mage.cards.CardsImpl)18 UUID (java.util.UUID)16 Target (mage.target.Target)16 Permanent (mage.game.permanent.Permanent)14 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)11 FilterCreatureCard (mage.filter.common.FilterCreatureCard)10 TargetCardInHand (mage.target.common.TargetCardInHand)10 Cards (mage.cards.Cards)9 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)7 MageObject (mage.MageObject)6 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)5 HashSet (java.util.HashSet)4 ExileFromGraveCost (mage.abilities.costs.common.ExileFromGraveCost)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 FixedTarget (mage.target.targetpointer.FixedTarget)4