use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MaelstromArchangelCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Target target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(outcome, "Cast a spell from your hand without paying its mana cost?", source, game)) {
Card cardToCast = null;
boolean cancel = false;
while (controller.canRespond() && !cancel) {
if (controller.chooseTarget(outcome, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null && cardToCast.getSpellAbility().canChooseTarget(game, controller.getId())) {
cancel = true;
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class PlaneboundAccompliceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
if (!controller.chooseUse(Outcome.PutCardInPlay, "Put a planeswalker card from your hand onto the battlefield?", source, game)) {
return true;
}
TargetCardInHand target = new TargetCardInHand(filter);
if (!controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
return true;
}
Card card = game.getCard(target.getFirstTarget());
if (card == null) {
return false;
}
if (!controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return true;
}
SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ScrollRackEffect 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) {
FilterCard filter = new FilterCard("card in your hand to exile");
TargetCardInHand target = new TargetCardInHand(0, controller.getHand().size(), filter);
target.setRequired(false);
int amountExiled = 0;
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
for (UUID targetId : target.getTargets()) {
Card card = game.getCard(targetId);
if (card != null) {
card.setFaceDown(true, game);
amountExiled++;
}
}
controller.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, false, source.getSourceId(), sourceObject.getIdName());
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
if (exileZone != null) {
for (Card card : exileZone.getCards(game)) {
card.setFaceDown(true, game);
}
}
}
}
// Put that many cards from the top of your library into your hand.
if (amountExiled > 0) {
controller.moveCards(controller.getLibrary().getTopCards(game, amountExiled), Zone.HAND, source, game);
}
// Then look at the exiled cards and put them on top of your library in any order
controller.putCardsOnTopOfLibrary(game.getExile().getExileZone(source.getSourceId()), game, source, true);
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class SurtlandElementalistEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
TargetCardInHand target = new TargetCardInHand(0, 1, StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
boolean cardWasCast = player.cast(player.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
return cardWasCast;
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class SurpriseDeploymentEffect 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)) {
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) {
ReturnToHandTargetEffect effect = new ReturnToHandTargetEffect();
effect.setTargetPointer(new FixedTarget(permanent, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
}
}
return false;
}
}
return true;
}
return false;
}
Aggregations