Search in sources :

Example 6 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent 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 7 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class LichsMirrorEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player player = game.getPlayer(event.getPlayerId());
    if (player != null) {
        Cards toLib = new CardsImpl();
        FilterControlledPermanent filter = new FilterControlledPermanent();
        filter.add(new OwnerIdPredicate(player.getId()));
        toLib.addAll(player.getHand());
        toLib.addAll(player.getGraveyard());
        for (Permanent permanent : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game)) {
            toLib.add(permanent);
        }
        player.shuffleCardsToLibrary(toLib, game, source);
        game.getState().processAction(game);
        // original event is not a draw event, so skip it in params
        player.drawCards(7, source, game);
        player.setLife(20, game, source);
    }
    // replace the loses event
    return true;
}
Also used : Player(mage.players.Player) OwnerIdPredicate(mage.filter.predicate.card.OwnerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 8 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent 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 9 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class TormentOfVenomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
        Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
        if (controllingPlayer != null) {
            int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
            if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
                FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
                filter.add(Predicates.not(CardType.LAND.getPredicate()));
                filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
                Target target = new TargetPermanent(filter);
                if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                        return true;
                    }
                }
            }
            if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
                controllingPlayer.discardOne(false, false, source, game);
                return true;
            }
            controllingPlayer.loseLife(3, game, source, false);
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 10 with FilterControlledPermanent

use of mage.filter.common.FilterControlledPermanent in project mage by magefree.

the class AffinityForLandTypeAbility method getFilter.

private static FilterControlledPermanent getFilter(SubType landType) {
    FilterControlledPermanent affinityfilter = new FilterControlledPermanent();
    affinityfilter.add(landType.getPredicate());
    return affinityfilter;
}
Also used : FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)47 Player (mage.players.Player)41 Permanent (mage.game.permanent.Permanent)34 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)28 UUID (java.util.UUID)17 Target (mage.target.Target)16 FilterPermanent (mage.filter.FilterPermanent)9 TargetPermanent (mage.target.TargetPermanent)9 Card (mage.cards.Card)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 ArrayList (java.util.ArrayList)4 Effect (mage.abilities.effects.Effect)4 Choice (mage.choices.Choice)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 TargetPlayer (mage.target.TargetPlayer)4 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)3 Cards (mage.cards.Cards)3 FilterCard (mage.filter.FilterCard)3