Search in sources :

Example 11 with TargetOpponent

use of mage.target.common.TargetOpponent 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 12 with TargetOpponent

use of mage.target.common.TargetOpponent 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)

Example 13 with TargetOpponent

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

the class AkroanHorseCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Target target = new TargetOpponent();
    target.setNotTarget(true);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.chooseTarget(outcome, target, source, game)) {
            ContinuousEffect effect = new AkroanHorseGainControlEffect(Duration.Custom, target.getFirstTarget());
            effect.setTargetPointer(new FixedTarget(source.getSourceId(), 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) TargetOpponent(mage.target.common.TargetOpponent) Player(mage.players.Player) ContinuousEffect(mage.abilities.effects.ContinuousEffect)

Example 14 with TargetOpponent

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

the class EcologicalAppreciationEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    FilterCard filter = new FilterCreatureCard();
    filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, xValue + 1));
    TargetCard targetCardsInLibrary = new TargetCardInLibrary(0, 4, filter) {

        @Override
        public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
            if (!super.canTarget(playerId, id, source, game)) {
                return false;
            }
            Card card = game.getCard(id);
            Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
            return isValidTarget(card, disallowedCards);
        }
    };
    targetCardsInLibrary.setNotTarget(true);
    targetCardsInLibrary.withChooseHint("Step 1 of 2: Search library");
    player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getLibrary().getCards(game)), targetCardsInLibrary, game);
    Cards cards = new CardsImpl(targetCardsInLibrary.getTargets());
    boolean status = !cards.isEmpty();
    if (status) {
        int remainingCards = 4 - cards.size();
        if (remainingCards > 0) {
            TargetCard targetCardsInGY = new TargetCardInYourGraveyard(0, remainingCards, filter) {

                @Override
                public boolean canTarget(UUID playerId, UUID id, Ability source, Game game) {
                    if (!super.canTarget(playerId, id, source, game)) {
                        return false;
                    }
                    Card card = game.getCard(id);
                    Set<Card> disallowedCards = this.getTargets().stream().map(game::getCard).collect(Collectors.toSet());
                    Set<Card> checkList = new HashSet<>();
                    checkList.addAll(disallowedCards);
                    checkList.addAll(cards.getCards(game));
                    return isValidTarget(card, checkList);
                }
            };
            targetCardsInGY.setNotTarget(true);
            targetCardsInGY.withChooseHint("Step 2 of 2: Search graveyard");
            player.choose(Outcome.PutCreatureInPlay, new CardsImpl(player.getGraveyard().getCards(game)), targetCardsInGY, game);
            cards.addAll(targetCardsInGY.getTargets());
        }
        TargetOpponent targetOpponent = new TargetOpponent();
        targetOpponent.setNotTarget(true);
        player.choose(outcome, targetOpponent, source.getSourceId(), game);
        Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
        if (opponent == null) {
            status = false;
        }
        if (status) {
            TargetCard chosenCards = new TargetCard(2, Zone.ALL, StaticFilters.FILTER_CARD);
            chosenCards.setNotTarget(true);
            opponent.choose(outcome, cards, chosenCards, game);
            Cards toShuffle = new CardsImpl(chosenCards.getTargets().stream().map(game::getCard).collect(Collectors.toList()));
            player.putCardsOnTopOfLibrary(toShuffle, game, source, false);
            cards.removeAll(toShuffle);
            player.moveCards(cards, Zone.BATTLEFIELD, source, game);
        }
    }
    player.shuffleLibrary(source, game);
    return status;
}
Also used : Ability(mage.abilities.Ability) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCreatureCard(mage.filter.common.FilterCreatureCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) FilterCreatureCard(mage.filter.common.FilterCreatureCard) ManaValuePredicate(mage.filter.predicate.mageobject.ManaValuePredicate) Game(mage.game.Game) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 15 with TargetOpponent

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

the class WakeToSlaughterEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
    if (player != null && !pickedCards.isEmpty()) {
        Card cardToHand;
        if (pickedCards.size() == 1) {
            cardToHand = pickedCards.getRandom(game);
        } else {
            Player opponent;
            Set<UUID> opponents = game.getOpponents(player.getId());
            if (opponents.size() == 1) {
                opponent = game.getPlayer(opponents.iterator().next());
            } else {
                Target targetOpponent = new TargetOpponent(true);
                player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
                opponent = game.getPlayer(targetOpponent.getFirstTarget());
            }
            TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
            target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
            opponent.chooseTarget(outcome, pickedCards, target, source, game);
            cardToHand = game.getCard(target.getFirstTarget());
        }
        for (Card card : pickedCards.getCards(game)) {
            if (card == cardToHand) {
                player.moveCards(cardToHand, Zone.HAND, source, game);
            } else {
                player.moveCards(card, Zone.BATTLEFIELD, source, game);
                FixedTarget fixedTarget = new FixedTarget(card, game);
                ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
                effect.setTargetPointer(fixedTarget);
                game.addEffect(effect, source);
                ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
                exileEffect.setTargetPointer(fixedTarget);
                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
        }
        pickedCards.clear();
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) TargetCard(mage.target.TargetCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) UUID(java.util.UUID) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

Player (mage.players.Player)67 TargetOpponent (mage.target.common.TargetOpponent)67 Target (mage.target.Target)35 UUID (java.util.UUID)25 MageObject (mage.MageObject)22 TargetCard (mage.target.TargetCard)22 FilterCard (mage.filter.FilterCard)21 Permanent (mage.game.permanent.Permanent)20 Card (mage.cards.Card)13 FixedTarget (mage.target.targetpointer.FixedTarget)12 ArrayList (java.util.ArrayList)8 CardsImpl (mage.cards.CardsImpl)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)7 Cards (mage.cards.Cards)7 Zone (mage.constants.Zone)6 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)5 Effect (mage.abilities.effects.Effect)4 OneShotEffect (mage.abilities.effects.OneShotEffect)4 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)4