use of mage.target.common.TargetOpponent in project mage by magefree.
the class SharedFateLookEffect method replaceEvent.
@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
Player playerToDraw = game.getPlayer(event.getPlayerId());
if (playerToDraw != null && sourcePermanent != null) {
TargetOpponent target = new TargetOpponent(true);
if (playerToDraw.choose(Outcome.DrawCard, target, source.getSourceId(), game)) {
Player chosenPlayer = game.getPlayer(target.getFirstTarget());
if (chosenPlayer != null) {
Card card = chosenPlayer.getLibrary().getFromTop(game);
if (card != null) {
playerToDraw.moveCardsToExile(card, source, game, false, CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + playerToDraw.getId().toString(), game), sourcePermanent.getIdName() + "-" + sourcePermanent.getZoneChangeCounter(game) + " (" + playerToDraw.getName() + ')');
card.setFaceDown(true, game);
}
}
}
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class SteamAuguryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
Set<Card> cardsToGraveyard = new LinkedHashSet<>();
Set<Card> cardsToHand = new LinkedHashSet<>();
if (controller == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
controller.revealCards(sourceObject.getIdName(), cards, game);
Player opponent;
Set<UUID> opponents = game.getOpponents(controller.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(Outcome.Detriment, target, source, game);
opponent = game.getPlayer(target.getFirstTarget());
}
if (opponent != null) {
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
Cards pile1CardsIds = new CardsImpl();
target.setRequired(false);
if (controller.choose(Outcome.Neutral, cards, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = game.getCard(targetId);
if (card != null) {
pile1.add(card);
pile1CardsIds.add(card.getId());
}
}
}
List<Card> pile2 = new ArrayList<>();
Cards pile2CardsIds = new CardsImpl();
for (UUID cardId : cards) {
Card card = game.getCard(cardId);
if (card != null && !pile1.contains(card)) {
pile2.add(card);
pile2CardsIds.add(card.getId());
}
}
boolean choice = opponent.choosePile(Outcome.Detriment, "Choose a pile to put into " + controller.getName() + "'s hand.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.HAND;
if (choice) {
pile1Zone = Zone.HAND;
pile2Zone = Zone.GRAVEYARD;
}
StringBuilder sb = new StringBuilder(sourceObject.getLogName() + ": Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
int i = 0;
for (UUID cardUuid : pile1CardsIds) {
i++;
Card card = game.getCard(cardUuid);
if (card != null) {
sb.append(GameLog.getColoredObjectName(card));
if (i < pile1CardsIds.size()) {
sb.append(", ");
}
cardsToGraveyard.add(card);
}
}
controller.moveCards(cardsToGraveyard, pile1Zone, source, game);
game.informPlayers(sb.toString());
sb = new StringBuilder(sourceObject.getLogName() + ": Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
i = 0;
for (UUID cardUuid : pile2CardsIds) {
Card card = game.getCard(cardUuid);
if (card != null) {
i++;
sb.append(' ').append(GameLog.getColoredObjectName(card));
if (i < pile2CardsIds.size()) {
sb.append(", ");
}
cardsToHand.add(card);
}
}
controller.moveCards(cardsToHand, pile2Zone, source, game);
game.informPlayers(sb.toString());
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class UneshCriosphinxSovereignEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Set<Card> cardsToGraveyard = new LinkedHashSet<>();
Set<Card> cardsToHand = new LinkedHashSet<>();
MageObject sourceObject = source.getSourceObject(game);
if (controller == null || sourceObject == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 4));
controller.revealCards(sourceObject.getName(), cards, game);
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
Player opponent = game.getPlayer(opponents.iterator().next());
if (opponents.size() > 1) {
Target targetOpponent = new TargetOpponent(true);
if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
opponent = game.getPlayer(targetOpponent.getFirstTarget());
game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to separate the revealed cards");
}
}
TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (opponent.choose(Outcome.Neutral, cards, target, game)) {
List<UUID> targets = target.getTargets();
for (UUID targetId : targets) {
Card card = cards.get(targetId, game);
if (card != null) {
pile1.add(card);
cards.remove(card);
}
}
}
List<Card> pile2 = new ArrayList<>();
pile2.addAll(cards.getCards(game));
boolean choice = controller.choosePile(outcome, "Choose a pile to put into your hand.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.HAND;
if (choice) {
pile1Zone = Zone.HAND;
pile2Zone = Zone.GRAVEYARD;
}
StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
int i = 0;
for (Card card : pile1) {
i++;
sb.append(card.getName());
if (i < pile1.size()) {
sb.append(", ");
}
cardsToGraveyard.add(card);
}
controller.moveCards(cardsToGraveyard, pile1Zone, source, game);
game.informPlayers(sb.toString());
sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
i = 0;
for (Card card : pile2) {
i++;
sb.append(' ').append(card.getName());
if (i < pile2.size()) {
sb.append(", ");
}
cardsToHand.add(card);
}
controller.moveCards(cardsToHand, pile2Zone, source, game);
game.informPlayers(sb.toString());
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class BalefulMasteryAlternativeCostEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
if (!AlternativeCostSourceAbility.getActivatedStatus(game, source, this.alternativeCostOriginalID, false)) {
return false;
}
Player player = game.getPlayer(source.getControllerId());
TargetOpponent targetOpponent = new TargetOpponent(true);
if (player.chooseTarget(Outcome.DrawCard, targetOpponent, source, game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
opponent.drawCards(1, source, game);
return true;
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class BuzzCondition method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int whackCount = 0;
int doodleCount = 0;
if (controller.chooseUse(Outcome.Benefit, "Choose Whack (yes) or Doodle (no)?", source, game)) {
whackCount++;
} else {
doodleCount++;
}
Set<UUID> opponents = game.getOpponents(source.getControllerId());
if (!opponents.isEmpty()) {
Player opponent = game.getPlayer(opponents.iterator().next());
if (opponents.size() > 1) {
Target targetOpponent = new TargetOpponent(true);
if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
opponent = game.getPlayer(targetOpponent.getFirstTarget());
game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to choose Whack or Doodle");
}
}
if (opponent != null) {
if (opponent.chooseUse(Outcome.Benefit, "Choose Whack (yes) or Doodle (no)?", source, game)) {
whackCount++;
} else {
doodleCount++;
}
}
}
if (whackCount == 2) {
game.informPlayers("Whack was chosen");
game.getState().setValue("whack" + source.getSourceId(), Boolean.TRUE);
} else if (doodleCount == 2) {
game.informPlayers("Doodle was chosen");
game.getState().setValue("doodle" + source.getSourceId(), Boolean.TRUE);
} else {
game.informPlayers("Buzz was chosen");
game.getState().setValue("buzz" + source.getSourceId(), Boolean.TRUE);
}
return true;
}
return false;
}
Aggregations