Search in sources :

Example 86 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class LavalancheEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayerOrPlaneswalkerController(source.getFirstTarget());
    if (targetPlayer == null) {
        return false;
    }
    targetPlayer.damage(amount.calculate(game, source, this), source.getSourceId(), source, game);
    FilterPermanent filter = new FilterPermanent("and each creature that player or that planeswalker's controller controls");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(new ControllerIdPredicate(targetPlayer.getId()));
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getSourceId(), game);
    for (Permanent permanent : permanents) {
        permanent.damage(amount.calculate(game, source, this), source.getSourceId(), source, game, false, true);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

Example 87 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class OrvarTheAllFormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) this.getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
    if (predicates.isEmpty()) {
        return false;
    }
    FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
    filter.add(Predicates.or(predicates));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) MageItem(mage.MageItem) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Spell(mage.game.stack.Spell) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 88 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class PsychicAllergyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player != null) {
        FilterPermanent filter = new FilterPermanent();
        filter.add(new ColorPredicate((ObjectColor) game.getState().getValue(source.getSourceId() + "_color")));
        filter.add(TokenPredicate.FALSE);
        int damage = game.getBattlefield().countAll(filter, player.getId(), game);
        player.damage(damage, source.getSourceId(), source, game);
        return true;
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) ObjectColor(mage.ObjectColor)

Example 89 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SingleCombatRestrictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent filterSac = new FilterCreatureOrPlaneswalkerPermanent();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        Target target = new TargetPermanent(filter);
        target.setNotTarget(true);
        if (player.choose(outcome, target, source.getSourceId(), game)) {
            filterSac.add(Predicates.not(new PermanentIdPredicate(target.getFirstTarget())));
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filterSac, source.getControllerId(), game)) {
        permanent.sacrifice(source, game);
    }
    return true;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) FilterCreatureOrPlaneswalkerPermanent(mage.filter.common.FilterCreatureOrPlaneswalkerPermanent)

Example 90 with FilterPermanent

use of mage.filter.FilterPermanent in project mage by magefree.

the class SteelHellkiteWatcher method apply.

@Override
public boolean apply(Game game, Ability source) {
    SteelHellkiteWatcher watcher = game.getState().getWatcher(SteelHellkiteWatcher.class);
    if (watcher == null || watcher.getDamagedPlayers(source.getSourceId()).isEmpty()) {
        return false;
    }
    Set<Predicate<Permanent>> predicateSet = new HashSet<>();
    for (UUID playerId : watcher.getDamagedPlayers(source.getSourceId())) {
        predicateSet.add(new ControllerIdPredicate(playerId));
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, source.getManaCostsToPay().getX()));
    filter.add(Predicates.or(predicateSet));
    return new DestroyAllEffect(filter).apply(game, source);
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Predicate(mage.filter.predicate.Predicate) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) DestroyAllEffect(mage.abilities.effects.common.DestroyAllEffect)

Aggregations

FilterPermanent (mage.filter.FilterPermanent)155 Permanent (mage.game.permanent.Permanent)99 Player (mage.players.Player)99 TargetPermanent (mage.target.TargetPermanent)62 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)49 UUID (java.util.UUID)41 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)30 Target (mage.target.Target)24 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)18 ColorPredicate (mage.filter.predicate.mageobject.ColorPredicate)17 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)16 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)14 OneShotEffect (mage.abilities.effects.OneShotEffect)13 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)13 FilterCard (mage.filter.FilterCard)11 FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)11 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)11 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)11 CardsImpl (mage.cards.CardsImpl)10