Search in sources :

Example 6 with FilterNonlandPermanent

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

the class BladegriffPrototypeAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player player = game.getPlayer(getControllerId());
    if (player == null || !event.getSourceId().equals(this.sourceId) || !((DamagedEvent) event).isCombatDamage()) {
        return false;
    }
    FilterPermanent filter = new FilterNonlandPermanent("nonland permanent controlled by an opponent of " + player.getName());
    filter.add(Predicates.or(game.getOpponents(getControllerId()).stream().map(ControllerIdPredicate::new).collect(Collectors.toSet())));
    TargetPermanent target = new TargetPermanent(filter);
    target.setTargetController(event.getPlayerId());
    this.getTargets().clear();
    this.addTarget(target);
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) DamagedEvent(mage.game.events.DamagedEvent) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 7 with FilterNonlandPermanent

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

the class ScalelardReckonerTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (game.getOpponents(this.controllerId).contains(event.getPlayerId())) {
        Permanent creature = game.getPermanent(event.getTargetId());
        if (creature != null && filter.match(creature, getSourceId(), getControllerId(), game)) {
            FilterNonlandPermanent filter = new FilterNonlandPermanent("nonland permanent that player controls");
            filter.add(new ControllerIdPredicate(event.getPlayerId()));
            this.getTargets().clear();
            this.addTarget(new TargetPermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) TargetPermanent(mage.target.TargetPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 8 with FilterNonlandPermanent

use of mage.filter.common.FilterNonlandPermanent 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)

Example 9 with FilterNonlandPermanent

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

the class IntellectualOfferingUntapEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Target target = new TargetOpponent(true);
        target.choose(Outcome.Untap, source.getControllerId(), source.getSourceId(), game);
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), player.getId(), game)) {
            permanent.untap(game);
        }
        Player opponent = game.getPlayer(target.getFirstTarget());
        if (opponent != null) {
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterNonlandPermanent(), opponent.getId(), game)) {
                permanent.untap(game);
            }
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent)

Example 10 with FilterNonlandPermanent

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

the class TheBattleOfYavinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getTargets().getFirstTarget());
    if (opponent == null) {
        return false;
    }
    int amount = (ManacostVariableValue.REGULAR).calculate(game, source, this);
    if (amount > 0) {
        LinkedList<Permanent> sacrifices = new LinkedList<>();
        FilterNonlandPermanent filter = new FilterNonlandPermanent();
        List<Permanent> permanents = game.getBattlefield().getAllActivePermanents(filter, opponent.getId(), game);
        int lifePaid = 0;
        int playerLife = opponent.getLife();
        for (Permanent permanent : permanents) {
            String message = "Pay " + amount + " life? If you don't, " + permanent.getName() + " will be sacrificed.";
            if (playerLife - amount - lifePaid >= 0 && opponent.chooseUse(Outcome.Neutral, message, source, game)) {
                game.informPlayers(opponent.getLogName() + " pays " + amount + " life. They will not sacrifice " + permanent.getName());
                lifePaid += amount;
            } else {
                game.informPlayers(opponent.getLogName() + " will sacrifice " + permanent.getName());
                sacrifices.add(permanent);
            }
        }
        if (lifePaid > 0) {
            Player player = game.getPlayer(opponent.getId());
            if (player != null) {
                player.loseLife(lifePaid, game, source, false);
            }
        }
        for (Permanent permanent : sacrifices) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) Permanent(mage.game.permanent.Permanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) LinkedList(java.util.LinkedList)

Aggregations

FilterNonlandPermanent (mage.filter.common.FilterNonlandPermanent)17 Permanent (mage.game.permanent.Permanent)13 FilterPermanent (mage.filter.FilterPermanent)11 Player (mage.players.Player)11 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)8 TargetPermanent (mage.target.TargetPermanent)7 ManaValuePredicate (mage.filter.predicate.mageobject.ManaValuePredicate)5 UUID (java.util.UUID)3 DestroyAllEffect (mage.abilities.effects.common.DestroyAllEffect)3 Target (mage.target.Target)3 HashMap (java.util.HashMap)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)2 NamePredicate (mage.filter.predicate.mageobject.NamePredicate)2 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)2 PlayerList (mage.players.PlayerList)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1