Search in sources :

Example 36 with TargetPlayer

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

the class AgonizingMemoriesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    Player you = game.getPlayer(source.getControllerId());
    if (targetPlayer != null && you != null) {
        chooseCardInHandAndPutOnTopOfLibrary(game, source, you, targetPlayer);
        chooseCardInHandAndPutOnTopOfLibrary(game, source, you, targetPlayer);
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player)

Example 37 with TargetPlayer

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

the class CloudhoofKirinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getSpellOrLKIStack(this.getTargetPointer().getFirst(game, source));
    if (spell != null) {
        Player targetPlayer = null;
        for (Target target : source.getTargets()) {
            if (target instanceof TargetPlayer) {
                targetPlayer = game.getPlayer(target.getFirstTarget());
            }
        }
        int cmc = spell.getManaValue();
        if (targetPlayer != null && cmc > 0) {
            targetPlayer.millCards(cmc, source, game);
            return true;
        }
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Target(mage.target.Target) Spell(mage.game.stack.Spell) TargetPlayer(mage.target.TargetPlayer)

Example 38 with TargetPlayer

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

the class CurseOfLeechesEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    TargetPlayer target = new TargetPlayer();
    target.withChooseHint("Player to attach to").setNotTarget(true);
    controller.choose(Outcome.Detriment, target, source.getSourceId(), game);
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent == null) {
        return false;
    }
    permanent.addAttachment(target.getFirstTarget(), source, game);
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPlayer(mage.target.TargetPlayer)

Example 39 with TargetPlayer

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

the class CurseOfMisfortunesEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent enchantment = game.getPermanent(source.getSourceId());
    if (controller != null && enchantment != null && enchantment.getAttachedTo() != null) {
        Player targetPlayer = game.getPlayer(enchantment.getAttachedTo());
        Player player = game.getPlayer(source.getControllerId());
        if (player != null && targetPlayer != null) {
            FilterCard filter = new FilterCard("Curse card that doesn't have the same name as a Curse attached to enchanted player");
            filter.add(SubType.CURSE.getPredicate());
            // get the names of attached Curses
            for (UUID attachmentId : targetPlayer.getAttachments()) {
                Permanent attachment = game.getPermanent(attachmentId);
                if (attachment != null && attachment.hasSubtype(SubType.CURSE, game)) {
                    filter.add(Predicates.not(new NamePredicate(attachment.getName())));
                }
            }
            TargetCardInLibrary targetCard = new TargetCardInLibrary(filter);
            if (player.searchLibrary(targetCard, source, game)) {
                Card card = game.getCard(targetCard.getFirstTarget());
                if (card != null) {
                    this.setTargetPointer(new FixedTarget(targetPlayer.getId()));
                    game.getState().setValue("attachTo:" + card.getId(), targetPlayer.getId());
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        targetPlayer.addAttachment(card.getId(), source, game);
                    }
                }
            }
            player.shuffleLibrary(source, game);
        }
        return true;
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) FixedTarget(mage.target.targetpointer.FixedTarget) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 40 with TargetPlayer

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

the class CurseOfTheCabalTriggeredAbilityConditionalDelay method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(source.getFirstTarget());
    if (targetPlayer != null) {
        int amount = game.getBattlefield().countAll(StaticFilters.FILTER_CONTROLLED_PERMANENT, targetPlayer.getId(), game) / 2;
        if (amount < 1) {
            return true;
        }
        Target target = new TargetControlledPermanent(amount, amount, StaticFilters.FILTER_CONTROLLED_PERMANENT, true);
        if (target.canChoose(source.getSourceId(), targetPlayer.getId(), game)) {
            while (!target.isChosen() && target.canChoose(source.getSourceId(), targetPlayer.getId(), game) && targetPlayer.canRespond()) {
                targetPlayer.choose(Outcome.Sacrifice, target, source.getSourceId(), game);
            }
            // sacrifice all chosen (non null) permanents
            target.getTargets().stream().map(game::getPermanent).filter(Objects::nonNull).forEach(permanent -> permanent.sacrifice(source, game));
        }
        return true;
    }
    return false;
}
Also used : TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) TargetPlayer(mage.target.TargetPlayer) Target(mage.target.Target)

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