use of mage.target.common.TargetOpponent in project mage by magefree.
the class BoneyardParleyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Cards cards = new CardsImpl();
for (Target target : source.getTargets()) {
for (UUID cardId : target.getTargets()) {
cards.add(cardId);
}
}
if (!cards.isEmpty() && player.moveCards(cards, Zone.EXILED, source, game)) {
TargetOpponent targetOpponent = new TargetOpponent(true);
if (player.choose(Outcome.Neutral, targetOpponent, source.getSourceId(), game)) {
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent != null) {
TargetCard targetCards = new TargetCard(0, cards.size(), Zone.EXILED, new FilterCard("cards to put in the first pile"));
List<Card> pile1 = new ArrayList<>();
if (opponent.choose(Outcome.Neutral, cards, targetCards, game)) {
List<UUID> targets = targetCards.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 = player.choosePile(outcome, "Choose a pile to put onto the battlefield.", pile1, pile2, game);
Zone pile1Zone = Zone.GRAVEYARD;
Zone pile2Zone = Zone.BATTLEFIELD;
if (choice) {
pile1Zone = Zone.BATTLEFIELD;
pile2Zone = Zone.GRAVEYARD;
}
Set<Card> pile1Set = new HashSet<>();
Set<Card> pile2Set = new HashSet<>();
pile1Set.addAll(pile1);
pile2Set.addAll(pile2);
// Cards toBattlefield = new CardsImpl();
// Cards toGraveyard = new CardsImpl();
//
// if (pile1Zone == Zone.BATTLEFIELD) {
// toBattlefield.addAll(pile1);
// toGraveyard.addAll(pile2);
// } else {
// toBattlefield.addAll(pile2);
// toGraveyard.addAll(pile1);
// }
player.moveCards(pile1Set, pile1Zone, source, game, false, false, false, null);
player.moveCards(pile2Set, pile2Zone, source, game, false, false, false, null);
// StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(": ");
// game.informPlayers(sb.toString());
// sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.BATTLEFIELD ? "Battlefield" : "Graveyard").append(':');
// game.informPlayers(sb.toString());
}
return true;
}
}
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class DeliverUntoEvilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(source.getTargets().get(0).getTargets());
if (cards.isEmpty()) {
return false;
}
if (!game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game).isEmpty()) {
return player.moveCards(cards, Zone.HAND, source, game);
}
TargetOpponent targetOpponent = new TargetOpponent();
targetOpponent.setNotTarget(true);
if (!player.choose(outcome, targetOpponent, source.getSourceId(), game)) {
return false;
}
Player opponent = game.getPlayer(targetOpponent.getFirstTarget());
if (opponent == null) {
return false;
}
TargetCard targetCard = new TargetCardInGraveyard(Math.min(2, cards.size()), filter2);
if (!opponent.choose(outcome, cards, targetCard, game)) {
return false;
}
cards.removeAll(targetCard.getTargets());
return player.moveCards(cards, Zone.HAND, source, game);
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class MurmursFromBeyondEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && controller != null) {
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 3));
if (!cards.isEmpty()) {
controller.revealCards(staticText, cards, game);
Card cardToGraveyard;
if (cards.size() == 1) {
cardToGraveyard = cards.getRandom(game);
} else {
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());
}
TargetCard target = new TargetCard(1, Zone.LIBRARY, new FilterCard());
opponent.chooseTarget(outcome, cards, target, source, game);
cardToGraveyard = game.getCard(target.getFirstTarget());
}
if (cardToGraveyard != null) {
controller.moveCards(cardToGraveyard, Zone.GRAVEYARD, source, game);
cards.remove(cardToGraveyard);
}
controller.moveCards(cards, Zone.HAND, source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class NullChamberReplacementEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
TargetOpponent chosenOpponent = new TargetOpponent(true);
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getPermanentEntering(source.getSourceId());
if (sourceObject == null) {
sourceObject = source.getSourceObject(game);
}
if (controller == null || sourceObject == null) {
return false;
}
controller.choose(Outcome.Neutral, chosenOpponent, source.getSourceId(), game);
Player opponent = game.getPlayer(chosenOpponent.getFirstTarget());
String cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(controller, game, source, false);
if (cardName != null) {
game.getState().setValue(source.getSourceId().toString() + INFO_KEY_CONTROLLER, cardName);
if (sourceObject instanceof Permanent) {
((Permanent) sourceObject).addInfo(INFO_KEY_CONTROLLER, CardUtil.addToolTipMarkTags("Named card (Controller): " + cardName), game);
}
}
if (opponent == null) {
return true;
}
cardName = ChooseACardNameEffect.TypeOfName.NOT_BASIC_LAND_NAME.getChoice(opponent, game, source, false);
if (cardName == null) {
return true;
}
game.getState().setValue(source.getSourceId().toString() + INFO_KEY_OPPONENT, cardName);
if (sourceObject instanceof Permanent) {
((Permanent) sourceObject).addInfo(INFO_KEY_OPPONENT, CardUtil.addToolTipMarkTags("Named card (Opponent): " + cardName), game);
}
return true;
}
use of mage.target.common.TargetOpponent in project mage by magefree.
the class OpponentGainControlEffect method init.
@Override
public void init(Ability source, Game game) {
super.init(source, game);
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
if (game.getOpponents(controller.getId()).size() == 1) {
opponentId = game.getOpponents(controller.getId()).iterator().next();
} else {
Target target = new TargetOpponent(true);
controller.chooseTarget(outcome, target, source, game);
opponentId = target.getFirstTarget();
}
}
Player targetOpponent = game.getPlayer(opponentId);
if (targetOpponent != null && permanent != null) {
game.informPlayers(permanent.getLogName() + " is now controlled by " + targetOpponent.getLogName());
} else {
discard();
}
}
Aggregations