Search in sources :

Example 61 with FilterControlledCreaturePermanent

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

the class RhonasTheIndomitableRestrictionEffect method applies.

@Override
public boolean applies(Permanent permanent, Ability source, Game game) {
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(new PowerPredicate(ComparisonType.MORE_THAN, 3));
    filter.add(AnotherPredicate.instance);
    if (permanent.getId().equals(source.getSourceId())) {
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            int permanentsOnBattlefield = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
            // is this correct?
            return permanentsOnBattlefield < 1;
        }
        return true;
    }
    // do not apply to other creatures.
    return false;
}
Also used : Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate)

Example 62 with FilterControlledCreaturePermanent

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

the class SigilOfValorCount method calculate.

@Override
public int calculate(Game game, Ability sourceAbility, Effect effect) {
    Permanent equipment = game.getPermanent(sourceAbility.getSourceId());
    if (equipment != null && equipment.getAttachedTo() != null) {
        FilterPermanent filterPermanent = new FilterControlledCreaturePermanent();
        filterPermanent.add(Predicates.not(new CardIdPredicate(equipment.getAttachedTo())));
        return game.getBattlefield().count(filterPermanent, sourceAbility.getSourceId(), sourceAbility.getControllerId(), game);
    }
    return 0;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CardIdPredicate(mage.filter.predicate.mageobject.CardIdPredicate)

Example 63 with FilterControlledCreaturePermanent

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

the class TariffEffect method processPlayer.

private void processPlayer(Game game, Ability source, Player player) {
    MageObject sourceObject = game.getObject(source.getSourceId());
    List<Permanent> creatures = getPermanentsWithTheHighestCMC(game, player.getId(), new FilterControlledCreaturePermanent());
    Permanent creatureToPayFor = chooseOnePermanent(game, player, creatures);
    if (creatureToPayFor != null && sourceObject != null) {
        ManaCosts manaCost = ManaCosts.removeVariableManaCost(creatureToPayFor.getManaCost());
        String message = "Pay " + manaCost.getText() + " (otherwise sacrifice " + creatureToPayFor.getName() + ")?";
        if (player.chooseUse(Outcome.Benefit, message, source, game)) {
            if (manaCost.pay(source, game, source, player.getId(), false, null)) {
                game.informPlayers(sourceObject.getName() + ": " + player.getLogName() + " has paid");
                return;
            }
        }
        game.informPlayers(sourceObject.getName() + ": " + player.getLogName() + " hasn't paid");
        creatureToPayFor.sacrifice(source, game);
    }
}
Also used : ManaCosts(mage.abilities.costs.mana.ManaCosts) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) MageObject(mage.MageObject) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 64 with FilterControlledCreaturePermanent

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

the class TributeToHungerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getTargets().getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && opponent != null) {
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
        if (target.canChoose(source.getSourceId(), opponent.getId(), game)) {
            opponent.chooseTarget(Outcome.Sacrifice, target, source, game);
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                permanent.sacrifice(source, game);
                controller.gainLife(permanent.getToughness().getValue(), game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 65 with FilterControlledCreaturePermanent

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

the class XathridDemonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent == null) {
        sourcePermanent = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    }
    if (controller == null || sourcePermanent == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
    filter.add(AnotherPredicate.instance);
    Target target = new TargetControlledCreaturePermanent(1, 1, filter, true);
    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
        controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            int amount = permanent.getPower().getValue();
            permanent.sacrifice(source, game);
            if (amount > 0) {
                Set<UUID> opponents = game.getOpponents(source.getControllerId());
                for (UUID opponentId : opponents) {
                    Player opponent = game.getPlayer(opponentId);
                    if (opponent != null) {
                        opponent.loseLife(amount, game, source, false);
                    }
                }
            }
            return true;
        }
    } else {
        sourcePermanent.tap(source, game);
        controller.loseLife(7, game, source, false);
        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)

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