use of mage.target.TargetCard in project mage by magefree.
the class StruggleForSanityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
Player controller = game.getPlayer(source.getControllerId());
if (targetPlayer == null || sourceObject == null || controller == null) {
return false;
}
targetPlayer.revealCards(sourceObject.getIdName(), targetPlayer.getHand(), game);
Cards cardsLeft = new CardsImpl(targetPlayer.getHand());
Cards exiledByController = new CardsImpl();
UUID exileZoneController = UUID.randomUUID();
Cards exiledByOpponent = new CardsImpl();
UUID exileZoneOpponent = UUID.randomUUID();
boolean opponentsChoice = true;
TargetCard target = new TargetCard(Zone.HAND, new FilterCard("a card to exile"));
while (!cardsLeft.isEmpty()) {
if (opponentsChoice) {
targetPlayer.choose(Outcome.ReturnToHand, cardsLeft, target, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
exiledByOpponent.add(card);
cardsLeft.remove(card);
targetPlayer.moveCardsToExile(card, source, game, true, exileZoneOpponent, sourceObject.getIdName() + " exiled by " + targetPlayer.getName());
}
} else {
controller.choose(Outcome.Discard, cardsLeft, target, game);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
exiledByController.add(card);
cardsLeft.remove(card);
controller.moveCardsToExile(card, source, game, true, exileZoneController, sourceObject.getIdName() + " exiled by " + controller.getName());
}
}
target.clearChosen();
opponentsChoice = !opponentsChoice;
}
targetPlayer.moveCards(exiledByOpponent, Zone.HAND, source, game);
targetPlayer.moveCards(exiledByController, Zone.GRAVEYARD, source, game);
return true;
}
use of mage.target.TargetCard in project mage by magefree.
the class TombOfTheDuskRoseEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
UUID exileId = CardUtil.getCardExileZoneId(game, source);
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && exileId != null && sourceObject != null) {
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null) {
TargetCard targetCard = new TargetCard(Zone.EXILED, StaticFilters.FILTER_CARD_CREATURE);
controller.chooseTarget(outcome, exileZone, targetCard, source, game);
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class WakeToSlaughterEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Cards pickedCards = new CardsImpl(getTargetPointer().getTargets(game, source));
if (player != null && !pickedCards.isEmpty()) {
Card cardToHand;
if (pickedCards.size() == 1) {
cardToHand = pickedCards.getRandom(game);
} else {
Player opponent;
Set<UUID> opponents = game.getOpponents(player.getId());
if (opponents.size() == 1) {
opponent = game.getPlayer(opponents.iterator().next());
} else {
Target targetOpponent = new TargetOpponent(true);
player.chooseTarget(Outcome.Detriment, targetOpponent, source, game);
opponent = game.getPlayer(targetOpponent.getFirstTarget());
}
TargetCard target = new TargetCard(1, Zone.GRAVEYARD, new FilterCard());
target.withChooseHint("Card to go to opponent's hand (other goes to battlefield)");
opponent.chooseTarget(outcome, pickedCards, target, source, game);
cardToHand = game.getCard(target.getFirstTarget());
}
for (Card card : pickedCards.getCards(game)) {
if (card == cardToHand) {
player.moveCards(cardToHand, Zone.HAND, source, game);
} else {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
FixedTarget fixedTarget = new FixedTarget(card, game);
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfGame);
effect.setTargetPointer(fixedTarget);
game.addEffect(effect, source);
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(fixedTarget);
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
}
}
pickedCards.clear();
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class WuSpyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (controller != null && opponent != null) {
Cards cards = new CardsImpl(opponent.getLibrary().getTopCards(game, 2));
if (!cards.isEmpty()) {
TargetCard target = new TargetCardInLibrary(new FilterCard("card to put into graveyard"));
controller.choose(Outcome.Benefit, cards, target, game);
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
}
return true;
}
return false;
}
use of mage.target.TargetCard in project mage by magefree.
the class WorldlyCounselEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, (new DomainValue()).calculate(game, source, this)));
controller.lookAtCards(source, null, cards, game);
if (!cards.isEmpty()) {
if (cards.size() == 1) {
controller.moveCards(cards, Zone.HAND, source, game);
} else {
TargetCard target = new TargetCard(Zone.LIBRARY, new FilterCard("card to put into your hand"));
if (controller.choose(Outcome.DrawCard, cards, target, game)) {
Card card = cards.get(target.getFirstTarget(), game);
if (card != null) {
cards.remove(card);
controller.moveCards(card, Zone.HAND, source, game);
}
}
controller.putCardsOnBottomOfLibrary(cards, game, source, true);
}
}
return true;
}
Aggregations