use of mage.players.Library in project mage by magefree.
the class TransmogrifyEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = getTargetPointer().getFirstTargetPermanentOrLKI(game, source);
if (permanent != null) {
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
Library library = player.getLibrary();
if (library.hasCards()) {
Cards cards = new CardsImpl();
Card toBattlefield = null;
for (Card card : library.getCards(game)) {
cards.add(card);
if (card.isCreature(game)) {
toBattlefield = card;
break;
}
}
if (toBattlefield != null) {
player.moveCards(toBattlefield, Zone.BATTLEFIELD, source, game);
}
player.revealCards(source, cards, game);
cards.remove(toBattlefield);
if (!cards.isEmpty()) {
player.shuffleLibrary(source, game);
}
}
return true;
}
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class ReweaveEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
MageObject sourceObject = source.getSourceObject(game);
if (permanent != null && sourceObject != null) {
if (permanent.sacrifice(source, game)) {
Player permanentController = game.getPlayer(permanent.getControllerId());
if (permanentController != null) {
Library library = permanentController.getLibrary();
if (library.hasCards()) {
Cards cards = new CardsImpl();
Card permanentCard = null;
for (Card card : permanentController.getLibrary().getCards(game)) {
cards.add(card);
if (card.isPermanent(game)) {
for (CardType cardType : permanent.getCardType(game)) {
if (card.getCardType(game).contains(cardType)) {
permanentCard = card;
break;
}
}
}
}
permanentController.revealCards(source, cards, game);
if (permanentCard != null) {
permanentController.moveCards(permanentCard, Zone.BATTLEFIELD, source, game);
}
permanentController.shuffleLibrary(source, game);
}
return true;
}
return false;
}
}
return true;
}
use of mage.players.Library in project mage by magefree.
the class KnacksawCliqueCastFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject != null && opponent != null) {
if (opponent.getLibrary().hasCards()) {
Library library = opponent.getLibrary();
Card card = library.getFromTop(game);
if (card != null) {
opponent.moveCardToExileWithInfo(card, source.getSourceId(), sourceObject.getName(), source, game, Zone.LIBRARY, true);
ContinuousEffect effect = new KnacksawCliqueCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId(), game));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class KillerInstinctEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
if (player == null || sourceObject == null) {
return false;
}
Library library = player.getLibrary();
if (library == null || !library.hasCards()) {
return false;
}
Card card = library.getFromTop(game);
if (card == null) {
return false;
}
player.revealCards(sourceObject.getIdName(), new CardsImpl(card), game);
if (card.isCreature(game) && player.moveCards(card, Zone.BATTLEFIELD, source, game)) {
Permanent permanent = game.getPermanent(card.getId());
if (permanent != null) {
FixedTarget ft = new FixedTarget(permanent, game);
ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.EndOfTurn);
effect.setTargetPointer(ft);
game.addEffect(effect, source);
Effect sacrificeEffect = new SacrificeTargetEffect("Sacrifice it at the beginning of the next end step", source.getControllerId());
sacrificeEffect.setTargetPointer(ft);
game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect), source);
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class NicolBolasGodPharaohPlusTwoEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player opponent = game.getPlayer(targetPointer.getFirst(game, source));
if (opponent == null) {
return false;
}
Library library = opponent.getLibrary();
Card card;
do {
card = library.getFromTop(game);
if (card == null) {
continue;
}
opponent.moveCards(card, Zone.EXILED, source, game);
if (card.isLand(game)) {
continue;
}
ContinuousEffect effect = new PlayFromNotOwnHandZoneTargetEffect(Zone.EXILED, TargetController.YOU, Duration.EndOfTurn, true);
effect.setTargetPointer(new FixedTarget(card, game));
game.addEffect(effect, source);
break;
} while (library.hasCards() && card != null);
return true;
}
Aggregations