Search in sources :

Example 46 with FilterControlledPermanent

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

the class ChoiceOfDamnationsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer != null) {
        int numberPermanents = game.getState().getBattlefield().countAll(new FilterPermanent(), targetPlayer.getId(), game);
        // AI hint
        int amount;
        if (targetPlayer.isComputer()) {
            // AI as defender
            int safeLifeToLost = Math.max(0, targetPlayer.getLife() / 2);
            amount = Math.min(numberPermanents, safeLifeToLost);
        } else {
            // Human must choose
            amount = targetPlayer.getAmount(0, Integer.MAX_VALUE, "Chooses a number", game);
        }
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            // AI hint
            boolean chooseLoseLife;
            if (targetPlayer.isComputer()) {
                // AI as attacker
                chooseLoseLife = (numberPermanents == 0 || amount <= numberPermanents || targetPlayer.getLife() < amount);
            } else {
                // Human must choose
                chooseLoseLife = controller.chooseUse(outcome, "Shall " + targetPlayer.getLogName() + " lose " + amount + " life?", source, game);
            }
            if (chooseLoseLife) {
                targetPlayer.loseLife(amount, game, source, false);
            } else {
                // (2005-06-01)
                if (numberPermanents > amount) {
                    int numberToSacrifice = numberPermanents - amount;
                    Target target = new TargetControlledPermanent(numberToSacrifice, numberToSacrifice, new FilterControlledPermanent("permanent you control to sacrifice"), false);
                    targetPlayer.chooseTarget(Outcome.Sacrifice, target, source, game);
                    for (UUID uuid : target.getTargets()) {
                        Permanent permanent = game.getPermanent(uuid);
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
            return true;
        }
    }
    return false;
}
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) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 47 with FilterControlledPermanent

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

the class ConsumingVaporsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getTargets().getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    FilterControlledPermanent filter = new FilterControlledPermanent("creature");
    filter.add(CardType.CREATURE.getPredicate());
    filter.add(TargetController.YOU.getControllerPredicate());
    TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
    if (player != null && target.canChoose(source.getSourceId(), player.getId(), game)) {
        player.choose(Outcome.Sacrifice, target, source.getSourceId(), 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) 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)

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