Search in sources :

Example 51 with FilterControlledCreaturePermanent

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

the class PlungeIntoDarknessSearchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, new FilterControlledCreaturePermanent(), true);
        player.chooseTarget(Outcome.Sacrifice, target, source, game);
        int numSacrificed = 0;
        for (UUID permanentId : target.getTargets()) {
            Permanent permanent = game.getPermanent(permanentId);
            if (permanent != null) {
                if (permanent.sacrifice(source, game)) {
                    numSacrificed++;
                }
            }
        }
        if (numSacrificed > 0) {
            player.gainLife(3 * numSacrificed, game, source);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 52 with FilterControlledCreaturePermanent

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

the class RagingRiverEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> left = new ArrayList<>();
        List<Permanent> right = new ArrayList<>();
        for (UUID defenderId : game.getCombat().getPlayerDefenders(game)) {
            Player defender = game.getPlayer(defenderId);
            if (defender != null) {
                List<Permanent> leftLog = new ArrayList<>();
                List<Permanent> rightLog = new ArrayList<>();
                FilterControlledCreaturePermanent filterBlockers = new FilterControlledCreaturePermanent("creatures without flying you control to assign to the \"left\" pile (creatures not chosen will be assigned to the \"right\" pile)");
                filterBlockers.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                Target target = new TargetControlledCreaturePermanent(0, Integer.MAX_VALUE, filterBlockers, true);
                if (target.canChoose(source.getSourceId(), defenderId, game)) {
                    if (defender.chooseTarget(Outcome.Neutral, target, source, game)) {
                        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterCreaturePermanent(), defenderId, game)) {
                            if (target.getTargets().contains(permanent.getId())) {
                                left.add(permanent);
                                leftLog.add(permanent);
                            } else if (filterBlockers.match(permanent, source.getSourceId(), defenderId, game)) {
                                right.add(permanent);
                                rightLog.add(permanent);
                            }
                        }
                    }
                    // it could be nice to invoke some graphic indicator of which creature is Left or Right in this spot
                    StringBuilder sb = new StringBuilder("Left pile of ").append(defender.getLogName()).append(": ");
                    sb.append(leftLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                    sb = new StringBuilder("Right pile of ").append(defender.getLogName()).append(": ");
                    sb.append(rightLog.stream().map(MageObject::getLogName).collect(Collectors.joining(", ")));
                    game.informPlayers(sb.toString());
                }
            }
        }
        for (UUID attackers : game.getCombat().getAttackers()) {
            Permanent attacker = game.getPermanent(attackers);
            if (attacker != null && Objects.equals(attacker.getControllerId(), controller.getId())) {
                CombatGroup combatGroup = game.getCombat().findGroup(attacker.getId());
                if (combatGroup != null) {
                    FilterCreaturePermanent filter = new FilterCreaturePermanent();
                    Player defender = game.getPlayer(combatGroup.getDefendingPlayerId());
                    if (defender != null) {
                        if (left.isEmpty() && right.isEmpty()) {
                            // shortcut in case of no labeled blockers available
                            filter.add(Predicates.not(new AbilityPredicate(FlyingAbility.class)));
                        } else {
                            List<Permanent> leftLog = left.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            List<Permanent> rightLog = right.stream().filter(permanent -> permanent.getControllerId() != null).filter(permanent -> permanent.isControlledBy(defender.getId())).collect(Collectors.toList());
                            if (controller.choosePile(outcome, attacker.getName() + ": attacking " + defender.getName(), leftLog, rightLog, game)) {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(left))));
                                game.informPlayers(attacker.getLogName() + ": attacks left (" + defender.getLogName() + ")");
                            } else {
                                filter.add(Predicates.not(Predicates.or(new AbilityPredicate(FlyingAbility.class), new PermanentInListPredicate(right))));
                                game.informPlayers(attacker.getLogName() + ": attacks right (" + defender.getLogName() + ")");
                            }
                        }
                        RestrictionEffect effect = new CantBeBlockedByAllTargetEffect(filter, Duration.EndOfCombat);
                        effect.setTargetPointer(new FixedTarget(attacker.getId(), game));
                        game.addEffect(effect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Target(mage.target.Target) RestrictionEffect(mage.abilities.effects.RestrictionEffect) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect) Predicates(mage.filter.predicate.Predicates) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) ArrayList(java.util.ArrayList) AttacksWithCreaturesTriggeredAbility(mage.abilities.common.AttacksWithCreaturesTriggeredAbility) CardType(mage.constants.CardType) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CombatGroup(mage.game.combat.CombatGroup) FlyingAbility(mage.abilities.keyword.FlyingAbility) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) List(java.util.List) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) PermanentInListPredicate(mage.filter.predicate.permanent.PermanentInListPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FlyingAbility(mage.abilities.keyword.FlyingAbility) UUID(java.util.UUID) RestrictionEffect(mage.abilities.effects.RestrictionEffect) AbilityPredicate(mage.filter.predicate.mageobject.AbilityPredicate) CombatGroup(mage.game.combat.CombatGroup) CantBeBlockedByAllTargetEffect(mage.abilities.effects.common.combat.CantBeBlockedByAllTargetEffect)

Example 53 with FilterControlledCreaturePermanent

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

the class KindredChargeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        SubType subType = ChooseCreatureTypeEffect.getChosenCreatureType(source.getSourceId(), game);
        if (subType != null) {
            FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature you control of the chosen type");
            filter.add(subType.getPredicate());
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, controller.getId(), game)) {
                if (permanent != null) {
                    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    effect.apply(game, source);
                    for (Permanent addedToken : effect.getAddedPermanents()) {
                        Effect exileEffect = new ExileTargetEffect();
                        exileEffect.setTargetPointer(new FixedTarget(addedToken, game));
                        game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect), source);
                    }
                }
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) SubType(mage.constants.SubType) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ChooseCreatureTypeEffect(mage.abilities.effects.common.ChooseCreatureTypeEffect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) Effect(mage.abilities.effects.Effect) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 54 with FilterControlledCreaturePermanent

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

the class MilitiasPrideTriggerAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(TokenPredicate.FALSE);
    Permanent permanent = game.getPermanent(event.getSourceId());
    return permanent != null && filter.match(permanent, sourceId, controllerId, game);
}
Also used : Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 55 with FilterControlledCreaturePermanent

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

the class PacksDisdainEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Choice typeChoice = new ChoiceCreatureType(game.getObject(source.getSourceId()));
    if (player != null && player.choose(Outcome.UnboostCreature, typeChoice, game)) {
        FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
        filter.add(SubType.byDescription(typeChoice.getChoice()).getPredicate());
        DynamicValue negativePermanentsCount = new PermanentsOnBattlefieldCount(filter, -1);
        ContinuousEffect effect = new BoostTargetEffect(negativePermanentsCount, negativePermanentsCount, Duration.EndOfTurn, true);
        effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Choice(mage.choices.Choice) BoostTargetEffect(mage.abilities.effects.common.continuous.BoostTargetEffect) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ChoiceCreatureType(mage.choices.ChoiceCreatureType) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) ContinuousEffect(mage.abilities.effects.ContinuousEffect) DynamicValue(mage.abilities.dynamicvalue.DynamicValue)

Aggregations

FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)75 Permanent (mage.game.permanent.Permanent)62 Player (mage.players.Player)60 UUID (java.util.UUID)29 Target (mage.target.Target)27 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)21 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)16 ArrayList (java.util.ArrayList)13 Card (mage.cards.Card)11 TargetPermanent (mage.target.TargetPermanent)11 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)10 FixedTarget (mage.target.targetpointer.FixedTarget)9 MageObject (mage.MageObject)7 OneShotEffect (mage.abilities.effects.OneShotEffect)7 Effect (mage.abilities.effects.Effect)6 Ability (mage.abilities.Ability)5 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)5 FilterPermanent (mage.filter.FilterPermanent)5 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)5 Spell (mage.game.stack.Spell)5