Search in sources :

Example 21 with FilterControlledPermanent

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

the class MalakirBloodwitchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    FilterControlledPermanent filter = new FilterControlledPermanent("Vampire");
    filter.add(SubType.VAMPIRE.getPredicate());
    int amount = game.getBattlefield().countAll(filter, source.getControllerId(), game);
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    int total = 0;
    for (UUID opponentUuid : opponents) {
        Player opponent = game.getPlayer(opponentUuid);
        if (opponent != null) {
            total += opponent.loseLife(amount, game, source, false);
        }
    }
    if (total > 0) {
        player.gainLife(total, game, source);
    }
    return true;
}
Also used : Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) UUID(java.util.UUID)

Example 22 with FilterControlledPermanent

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

the class OrvarTheAllFormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = (Spell) this.getValue("spellCast");
    if (player == null || spell == null) {
        return false;
    }
    List<Predicate<Permanent>> predicates = spell.getSpellAbility().getModes().values().stream().map(Mode::getTargets).flatMap(Collection::stream).map(Target::getTargets).flatMap(Collection::stream).map(game::getPermanent).filter(Objects::nonNull).map(MageItem::getId).map(PermanentIdPredicate::new).collect(Collectors.toList());
    if (predicates.isEmpty()) {
        return false;
    }
    FilterPermanent filter = new FilterControlledPermanent("a permanent you control targeted by that spell");
    filter.add(Predicates.or(predicates));
    filter.add(Predicates.not(new MageObjectReferencePredicate(new MageObjectReference(source))));
    TargetPermanent target = new TargetPermanent(filter);
    target.setNotTarget(true);
    player.choose(outcome, target, source.getSourceId(), game);
    return new CreateTokenCopyTargetEffect().setTargetPointer(new FixedTarget(target.getFirstTarget(), game)).apply(game, source);
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Mode(mage.abilities.Mode) MageItem(mage.MageItem) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Spell(mage.game.stack.Spell) PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Predicate(mage.filter.predicate.Predicate) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) MageObjectReferencePredicate(mage.filter.predicate.mageobject.MageObjectReferencePredicate) TargetPermanent(mage.target.TargetPermanent) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) MageObjectReference(mage.MageObjectReference)

Example 23 with FilterControlledPermanent

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

the class RaziasPurificationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<Card> chosen = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledPermanent(), true);
        if (player != null && target1.canChoose(source.getSourceId(), player.getId(), game)) {
            int chosenPermanents = 0;
            while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game) && chosenPermanents < 3) {
                player.chooseTarget(Outcome.Benefit, target1, source, game);
                for (UUID targetId : target1.getTargets()) {
                    Permanent p = game.getPermanent(targetId);
                    if (p != null) {
                        chosen.add(p);
                        chosenPermanents++;
                    }
                }
                target1.clearChosen();
            }
        }
    }
    for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
        if (!chosen.contains(permanent)) {
            permanent.sacrifice(source, game);
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Card(mage.cards.Card)

Example 24 with FilterControlledPermanent

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

the class ReadTheRunesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        int drawnCards = controller.drawCards(source.getManaCostsToPay().getX(), source, game);
        Target target = new TargetControlledPermanent(0, drawnCards, new FilterControlledPermanent(), true);
        controller.chooseTarget(Outcome.Sacrifice, target, source, game);
        int sacrificedPermanents = 0;
        for (UUID permanentId : target.getTargets()) {
            Permanent permanent = game.getPermanent(permanentId);
            if (permanent != null) {
                if (permanent.sacrifice(source, game)) {
                    sacrificedPermanents++;
                }
            }
        }
        controller.discard(drawnCards - sacrificedPermanents, false, false, source, game);
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) 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 25 with FilterControlledPermanent

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

the class TouchOfTheEternalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    FilterControlledPermanent filter = new FilterControlledPermanent();
    Player player = game.getPlayer(source.getControllerId());
    int permanentsInPlay = game.getBattlefield().countAll(filter, source.getControllerId(), game);
    if (player != null) {
        player.setLife(permanentsInPlay, game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) 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