Search in sources :

Example 31 with FilterControlledPermanent

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

the class RoarOfTheCrowdEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
        if (!player.choose(Outcome.LoseLife, typeChoice, game)) {
            return false;
        }
        FilterControlledPermanent filter = new FilterControlledPermanent();
        filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
        return new DamageTargetEffect(new PermanentsOnBattlefieldCount(filter)).apply(game, source);
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) ChoiceCreatureType(mage.choices.ChoiceCreatureType) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect)

Example 32 with FilterControlledPermanent

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

the class ShimatsuTheBloodcloakedEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent creature = ((EntersTheBattlefieldEvent) event).getTarget();
    Player controller = game.getPlayer(source.getControllerId());
    if (creature != null && controller != null) {
        Target target = new TargetControlledPermanent(0, Integer.MAX_VALUE, new FilterControlledPermanent(), true);
        if (!target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
            return false;
        }
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        if (!target.getTargets().isEmpty()) {
            int sacrificedCreatures = target.getTargets().size();
            game.informPlayers(controller.getLogName() + " sacrifices " + sacrificedCreatures + " creatures for " + creature.getLogName());
            for (UUID targetId : target.getTargets()) {
                Permanent targetCreature = game.getPermanent(targetId);
                if (targetCreature == null || !targetCreature.sacrifice(source, game)) {
                    return false;
                }
            }
            creature.addCounters(CounterType.P1P1.createInstance(sacrificedCreatures), source.getControllerId(), source, game);
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 33 with FilterControlledPermanent

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

the class SmokestackEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player activePlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (activePlayer != null && sourcePermanent != null) {
        int count = sourcePermanent.getCounters(game).getCount(CounterType.SOOT);
        if (count > 0) {
            int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), activePlayer.getId(), game));
            Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
            // had, if thats the case this ability should fizzle.
            if (target.canChoose(source.getSourceId(), activePlayer.getId(), game)) {
                while (!target.isChosen() && target.canChoose(source.getSourceId(), activePlayer.getId(), game) && activePlayer.canRespond()) {
                    activePlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                for (int idx = 0; idx < target.getTargets().size(); idx++) {
                    Permanent permanent = game.getPermanent(target.getTargets().get(idx));
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 34 with FilterControlledPermanent

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

the class SpiritSistersCallPredicate method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = source.getFirstTarget();
    Card card = game.getCard(targetId);
    if (card == null || game.getState().getZone(targetId) != Zone.GRAVEYARD) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("a permanent that shares a card type with the chosen card");
    filter.add(new SpiritSistersCallPredicate(new HashSet<CardType>(card.getCardType(game))));
    return new DoIfCostPaid(new SpiritSistersCallReturnToBattlefieldEffect(), new SacrificeTargetCost(filter)).apply(game, source);
}
Also used : SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card) FilterPermanentCard(mage.filter.common.FilterPermanentCard) HashSet(java.util.HashSet)

Example 35 with FilterControlledPermanent

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

the class CheeseStandsAloneContinuousEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.getHand().isEmpty()) {
            int numberPerms = new PermanentsOnBattlefieldCount(new FilterControlledPermanent()).calculate(game, source, this);
            if (numberPerms == 1) {
                if (game.getBattlefield().containsControlled(filter, source, game, 1)) {
                    if (!wonAlready) {
                        wonAlready = true;
                        controller.won(game);
                    }
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) 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