Search in sources :

Example 16 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class FettergeistUnlessPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player != null && permanent != null) {
        PermanentsOnBattlefieldCount amount = new PermanentsOnBattlefieldCount(filter, 1);
        int count = amount.calculate(game, source, this);
        if (player.chooseUse(Outcome.Benefit, "Pay {" + count + "}?  Or " + permanent.getName() + " will be sacrificed.", source, game)) {
            Cost cost = ManaUtil.createManaCost(count, false);
            if (cost.pay(source, game, source, source.getControllerId(), false)) {
                return true;
            }
        }
        permanent.sacrifice(source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) Cost(mage.abilities.costs.Cost)

Example 17 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount 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)

Example 18 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class NessianGameWardenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    int count = new PermanentsOnBattlefieldCount(filter).calculate(game, source, this);
    Cards cards = new CardsImpl();
    cards.addAll(controller.getLibrary().getTopCards(game, count));
    controller.lookAtCards(sourcePermanent.getIdName(), cards, game);
    if (!cards.isEmpty()) {
        TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCreatureCard("creature card to put into your hand"));
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(Outcome.DrawCard, cards, target, game)) {
            Card card = cards.get(target.getFirstTarget(), game);
            if (card != null) {
                controller.revealCards(sourcePermanent.getName(), new CardsImpl(card), game);
                cards.remove(card);
                controller.moveCards(card, Zone.HAND, source, game);
            }
        }
    }
    controller.putCardsOnBottomOfLibrary(cards, game, source, true);
    return true;
}
Also used : Player(mage.players.Player) FilterCreatureCard(mage.filter.common.FilterCreatureCard) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 19 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class PulseOfTheTangleReturnToHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    FilterControlledCreaturePermanent controllerFilter = new FilterControlledCreaturePermanent();
    PermanentsOnBattlefieldCount controllerCount = new PermanentsOnBattlefieldCount(controllerFilter);
    int controllerAmount = controllerCount.calculate(game, source, this);
    boolean check = false;
    if (controller != null) {
        for (UUID opponentID : game.getOpponents(controller.getId())) {
            if (opponentID != null) {
                FilterCreaturePermanent opponentFilter = new FilterCreaturePermanent();
                opponentFilter.add(new ControllerIdPredicate(opponentID));
                PermanentsOnBattlefieldCount opponentCreatureCount = new PermanentsOnBattlefieldCount(opponentFilter);
                check = opponentCreatureCount.calculate(game, source, this) > controllerAmount;
                if (check) {
                    break;
                }
            }
        }
        if (check) {
            Card card = game.getCard(source.getSourceId());
            controller.moveCards(card, Zone.HAND, source, game);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) UUID(java.util.UUID) Card(mage.cards.Card)

Example 20 with PermanentsOnBattlefieldCount

use of mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount in project mage by magefree.

the class DesertInGYorBFCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        for (Card card : player.getGraveyard().getCards(game)) {
            if (filter.match(card, game)) {
                return true;
            }
        }
    }
    PermanentsOnBattlefieldCount count = new PermanentsOnBattlefieldCount(filter2);
    return count.calculate(game, source, null) >= 1;
}
Also used : Player(mage.players.Player) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Aggregations

PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)22 Player (mage.players.Player)18 Permanent (mage.game.permanent.Permanent)6 Choice (mage.choices.Choice)5 ChoiceCreatureType (mage.choices.ChoiceCreatureType)5 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)4 Card (mage.cards.Card)4 FilterPermanent (mage.filter.FilterPermanent)4 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)4 ControllerIdPredicate (mage.filter.predicate.permanent.ControllerIdPredicate)4 UUID (java.util.UUID)3 CardsImpl (mage.cards.CardsImpl)3 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Cost (mage.abilities.costs.Cost)2 DynamicValue (mage.abilities.dynamicvalue.DynamicValue)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 BecomesCreatureTargetEffect (mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect)2