use of mage.target.common.TargetCardInHand in project mage by magefree.
the class PendantOfProsperityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
effect1.apply(game, source);
effect2.apply(game, source);
Player player = game.getPlayer(game.getOwnerId(game.getPermanent(source.getSourceId())));
if (player == null) {
return false;
}
player.drawCards(1, source, game);
if (!player.chooseUse(outcome, "Put a land into play from your hand?", source, game)) {
return true;
}
TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_LAND_A);
if (!player.choose(outcome, player.getHand(), target, game)) {
return true;
}
player.moveCards(new CardsImpl(target.getTargets()), Zone.BATTLEFIELD, source, game);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class RetracedImageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetCardInHand target = new TargetCardInHand();
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.choose(outcome, target, source.getSourceId(), game)) {
Card chosenCard = game.getCard(target.getFirstTarget());
if (chosenCard != null) {
Cards cards = new CardsImpl();
cards.add(chosenCard);
controller.revealCards(source, cards, game);
for (Permanent permanent : game.getBattlefield().getAllActivePermanents()) {
if (permanent.getName().equals(chosenCard.getName())) {
return controller.moveCards(chosenCard, Zone.BATTLEFIELD, source, game);
}
}
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class RofellossGiftEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter1);
if (!player.choose(outcome, player.getHand(), targetCardInHand, game)) {
return false;
}
Cards cards = new CardsImpl();
for (UUID cardId : targetCardInHand.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
}
}
player.revealCards(source, cards, game);
int enchantmentsToReturn = Math.min(player.getGraveyard().count(filter2, game), targetCardInHand.getTargets().size());
TargetCardInYourGraveyard targetCardInYourGraveyard = new TargetCardInYourGraveyard(enchantmentsToReturn, filter2);
targetCardInYourGraveyard.setNotTarget(true);
if (!player.choose(outcome, targetCardInYourGraveyard, source.getSourceId(), game)) {
return false;
}
cards = new CardsImpl();
for (UUID cardId : targetCardInYourGraveyard.getTargets()) {
Card card = game.getCard(cardId);
if (card != null) {
cards.add(card);
}
}
return player.moveCards(cards, Zone.HAND, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class SneakAttackEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
return true;
}
TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
if (!controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
return true;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent permanent = game.getPermanent(CardUtil.getDefaultCardSideForBattlefield(game, card).getId());
if (permanent == null) {
return true;
}
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId()).setTargetPointer(new FixedTarget(permanent, game))), source);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class StrongholdGambitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller != null && sourceObject != null) {
Map<UUID, UUID> choosenCard = new LinkedHashMap<>();
for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null && !player.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
if (player.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
choosenCard.put(playerId, target.getFirstTarget());
}
}
}
int lowestCMC = Integer.MAX_VALUE;
for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null && choosenCard.containsKey(playerId)) {
Card card = game.getCard(choosenCard.get(playerId));
if (card != null) {
Cards cardsToReveal = new CardsImpl(card);
player.revealCards(sourceObject.getIdName() + " (" + player.getName() + ')', cardsToReveal, game);
if (card.isCreature(game) && lowestCMC > card.getManaValue()) {
lowestCMC = card.getManaValue();
}
}
}
}
if (lowestCMC < Integer.MAX_VALUE) {
Cards creaturesToBattlefield = new CardsImpl();
for (UUID playerId : game.getState().getPlayerList(controller.getId())) {
Player player = game.getPlayer(playerId);
if (player != null && choosenCard.containsKey(playerId)) {
Card card = game.getCard(choosenCard.get(playerId));
if (card != null) {
if (card.isCreature(game) && lowestCMC == card.getManaValue()) {
creaturesToBattlefield.add(card);
}
}
}
}
controller.moveCards(creaturesToBattlefield.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
return true;
}
return false;
}
Aggregations