Search in sources :

Example 16 with TargetControlledPermanent

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

the class DesolationWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    DesolationWatcher watcher = game.getState().getWatcher(DesolationWatcher.class);
    if (watcher == null) {
        return false;
    }
    List<Permanent> permanents = new ArrayList<>();
    for (UUID playerId : watcher.getPlayersTappedForMana()) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        TargetPermanent target = new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND);
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), player.getId(), game)) {
            continue;
        }
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            permanents.add(permanent);
        }
    }
    for (Permanent permanent : permanents) {
        Player player = game.getPlayer(permanent.getControllerId());
        if (permanent != null && permanent.sacrifice(source, game) && permanent.hasSubtype(SubType.PLAINS, game) && player != null) {
            player.damage(2, source.getSourceId(), source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 17 with TargetControlledPermanent

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

the class DesecrationDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent descrationDemon = game.getPermanent(source.getSourceId());
    if (controller != null && descrationDemon != null) {
        for (UUID opponentId : game.getOpponents(controller.getId())) {
            Player opponent = game.getPlayer(opponentId);
            if (opponent != null) {
                FilterControlledPermanent filter = new FilterControlledPermanent("creature to sacrifice");
                filter.add(CardType.CREATURE.getPredicate());
                filter.add(TargetController.YOU.getControllerPredicate());
                TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
                if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
                    if (opponent.chooseUse(Outcome.AIDontUseIt, "Sacrifice a creature to tap " + descrationDemon.getLogName() + "and put a +1/+1 counter on it?", source, game)) {
                        opponent.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                        Permanent permanent = game.getPermanent(target.getFirstTarget());
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                            game.informPlayers(opponent.getLogName() + " sacrifices " + permanent.getLogName() + " to tap " + descrationDemon.getLogName() + ". A +1/+1 counter was put on it");
                            descrationDemon.tap(source, game);
                            descrationDemon.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 18 with TargetControlledPermanent

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

the class LichsMasteryLoseLifeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterPermanent filter = new FilterPermanent();
    filter.add(new ControllerIdPredicate(controller.getId()));
    for (int i = 0; i < amount; i++) {
        int handCount = controller.getHand().size();
        int graveCount = controller.getGraveyard().size();
        int permCount = game.getBattlefield().getActivePermanents(filter, controller.getId(), game).size();
        if (graveCount + handCount == 0 || (permCount > 0 && controller.chooseUse(Outcome.Exile, "Exile permanent you control? (No = from hand or graveyard)", source, game))) {
            Target target = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
            controller.choose(outcome, target, source.getSourceId(), game);
            Effect effect = new ExileTargetEffect();
            effect.setTargetPointer(new FixedTarget(target.getFirstTarget(), game));
            effect.apply(game, source);
        } else if (graveCount == 0 || (handCount > 0 && controller.chooseUse(Outcome.Exile, "Exile a card from your hand? (No = from graveyard)", source, game))) {
            Target target = new TargetCardInHand(1, 1, new FilterCard());
            controller.choose(outcome, target, source.getSourceId(), game);
            Card card = controller.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        } else if (graveCount > 0) {
            Target target = new TargetCardInYourGraveyard(1, 1, new FilterCard(), true);
            target.choose(Outcome.Exile, source.getControllerId(), source.getSourceId(), game);
            Card card = controller.getGraveyard().get(target.getFirstTarget(), game);
            if (card != null) {
                controller.moveCards(card, Zone.EXILED, source, game);
            }
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) TargetCardInHand(mage.target.common.TargetCardInHand) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) LoseGameSourceControllerEffect(mage.abilities.effects.common.LoseGameSourceControllerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 19 with TargetControlledPermanent

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

the class TazeemRaptorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    TargetPermanent target = new TargetControlledPermanent(0, 1, StaticFilters.FILTER_CONTROLLED_PERMANENT_LAND, true);
    player.choose(outcome, target, source.getSourceId(), game);
    return player.moveCards(game.getCard(target.getFirstTarget()), Zone.HAND, source, game);
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPermanent(mage.target.TargetPermanent)

Example 20 with TargetControlledPermanent

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

the class DeterminedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent("a creature (to sacrifice)"), true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            if (controller.chooseTarget(outcome, target, source, game)) {
                Permanent toSacrifice = game.getPermanent(target.getFirstTarget());
                if (toSacrifice != null) {
                    toSacrifice.sacrifice(source, game);
                    game.getState().processAction(game);
                    int colors = toSacrifice.getColor(game).getColorCount();
                    if (colors > 0) {
                        TargetCardInYourGraveyard targetCard = new TargetCardInYourGraveyard(0, colors, new FilterCard("up to " + colors + " card" + (colors > 1 ? "s" : "") + " from your graveyard"));
                        controller.chooseTarget(outcome, targetCard, source, game);
                        controller.moveCards(new CardsImpl(targetCard.getTargets()), Zone.HAND, source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) CardsImpl(mage.cards.CardsImpl)

Aggregations

TargetControlledPermanent (mage.target.common.TargetControlledPermanent)100 Player (mage.players.Player)94 Permanent (mage.game.permanent.Permanent)87 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)49 UUID (java.util.UUID)47 Target (mage.target.Target)45 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)23 Card (mage.cards.Card)17 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)16 ArrayList (java.util.ArrayList)13 TargetPermanent (mage.target.TargetPermanent)13 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)10 FilterCard (mage.filter.FilterCard)10 TargetPlayer (mage.target.TargetPlayer)10 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 Cost (mage.abilities.costs.Cost)7 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)7 TargetCardInHand (mage.target.common.TargetCardInHand)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5