Search in sources :

Example 16 with TargetDiscard

use of mage.target.common.TargetDiscard in project mage by magefree.

the class BlimComedicGeniusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    game.addEffect(new GainControlTargetEffect(Duration.Custom, true, targetPointer.getFirst(game, source)).setTargetPointer(new FixedTarget(source.getFirstTarget(), game)), source);
    game.getState().processAction(game);
    Map<UUID, Cards> cardsMap = new HashMap<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null) {
            continue;
        }
        int count = game.getBattlefield().count(filter, source.getSourceId(), playerId, game);
        if (count < 1) {
            continue;
        }
        player.loseLife(count, game, source, true);
        TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD, playerId);
        player.choose(outcome, target, source.getSourceId(), game);
        cardsMap.put(playerId, new CardsImpl(target.getTargets()));
    }
    for (Map.Entry<UUID, Cards> entry : cardsMap.entrySet()) {
        Player player = game.getPlayer(entry.getKey());
        if (player == null) {
            continue;
        }
        player.discard(entry.getValue(), false, source, game);
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) HashMap(java.util.HashMap) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) GainControlTargetEffect(mage.abilities.effects.common.continuous.GainControlTargetEffect) HashMap(java.util.HashMap) Map(java.util.Map) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 17 with TargetDiscard

use of mage.target.common.TargetDiscard in project mage by magefree.

the class BlastOfGeniusEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        player.drawCards(3, source, game);
        TargetDiscard target = new TargetDiscard(player.getId());
        if (target.canChoose(source.getSourceId(), player.getId(), game)) {
            player.choose(Outcome.Discard, target, source.getSourceId(), game);
            Card card = player.getHand().get(target.getFirstTarget(), game);
            if (card != null) {
                player.discard(card, false, source, game);
                int damage = card.getManaValue();
                Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
                if (creature != null) {
                    creature.damage(damage, source.getSourceId(), source, game, false, true);
                    return true;
                }
                Player targetPlayer = game.getPlayer(this.getTargetPointer().getFirst(game, source));
                if (targetPlayer != null) {
                    targetPlayer.damage(damage, source.getSourceId(), source, game);
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Example 18 with TargetDiscard

use of mage.target.common.TargetDiscard in project mage by magefree.

the class AzraBladeseekerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    List<PlayerCard> playerCardList = new ArrayList<>();
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player == null || player.hasOpponent(source.getControllerId(), game) || player.getHand().isEmpty() || !player.chooseUse(Outcome.DrawCard, "Discard a card?", source, game)) {
            continue;
        }
        Target target = new TargetDiscard(playerId);
        if (target.choose(Outcome.DrawCard, playerId, source.getSourceId(), game)) {
            Card card = game.getCard(target.getFirstTarget());
            if (card != null) {
                playerCardList.add(new PlayerCard(player, card));
            }
        }
    }
    for (PlayerCard playerCard : playerCardList) {
        if (playerCard.getPlayer().discard(playerCard.getCard(), false, source, game)) {
            playerCard.getPlayer().drawCards(1, source, game);
        }
    }
    return true;
}
Also used : Player(mage.players.Player) Target(mage.target.Target) ArrayList(java.util.ArrayList) UUID(java.util.UUID) TargetDiscard(mage.target.common.TargetDiscard) Card(mage.cards.Card)

Aggregations

TargetDiscard (mage.target.common.TargetDiscard)18 Player (mage.players.Player)17 UUID (java.util.UUID)10 HashMap (java.util.HashMap)9 Card (mage.cards.Card)9 Cards (mage.cards.Cards)7 CardsImpl (mage.cards.CardsImpl)7 Target (mage.target.Target)7 FilterCard (mage.filter.FilterCard)4 Permanent (mage.game.permanent.Permanent)3 TargetCard (mage.target.TargetCard)3 TargetPlayer (mage.target.TargetPlayer)3 Map (java.util.Map)2 MageObject (mage.MageObject)2 ArrayList (java.util.ArrayList)1 BoostSourceEffect (mage.abilities.effects.common.continuous.BoostSourceEffect)1 GainControlTargetEffect (mage.abilities.effects.common.continuous.GainControlTargetEffect)1 ValueHint (mage.abilities.hint.ValueHint)1 TargetCardInLibrary (mage.target.common.TargetCardInLibrary)1 FixedTarget (mage.target.targetpointer.FixedTarget)1