Search in sources :

Example 91 with TargetControlledPermanent

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

the class ArchfiendOfDepravityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (opponent != null) {
        List<Permanent> creaturesToSacrifice = new ArrayList<>();
        TargetControlledPermanent target = new TargetControlledPermanent(0, 2, new FilterControlledCreaturePermanent("creatures to keep"), true);
        if (opponent.chooseTarget(outcome, target, source, game)) {
            for (Permanent permanent : game.getBattlefield().getActivePermanents(new FilterControlledCreaturePermanent(), opponent.getId(), source.getSourceId(), game)) {
                if (permanent != null && !target.getTargets().contains(permanent.getId())) {
                    creaturesToSacrifice.add(permanent);
                }
            }
        }
        for (Permanent creature : creaturesToSacrifice) {
            creature.sacrifice(source, game);
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ArrayList(java.util.ArrayList) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent)

Example 92 with TargetControlledPermanent

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

the class ReleaseSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<UUID> chosen = new ArrayList<>();
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
        Player player = game.getPlayer(playerId);
        Target target1 = new TargetControlledPermanent(1, 1, new FilterControlledArtifactPermanent(), true);
        Target target2 = new TargetControlledPermanent(1, 1, new FilterControlledCreaturePermanent(), true);
        Target target3 = new TargetControlledPermanent(1, 1, new FilterControlledEnchantmentPermanent(), true);
        Target target4 = new TargetControlledPermanent(1, 1, new FilterControlledLandPermanent(), true);
        Target target5 = new TargetControlledPermanent(1, 1, new FilterControlledPlaneswalkerPermanent(), true);
        if (target1.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target1.isChosen() && target1.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target1, source, game);
            }
            Permanent artifact = game.getPermanent(target1.getFirstTarget());
            if (artifact != null) {
                chosen.add(artifact.getId());
            }
            target1.clearChosen();
        }
        if (target2.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target2.isChosen() && target2.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target2, source, game);
            }
            Permanent creature = game.getPermanent(target2.getFirstTarget());
            if (creature != null) {
                chosen.add(creature.getId());
            }
            target2.clearChosen();
        }
        if (target3.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target3.isChosen() && target3.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target3, source, game);
            }
            Permanent enchantment = game.getPermanent(target3.getFirstTarget());
            if (enchantment != null) {
                chosen.add(enchantment.getId());
            }
            target3.clearChosen();
        }
        if (target4.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target4.isChosen() && target4.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target4, source, game);
            }
            Permanent land = game.getPermanent(target4.getFirstTarget());
            if (land != null) {
                chosen.add(land.getId());
            }
            target4.clearChosen();
        }
        if (target5.canChoose(source.getSourceId(), player.getId(), game)) {
            while (player.canRespond() && !target5.isChosen() && target5.canChoose(source.getSourceId(), player.getId(), game)) {
                player.chooseTarget(Outcome.Benefit, target5, source, game);
            }
            Permanent planeswalker = game.getPermanent(target5.getFirstTarget());
            if (planeswalker != null) {
                chosen.add(planeswalker.getId());
            }
            target5.clearChosen();
        }
    }
    for (UUID uuid : chosen) {
        Permanent permanent = game.getPermanent(uuid);
        if (permanent != null) {
            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) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) TargetPermanent(mage.target.TargetPermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

Example 93 with TargetControlledPermanent

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

the class ClambassadorsEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetControlledPermanent(1, 1, filter, true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game) && controller.canRespond()) {
                controller.chooseTarget(outcome, target, source, game);
            }
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
        if (permanent != null && opponent != null) {
            ContinuousEffect effect = new GainControlTargetEffect(Duration.Custom, true, opponent.getId());
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
            game.informPlayers(opponent.getLogName() + " has gained control of " + permanent.getLogName());
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 94 with TargetControlledPermanent

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

the class ClarionUltimatumTarget method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int permCount = game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_PERMANENT, source.getSourceId(), source.getControllerId(), game);
    TargetPermanent targetPermanent = new TargetControlledPermanent(Math.max(permCount, 5));
    targetPermanent.setNotTarget(true);
    player.choose(outcome, targetPermanent, source.getSourceId(), game);
    Set<String> names = targetPermanent.getTargets().stream().map(game::getCard).filter(Objects::nonNull).map(MageObject::getName).collect(Collectors.toSet());
    TargetCardInLibrary targetCardInLibrary = new ClarionUltimatumTarget(names);
    player.searchLibrary(targetCardInLibrary, source, game);
    Cards cards = new CardsImpl(targetCardInLibrary.getTargets());
    player.moveCards(cards.getCards(game), Zone.BATTLEFIELD, source, game, true, false, false, null);
    player.shuffleLibrary(source, game);
    return true;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPermanent(mage.target.TargetPermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary)

Example 95 with TargetControlledPermanent

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

the class ClackbridgeTrollEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    boolean flag = false;
    for (UUID opponentId : game.getOpponents(controller.getId())) {
        Player opponent = game.getPlayer(opponentId);
        if (opponent == null) {
            continue;
        }
        TargetControlledPermanent target = new TargetControlledPermanent(filter);
        target.setNotTarget(true);
        if (!target.canChoose(source.getSourceId(), opponent.getId(), game) || !opponent.chooseUse(Outcome.AIDontUseIt, "Sacrifice a creature?", source, game) || !opponent.choose(Outcome.Sacrifice, target, source.getSourceId(), game)) {
            continue;
        }
        Permanent permanent = game.getPermanent(target.getFirstTarget());
        if (permanent == null || !permanent.sacrifice(source, game)) {
            continue;
        }
        flag = true;
    }
    if (flag) {
        Permanent sourcePerm = source.getSourcePermanentIfItStillExists(game);
        if (sourcePerm != null) {
            sourcePerm.tap(source, game);
        }
        controller.gainLife(3, game, source);
        controller.drawCards(1, 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) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) UUID(java.util.UUID)

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