Search in sources :

Example 91 with Target

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

the class OracleOfBonesCastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetCardInHand(filter);
        if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast an instant or sorcery " + "card from your hand without paying its mana cost?", source, game)) {
            Card cardToCast = null;
            boolean cancel = false;
            while (controller.canRespond() && !cancel) {
                if (controller.chooseTarget(outcome, target, source, game)) {
                    cardToCast = game.getCard(target.getFirstTarget());
                    if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
                        cancel = true;
                    }
                } else {
                    cancel = true;
                }
            }
            if (cardToCast != null) {
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
                controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
                game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ApprovingObject(mage.ApprovingObject) TargetCardInHand(mage.target.common.TargetCardInHand) FilterCard(mage.filter.FilterCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

Example 92 with Target

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

the class SixyBeastEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanentEntering(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent != null && controller != null) {
        int counterAmount = controller.getAmount(0, 6, "Secretly put up to six counters on " + permanent.getName(), game);
        permanent.addCounters(CounterType.P1P1.createInstance(counterAmount), source.getControllerId(), source, game);
        Player opponent = null;
        Set<UUID> opponents = game.getOpponents(source.getControllerId());
        if (!opponents.isEmpty()) {
            if (opponents.size() > 1) {
                Target targetOpponent = new TargetOpponent(true);
                if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                    opponent = game.getPlayer(targetOpponent.getFirstTarget());
                }
            } else {
                opponent = game.getPlayer(opponents.iterator().next());
            }
        }
        if (opponent != null) {
            int guessedAmount = opponent.getAmount(0, 6, "Guess the number of counters on " + permanent.getName(), game);
            game.informPlayers(opponent.getLogName() + " guessed " + guessedAmount + " as the number of counters on " + permanent.getLogName());
            if (counterAmount == guessedAmount) {
                permanent.sacrifice(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID)

Example 93 with Target

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

the class StonehewerGiantEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    FilterCard filter = new FilterCard("Equipment");
    filter.add(SubType.EQUIPMENT.getPredicate());
    TargetCardInLibrary target = new TargetCardInLibrary(filter);
    if (controller.searchLibrary(target, source, game)) {
        Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
        if (card != null) {
            controller.moveCards(card, Zone.BATTLEFIELD, source, game);
            Permanent equipment = game.getPermanent(card.getId());
            Target targetCreature = new TargetControlledCreaturePermanent();
            targetCreature.setNotTarget(true);
            if (equipment != null && controller.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
                Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
                permanent.addAttachment(equipment.getId(), source, game);
            }
        }
    }
    controller.shuffleLibrary(source, game);
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 94 with Target

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

the class TormentOfVenomEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (targetCreature != null) {
        new AddCountersTargetEffect(CounterType.M1M1.createInstance(3)).apply(game, source);
        Player controllingPlayer = game.getPlayer(targetCreature.getControllerId());
        if (controllingPlayer != null) {
            int permanents = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_NON_LAND, controllingPlayer.getId(), game);
            if (permanents > 0 && controllingPlayer.chooseUse(outcome, "Sacrifices a nonland permanent?", "Otherwise you have to discard a card or lose 3 life.", "Sacrifice", "Discard or life loss", source, game)) {
                FilterPermanent filter = new FilterControlledPermanent("another nonland permanent");
                filter.add(Predicates.not(CardType.LAND.getPredicate()));
                filter.add(Predicates.not(new PermanentIdPredicate(targetCreature.getId())));
                Target target = new TargetPermanent(filter);
                if (controllingPlayer.choose(outcome, target, source.getSourceId(), game)) {
                    Permanent permanent = game.getPermanent(target.getFirstTarget());
                    if (permanent != null) {
                        permanent.sacrifice(source, game);
                        return true;
                    }
                }
            }
            if (!controllingPlayer.getHand().isEmpty() && controllingPlayer.chooseUse(outcome, "Discard a card?", "Otherwise you lose 3 life.", "Discard", "Lose 3 life", source, game)) {
                controllingPlayer.discardOne(false, false, source, game);
                return true;
            }
            controllingPlayer.loseLife(3, game, source, false);
            return true;
        }
    }
    return false;
}
Also used : PermanentIdPredicate(mage.filter.predicate.permanent.PermanentIdPredicate) Player(mage.players.Player) Target(mage.target.Target) FilterPermanent(mage.filter.FilterPermanent) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect)

Example 95 with Target

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

the class FatesealEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Target target = new TargetOpponent(true);
        if (controller.choose(outcome, target, source.getSourceId(), game)) {
            Player opponent = game.getPlayer(target.getFirstTarget());
            if (opponent == null) {
                return false;
            }
            // by looking at the cards with fateseal you have not to reveal the next card
            boolean revealed = opponent.isTopCardRevealed();
            opponent.setTopCardRevealed(false);
            Cards cards = new CardsImpl();
            int count = Math.min(fatesealNumber, opponent.getLibrary().size());
            if (count == 0) {
                return true;
            }
            for (int i = 0; i < count; i++) {
                Card card = opponent.getLibrary().removeFromTop(game);
                cards.add(card);
            }
            TargetCard target1 = new TargetCard(Zone.LIBRARY, filter1);
            target1.setRequired(false);
            // move cards to the bottom of the library
            while (!cards.isEmpty() && controller.choose(Outcome.Detriment, cards, target1, game)) {
                if (!controller.canRespond() || !opponent.canRespond()) {
                    return false;
                }
                Card card = cards.get(target1.getFirstTarget(), game);
                if (card != null) {
                    cards.remove(card);
                    controller.moveCardToLibraryWithInfo(card, source, game, Zone.LIBRARY, false, false);
                }
                target1.clearChosen();
            }
            // move cards to the top of the library
            controller.putCardsOnTopOfLibrary(cards, game, source, true);
            game.fireEvent(new GameEvent(GameEvent.EventType.FATESEALED, opponent.getId(), source, source.getControllerId()));
            controller.setTopCardRevealed(revealed);
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) TargetOpponent(mage.target.common.TargetOpponent) GameEvent(mage.game.events.GameEvent) TargetCard(mage.target.TargetCard) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

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