Search in sources :

Example 31 with TargetControlledPermanent

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

the class BloodClockEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(targetPointer.getFirst(game, source));
    if (player == null) {
        return false;
    }
    if (player.getLife() > 2 && player.chooseUse(Outcome.Neutral, "Pay 2 life? If you don't, return a permanent you control to its owner's hand.", source, game)) {
        player.loseLife(2, game, source, false);
        game.informPlayers(player.getLogName() + " pays 2 life. They will not return a permanent they control.");
        return true;
    } else {
        Target target = new TargetControlledPermanent();
        if (target.canChoose(source.getSourceId(), player.getId(), game) && player.chooseTarget(outcome, target, source, game)) {
            Permanent permanent = game.getPermanent(target.getFirstTarget());
            if (permanent != null) {
                game.informPlayers(player.getLogName() + " returns " + permanent.getName() + " to hand.");
                return player.moveCards(permanent, Zone.HAND, source, game);
            }
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent)

Example 32 with TargetControlledPermanent

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

the class WormsOfTheEarthDestroyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        Cost cost = new SacrificeTargetCost(new TargetControlledPermanent(2, 2, new FilterControlledLandPermanent("two lands"), false));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                if (player.chooseUse(outcome, "Do you want to destroy " + sourcePermanent.getLogName() + "? (sacrifice two lands or have it deal 5 damage to you)", source, game)) {
                    cost.clearPaid();
                    if (cost.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Sacrifice, "Will you sacrifice two lands? (otherwise you'll be dealt 5 damage)", source, game)) {
                        if (!cost.pay(source, game, source, player.getId(), false, null)) {
                            player.damage(5, source.getSourceId(), source, game);
                        }
                    } else {
                        player.damage(5, source.getSourceId(), source, game);
                    }
                    sourcePermanent = game.getPermanent(source.getSourceId());
                    if (sourcePermanent != null) {
                        sourcePermanent.destroy(source, game, false);
                    }
                    break;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent)

Example 33 with TargetControlledPermanent

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

the class AnnihilatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID defendingPlayerId = (UUID) getValue("defendingPlayerId");
    Player player = null;
    if (defendingPlayerId != null) {
        player = game.getPlayer(defendingPlayerId);
    }
    if (player != null) {
        int amount = Math.min(count, game.getBattlefield().countAll(new FilterControlledPermanent(), player.getId(), game));
        if (amount > 0) {
            Target target = new TargetControlledPermanent(amount, amount, new FilterControlledPermanent(), true);
            if (target.canChoose(source.getSourceId(), player.getId(), game)) {
                while (player.canRespond() && target.canChoose(source.getSourceId(), player.getId(), game) && !target.isChosen()) {
                    player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
                }
                target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> permanent.sacrifice(source, game));
            }
            return true;
        }
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

Example 34 with TargetControlledPermanent

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

the class NahiriTheLithomancerSecondAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Token token = new KorSoldierToken();
        if (token.putOntoBattlefield(1, game, source, source.getControllerId())) {
            for (UUID tokenId : token.getLastAddedTokenIds()) {
                Permanent tokenPermanent = game.getPermanent(tokenId);
                if (tokenPermanent != null) {
                    // TODO: Make sure the Equipment can legally enchant the token, preferably on targetting.
                    Target target = new TargetControlledPermanent(0, 1, filter, true);
                    if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Attach an Equipment you control to the created " + tokenPermanent.getIdName() + '?', source, game)) {
                        if (target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
                            Permanent equipmentPermanent = game.getPermanent(target.getFirstTarget());
                            if (equipmentPermanent != null) {
                                Permanent attachedTo = game.getPermanent(equipmentPermanent.getAttachedTo());
                                if (attachedTo != null) {
                                    attachedTo.removeAttachment(equipmentPermanent.getId(), source, game);
                                }
                                tokenPermanent.addAttachment(equipmentPermanent.getId(), source, game);
                            }
                        }
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) KorSoldierToken(mage.game.permanent.token.KorSoldierToken) NahiriTheLithomancerEquipmentToken(mage.game.permanent.token.NahiriTheLithomancerEquipmentToken) Token(mage.game.permanent.token.Token) UUID(java.util.UUID)

Example 35 with TargetControlledPermanent

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

the class PlaguecrafterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    List<UUID> perms = new ArrayList<>();
    List<UUID> cantSac = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        FilterControlledPermanent filter = new FilterControlledPermanent("creature or planeswalker");
        filter.add(Predicates.or(CardType.CREATURE.getPredicate(), CardType.PLANESWALKER.getPredicate()));
        TargetControlledPermanent target = new TargetControlledPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), player.getId(), game)) {
            while (!target.isChosen() && player.canRespond()) {
                player.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            }
            perms.addAll(target.getTargets());
        } else {
            cantSac.add(playerId);
        }
    }
    for (UUID permID : perms) {
        Permanent permanent = game.getPermanent(permID);
        if (permanent != null) {
            permanent.sacrifice(source, game);
        }
    }
    for (UUID playerId : cantSac) {
        Effect discardEffect = new DiscardTargetEffect(1);
        discardEffect.setTargetPointer(new FixedTarget(playerId, game));
        discardEffect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) DiscardTargetEffect(mage.abilities.effects.common.discard.DiscardTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent)

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