Search in sources :

Example 56 with TargetControlledPermanent

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

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

the class RustElementalEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (sourceObject != null) {
        // create cost for sacrificing an artifact
        Player controller = game.getPlayer(source.getControllerId());
        if (controller != null) {
            TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
            // if they can pay the cost, then they must pay
            if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
                controller.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                Permanent artifactSacrifice = game.getPermanent(target.getFirstTarget());
                if (artifactSacrifice != null) {
                    // sacrifice the chosen artifact
                    artifactSacrifice.sacrifice(source, game);
                }
            } else {
                sourceObject.tap(source, game);
                controller.damage(4, source.getSourceId(), source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledArtifactPermanent(mage.filter.common.FilterControlledArtifactPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 58 with TargetControlledPermanent

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

the class SunkenHopeReturnToHandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    boolean result = false;
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
    if (target.canChoose(source.getSourceId(), player.getId(), game)) {
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.chooseTarget(Outcome.ReturnToHand, target, source, game);
        }
        for (UUID targetId : target.getTargets()) {
            Permanent permanent = game.getPermanent(targetId);
            if (permanent != null) {
                result |= player.moveCards(permanent, Zone.HAND, source, game);
            }
        }
    }
    return result;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) UUID(java.util.UUID)

Example 59 with TargetControlledPermanent

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

the class TangleWireEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    int targetCount = game.getBattlefield().countAll(filter, player.getId(), game);
    int counterCount = permanent.getCounters(game).getCount(CounterType.FADE);
    int amount = Math.min(counterCount, targetCount);
    Target target = new TargetControlledPermanent(amount, amount, filter, true);
    target.setNotTarget(true);
    if (amount > 0 && player.chooseTarget(Outcome.Tap, target, source, game)) {
        boolean abilityApplied = false;
        for (UUID uuid : target.getTargets()) {
            Permanent selectedPermanent = game.getPermanent(uuid);
            if (selectedPermanent != null) {
                abilityApplied |= selectedPermanent.tap(source, game);
            }
        }
        return abilityApplied;
    }
    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) UUID(java.util.UUID)

Example 60 with TargetControlledPermanent

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

the class EntrapmentManeuverSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
    filter.add(AttackingPredicate.instance);
    int realCount = game.getBattlefield().countAll(filter, player.getId(), game);
    if (realCount > 0) {
        Target target = new TargetControlledPermanent(1, 1, filter, true);
        while (player.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.chooseTarget(Outcome.Sacrifice, target, source, game);
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent != null) {
            int amount = permanent.getToughness().getValue();
            permanent.sacrifice(source, game);
            new CreateTokenEffect(new SoldierToken(), amount).apply(game, source);
        } else {
            return false;
        }
    }
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) SoldierToken(mage.game.permanent.token.SoldierToken) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

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