Search in sources :

Example 76 with FilterCreaturePermanent

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

the class MirrorWeaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    if (controller != null) {
        Permanent copyFromCreature = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
        if (copyFromCreature != null) {
            filter.add(Predicates.not(new PermanentIdPredicate(copyFromCreature.getId())));
            for (Permanent copyToCreature : game.getBattlefield().getAllActivePermanents(filter, game)) {
                if (copyToCreature != null) {
                    game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToCreature.getId(), source, new EmptyCopyApplier());
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier)

Example 77 with FilterCreaturePermanent

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

the class TargetCreatureWithLessPowerPermanent method canChoose.

@Override
public boolean canChoose(UUID sourceId, UUID sourceControllerId, Game game) {
    // get the most powerful controlled creature that can be targeted
    int maxPower = Integer.MIN_VALUE;
    Card sourceCard = game.getCard(sourceId);
    if (sourceCard == null) {
        return false;
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, sourceControllerId, game)) {
        if (permanent.getPower().getValue() > maxPower && permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
            maxPower = permanent.getPower().getValue();
        }
    }
    // now check, if another creature has less power and can be targeted
    FilterCreaturePermanent checkFilter = new FilterCreaturePermanent();
    checkFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, maxPower));
    for (Permanent permanent : game.getBattlefield().getActivePermanents(checkFilter, sourceControllerId, sourceId, game)) {
        if (permanent.canBeTargetedBy(sourceCard, sourceControllerId, game)) {
            return true;
        }
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Card(mage.cards.Card)

Example 78 with FilterCreaturePermanent

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

the class NightmareUnmakingEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    FilterPermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(comparisonType, player.getHand().size()));
    return new ExileAllEffect(filter).apply(game, source);
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ExileAllEffect(mage.abilities.effects.common.ExileAllEffect) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 79 with FilterCreaturePermanent

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

the class OrzhovAdvokistEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<UUID> players = new ArrayList<>();
        List<UUID> creatures = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.chooseUse(outcome, "Put two +1/+1 counters on a creature you control?", source, game)) {
                    Target target = new TargetControlledCreaturePermanent(new FilterControlledCreaturePermanent("a creature you control (to add two +1/+1 counters on it)"));
                    if (player.choose(outcome, target, playerId, game)) {
                        creatures.add(target.getFirstTarget());
                        players.add(player.getId());
                    }
                }
            }
        }
        for (UUID creatureId : creatures) {
            Permanent creature = game.getPermanent(creatureId);
            if (creature != null) {
                creature.addCounters(CounterType.P1P1.createInstance(2), creature.getControllerId(), source, game);
            }
        }
        for (UUID playerId : players) {
            if (!Objects.equals(playerId, source.getControllerId())) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent();
                filter.add(new ControllerIdPredicate(playerId));
                game.addEffect(new CantAttackYouAllEffect(Duration.UntilYourNextTurn, filter, true), source);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) CantAttackYouAllEffect(mage.abilities.effects.common.combat.CantAttackYouAllEffect) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 80 with FilterCreaturePermanent

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

the class PolymorphousRushCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCreaturePermanent(new FilterCreaturePermanent(""));
        target.setNotTarget(true);
        target.setTargetName("a creature on the battlefield (creature to copy)");
        if (target.canChoose(source.getId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Permanent copyFromCreature = game.getPermanent(target.getFirstTarget());
            if (copyFromCreature != null) {
                for (UUID copyToId : getTargetPointer().getTargets(game, source)) {
                    Permanent copyToCreature = game.getPermanent(copyToId);
                    if (copyToCreature != null) {
                        game.copyPermanent(Duration.EndOfTurn, copyFromCreature, copyToId, source, new EmptyCopyApplier());
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) EmptyCopyApplier(mage.util.functions.EmptyCopyApplier) UUID(java.util.UUID)

Aggregations

FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)187 Player (mage.players.Player)125 Permanent (mage.game.permanent.Permanent)108 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)83 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)67 UUID (java.util.UUID)55 TargetPermanent (mage.target.TargetPermanent)32 Target (mage.target.Target)31 FilterPermanent (mage.filter.FilterPermanent)27 FixedTarget (mage.target.targetpointer.FixedTarget)25 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)23 ContinuousEffect (mage.abilities.effects.ContinuousEffect)22 MageObject (mage.MageObject)16 PowerPredicate (mage.filter.predicate.mageobject.PowerPredicate)16 OneShotEffect (mage.abilities.effects.OneShotEffect)14 Effect (mage.abilities.effects.Effect)13 Choice (mage.choices.Choice)13 TargetPlayer (mage.target.TargetPlayer)13 Card (mage.cards.Card)12 ChoiceCreatureType (mage.choices.ChoiceCreatureType)12