use of mage.target.common.TargetDiscard in project mage by magefree.
the class StrongarmTacticsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
// Store for each player the cards to discard, that's important because all discard shall happen at the same time
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
if (controller != null) {
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
int numberOfCardsToDiscard = Math.min(1, player.getHand().size());
Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, new FilterCard(), playerId);
player.chooseTarget(outcome, target, source, game);
Cards cards = new CardsImpl();
cards.addAll(target.getTargets());
cardsToDiscard.put(playerId, cards);
}
}
// discard all choosen cards
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToDiscard.get(playerId);
if (cardsPlayer != null) {
for (UUID cardId : cardsPlayer) {
Card card = game.getCard(cardId);
if (card != null) {
if (!(player.discard(card, false, source, game) && card.isCreature(game))) {
player.loseLife(4, game, source, false);
}
}
}
}
}
}
}
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class FiendOfTheShadowsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(targetPointer.getFirst(game, source));
if (player == null || player.getHand().isEmpty()) {
return false;
}
TargetCard targetCard = new TargetDiscard(player.getId());
player.choose(outcome, targetCard, source.getSourceId(), game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card == null) {
return false;
}
player.moveCardToExileWithInfo(card, CardUtil.getExileZoneId(game, source), CardUtil.getSourceName(game, source), source, game, Zone.HAND, true);
CardUtil.makeCardPlayable(game, source, card, Duration.Custom, false);
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class MindMaggotsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
TargetCard target = new TargetDiscard(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_CREATURE, controller.getId());
controller.choose(outcome, controller.getHand(), target, game);
int counters = controller.discard(new CardsImpl(target.getTargets()), false, source, game).size();
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent == null || counters < 1) {
return true;
}
permanent.addCounters(CounterType.P1P1.createInstance(counters), source.getControllerId(), source, game);
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class ProfessorOnyxEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
for (int i = 0; i < 6; i++) {
Map<UUID, Card> playerMap = new HashMap<>();
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
TargetDiscard target = new TargetDiscard(0, 1, StaticFilters.FILTER_CARD, playerId);
player.choose(Outcome.Discard, target, source.getSourceId(), game);
playerMap.put(playerId, game.getCard(target.getFirstTarget()));
}
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
if (playerMap.get(playerId) == null || !player.discard(playerMap.get(playerId), false, source, game)) {
player.loseLife(3, game, source, false);
}
}
}
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class PlayerImpl method getToDiscard.
private Cards getToDiscard(int minAmount, int maxAmount, Ability source, Game game) {
Cards toDiscard = new CardsImpl();
if (minAmount > maxAmount) {
return getToDiscard(maxAmount, minAmount, source, game);
}
if (maxAmount < 1) {
return toDiscard;
}
if (getHand().size() <= minAmount) {
toDiscard.addAll(getHand());
return toDiscard;
}
TargetDiscard target = new TargetDiscard(minAmount, maxAmount, StaticFilters.FILTER_CARD, getId());
choose(Outcome.Discard, target, source != null ? source.getSourceId() : null, game);
toDiscard.addAll(target.getTargets());
return toDiscard;
}
Aggregations