Search in sources :

Example 21 with TargetPlayer

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

the class LammastideWeaveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (controller == null || targetPlayer == null || cardName == null || cardName.isEmpty()) {
        return false;
    }
    for (Card card : targetPlayer.millCards(1, source, game).getCards(game)) {
        if (CardUtil.haveSameNames(card, cardName, game)) {
            controller.gainLife(card.getManaValue(), game, source);
        }
    }
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Card(mage.cards.Card)

Example 22 with TargetPlayer

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

the class MultipleChoiceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    int xValue = source.getManaCostsToPay().getX();
    if (xValue == 1 || xValue >= 4) {
        controller.scry(1, source, game);
        controller.drawCards(1, source, game);
    }
    if (xValue == 3 || xValue >= 4) {
        new Elemental44Token().putOntoBattlefield(1, game, source, source.getControllerId());
    }
    if (xValue != 2 && xValue < 4) {
        return true;
    }
    TargetPlayer targetPlayer = new TargetPlayer(0, 1, true);
    controller.choose(Outcome.Detriment, targetPlayer, source.getSourceId(), game);
    Player player = game.getPlayer(targetPlayer.getFirstTarget());
    if (player == null || game.getBattlefield().count(StaticFilters.FILTER_CONTROLLED_CREATURE, source.getSourceId(), player.getId(), game) <= 0) {
        return true;
    }
    TargetPermanent targetPermanent = new TargetControlledCreaturePermanent();
    targetPermanent.setNotTarget(true);
    player.choose(Outcome.ReturnToHand, targetPermanent, source.getSourceId(), game);
    Permanent permanent = game.getPermanent(targetPermanent.getFirstTarget());
    return permanent == null || player.moveCards(permanent, Zone.HAND, source, game);
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) Elemental44Token(mage.game.permanent.token.Elemental44Token) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPlayer(mage.target.TargetPlayer)

Example 23 with TargetPlayer

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

the class OathOfGhoulsEffect method apply.

@Override
public boolean apply(ObjectSourcePlayer<Player> input, Game game) {
    Player targetPlayer = input.getObject();
    Player firstPlayer = game.getPlayer(game.getActivePlayerId());
    if (targetPlayer == null || firstPlayer == null || !firstPlayer.hasOpponent(targetPlayer.getId(), game)) {
        return false;
    }
    int countGraveyardTargetPlayer = targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).size();
    int countGraveyardFirstPlayer = firstPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game).size();
    return countGraveyardTargetPlayer < countGraveyardFirstPlayer;
}
Also used : Player(mage.players.Player) ObjectSourcePlayer(mage.filter.predicate.ObjectSourcePlayer) TargetPlayer(mage.target.TargetPlayer) FilterPlayer(mage.filter.FilterPlayer)

Example 24 with TargetPlayer

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

the class PredictEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    String cardName = (String) game.getState().getValue(source.getSourceId().toString() + ChooseACardNameEffect.INFO_KEY);
    if (controller == null || targetPlayer == null || cardName == null || cardName.isEmpty()) {
        return false;
    }
    int toDraw = 1;
    for (Card card : targetPlayer.millCards(1, source, game).getCards(game)) {
        if (CardUtil.haveSameNames(card, cardName, game)) {
            toDraw = 2;
            break;
        }
    }
    controller.drawCards(toDraw, source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Card(mage.cards.Card)

Example 25 with TargetPlayer

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

the class ReyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetPlayer != null && controller != null) {
        if (targetPlayer.getLibrary().hasCards()) {
            // reveal the top card of target player's library.
            Card topCard = targetPlayer.getLibrary().getFromTop(game);
            CardsImpl reveal = new CardsImpl();
            reveal.add(topCard);
            targetPlayer.revealCards(source, reveal, game);
            // You gain life equal to that card's converted mana cost.
            if (topCard != null) {
                controller.gainLife(topCard.getManaValue(), game, source);
            }
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card)

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