Search in sources :

Example 46 with TargetPlayer

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

the class NightmareIncursionEffect 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) {
        return false;
    }
    int amount = game.getBattlefield().count(filter, source.getSourceId(), source.getControllerId(), game);
    TargetCardInLibrary target = new TargetCardInLibrary(0, amount, StaticFilters.FILTER_CARD);
    if (controller.searchLibrary(target, source, game, targetPlayer.getId())) {
        Cards cards = new CardsImpl(target.getTargets());
        controller.moveCards(cards, Zone.EXILED, source, game);
    }
    targetPlayer.shuffleLibrary(source, game);
    return true;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 47 with TargetPlayer

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

the class WrenchMindEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    if (targetPlayer == null || targetPlayer.getHand().isEmpty()) {
        return false;
    }
    if (targetPlayer.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game) < 1 || !targetPlayer.chooseUse(Outcome.Benefit, "Discard an artifact card?", source, game)) {
        return !targetPlayer.discard(2, false, false, source, game).isEmpty();
    }
    TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD_ARTIFACT_AN, targetPlayer.getId());
    targetPlayer.choose(Outcome.Discard, target, source.getSourceId(), game);
    Card card = targetPlayer.getHand().get(target.getFirstTarget(), game);
    if (card != null && targetPlayer.discard(card, false, source, game)) {
        return true;
    }
    return !targetPlayer.discard(2, false, false, source, game).isEmpty();
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Example 48 with TargetPlayer

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

the class AssistEffect method addSpecialAction.

@Override
public void addSpecialAction(Ability source, Game game, ManaCost unpaid) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && source.getAbilityType() == AbilityType.SPELL && unpaid.getMana().getGeneric() >= 1 && game.getState().getValue(source.getSourceId().toString() + game.getState().getZoneChangeCounter(source.getSourceId()) + "_assisted") == null) {
        SpecialAction specialAction = new AssistSpecialAction(unpaid, this);
        specialAction.setControllerId(source.getControllerId());
        specialAction.setSourceId(source.getSourceId());
        Target target = new TargetPlayer(1, 1, true, filter);
        specialAction.addTarget(target);
        if (specialAction.canActivate(source.getControllerId(), game).canActivate()) {
            game.getState().getSpecialActions().add(specialAction);
        }
    }
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) SpecialAction(mage.abilities.SpecialAction) Target(mage.target.Target) TargetPlayer(mage.target.TargetPlayer)

Example 49 with TargetPlayer

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

the class CapricopianEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    if (!player.chooseUse(outcome, "Reselect attacker for " + permanent.getIdName() + "?", source, game)) {
        return false;
    }
    FilterPlayer filterPlayer = new FilterPlayer();
    filterPlayer.add(Predicates.not(new PlayerIdPredicate(permanent.getControllerId())));
    filterPlayer.add(Predicates.not(new PlayerIdPredicate(game.getCombat().getDefenderId(permanent.getId()))));
    TargetPlayer targetPlayer = new TargetPlayer(0, 1, true, filterPlayer);
    player.choose(outcome, targetPlayer, source.getSourceId(), game);
    Player newPlayer = game.getPlayer(targetPlayer.getFirstTarget());
    if (newPlayer == null) {
        return false;
    }
    game.getCombat().removeAttacker(permanent.getId(), game);
    return game.getCombat().addAttackingCreature(permanent.getId(), game, newPlayer.getId());
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterPlayer(mage.filter.FilterPlayer) Permanent(mage.game.permanent.Permanent) FilterPlayer(mage.filter.FilterPlayer) PlayerIdPredicate(mage.filter.predicate.other.PlayerIdPredicate) TargetPlayer(mage.target.TargetPlayer)

Example 50 with TargetPlayer

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

the class DoOrDieEffect 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) {
        int count = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_CREATURES, targetPlayer.getId(), game);
        TargetCreaturePermanent creatures = new TargetCreaturePermanent(0, count, new FilterCreaturePermanent("creatures to put in the first pile"), true);
        List<Permanent> pile1 = new ArrayList<>();
        creatures.setRequired(false);
        if (player.choose(Outcome.Neutral, creatures, source.getSourceId(), game)) {
            List<UUID> targets = creatures.getTargets();
            for (UUID targetId : targets) {
                Permanent p = game.getPermanent(targetId);
                if (p != null) {
                    pile1.add(p);
                }
            }
        }
        List<Permanent> pile2 = new ArrayList<>();
        for (Permanent p : game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, targetPlayer.getId(), game)) {
            if (!pile1.contains(p)) {
                pile2.add(p);
            }
        }
        boolean choice = targetPlayer.choosePile(Outcome.DestroyPermanent, "Choose a pile to destroy.", pile1, pile2, game);
        if (choice) {
            destroyPermanents(pile1, game, source);
        } else {
            destroyPermanents(pile2, game, source);
        }
        return true;
    }
    return false;
}
Also used : TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ArrayList(java.util.ArrayList) UUID(java.util.UUID)

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