Search in sources :

Example 21 with Target

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

the class MurmursFromBeyondEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (sourceObject != null && controller != null) {
        Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
        if (!cards.isEmpty()) {
            controller.revealCards(staticText, cards, game);
            Card cardToGraveyard;
            if (cards.size() == 1) {
                cardToGraveyard = cards.getRandom(game);
            } else {
                Player opponent;
                Set<UUID> opponents = game.getOpponents(controller.getId());
                if (opponents.size() == 1) {
                    opponent = game.getPlayer(opponents.iterator().next());
                } else {
                    Target target = new TargetOpponent(true);
                    controller.chooseTarget(Outcome.Detriment, target, source, game);
                    opponent = game.getPlayer(target.getFirstTarget());
                }
                TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
                opponent.chooseTarget(outcome, cards, target, source, game);
                cardToGraveyard = game.getCard(target.getFirstTarget());
            }
            if (cardToGraveyard != null) {
                controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
                cards.remove(cardToGraveyard);
            }
            controller.moveCards(cards, Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard)

Example 22 with Target

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

the class AwakenElementalToken method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID targetId = null;
    for (Target target : source.getTargets()) {
        targetId = target.getFirstTarget();
    }
    if (targetId != null) {
        FixedTarget fixedTarget = new FixedTarget(targetId, game);
        ContinuousEffect continuousEffect = new BecomesCreatureTargetEffect(new AwakenElementalToken(), false, true, Duration.EndOfGame);
        continuousEffect.setTargetPointer(fixedTarget);
        game.addEffect(continuousEffect, source);
        Effect effect = new AddCountersTargetEffect(CounterType.P1P1.createInstance(3));
        effect.setTargetPointer(fixedTarget);
        return effect.apply(game, source);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) BecomesCreatureTargetEffect(mage.abilities.effects.common.continuous.BecomesCreatureTargetEffect) Effect(mage.abilities.effects.Effect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 23 with Target

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

the class PurgingScytheEffect 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) {
        int leastToughness = Integer.MAX_VALUE;
        boolean multipleExist = false;
        Permanent permanentToDamage = null;
        for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURES, source.getControllerId(), game)) {
            if (permanent.getToughness().getValue() < leastToughness) {
                permanentToDamage = permanent;
                leastToughness = permanent.getToughness().getValue();
                multipleExist = false;
            } else {
                if (permanent.getToughness().getValue() == leastToughness) {
                    multipleExist = true;
                }
            }
        }
        if (multipleExist) {
            FilterCreaturePermanent filter = new FilterCreaturePermanent("one of the creatures with the least toughness");
            filter.add(new ToughnessPredicate(ComparisonType.EQUAL_TO, leastToughness));
            Target target = new TargetPermanent(filter);
            target.setNotTarget(true);
            if (target.canChoose(source.getSourceId(), source.getControllerId(), game)) {
                if (controller.choose(outcome, target, source.getSourceId(), game)) {
                    permanentToDamage = game.getPermanent(target.getFirstTarget());
                }
            }
        }
        if (permanentToDamage != null) {
            game.informPlayers(sourcePermanent.getName() + " chosen creature: " + permanentToDamage.getName());
            return permanentToDamage.damage(2, source.getSourceId(), source, game, false, true) > 0;
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ToughnessPredicate(mage.filter.predicate.mageobject.ToughnessPredicate) Target(mage.target.Target) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 24 with Target

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

the class RescuerSphinxEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    if (!player.chooseUse(outcome, "Return a nonland permanent you control to your hand?", source, game)) {
        return false;
    }
    Target target = new TargetPermanent(0, 1, filter, true);
    if (!player.choose(outcome, target, source.getSourceId(), game)) {
        return false;
    }
    Permanent permanent = game.getPermanent(target.getFirstTarget());
    if (permanent == null || !player.moveCards(permanent, Zone.HAND, source, game)) {
        return false;
    }
    return new AddCountersSourceEffect(CounterType.P1P1.createInstance()).apply(game, source);
}
Also used : AddCountersSourceEffect(mage.abilities.effects.common.counter.AddCountersSourceEffect) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent)

Example 25 with Target

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

the class SeismicWaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Targets targets = source.getTargets();
    if (targets.size() < 2) {
        return false;
    }
    UUID firstTarget = targets.get(0).getFirstTarget();
    if (firstTarget != null) {
        Permanent targetPermanent = game.getPermanent(firstTarget);
        if (targetPermanent != null) {
            targetPermanent.damage(2, source, game);
        } else {
            Player targetPlayer = game.getPlayer(firstTarget);
            if (targetPlayer != null) {
                targetPlayer.damage(2, source, game);
            }
        }
    }
    Target targetOpponent = targets.get(1);
    UUID opponentId = targetOpponent.getFirstTarget();
    if (opponentId != null && targetOpponent.isLegal(source, game)) {
        // Needs this check in case opponent gets hexproof at instant speed
        for (Permanent permanent : game.getBattlefield().getAllActivePermanents(filter, opponentId, game)) {
            permanent.damage(1, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetAnyTarget(mage.target.common.TargetAnyTarget) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Targets(mage.target.Targets) UUID(java.util.UUID)

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