use of mage.players.Library in project mage by magefree.
the class ChandraTorchOfDefianceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (controller != null && sourceObject != null && controller.getLibrary().hasCards()) {
Library library = controller.getLibrary();
Card card = library.getFromTop(game);
if (card != null) {
boolean cardWasCast = false;
controller.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
if (!card.getManaCost().isEmpty() || !card.isLand(game)) {
if (controller.chooseUse(Outcome.Benefit, "Cast " + card.getName() + "? (You still pay the costs)", source, game) && (game.getState().getZone(card.getId()) == Zone.EXILED)) {
// card must be in the exile zone
// enable the card to be cast from the exile zone
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, false), game, false, new ApprovingObject(source, game));
// reset to null
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
if (!cardWasCast) {
new DamagePlayersEffect(Outcome.Damage, StaticValue.get(2), TargetController.OPPONENT).apply(game, source);
}
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class NivixAerieOfTheFiremindCanCastEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Library library = controller.getLibrary();
if (library.hasCards()) {
Card card = library.getFromTop(game);
if (card != null && controller.moveCardsToExile(card, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null)) && card.isInstantOrSorcery(game)) {
ContinuousEffect effect = new NivixAerieOfTheFiremindCanCastEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class OrnateKanzashiCastFromExileEffect 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 OrnateKanzashiCastFromExileEffect();
effect.setTargetPointer(new FixedTarget(card.getId()));
game.addEffect(effect, source);
}
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class RevealCardsFromLibraryUntilEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (controller == null || !controller.getLibrary().hasCards()) {
return false;
}
Cards cards = new CardsImpl();
Library library = controller.getLibrary();
Card card = null;
do {
card = library.removeFromTop(game);
if (card != null) {
cards.add(card);
}
} while (library.hasCards() && !filter.match(card, game));
// reveal cards
if (cards.isEmpty()) {
return true;
}
controller.revealCards(sourceObject.getIdName(), cards, game);
if (filter.match(card, game)) {
// put card in correct zone
controller.moveCards(card, zoneToPutCard, source, game);
// remove it from revealed card list
cards.remove(card);
}
// Put the rest in correct zone
if (zoneToPutRest == Zone.LIBRARY) {
if (!cards.isEmpty()) {
if (shuffleRestInto) {
library.addAll(cards.getCards(game), game);
} else {
controller.putCardsOnBottomOfLibrary(cards, game, source, anyOrder);
}
}
} else {
if (!cards.isEmpty()) {
controller.moveCards(cards, zoneToPutRest, source, game);
}
}
return true;
}
use of mage.players.Library in project mage by magefree.
the class IndomitableCreativityEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
List<Permanent> destroyedPermanents = new ArrayList<>();
for (UUID targetId : getTargetPointer().getTargets(game, source)) {
Permanent target = game.getPermanent(targetId);
if (target != null) {
if (target.destroy(source, game, false)) {
destroyedPermanents.add(target);
}
}
}
for (Permanent permanent : destroyedPermanents) {
Player controllerOfDestroyedCreature = game.getPlayer(permanent.getControllerId());
if (controllerOfDestroyedCreature != null) {
Library library = controllerOfDestroyedCreature.getLibrary();
if (library.hasCards()) {
Cards cardsToReaveal = new CardsImpl();
for (Card card : library.getCards(game)) {
cardsToReaveal.add(card);
if (card.isCreature(game) || card.isArtifact(game)) {
controllerOfDestroyedCreature.moveCards(card, Zone.EXILED, source, game);
controllerOfDestroyedCreature.moveCards(card, Zone.BATTLEFIELD, source, game);
break;
}
}
controllerOfDestroyedCreature.revealCards(source, " for destroyed " + permanent.getIdName(), cardsToReaveal, game);
controllerOfDestroyedCreature.shuffleLibrary(source, game);
}
}
}
return true;
}
return false;
}
Aggregations