Search in sources :

Example 1 with FilterCreaturePermanent

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

the class AvalancheTuskerAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (event.getSourceId().equals(this.getSourceId())) {
        FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
        UUID defenderId = game.getCombat().getDefendingPlayerId(sourceId, game);
        filter.add(new ControllerIdPredicate(defenderId));
        this.getTargets().clear();
        TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 2 with FilterCreaturePermanent

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

the class ElementalAppealEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    CreateTokenEffect effect = new CreateTokenEffect(new RedElementalWithTrampleAndHaste());
    if (effect.apply(game, source)) {
        effect.exileTokensCreatedAtNextEndStep(game, source);
        if (KickedCondition.instance.apply(game, source)) {
            List<Predicate<MageObject>> predList = new ArrayList<>();
            for (UUID tokenId : effect.getLastAddedTokenIds()) {
                predList.add(new CardIdPredicate(tokenId));
            }
            if (!predList.isEmpty()) {
                FilterCreaturePermanent filter = new FilterCreaturePermanent();
                filter.add(Predicates.or(predList));
                game.addEffect(new BoostAllEffect(7, 0, Duration.EndOfTurn, filter, false), source);
            }
        }
        return true;
    }
    return false;
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ArrayList(java.util.ArrayList) RedElementalWithTrampleAndHaste(mage.game.permanent.token.RedElementalWithTrampleAndHaste) UUID(java.util.UUID) BoostAllEffect(mage.abilities.effects.common.continuous.BoostAllEffect) Predicate(mage.filter.predicate.Predicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 3 with FilterCreaturePermanent

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

the class FightOrFlightEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(game.getCombat().getAttackingPlayerId());
    if (player != null && targetPlayer != null) {
        int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
        TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        creatures.setRequired(false);
        if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
            List<UUID> targets = creatures.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(outcome, "Choose which pile can attack this turn.", pile1, pile2, game);
        List<Permanent> chosenPile = choice ? pile2 : pile1;
        List<Permanent> otherPile = choice ? pile1 : pile2;
        for (Permanent permanent : chosenPile) {
            if (permanent != null) {
                RestrictionEffect effect = new CantAttackTargetEffect(Duration.EndOfTurn);
                effect.setText("");
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
        }
        game.informPlayers("Creatures that can attack this turn: " + otherPile.stream().map(Permanent::getLogName).collect(Collectors.joining(", ")));
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) CantAttackTargetEffect(mage.abilities.effects.common.combat.CantAttackTargetEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect)

Example 4 with FilterCreaturePermanent

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

the class HeartPiercerBowAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        Permanent equipment = game.getPermanent(getSourceId());
        if (equipment != null && equipment.getAttachedTo() != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature defending player controls");
            UUID defenderId = game.getCombat().getDefendingPlayerId(equipment.getAttachedTo(), game);
            if (defenderId != null) {
                filter.add(new ControllerIdPredicate(defenderId));
                this.getTargets().clear();
                TargetCreaturePermanent target = new TargetCreaturePermanent(filter);
                this.addTarget(target);
                return true;
            }
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) UUID(java.util.UUID)

Example 5 with FilterCreaturePermanent

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

the class MayaelsAriaEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    // put a +1/+1 counter on each creature you control if you control a creature with power 5 or greater.
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 4));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
            creature.addCounters(CounterType.P1P1.createInstance(), source.getControllerId(), source, game);
        }
    }
    // needed because otehrwise the +1/+1 counters wouldn't be taken into account
    game.getState().processAction(game);
    // Then you gain 10 life if you control a creature with power 10 or greater.
    filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 9));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        controller.gainLife(10, game, source);
    }
    // Then you win the game if you control a creature with power 20 or greater.
    filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 19));
    if (game.getState().getBattlefield().countAll(filter, controller.getId(), game) > 0) {
        controller.won(game);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

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