use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MaximumHandSizeEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
TargetCardInHand target = new TargetCardInHand();
controller.chooseTarget(Outcome.ReturnToHand, target, source, game);
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
controller.putCardsOnTopOfLibrary(new CardsImpl(card), game, source, false);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class FlashEffect 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 false;
}
TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
ManaCosts<ManaCost> reducedCost = ManaCosts.removeVariableManaCost(CardUtil.reduceCost(card.getManaCost(), 2));
if (controller.chooseUse(Outcome.Benefit, String.valueOf("Pay " + reducedCost.getText()) + Character.toString('?'), source, game)) {
reducedCost.clearPaid();
if (reducedCost.pay(source, game, source, source.getControllerId(), false, null)) {
return true;
}
}
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
permanent.sacrifice(source, game);
}
return true;
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class InSearchOfGreatnessEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
int cmc = 0;
UUID permId = source.getSourceId();
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(controller.getId())) {
if (permanent != null && !permanent.getId().equals(permId)) {
int permCmc = permanent.getManaValue();
if (permCmc > cmc) {
cmc = permCmc;
}
}
}
if (controller.chooseUse(outcome, "Cast a permanent spell from your hand with CMC equal to " + ++cmc + "?", source, game)) {
FilterPermanentCard filter = new FilterPermanentCard("permanent spell from your hand");
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, cmc));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.chooseTarget(outcome, target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (cardWasCast) {
return true;
}
}
}
}
return controller.scry(1, source, game);
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MercadianLiftEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
int numberOfCounters = 0;
for (Cost cost : source.getCosts()) {
if (cost instanceof RemoveVariableCountersSourceCost) {
numberOfCounters = ((RemoveVariableCountersSourceCost) cost).getAmount();
}
}
System.out.println("The number is " + numberOfCounters);
FilterCreatureCard filter = new FilterCreatureCard();
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, numberOfCounters));
filter.setMessage("creature card with mana value " + numberOfCounters);
TargetCardInHand target = new TargetCardInHand(filter);
if (target.canChoose(source.getSourceId(), controller.getId(), game) && controller.chooseUse(Outcome.PutCardInPlay, "Put " + filter.getMessage() + " from your hand onto the battlefield?", source, game) && controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
target.setRequired(false);
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
return controller.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class MetalworkerManaEffect method produceMana.
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) {
return mana;
}
Player controller = getPlayer(game, source);
if (controller == null) {
return mana;
}
int artifacts = controller.getHand().count(StaticFilters.FILTER_CARD_ARTIFACT, game);
if (artifacts > 0) {
TargetCardInHand target = new TargetCardInHand(0, Integer.MAX_VALUE, StaticFilters.FILTER_CARD_ARTIFACT);
if (controller.choose(Outcome.Benefit, target, source.getSourceId(), game)) {
Cards cards = new CardsImpl(target.getTargets());
controller.revealCards(source, cards, game);
return Mana.ColorlessMana(target.getTargets().size() * 2);
}
}
return mana;
}
Aggregations