use of mage.target.common.TargetCardInHand in project mage by magefree.
the class BoonweaverGiantEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
FilterCard filter = new FilterCard("Aura card");
filter.add(CardType.ENCHANTMENT.getPredicate());
filter.add(SubType.AURA.getPredicate());
Card card = null;
Zone zone = null;
if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for an Aura card?", source, game)) {
TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.GRAVEYARD;
}
}
}
if (card == null && controller.chooseUse(Outcome.Neutral, "Search your Hand for an Aura card?", source, game)) {
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.HAND;
}
}
}
if (card == null) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
card = game.getCard(target.getFirstTarget());
if (card != null) {
zone = Zone.LIBRARY;
}
}
controller.shuffleLibrary(source, game);
}
// aura card found - attach it
if (card != null) {
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
game.getState().setValue("attachTo:" + card.getId(), permanent);
}
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
if (permanent != null) {
return permanent.addAttachment(card.getId(), source, game);
}
}
return true;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ChecksAndBalancesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(this.getTargetPointer().getFirst(game, source));
if (spell != null) {
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (player.getHand().isEmpty()) {
game.informPlayers(player.getLogName() + " doesn't have a card in hand to discard to counter " + spell.getLogName() + ", effect aborted.");
return true;
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null) {
if (!player.chooseUse(outcome, "Discard a card to counter " + spell.getLogName() + '?', source, game)) {
game.informPlayers(player.getLogName() + " refuses to discard a card to counter " + spell.getLogName());
return true;
} else {
game.informPlayers(player.getLogName() + " agrees to discard a card to counter " + spell.getLogName());
}
}
}
for (UUID uuid : game.getOpponents(spell.getControllerId())) {
Player player = game.getPlayer(uuid);
if (player != null && !player.getHand().isEmpty()) {
TargetCardInHand target = new TargetCardInHand();
if (player.choose(Outcome.Discard, target, source.getSourceId(), game)) {
Card card = game.getCard(target.getFirstTarget());
player.discard(card, false, source, game);
}
}
}
game.getStack().counter(spell.getId(), source, game);
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class CounterlashEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
StackObject stackObject = game.getStack().getStackObject(source.getFirstTarget());
Player controller = game.getPlayer(source.getControllerId());
if (stackObject != null && controller != null) {
game.getStack().counter(source.getFirstTarget(), source, game);
if (controller.chooseUse(Outcome.PlayForFree, "Cast a nonland card in your hand that " + "shares a card type with that spell without paying its mana cost?", source, game)) {
FilterCard filter = new FilterCard();
List<Predicate<MageObject>> types = new ArrayList<>();
for (CardType type : stackObject.getCardType(game)) {
if (type != CardType.LAND) {
types.add(type.getPredicate());
}
}
filter.add(Predicates.or(types));
TargetCardInHand target = new TargetCardInHand(filter);
if (controller.choose(Outcome.PutCardInPlay, target, source.getSourceId(), game)) {
Card card = controller.getHand().get(target.getFirstTarget(), game);
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class DiscipleOfDeceitEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject mageObject = game.getObject(source.getSourceId());
if (player != null && mageObject != null) {
Cost cost = new DiscardTargetCost(new TargetCardInHand(new FilterNonlandCard()));
String message = "Discard a nonland card to search your library?";
if (cost.canPay(source, source, source.getControllerId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
if (cost.pay(source, game, source, source.getControllerId(), false, null)) {
Card card = game.getCard(cost.getTargets().getFirstTarget());
if (card == null) {
return false;
}
String targetName = "card with mana value of " + card.getManaValue();
FilterCard filter = new FilterCard(targetName);
filter.add(new ManaValuePredicate(ComparisonType.EQUAL_TO, card.getManaValue()));
return new SearchLibraryPutInHandEffect(new TargetCardInLibrary(filter), true, true).apply(game, source);
}
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInHand in project mage by magefree.
the class ElevenTheMageEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
player.drawCards(1, source, game);
player.loseLife(1, game, source, false);
if (player.getHand().size() < 11) {
return true;
}
// TODO: change this to fit with changes made in https://github.com/magefree/mage/pull/8136 when merged
Target target = new TargetCardInHand(StaticFilters.FILTER_CARD_INSTANT_OR_SORCERY);
if (!target.canChoose(source.getSourceId(), player.getId(), game) || !player.chooseUse(Outcome.PlayForFree, "Cast an instant or sorcery spell " + "from your hand without paying its mana cost?", source, game)) {
return true;
}
Card cardToCast = null;
boolean cancel = false;
while (player.canRespond() && !cancel) {
if (player.chooseTarget(Outcome.PlayForFree, target, source, game)) {
cardToCast = game.getCard(target.getFirstTarget());
if (cardToCast != null) {
if (cardToCast.getSpellAbility() == null) {
Logger.getLogger(CastWithoutPayingManaCostEffect.class).fatal("Card: " + cardToCast.getName() + " is no land and has no spell ability!");
cancel = true;
}
if (cardToCast.getSpellAbility().canChooseTarget(game, player.getId())) {
cancel = true;
}
}
} else {
cancel = true;
}
}
if (cardToCast != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
return true;
}
Aggregations