Search in sources :

Example 36 with TargetControlledPermanent

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

the class ShattergangBrothersEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (!Objects.equals(playerId, source.getControllerId())) {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    TargetControlledPermanent target = new TargetControlledPermanent(filter);
                    target.setNotTarget(true);
                    if (target.canChoose(source.getSourceId(), playerId, game) && player.chooseTarget(outcome, target, source, game)) {
                        Permanent permanent = game.getPermanent(target.getFirstTarget());
                        if (permanent != null) {
                            permanent.sacrifice(source, game);
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) UUID(java.util.UUID)

Example 37 with TargetControlledPermanent

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

the class AetherbornMarauderEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanent(source.getSourceId());
    if (controller != null && sourceObject != null) {
        FilterControlledPermanent filter = new FilterControlledPermanent("permanent you control to remove +1/+1 counters from");
        filter.add(AnotherPredicate.instance);
        filter.add(CounterType.P1P1.getPredicate());
        boolean firstRun = true;
        while (game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game) > 0) {
            if (controller.chooseUse(outcome, "Move " + (firstRun ? "any" : "more") + " +1/+1 counters from other permanents you control to " + sourceObject.getLogName() + '?', source, game)) {
                firstRun = false;
                TargetControlledPermanent target = new TargetControlledPermanent(filter);
                target.setNotTarget(true);
                if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                    Permanent fromPermanent = game.getPermanent(target.getFirstTarget());
                    if (fromPermanent != null) {
                        int numberOfCounters = fromPermanent.getCounters(game).getCount(CounterType.P1P1);
                        int numberToMove = 1;
                        if (numberOfCounters > 1) {
                            numberToMove = controller.getAmount(0, numberOfCounters, "Choose how many +1/+1 counters to move", game);
                        }
                        if (numberToMove > 0) {
                            fromPermanent.removeCounters(CounterType.P1P1.createInstance(numberToMove), source, game);
                            sourceObject.addCounters(CounterType.P1P1.createInstance(numberToMove), source.getControllerId(), source, game);
                        }
                    }
                }
            } else {
                break;
            }
        }
        return true;
    }
    return false;
}
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) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 38 with TargetControlledPermanent

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

the class BaneOfBalaGedEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player defendingPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (defendingPlayer != null) {
        Target target = new TargetControlledPermanent(2);
        defendingPlayer.chooseTarget(outcome, target, source, game);
        Set<Card> toExile = target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).collect(Collectors.toSet());
        defendingPlayer.moveCards(toExile, Zone.EXILED, source, game);
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Card(mage.cards.Card)

Example 39 with TargetControlledPermanent

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

the class BurningOfXinyeEffect method playerDestroys.

public boolean playerDestroys(Game game, Ability source, Player player) {
    boolean abilityApplied = false;
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    int amount = Math.min(4, realCount);
    Target target = new TargetControlledPermanent(amount, amount, filter, true);
    if (amount > 0 && target.canChoose(source.getSourceId(), player.getId(), game)) {
        while (!target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game) && player.canRespond()) {
            player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
        }
        for (int idx = 0; idx < target.getTargets().size(); idx++) {
            Permanent permanent = game.getPermanent(target.getTargets().get(idx));
            if (permanent != null) {
                abilityApplied |= permanent.destroy(source, game, false);
            }
        }
    }
    return abilityApplied;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 40 with TargetControlledPermanent

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

the class ChainOfVaporEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        controller.moveCards(permanent, Zone.HAND, source, game);
        Player player = game.getPlayer(permanent.getControllerId());
        TargetControlledPermanent target = new TargetControlledPermanent(0, 1, new FilterControlledLandPermanent("a land to sacrifice (to be able to copy " + sourceObject.getName() + ')'), true);
        if (player != null && player.chooseTarget(Outcome.Sacrifice, target, source, game)) {
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null && land.sacrifice(source, game)) {
                if (player.chooseUse(outcome, "Copy the spell?", source, game)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, player.getId(), true);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) MageObject(mage.MageObject) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Spell(mage.game.stack.Spell)

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