Search in sources :

Example 26 with FilterControlledPermanent

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

the class EquipoiseEffect method phaseOutCardType.

private void phaseOutCardType(Player controller, Player targetPlayer, CardType cardType, Ability source, Game game) {
    FilterPermanent filter = new FilterControlledPermanent();
    filter.add(cardType.getPredicate());
    int numberController = game.getBattlefield().count(filter, source.getSourceId(), controller.getId(), game);
    int numberTargetPlayer = game.getBattlefield().count(filter, source.getSourceId(), targetPlayer.getId(), game);
    int excess = numberTargetPlayer - numberController;
    if (excess > 0) {
        FilterPermanent filterChoose = new FilterPermanent(cardType.toString().toLowerCase(Locale.ENGLISH) + (excess > 1 ? "s" : "") + " of target player");
        filterChoose.add(new ControllerIdPredicate(targetPlayer.getId()));
        filterChoose.add(cardType.getPredicate());
        Target target = new TargetPermanent(excess, excess, filterChoose, true);
        controller.chooseTarget(outcome, target, source, game);
        new PhaseOutAllEffect(target.getTargets()).apply(game, source);
    }
}
Also used : Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) PhaseOutAllEffect(mage.abilities.effects.common.PhaseOutAllEffect) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 27 with FilterControlledPermanent

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

the class FeastOfWormsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentOrLKIBattlefield(id);
    Player targetPlayer = null;
    if (permanent != null) {
        targetPlayer = game.getPlayer(permanent.getControllerId());
    }
    if (targetPlayer != null && permanent != null && (permanent.isLegendary())) {
        FilterControlledPermanent filter = new FilterControlledLandPermanent("land to sacrifice");
        filter.add(new ControllerIdPredicate(targetPlayer.getId()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, false);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null) {
                land.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 28 with FilterControlledPermanent

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

the class RunEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getTargets().getFirstTarget());
    if (targetPlayer != null) {
        FilterControlledPermanent filter = new FilterControlledPermanent("artifact or creature");
        filter.add(Predicates.or(CardType.ARTIFACT.getPredicate(), CardType.CREATURE.getPredicate()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                permanent.sacrifice(source, game);
                int damage = permanent.getManaValue();
                if (damage > 0) {
                    targetPlayer.damage(damage, source.getSourceId(), source, game);
                }
            }
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 29 with FilterControlledPermanent

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

the class LilianaDreadhordeGeneralEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterPermanent keepFilter = new FilterPermanent();
    keepFilter.add(TargetController.OPPONENT.getControllerPredicate());
    for (UUID opponentId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null || !opponent.hasOpponent(source.getControllerId(), game)) {
            continue;
        }
        for (CardType cardType : CardType.values()) {
            if (!cardType.isPermanentType()) {
                continue;
            }
            FilterControlledPermanent filter = new FilterControlledPermanent("a " + cardType.toString() + " you control " + "(everything you don't choose will be sacrificed)");
            filter.add(cardType.getPredicate());
            Target target = new TargetControlledPermanent(filter);
            target.setNotTarget(true);
            if (opponent.choose(outcome, target, source.getSourceId(), game)) {
                keepFilter.add(Predicates.not(new CardIdPredicate(target.getFirstTarget())));
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
        if (keepFilter.match(permanent, source.getSourceId(), source.getControllerId(), game)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 30 with FilterControlledPermanent

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

the class MinionLeshracEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent minionLeshrac = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && minionLeshrac != null) {
        FilterControlledPermanent filterCreature = new FilterControlledPermanent();
        filterCreature.add(CardType.CREATURE.getPredicate());
        filterCreature.add(AnotherPredicate.instance);
        TargetControlledPermanent target = new TargetControlledPermanent(filterCreature);
        SacrificeTargetCost cost = new SacrificeTargetCost(target);
        if (controller.chooseUse(Outcome.AIDontUseIt, "Sacrifice another creature to prevent the damage?", source, game) && cost.canPay(source, source, source.getControllerId(), game) && cost.pay(source, game, source, source.getControllerId(), true)) {
            return true;
        }
        if (controller.damage(5, minionLeshrac.getId(), source, game) > 0) {
            minionLeshrac.tap(source, game);
            return true;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Aggregations

FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)47 Player (mage.players.Player)41 Permanent (mage.game.permanent.Permanent)34 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)28 UUID (java.util.UUID)17 Target (mage.target.Target)16 FilterPermanent (mage.filter.FilterPermanent)9 TargetPermanent (mage.target.TargetPermanent)9 Card (mage.cards.Card)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 ArrayList (java.util.ArrayList)4 Effect (mage.abilities.effects.Effect)4 Choice (mage.choices.Choice)4 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)4 PermanentIdPredicate (mage.filter.predicate.permanent.PermanentIdPredicate)4 TargetPlayer (mage.target.TargetPlayer)4 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)3 Cards (mage.cards.Cards)3 FilterCard (mage.filter.FilterCard)3