Search in sources :

Example 66 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class InvokeDespairEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    if (opponent == null || controller == null) {
        return false;
    }
    Target target = new TargetControlledCreaturePermanent();
    target.setNotTarget(true);
    opponent.choose(outcome, target, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    boolean sacrificed = false;
    if (permanent != null) {
        sacrificed = permanent.sacrifice(source, game);
    }
    if (!sacrificed) {
        opponent.loseLife(2, game, source, false);
        controller.drawCards(1, source, game);
    }
    target = new TargetControlledPermanent(enchantmentFilter);
    target.setNotTarget(true);
    opponent.choose(outcome, target, source.getSourceId(), game);
    permanent = game.getPermanent(target.getFirstTarget());
    sacrificed = false;
    if (permanent != null) {
        sacrificed = permanent.sacrifice(source, game);
    }
    if (!sacrificed) {
        opponent.loseLife(2, game, source, false);
        controller.drawCards(1, source, game);
    }
    target = new TargetControlledPermanent(StaticFilters.FILTER_CONTROLLED_PERMANENT_PLANESWALKER);
    target.setNotTarget(true);
    opponent.choose(outcome, target, source.getSourceId(), game);
    permanent = game.getPermanent(target.getFirstTarget());
    sacrificed = false;
    if (permanent != null) {
        sacrificed = permanent.sacrifice(source, game);
    }
    if (!sacrificed) {
        opponent.loseLife(2, game, source, false);
        controller.drawCards(1, source, game);
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FilterControlledEnchantmentPermanent(mage.filter.common.FilterControlledEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent)

Example 67 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent 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 68 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent 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)

Example 69 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class ReprocessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int amount = 0;
    TargetControlledPermanent toSacrifice = new TargetControlledPermanent(0, Integer.MAX_VALUE, filter, true);
    if (player.chooseTarget(Outcome.Sacrifice, toSacrifice, source, game)) {
        for (UUID uuid : toSacrifice.getTargets()) {
            Permanent permanent = game.getPermanent(uuid);
            if (permanent != null) {
                permanent.sacrifice(source, game);
                amount++;
            }
        }
        player.drawCards(amount, source, game);
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID)

Example 70 with TargetControlledPermanent

use of mage.target.common.TargetControlledPermanent in project mage by magefree.

the class ShivanWumpusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        boolean costPaid = false;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(new FilterControlledLandPermanent()));
            Player player = game.getPlayer(playerId);
            if (player != null && cost.canPay(source, source, playerId, game) && player.chooseUse(Outcome.Sacrifice, "Sacrifice a land?", source, game) && cost.pay(source, game, source, playerId, true, null)) {
                costPaid = true;
            }
        }
        if (costPaid) {
            super.apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Aggregations

TargetControlledPermanent (mage.target.common.TargetControlledPermanent)100 Player (mage.players.Player)94 Permanent (mage.game.permanent.Permanent)87 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)49 UUID (java.util.UUID)47 Target (mage.target.Target)45 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)23 Card (mage.cards.Card)17 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)16 ArrayList (java.util.ArrayList)13 TargetPermanent (mage.target.TargetPermanent)13 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)10 FilterCard (mage.filter.FilterCard)10 TargetPlayer (mage.target.TargetPlayer)10 FilterPermanent (mage.filter.FilterPermanent)8 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)8 Cost (mage.abilities.costs.Cost)7 FilterControlledArtifactPermanent (mage.filter.common.FilterControlledArtifactPermanent)7 TargetCardInHand (mage.target.common.TargetCardInHand)6 OneShotEffect (mage.abilities.effects.OneShotEffect)5