Search in sources :

Example 26 with TargetPlayer

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

the class ThoughtPrisonDamageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (player != null && targetPlayer != null) {
        targetPlayer.revealCards("Thought Prison ", targetPlayer.getHand(), game);
        TargetCard target = new TargetCard(1, Zone.HAND, filter);
        if (player.choose(Outcome.Benefit, targetPlayer.getHand(), target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = targetPlayer.getHand().get(targetId, game);
                if (card != null) {
                    card.moveToExile(source.getSourceId(), "Thought Prison", source, game);
                    Permanent permanent = game.getPermanent(source.getSourceId());
                    if (permanent != null) {
                        permanent.imprint(card.getId(), game);
                        permanent.addInfo("imprint", "[Exiled card - " + card.getName() + ']', game);
                    }
                    return true;
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Permanent(mage.game.permanent.Permanent) TargetCard(mage.target.TargetCard) UUID(java.util.UUID) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 27 with TargetPlayer

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

the class ThoughtHemorrhageEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (sourceObject != null && controller != null && cardName != null && !cardName.isEmpty()) {
        Player targetPlayer = game.getPlayer(source.getFirstTarget());
        if (targetPlayer != null) {
            targetPlayer.revealCards("hand of " + targetPlayer.getName(), targetPlayer.getHand(), game);
            int cardsFound = 0;
            for (Card card : targetPlayer.getHand().getCards(game)) {
                if (CardUtil.haveSameNames(card, cardName, game)) {
                    cardsFound++;
                }
            }
            if (cardsFound > 0) {
                targetPlayer.damage(3 * cardsFound, source.getSourceId(), source, game);
            }
            // Exile all cards with the same name
            // Building a card filter with the name
            FilterCard filterNamedCards = new FilterCard();
            filterNamedCards.add(new NamePredicate(cardName));
            Set<Card> toExile = new LinkedHashSet<>();
            // search cards in graveyard
            for (Card checkCard : targetPlayer.getGraveyard().getCards(game)) {
                if (checkCard.getName().equals(cardName)) {
                    toExile.add(checkCard);
                }
            }
            // search cards in Hand
            TargetCard targetCardInHand = new TargetCard(0, Integer.MAX_VALUE, Zone.HAND, filterNamedCards);
            if (controller.chooseTarget(Outcome.Exile, targetPlayer.getHand(), targetCardInHand, source, game)) {
                List<UUID> targets = targetCardInHand.getTargets();
                for (UUID targetId : targets) {
                    Card targetCard = targetPlayer.getHand().get(targetId, game);
                    if (targetCard != null) {
                        toExile.add(targetCard);
                    }
                }
            }
            // search cards in Library
            // If the player has no nonland cards in their hand, you can still search
            // that player's library and have that player shuffle it.
            TargetCardInLibrary targetCardsLibrary = new TargetCardInLibrary(0, Integer.MAX_VALUE, filterNamedCards);
            controller.searchLibrary(targetCardsLibrary, source, game, targetPlayer.getId());
            for (UUID cardId : targetCardsLibrary.getTargets()) {
                Card card = game.getCard(cardId);
                if (card != null) {
                    toExile.add(card);
                }
            }
            controller.moveCards(toExile, Zone.EXILED, source, game);
            targetPlayer.shuffleLibrary(source, game);
            return true;
        }
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) TargetCard(mage.target.TargetCard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) UUID(java.util.UUID)

Example 28 with TargetPlayer

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

the class ChoosePlayerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getPermanentEntering(source.getSourceId());
    if (mageObject == null) {
        mageObject = game.getObject(source.getSourceId());
    }
    if (controller != null && mageObject != null) {
        TargetPlayer target = new TargetPlayer(1, 1, true);
        if (controller.choose(this.outcome, target, source.getSourceId(), game)) {
            Player chosenPlayer = game.getPlayer(target.getFirstTarget());
            if (chosenPlayer != null) {
                game.informPlayers(mageObject.getName() + ": " + controller.getLogName() + " has chosen " + chosenPlayer.getLogName());
                game.getState().setValue(mageObject.getId() + "_player", target.getFirstTarget());
                if (mageObject instanceof Permanent) {
                    ((Permanent) mageObject).addInfo("chosen player", CardUtil.addToolTipMarkTags("Chosen player: " + chosenPlayer.getLogName()), game);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) TargetPlayer(mage.target.TargetPlayer)

Example 29 with TargetPlayer

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

the class BurnAwayDelayedTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = (ZoneChangeEvent) event;
    if (zEvent.isDiesEvent() && zEvent.getTarget() != null && zEvent.getTargetId().equals(getTargets().getFirstTarget())) {
        // else spell fizzles because target creature died
        this.getTargets().clear();
        Target target = new TargetPlayer();
        target.add(zEvent.getTarget().getControllerId(), game);
        this.addTarget(target);
        return true;
    }
    return false;
}
Also used : ZoneChangeEvent(mage.game.events.ZoneChangeEvent) Target(mage.target.Target) TargetPlayer(mage.target.TargetPlayer)

Example 30 with TargetPlayer

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

the class BrowbeatDrawEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    StackObject spell = null;
    for (StackObject object : game.getStack()) {
        if (object instanceof Spell && object.getSourceId().equals(source.getSourceId())) {
            spell = object;
        }
    }
    if (spell != null) {
        boolean drawCards = true;
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.chooseUse(Outcome.Detriment, "Have " + spell.getLogName() + " deal 5 damage to you?", source, game)) {
                drawCards = false;
                player.damage(5, source.getSourceId(), source, game);
                game.informPlayers(player.getLogName() + " has " + spell.getLogName() + " deal 5 to them");
            }
        }
        if (drawCards) {
            UUID targetPlayer = getTargetPointer().getFirst(game, source);
            if (targetPlayer != null) {
                Player player = game.getPlayer(targetPlayer);
                if (player != null) {
                    player.drawCards(3, source, game);
                }
            }
        }
        return drawCards;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Aggregations

TargetPlayer (mage.target.TargetPlayer)134 Player (mage.players.Player)129 Card (mage.cards.Card)38 Permanent (mage.game.permanent.Permanent)32 FilterCard (mage.filter.FilterCard)27 UUID (java.util.UUID)25 MageObject (mage.MageObject)16 CardsImpl (mage.cards.CardsImpl)16 FilterPlayer (mage.filter.FilterPlayer)16 TargetCard (mage.target.TargetCard)13 Cards (mage.cards.Cards)12 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)12 ObjectSourcePlayer (mage.filter.predicate.ObjectSourcePlayer)10 Target (mage.target.Target)10 FixedTarget (mage.target.targetpointer.FixedTarget)10 Spell (mage.game.stack.Spell)9 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 TargetPermanent (mage.target.TargetPermanent)7 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)5