use of mage.target.common.TargetCardInHand in project mage by magefree.
the class IncandescentSoulstokeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
FilterCard filter = new FilterCreatureCard();
filter.add(SubType.ELEMENTAL.getPredicate());
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
effect.setTargetPointer(new FixedTarget(permanent, game));
game.addEffect(effect, source);
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
}
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class KaaliaOfTheVastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || !controller.chooseUse(Outcome.PutCreatureInPlay, "Put an Angel, Demon, or Dragon creature card from your hand onto the battlefield tapped and attacking?", source, game)) {
return false;
}
TargetCardInHand target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && target.choose(outcome, controller.getId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
UUID cardId = target.getFirstTarget();
Card card = game.getCard(cardId);
if (card != null && game.getCombat() != null) {
UUID defenderId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
if (defenderId != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, false, null);
Permanent creature = game.getPermanent(cardId);
if (creature != null) {
game.getCombat().addAttackerToCombat(card.getId(), defenderId, game);
return true;
}
}
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class KotoseTheSilentSpiderWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (controller == null || card == null) {
return false;
}
Player opponent = game.getPlayer(card.getOwnerId());
if (opponent == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(game, source);
String exileName = CardUtil.getSourceName(game, source);
controller.moveCardsToExile(card, source, game, true, exileId, exileName);
Cards cards = new CardsImpl();
FilterCard filter = new FilterCard("cards named " + card.getName() + " from " + opponent.getName() + "'s graveyard");
filter.add(new NamePredicate(card.getName()));
TargetCardInGraveyard targetCardInGraveyard = new TargetCardInGraveyard(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getGraveyard(), targetCardInGraveyard, game);
cards.addAll(targetCardInGraveyard.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s hand");
TargetCardInHand targetCardInHand = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
controller.choose(outcome, opponent.getHand(), targetCardInHand, game);
cards.addAll(targetCardInHand.getTargets());
filter.setMessage("cards named " + card.getName() + " from " + opponent.getName() + "'s library");
TargetCardInLibrary target = new TargetCardInLibrary(0, Integer.MAX_VALUE, filter);
controller.searchLibrary(target, source, game, opponent.getId());
target.getTargets().stream().map(cardId -> opponent.getLibrary().getCard(cardId, game)).forEach(cards::add);
Set<Card> cardSet = cards.getCards(game);
controller.moveCardsToExile(cardSet, source, game, true, exileId, exileName);
opponent.shuffleLibrary(source, game);
cardSet.add(card);
if (cardSet.isEmpty() || source.getSourcePermanentIfItStillExists(game) == null) {
return true;
}
KotoseTheSilentSpiderWatcher.addCards(source, cardSet, game);
for (Card exiledCard : cardSet) {
CardUtil.makeCardPlayable(game, source, exiledCard, Duration.WhileControlled, true, null, new KotoseTheSilentSpiderCondition(exiledCard, game));
}
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class KozilekDiscardCost method pay.
@Override
public boolean pay(Ability ability, Game game, Ability source, UUID controllerId, boolean noMana, Cost costToPay) {
Spell targetSpell = game.getStack().getSpell(ability.getFirstTarget());
if (targetSpell == null) {
return false;
}
Player player = game.getPlayer(controllerId);
if (player == null) {
return false;
}
FilterCard filter = new FilterCard("card with mana value of " + targetSpell.getManaValue());
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, targetSpell.getManaValue()));
TargetCardInHand target = new TargetCardInHand(filter);
this.getTargets().clear();
this.getTargets().add(target);
if (targets.choose(Outcome.Discard, controllerId, source.getSourceId(), game)) {
for (UUID targetId : targets.get(0).getTargets()) {
Card card = player.getHand().get(targetId, game);
if (card == null) {
return false;
}
player.discard(card, true, source, game);
paid = true;
}
}
return paid;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class PryingQuestionsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player targetOpponent = game.getPlayer(this.getTargetPointer().getFirst(game, source));
if (targetOpponent != null) {
if (!targetOpponent.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
target.setNotTarget(true);
target.setTargetName("a card from your hand to put on top of your library");
targetOpponent.choose(Outcome.Detriment, target, source.getSourceId(), game);
Card card = targetOpponent.getHand().get(target.getFirstTarget(), game);
if (card != null) {
targetOpponent.moveCardToLibraryWithInfo(card, source, game, Zone.HAND, true, false);
}
}
return true;
}
return false;
}
Aggregations