use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class ConditionalAsThoughTest method test_TargetCardInLibrary_CantUseAsAbilityTarget.
@Test(expected = IllegalArgumentException.class)
public void test_TargetCardInLibrary_CantUseAsAbilityTarget() {
Ability ability = new SimpleActivatedAbility(Zone.ALL, new InfoEffect("test"), new ManaCostsImpl("{R}"));
ability.addTarget(new TargetCardInLibrary());
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class ReplaceOpponentCardsInHandWithSelectedEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Player targetOpponent = game.getPlayer(getTargetPointer().getFirst(game, source));
if (controller != null && targetOpponent != null) {
int originalHandSize = targetOpponent.getHand().size();
if (originalHandSize > 0) {
targetOpponent.putCardsOnTopOfLibrary(targetOpponent.getHand(), game, source, false);
int librarySize = targetOpponent.getLibrary().size();
int searchLibraryForNum = min(originalHandSize, librarySize);
TargetCardInLibrary target = new TargetCardInLibrary(searchLibraryForNum, searchLibraryForNum, new FilterCard());
controller.searchLibrary(target, source, game, targetOpponent.getId());
for (UUID cardId : target.getTargets()) {
Card targetCard = game.getCard(cardId);
targetOpponent.moveCards(targetCard, Zone.HAND, source, game);
}
targetOpponent.shuffleLibrary(source, game);
}
return true;
}
return false;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class AchHansRunEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
String cardName = ChooseACardNameEffect.TypeOfName.CREATURE_NAME.getChoice(controller, game, source, false);
game.informPlayers(controller.getLogName() + ": \"Ach! Hans, run! It's the " + cardName + "!\"");
FilterCard nameFilter = new FilterCard();
nameFilter.add(new NamePredicate(cardName));
TargetCardInLibrary target = new TargetCardInLibrary(1, 1, nameFilter);
if (!controller.searchLibrary(target, source, game)) {
return false;
}
Card card = controller.getLibrary().remove(target.getFirstTarget(), game);
if (card == null || !controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return false;
}
Permanent creature = game.getPermanent(card.getId());
if (creature == null) {
return false;
}
// gains haste
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(new FixedTarget(creature, game));
game.addEffect(effect, source);
// Exile at begin of next end step
ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
exileEffect.setTargetPointer(new FixedTarget(creature, game));
DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
game.addDelayedTriggeredAbility(delayedAbility, source);
controller.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class AlpineHoundmasterTarget method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
TargetCardInLibrary target = new AlpineHoundmasterTarget();
player.searchLibrary(target, source, game);
Cards cards = new CardsImpl(target.getTargets());
player.revealCards(source, cards, game);
player.moveCards(cards, Zone.HAND, source, game);
player.shuffleLibrary(source, game);
return true;
}
use of mage.target.common.TargetCardInLibrary in project mage by magefree.
the class ArcumDagssonEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent artifactCreature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
if (artifactCreature != null) {
Player player = game.getPlayer(artifactCreature.getControllerId());
if (player != null) {
artifactCreature.sacrifice(source, game);
// Workaround for https://github.com/magefree/mage/issues/8501
game.getState().processAction(game);
if (player.chooseUse(Outcome.PutCardInPlay, "Search your library for a noncreature artifact card?", source, game)) {
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.searchLibrary(target, source, game)) {
Card card = game.getCard(target.getFirstTarget());
if (card != null) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
player.shuffleLibrary(source, game);
}
return true;
}
}
return false;
}
Aggregations