Search in sources :

Example 16 with FilterCreaturePermanent

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

the class BrineHagEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourcePermanent != null) {
        List<Permanent> list = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                    if (sourcePermanent.getDealtDamageByThisTurn().contains(new MageObjectReference(creature.getId(), game))) {
                        list.add(creature);
                    }
                }
            }
        }
        if (!list.isEmpty()) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent();
            filter.add(new PermanentInListPredicate(list));
            game.addEffect(new SetPowerToughnessAllEffect(0, 2, Duration.Custom, filter, true), source);
        }
        return true;
    }
    return false;
}
Also used : SetPowerToughnessAllEffect(mage.abilities.effects.common.continuous.SetPowerToughnessAllEffect) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) MageObjectReference(mage.MageObjectReference)

Example 17 with FilterCreaturePermanent

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

the class CelestialJudgmentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game);
    Map<Integer, List<Permanent>> powerMap = permanents.stream().collect(Collectors.toMap(permanent -> permanent.getPower().getValue(), permanent -> Arrays.asList(permanent), (a1, a2) -> {
        a1.addAll(a2);
        return a1;
    }));
    Set<UUID> toKeep = new HashSet<>();
    for (Map.Entry<Integer, List<Permanent>> entry : powerMap.entrySet()) {
        if (entry.getValue().size() == 1) {
            toKeep.add(entry.getValue().get(0).getId());
            continue;
        }
        FilterPermanent filter = new FilterCreaturePermanent("creature with power " + entry.getKey() + " to save");
        filter.add(new PowerPredicate(ComparisonType.EQUAL_TO, entry.getKey()));
        TargetPermanent target = new TargetPermanent(filter);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        toKeep.add(target.getFirstTarget());
    }
    for (Permanent permanent : permanents) {
        if (!toKeep.contains(permanent.getId())) {
            permanent.destroy(source, game);
        }
    }
    return true;
}
Also used : StaticFilters(mage.filter.StaticFilters) java.util(java.util) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) FilterPermanent(mage.filter.FilterPermanent) Collectors(java.util.stream.Collectors) Player(mage.players.Player) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) ComparisonType(mage.constants.ComparisonType) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent)

Example 18 with FilterCreaturePermanent

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

the class CommandoRaidEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    DamagedPlayerEvent damageEvent = (DamagedPlayerEvent) event;
    Player opponent = game.getPlayer(event.getPlayerId());
    if (!damageEvent.isCombatDamage() || !event.getSourceId().equals(this.getSourceId()) || opponent == null) {
        return false;
    }
    FilterCreaturePermanent filter = new FilterCreaturePermanent("creature " + opponent.getLogName() + " controls");
    filter.add(new ControllerIdPredicate(opponent.getId()));
    this.getTargets().clear();
    this.addTarget(new TargetCreaturePermanent(filter));
    for (Effect effect : this.getAllEffects()) {
        effect.setTargetPointer(new FixedTarget(event.getPlayerId()));
        effect.setValue("damage", event.getAmount());
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 19 with FilterCreaturePermanent

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

the class EngulfTheShoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int islands = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
        FilterPermanent creatureFilter = new FilterCreaturePermanent();
        creatureFilter.add(new ToughnessPredicate(ComparisonType.FEWER_THAN, islands + 1));
        Set<Card> cardsToHand = new HashSet<>();
        for (Permanent permanent : game.getBattlefield().getActivePermanents(creatureFilter, source.getControllerId(), source.getSourceId(), game)) {
            cardsToHand.add(permanent);
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Card(mage.cards.Card) HashSet(java.util.HashSet)

Example 20 with FilterCreaturePermanent

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

the class FatalLoreEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player chosenOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (controller != null && chosenOpponent != null) {
        if (chosenOpponent.chooseUse(Outcome.Neutral, "If you choose Yes, the controller draws three cards. If no, the controller gets to destroy up to two target creatures that you control and you get to draw up to 3 cards. Those creatures can't be regenerated.", source, game)) {
            controller.drawCards(3, source, game);
        } else {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("chosen opponent's creature");
            filter.add(new ControllerIdPredicate(chosenOpponent.getId()));
            TargetCreaturePermanent target = new TargetCreaturePermanent(0, 2, filter, false);
            if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DestroyPermanent, target, source.getSourceId(), game)) {
                for (UUID targetId : target.getTargets()) {
                    Effect destroyCreature = new DestroyTargetEffect(true);
                    destroyCreature.setTargetPointer(new FixedTarget(targetId, game));
                    destroyCreature.apply(game, source);
                }
                Effect opponentDrawsCards = new DrawCardTargetEffect(StaticValue.get(3), false, true);
                opponentDrawsCards.setTargetPointer(new FixedTarget(chosenOpponent.getId()));
                opponentDrawsCards.apply(game, source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) DrawCardTargetEffect(mage.abilities.effects.common.DrawCardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID)

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