Search in sources :

Example 26 with Target

use of mage.target.Target in project mage by magefree.

the class SlaughterTheStrongEffect 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)) {
            Player player = game.getPlayer(playerId);
            if (player != null) {
                boolean selectionDone = false;
                Set<UUID> selectedCreatures = new HashSet<>();
                while (player.canRespond() && selectionDone == false) {
                    int powerSum = 0;
                    for (UUID creatureId : selectedCreatures) {
                        Permanent creature = game.getPermanent(creatureId);
                        if (creature != null) {
                            powerSum += creature.getPower().getValue();
                        }
                    }
                    FilterControlledCreaturePermanent currentFilter = new FilterControlledCreaturePermanent("any number of creatures you control with total power 4 or less (already selected total power " + powerSum + ")");
                    Set<PermanentIdPredicate> alreadySelectedCreatures = new HashSet<>();
                    if (!selectedCreatures.isEmpty()) {
                        for (UUID creatureId : selectedCreatures) {
                            alreadySelectedCreatures.add(new PermanentIdPredicate(creatureId));
                        }
                        currentFilter.add(Predicates.or(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum), Predicates.or(alreadySelectedCreatures)));
                    } else {
                        currentFilter.add(new PowerPredicate(ComparisonType.FEWER_THAN, 5 - powerSum));
                    }
                    // human can de-select targets, but AI must choose only one time
                    Target target;
                    if (player.isComputer()) {
                        // AI settings
                        FilterControlledCreaturePermanent strictFilter = currentFilter.copy();
                        selectedCreatures.stream().forEach(id -> {
                            strictFilter.add(Predicates.not(new PermanentIdPredicate(id)));
                        });
                        target = new TargetPermanent(0, 1, strictFilter, true);
                    } else {
                        // Human settings
                        target = new TargetPermanent(0, 1, currentFilter, true);
                    }
                    player.chooseTarget(Outcome.BoostCreature, target, source, game);
                    if (target.getFirstTarget() != null) {
                        if (selectedCreatures.contains(target.getFirstTarget())) {
                            selectedCreatures.remove(target.getFirstTarget());
                        } else {
                            selectedCreatures.add(target.getFirstTarget());
                        }
                    } else {
                        if (player.isComputer()) {
                            // AI stops
                            selectionDone = true;
                        } else {
                            // Human can continue
                            String selected = "Selected: ";
                            for (UUID creatureId : selectedCreatures) {
                                Permanent creature = game.getPermanent(creatureId);
                                if (creature != null) {
                                    selected += creature.getLogName() + " ";
                                }
                            }
                            selectionDone = player.chooseUse(Outcome.Detriment, "Creature selection", selected, "End the selection", "Continue the selection", source, game);
                        }
                    }
                }
                for (Permanent creature : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, playerId, game)) {
                    if (!selectedCreatures.contains(creature.getId())) {
                        creature.sacrifice(source, game);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) PowerPredicate(mage.filter.predicate.mageobject.PowerPredicate) Target(mage.target.Target) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 27 with Target

use of mage.target.Target in project mage by magefree.

the class SkyfireKirinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = null;
    for (Target target : source.getTargets()) {
        if (target instanceof TargetPermanent) {
            targetCreature = game.getPermanent(target.getFirstTarget());
        }
    }
    if (targetCreature != null) {
        ContinuousEffect effect = new GainControlTargetEffect(Duration.EndOfTurn);
        effect.setTargetPointer(new FixedTarget(targetCreature.getId(), game));
        game.addEffect(effect, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) ContinuousEffect(mage.abilities.effects.ContinuousEffect) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect)

Example 28 with Target

use of mage.target.Target in project mage by magefree.

the class SuddenReclamationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cardsToHand = new CardsImpl();
        Target target = new TargetCardInYourGraveyard(StaticFilters.FILTER_CARD_CREATURE_YOUR_GRAVEYARD);
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                cardsToHand.add(card);
            }
        }
        target = new TargetCardInYourGraveyard(new FilterLandCard("land card from your graveyard"));
        target.setNotTarget(true);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseTarget(outcome, target, source, game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                cardsToHand.add(card);
            }
        }
        controller.moveCards(cardsToHand, Zone.HAND, source, game);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) FilterLandCard(mage.filter.common.FilterLandCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterLandCard(mage.filter.common.FilterLandCard) Card(mage.cards.Card)

Example 29 with Target

use of mage.target.Target in project mage by magefree.

the class SunderingTitanDestroyLandEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Set<UUID> lands = new HashSet<>();
    if (controller != null && sourcePermanent != null) {
        for (SubType landName : SubType.getBasicLands()) {
            FilterLandPermanent filter = new FilterLandPermanent(landName + " to destroy");
            filter.add(landName.getPredicate());
            Target target = new TargetLandPermanent(1, 1, filter, true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                controller.chooseTarget(outcome, target, source, game);
                lands.add(target.getFirstTarget());
            }
        }
        if (!lands.isEmpty()) {
            int destroyedLands = 0;
            for (UUID landId : lands) {
                Permanent land = game.getPermanent(landId);
                if (land != null) {
                    if (land.destroy(source, game, false)) {
                        destroyedLands++;
                    }
                }
            }
            game.informPlayers(sourcePermanent.getLogName() + ": " + destroyedLands + (destroyedLands > 1 ? " lands were" : "land was") + " destroyed");
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) SubType(mage.constants.SubType) FilterLandPermanent(mage.filter.common.FilterLandPermanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) FilterLandPermanent(mage.filter.common.FilterLandPermanent) Permanent(mage.game.permanent.Permanent) TargetLandPermanent(mage.target.common.TargetLandPermanent) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 30 with Target

use of mage.target.Target in project mage by magefree.

the class TheFirstEruptionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Target target = new TargetControlledPermanent(1, 1, filter, false);
    boolean sacrificed = false;
    if (target.canChoose(source.getSourceId(), controller.getId(), game)) {
        while (controller.canRespond() && !target.isChosen() && target.canChoose(source.getSourceId(), controller.getId(), game)) {
            controller.chooseTarget(Outcome.Sacrifice, target, source, game);
        }
        for (int idx = 0; idx < target.getTargets().size(); idx++) {
            Permanent permanent = game.getPermanent(target.getTargets().get(idx));
            if (permanent != null) {
                sacrificed |= permanent.sacrifice(source, game);
            }
        }
    }
    if (sacrificed) {
        return new DamageAllEffect(3, StaticFilters.FILTER_PERMANENT_CREATURE).apply(game, source);
    }
    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) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) DamageAllEffect(mage.abilities.effects.common.DamageAllEffect)

Aggregations

Target (mage.target.Target)385 Player (mage.players.Player)291 Permanent (mage.game.permanent.Permanent)223 UUID (java.util.UUID)155 Card (mage.cards.Card)86 TargetPermanent (mage.target.TargetPermanent)80 FilterCard (mage.filter.FilterCard)62 FilterPermanent (mage.filter.FilterPermanent)56 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)54 FixedTarget (mage.target.targetpointer.FixedTarget)49 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)45 TargetControlledPermanent (mage.target.common.TargetControlledPermanent)45 MageObject (mage.MageObject)43 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)42 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 TargetOpponent (mage.target.common.TargetOpponent)35 CardsImpl (mage.cards.CardsImpl)32 ArrayList (java.util.ArrayList)31 ContinuousEffect (mage.abilities.effects.ContinuousEffect)31 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)30