use of mage.target.common.TargetDiscard in project mage by magefree.
the class DiscardEachPlayerEffect 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) {
return true;
}
int toDiscard = amount.calculate(game, source, this);
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
switch(targetController) {
case NOT_YOU:
if (playerId.equals(source.getControllerId())) {
continue;
}
break;
case OPPONENT:
if (!game.getOpponents(source.getControllerId()).contains(playerId)) {
continue;
}
break;
}
if (randomDiscard) {
player.discard(toDiscard, true, false, source, game);
continue;
}
int numberOfCardsToDiscard = Math.min(toDiscard, player.getHand().size());
Cards cards = new CardsImpl();
if (numberOfCardsToDiscard > 0) {
Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
player.chooseTarget(outcome, target, source, game);
cards.addAll(target.getTargets());
}
cardsToDiscard.put(playerId, cards);
}
if (randomDiscard) {
return true;
}
// discard all choosen cards
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
player.discard(cardsToDiscard.get(playerId), false, source, game);
}
return true;
}
use of mage.target.common.TargetDiscard 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();
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class SpellboundDragonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player you = game.getPlayer(source.getControllerId());
Permanent dragon = game.getPermanent(source.getSourceId());
if (you != null) {
you.drawCards(1, source, game);
TargetDiscard target = new TargetDiscard(you.getId());
you.choose(Outcome.Discard, target, source.getSourceId(), game);
Card card = you.getHand().get(target.getFirstTarget(), game);
if (card != null && you.discard(card, false, source, game)) {
int cmc = card.getManaValue();
if (dragon != null) {
game.addEffect(new BoostSourceEffect(cmc, 0, Duration.EndOfTurn), source);
return true;
}
}
}
return false;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class LilianaWakerOfTheDeadDiscardEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
if (controller == null) {
return true;
}
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
int numberOfCardsToDiscard = Math.min(1, player.getHand().size());
Cards cards = new CardsImpl();
Target target = new TargetDiscard(numberOfCardsToDiscard, numberOfCardsToDiscard, StaticFilters.FILTER_CARD, playerId);
player.chooseTarget(outcome, target, source, game);
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) {
continue;
}
int amountDiscarded = player.discard(cardsToDiscard.get(playerId), false, source, game).size();
if (controller.hasOpponent(playerId, game) && amountDiscarded == 0) {
player.loseLife(3, game, source, false);
}
}
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class ScytheSpecterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Map<UUID, Card> cardDiscarded = new HashMap<>();
Map<UUID, Integer> discardedCheck = new HashMap<>();
Integer highestCMC = 0;
Integer currentCMC = 0;
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
for (UUID playerId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(playerId);
if (opponent != null) {
Target target = new TargetDiscard(new FilterCard(), playerId);
opponent.chooseTarget(Outcome.Discard, target, source, game);
Card targetCard = game.getCard(target.getFirstTarget());
if (targetCard != null) {
currentCMC = targetCard.getManaValue();
if (highestCMC <= currentCMC) {
highestCMC = currentCMC;
}
cardDiscarded.put(playerId, targetCard);
}
}
}
for (UUID opponentId : cardDiscarded.keySet()) {
// discard must happen simultaneously
Player player = game.getPlayer(opponentId);
if (player != null && player.discard(cardDiscarded.get(opponentId), false, source, game)) {
// note that a card was discarded
discardedCheck.put(opponentId, 1);
}
}
for (UUID playerId : game.getOpponents(controller.getId())) {
// lose life equal to CMC
Card card = cardDiscarded.get(playerId);
if ((card != null) && (card.getManaValue() == highestCMC)) {
Player opponent = game.getPlayer(playerId);
if (opponent != null && discardedCheck.get(playerId) == 1) {
// check that card was discarded
opponent.loseLife(highestCMC, game, source, false);
}
}
}
cardDiscarded.clear();
discardedCheck.clear();
return true;
}
return false;
}
Aggregations