use of mage.target.common.TargetDiscard in project mage by magefree.
the class BorderlandExplorerEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null) {
// 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<>();
// Store for each player the lands to reveal, that's important because all reveals shall happen at the same time
Map<UUID, Cards> cardsToReveal = new HashMap<>();
// choose cards to discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Target target = new TargetDiscard(0, 1, new FilterCard(), playerId);
player.chooseTarget(outcome, target, source, game);
Cards cards = new CardsImpl(target.getTargets());
cardsToDiscard.put(playerId, cards);
}
}
// discard all chosen 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);
player.discard(card, false, source, game);
}
}
}
}
// search for a land for each player that discarded
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 && !cardsPlayer.isEmpty()) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, StaticFilters.FILTER_CARD_BASIC_LAND);
if (player.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
Cards cards = new CardsImpl(target.getTargets());
cards.addAll(target.getTargets());
cardsToReveal.put(playerId, cards);
}
}
}
}
}
// reveal the searched lands, put in hands, and shuffle
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToReveal.get(playerId);
if (cardsPlayer != null) {
for (UUID cardId : cardsPlayer) {
Card card = game.getCard(cardId);
Cards cards = new CardsImpl(game.getCard(cardId));
if (card != null && !cards.isEmpty()) {
player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cards, game);
player.moveCards(card, Zone.HAND, source, game);
player.shuffleLibrary(source, game);
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class CourtOfAmbitionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
int discardCount = source.isControlledBy(game.getMonarchId()) ? 2 : 1;
String message = "Discard " + CardUtil.numberToText(discardCount, "a") + " card" + (discardCount > 1 ? 's' : "") + "? If not you lose " + (discardCount * 3) + " life";
Map<UUID, Cards> discardMap = new HashMap<>();
for (UUID playerId : game.getOpponents(source.getControllerId())) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
if (player.getHand().size() < discardCount || !player.chooseUse(Outcome.LoseLife, message, source, game)) {
player.loseLife(discardCount * 3, game, source, false);
continue;
}
TargetDiscard target = new TargetDiscard(discardCount, StaticFilters.FILTER_CARD, playerId);
player.choose(Outcome.Discard, target, source.getSourceId(), game);
discardMap.put(playerId, new CardsImpl(target.getTargets()));
}
for (Map.Entry<UUID, Cards> entry : discardMap.entrySet()) {
Player player = game.getPlayer(entry.getKey());
if (player != null) {
player.discard(entry.getValue(), false, source, game);
}
}
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class CompulsiveResearchDiscardEffect 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_LAND, game) < 1 || !targetPlayer.chooseUse(outcome, "Discard a land card?", source, game)) {
return !targetPlayer.discard(2, false, false, source, game).isEmpty();
}
TargetDiscard target = new TargetDiscard(StaticFilters.FILTER_CARD_LAND_A, 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 MindBombEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
Map<UUID, Cards> cardsToDiscard = new HashMap<>();
// choose
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Cards cards = new CardsImpl();
Target target = new TargetDiscard(0, 3, new FilterCard(), playerId);
player.chooseTarget(Outcome.Discard, target, source, game);
cards.addAll(target.getTargets());
cardsToDiscard.put(playerId, cards);
}
// discard
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player != null) {
Cards cardsPlayer = cardsToDiscard.get(playerId);
cardsToDiscard.put(playerId, player.discard(cardsPlayer, false, source, game));
}
}
// damage
for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
Player player = game.getPlayer(playerId);
if (player == null) {
continue;
}
Cards cardsPlayer = cardsToDiscard.get(playerId);
if (cardsPlayer != null) {
player.damage(3 - cardsPlayer.size(), source.getSourceId(), source, game);
}
}
return true;
}
use of mage.target.common.TargetDiscard in project mage by magefree.
the class MonomaniaEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getFirstTarget());
if (player == null || player.getHand().isEmpty()) {
return false;
}
TargetCard target = new TargetDiscard(player.getId());
player.choose(Outcome.Benefit, player.getHand(), target, game);
Cards cards = player.getHand().copy();
cards.removeIf(target.getTargets()::contains);
return !player.discard(cards, false, source, game).isEmpty();
}
Aggregations