use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SkyclavePlunderEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
int xValue = 3 + PartyCount.instance.calculate(game, source, this);
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, xValue));
int toTake = Math.min(cards.size(), 3);
TargetCard target = new TargetCardInLibrary(toTake, toTake, StaticFilters.FILTER_CARD);
player.choose(outcome, cards, target, game);
Cards toHand = new CardsImpl(target.getTargets());
cards.removeIf(target.getTargets()::contains);
player.moveCards(toHand, Zone.HAND, source, game);
player.putCardsOnBottomOfLibrary(cards, game, source, false);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class StonehewerGiantEffect 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("Equipment");
filter.add(SubType.EQUIPMENT.getPredicate());
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (controller.searchLibrary(target, source, game)) {
Card card = controller.getLibrary().getCard(target.getFirstTarget(), game);
if (card != null) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
Permanent equipment = game.getPermanent(card.getId());
Target targetCreature = new TargetControlledCreaturePermanent();
targetCreature.setNotTarget(true);
if (equipment != null && controller.choose(Outcome.BoostCreature, targetCreature, source.getSourceId(), game)) {
Permanent permanent = game.getPermanent(targetCreature.getFirstTarget());
permanent.addAttachment(equipment.getId(), source, game);
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SameNameAsExiledCountValue method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInLibrary target = new TargetCardInLibrary(new FilterLandCard());
if (player.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
UUID cardId = target.getTargets().get(0);
Card card = player.getLibrary().remove(cardId, game);
if (card != null) {
card.moveToExile(source.getSourceId(), "Strata Scythe", source, game);
Permanent permanent = game.getPermanent(source.getSourceId());
if (permanent != null) {
permanent.imprint(card.getId(), game);
}
}
}
}
player.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class WinotaJoinerOfForcesEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
TargetCardInLibrary targetCardInLibrary = new TargetCardInLibrary(0, 1, filter);
player.choose(outcome, cards, targetCardInLibrary, game);
Card card = game.getCard(targetCardInLibrary.getFirstTarget());
if (card == null || !player.moveCards(card, Zone.BATTLEFIELD, source, game, true, false, true, null)) {
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
Permanent permanent = game.getPermanent(card.getId());
if (permanent == null) {
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
game.getCombat().addAttackingCreature(permanent.getId(), game);
cards.remove(card);
game.addEffect(new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Duration.EndOfTurn).setTargetPointer(new FixedTarget(permanent, game)), source);
return player.putCardsOnBottomOfLibrary(cards, game, source, false);
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class SearchLibraryGraveyardPutInHandEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
Card cardFound = null;
boolean needShuffle = false;
if (controller != null && sourceObject != null) {
if (forceToSearchBoth || controller.chooseUse(outcome, "Search your library for a card named " + filter.getMessage() + '?', source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(0, 1, filter);
target.clearChosen();
if (controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
cardFound = game.getCard(target.getFirstTarget());
}
}
needShuffle = true;
}
if (cardFound == null && controller.chooseUse(outcome, "Search your graveyard for a card named " + filter.getMessage() + '?', source, game)) {
TargetCard target = new TargetCardInYourGraveyard(0, 1, filter, true);
target.clearChosen();
if (controller.choose(outcome, controller.getGraveyard(), target, game)) {
if (!target.getTargets().isEmpty()) {
cardFound = game.getCard(target.getFirstTarget());
}
}
}
if (cardFound != null) {
controller.revealCards(sourceObject.getIdName(), new CardsImpl(cardFound), game);
controller.moveCards(cardFound, Zone.HAND, source, game);
}
if (needShuffle) {
controller.shuffleLibrary(source, game);
}
return true;
}
return false;
}
Aggregations