Search in sources :

Example 61 with FilterCreaturePermanent

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

the class FavorOfTheMightyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int maxCMC = Integer.MIN_VALUE;
    for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game)) {
        if (permanent != null && permanent.getManaValue() > maxCMC) {
            maxCMC = permanent.getManaValue();
        }
    }
    FilterPermanent filterMaxCMC = new FilterCreaturePermanent();
    filterMaxCMC.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, maxCMC));
    for (Permanent permanent : game.getBattlefield().getActivePermanents(filterMaxCMC, source.getControllerId(), game)) {
        if (permanent != null) {
            permanent.addAbility(new ProtectionAbility(filter), source.getSourceId(), game);
        }
    }
    return true;
}
Also used : ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ProtectionAbility(mage.abilities.keyword.ProtectionAbility)

Example 62 with FilterCreaturePermanent

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

the class HighcliffFelidarEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Set<UUID> toDestroy = new HashSet();
    game.getOpponents(source.getControllerId()).stream().map(game::getPlayer).filter(Objects::nonNull).forEachOrdered(opponent -> {
        int maxPower = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, opponent.getId(), game).stream().map(Permanent::getPower).mapToInt(MageInt::getValue).max().orElse(Integer.MIN_VALUE);
        if (maxPower > Integer.MIN_VALUE) {
            FilterPermanent filter = new FilterCreaturePermanent("creature with the greatest power controlled by " + opponent.getName());
            filter.add(new ControllerIdPredicate(opponent.getId()));
            filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, maxPower));
            TargetPermanent target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (controller.choose(outcome, target, source.getSourceId(), game)) {
                toDestroy.add(target.getFirstTarget());
            }
        }
    });
    toDestroy.stream().map(game::getPermanent).filter(Objects::nonNull).forEachOrdered(permanent -> permanent.destroy(source, game, false));
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) MageInt(mage.MageInt) HashSet(java.util.HashSet)

Example 63 with FilterCreaturePermanent

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

the class BecomesChosenCreatureTypeControlledEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Card card = game.getCard(source.getSourceId());
    String chosenType = "";
    if (player != null && card != null) {
        Choice typeChoice = new ChoiceCreatureType();
        String msg = "Choose a creature type";
        typeChoice.setMessage(msg);
        while (!player.choose(Outcome.BoostCreature, typeChoice, game)) {
            if (!player.canRespond()) {
                return false;
            }
        }
        game.informPlayers(card.getName() + ": " + player.getLogName() + " has chosen " + typeChoice.getChoice());
        chosenType = typeChoice.getChoice();
        if (chosenType != null && !chosenType.isEmpty()) {
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), player.getId(), game)) {
                ContinuousEffect effect = new BecomesCreatureTypeTargetEffect(Duration.EndOfTurn, SubType.byDescription(chosenType));
                effect.setTargetPointer(new FixedTarget(permanent, game));
                game.addEffect(effect, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) BecomesCreatureTypeTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTypeTargetEffect) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) ChoiceCreatureType(mage.choices.ChoiceCreatureType) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card)

Example 64 with FilterCreaturePermanent

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

the class MobRuleControlAllEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean applied = false;
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new PowerPredicate(type, power));
    List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(filter, game);
    for (Permanent creature : creatures) {
        ContinuousEffect effect = new MobRuleControlAllEffect(source.getControllerId());
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
        applied = true;
    }
    for (Permanent creature : creatures) {
        creature.untap(game);
        applied = true;
    }
    for (Permanent creature : creatures) {
        ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(creature.getId(), game));
        game.addEffect(effect, source);
        applied = true;
    }
    return applied;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 65 with FilterCreaturePermanent

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

the class MistbladeShinobiTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((DamagedPlayerEvent) event).isCombatDamage() && event.getSourceId().equals(sourceId)) {
        Player opponent = game.getPlayer(event.getPlayerId());
        if (opponent != null) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
            filter.add(new ControllerIdPredicate(opponent.getId()));
            this.getTargets().clear();
            this.addTarget(new TargetCreaturePermanent(filter));
            return true;
        }
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate)

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