Search in sources :

Example 26 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class HomingLightningEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
    if (targetPermanent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    if (CardUtil.haveEmptyName(targetPermanent)) {
        // if no name (face down creature) only the creature itself is selected
        filter.add(new PermanentIdPredicate(targetPermanent.getId()));
    } else {
        filter.add(new NamePredicate(targetPermanent.getName()));
    }
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game)) {
        if (creature != null) {
            creature.damage(4, source.getSourceId(), source, game, false, true);
        }
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent)

Example 27 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class MasterOfTheVeilEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
    for (Target target : source.getTargets()) {
        for (UUID targetId : target.getTargets()) {
            pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
        }
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(pred);
    game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BecomesFaceDownCreatureAllEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect) UUID(java.util.UUID) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate)

Example 28 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class SlipperyBogbonderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent creature = game.getPermanent(source.getFirstTarget());
    FilterPermanent filterPermanent = filter.copy();
    filterPermanent.add(Predicates.not(new PermanentIdPredicate(source.getFirstTarget())));
    if (player == null || creature == null || game.getBattlefield().count(filterPermanent, source.getSourceId(), source.getControllerId(), game) < 1) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, Integer.MAX_VALUE, filterPermanent, true);
    player.choose(outcome, target, source.getSourceId(), game);
    List<Permanent> permanents = target.getTargets().stream().filter(uuid -> !creature.getId().equals(uuid)).map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toList());
    if (permanents.isEmpty()) {
        return false;
    }
    Map<UUID, Map<String, Integer>> counterMap = new HashMap<>();
    for (Permanent permanent : permanents) {
        permanent.getCounters(game).entrySet().stream().forEach(entry -> {
            int num = player.getAmount(0, entry.getValue().getCount(), "Choose how many " + entry.getKey() + " counters to remove from " + permanent.getLogName(), game);
            counterMap.computeIfAbsent(permanent.getId(), x -> new HashMap<>()).put(entry.getKey(), num);
        });
    }
    for (Permanent permanent : permanents) {
        counterMap.get(permanent.getId()).entrySet().stream().filter(entry -> entry.getValue() > 0).map(entry -> CounterType.findByName(entry.getKey()).createInstance(entry.getValue())).filter(counter -> creature.addCounters(counter, source.getControllerId(), source, game)).forEach(counter -> permanent.removeCounters(counter, source, game));
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) java.util(java.util) CounterAnyPredicate(mage.filter.predicate.permanent.CounterAnyPredicate) Predicates(mage.filter.predicate.Predicates) SubType(mage.constants.SubType) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) EntersBattlefieldTriggeredAbility(mage.abilities.common.EntersBattlefieldTriggeredAbility) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) FlashAbility(mage.abilities.keyword.FlashAbility) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) HexproofAbility(mage.abilities.keyword.HexproofAbility) CounterType(mage.counters.CounterType) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 29 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class WeaverOfLiesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Predicate pred = new PermanentIdPredicate(UUID.randomUUID());
    for (Target target : source.getTargets()) {
        for (UUID targetId : target.getTargets()) {
            pred = Predicates.or(pred, new PermanentIdPredicate(targetId));
        }
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(pred);
    game.addEffect(new BecomesFaceDownCreatureAllEffect(filter), source);
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BecomesFaceDownCreatureAllEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect) UUID(java.util.UUID) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) AnotherPredicate(mage.filter.predicate.mageobject.AnotherPredicate)

Example 30 with PermanentIdPredicate

use of mage.filter.predicate.permanent.PermanentIdPredicate in project mage by magefree.

the class InquisitorsSnareEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(source.getFirstTarget());
    if (targetCreature != null) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent();
        filter.add(new PermanentIdPredicate(targetCreature.getId()));
        game.addEffect(new PreventAllDamageByAllPermanentsEffect(filter, Duration.EndOfTurn, false), source);
        if (targetCreature.getColor(game).isBlack() || targetCreature.getColor(game).isRed()) {
            return targetCreature.destroy(source, game, false);
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PreventAllDamageByAllPermanentsEffect(mage.abilities.effects.common.PreventAllDamageByAllPermanentsEffect)

Aggregations

PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)45 Permanent (mage.game.permanent.Permanent)38 Player (mage.players.Player)26 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)24 FilterPermanent (mage.filter.FilterPermanent)19 TargetPermanent (mage.target.TargetPermanent)19 Target (mage.target.Target)17 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)17 UUID (java.util.UUID)14 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)9 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)7 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)5 MageObject (mage.MageObject)4 Predicate (mage.filter.predicate.Predicate)4 ContinuousEffect (mage.abilities.effects.ContinuousEffect)3 BecomesFaceDownCreatureAllEffect (mage.abilities.effects.common.continuous.BecomesFaceDownCreatureAllEffect)3 BoostAllEffect (mage.abilities.effects.common.continuous.BoostAllEffect)3 AbilityPredicate (mage.filter.predicate.mageobject.AbilityPredicate)3 ArrayList (java.util.ArrayList)2