Search in sources :

Example 61 with TargetPlayer

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

the class BitterheartWitchEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (controller != null && targetPlayer != null) {
        TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(targetCard, source, game)) {
            Card card = game.getCard(targetCard.getFirstTarget());
            if (card != null) {
                game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
                if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                    targetPlayer.addAttachment(card.getId(), source, game);
                }
            }
        }
        controller.shuffleLibrary(source, game);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 62 with TargetPlayer

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

the class CabalTherapistDiscardEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, 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 (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
        return false;
    }
    Cards hand = targetPlayer.getHand().copy();
    targetPlayer.revealCards(source, hand, game);
    hand.removeIf(uuid -> {
        Card card = hand.get(uuid, game);
        if (card == null) {
            return true;
        }
        return !CardUtil.haveSameNames(card, cardName, game);
    });
    targetPlayer.discard(hand, false, source, game);
    return true;
}
Also used : Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) MageObject(mage.MageObject) Cards(mage.cards.Cards) Card(mage.cards.Card)

Example 63 with TargetPlayer

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

the class CabalTherapyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(targetPointer.getFirst(game, 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 (targetPlayer == null || controller == null || sourceObject == null || cardName == null) {
        return false;
    }
    Cards hand = targetPlayer.getHand().copy();
    targetPlayer.revealCards(source, hand, game);
    hand.removeIf(uuid -> {
        Card card = hand.get(uuid, game);
        if (card == null) {
            return true;
        }
        return !CardUtil.haveSameNames(card, cardName, game);
    });
    targetPlayer.discard(hand, false, source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) MageObject(mage.MageObject) Cards(mage.cards.Cards) Card(mage.cards.Card)

Example 64 with TargetPlayer

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

the class EssenceHarvestEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (controller != null && targetPlayer != null) {
        List<Permanent> creatures = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, controller.getId(), game);
        int amount = 0;
        for (Permanent creature : creatures) {
            int power = creature.getPower().getValue();
            if (amount < power) {
                amount = power;
            }
        }
        if (amount > 0) {
            targetPlayer.loseLife(amount, game, source, false);
            controller.gainLife(amount, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent)

Example 65 with TargetPlayer

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

the class GhastlyConscriptionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
    if (controller != null && targetPlayer != null) {
        List<Card> cardsToManifest = new ArrayList<>();
        for (Card card : targetPlayer.getGraveyard().getCards(StaticFilters.FILTER_CARD_CREATURE, game)) {
            cardsToManifest.add(card);
            controller.moveCardToExileWithInfo(card, null, "", source, game, Zone.GRAVEYARD, true);
        }
        if (cardsToManifest.isEmpty()) {
            return true;
        }
        Collections.shuffle(cardsToManifest);
        game.informPlayers(controller.getLogName() + " shuffles the face-down pile");
        Ability newSource = source.copy();
        newSource.setWorksFaceDown(true);
        for (Card card : cardsToManifest) {
            ManaCosts manaCosts = null;
            if (card.isCreature(game)) {
                manaCosts = card.getSpellAbility().getManaCosts();
                if (manaCosts == null) {
                    manaCosts = new ManaCostsImpl("{0}");
                }
            }
            MageObjectReference objectReference = new MageObjectReference(card.getId(), card.getZoneChangeCounter(game) + 1, game);
            game.addEffect(new BecomesFaceDownCreatureEffect(manaCosts, objectReference, Duration.Custom, FaceDownType.MANIFESTED), newSource);
        }
        Set<Card> toBattlefield = new LinkedHashSet();
        toBattlefield.addAll(cardsToManifest);
        controller.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game, false, true, false, null);
        return true;
    }
    return false;
}
Also used : Ability(mage.abilities.Ability) ManaCosts(mage.abilities.costs.mana.ManaCosts) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card) BecomesFaceDownCreatureEffect(mage.abilities.effects.common.continuous.BecomesFaceDownCreatureEffect)

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