use of mage.players.Library in project mage by magefree.
the class PossibilityStormEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
// spell was exiled already by another effect, for example NivMagus Elemental
boolean noLongerOnStack = false;
if (spell == null) {
spell = ((Spell) game.getLastKnownInformation(targetPointer.getFirst(game, source), Zone.STACK));
noLongerOnStack = true;
}
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null && spell != null) {
Player spellController = game.getPlayer(spell.getControllerId());
if (spellController != null) {
if (!noLongerOnStack) {
spellController.moveCardsToExile(spell, source, game, true, source.getSourceId(), sourceObject.getIdName());
}
if (spellController.getLibrary().hasCards()) {
Library library = spellController.getLibrary();
Card card;
do {
card = library.getFromTop(game);
if (card != null) {
spellController.moveCardsToExile(card, source, game, true, source.getSourceId(), sourceObject.getIdName());
}
} while (library.hasCards() && card != null && !sharesType(card, spell.getCardType(game), game));
if (card != null && sharesType(card, spell.getCardType(game), game) && !card.isLand(game) && card.getSpellAbility().canChooseTarget(game, spellController.getId())) {
if (spellController.chooseUse(Outcome.PlayForFree, "Cast " + card.getLogName() + " without paying cost?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
spellController.cast(spellController.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
spellController.putCardsOnBottomOfLibrary(exile, game, source, false);
}
}
return true;
}
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class PolymorphEffect 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 VigeanIntuitionEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player player = game.getPlayer(source.getControllerId());
if (sourceObject == null || player == null) {
return false;
}
Library library = player.getLibrary();
if (library == null) {
return false;
}
Choice choiceImpl = new ChoiceImpl();
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
String choosenType = choiceImpl.getChoice();
if (choosenType == null || choosenType.isEmpty()) {
return false;
}
CardType type = null;
if (choosenType.equals(CardType.ARTIFACT.toString())) {
type = CardType.ARTIFACT;
} else if (choosenType.equals(CardType.LAND.toString())) {
type = CardType.LAND;
} else if (choosenType.equals(CardType.CREATURE.toString())) {
type = CardType.CREATURE;
} else if (choosenType.equals(CardType.ENCHANTMENT.toString())) {
type = CardType.ENCHANTMENT;
} else if (choosenType.equals(CardType.INSTANT.toString())) {
type = CardType.INSTANT;
} else if (choosenType.equals(CardType.SORCERY.toString())) {
type = CardType.SORCERY;
} else if (choosenType.equals(CardType.PLANESWALKER.toString())) {
type = CardType.PLANESWALKER;
} else if (choosenType.equals(CardType.TRIBAL.toString())) {
type = CardType.TRIBAL;
}
if (type != null) {
Set<Card> top = library.getTopCards(game, 4);
player.revealCards(source, new CardsImpl(top), game);
Cards putInHand = new CardsImpl();
Cards putInGraveyard = new CardsImpl();
for (Card card : top) {
if (card != null && card.getCardType(game).contains(type)) {
putInHand.add(card);
} else {
putInGraveyard.add(card);
}
}
player.moveCards(putInHand, Zone.HAND, source, game);
player.moveCards(putInGraveyard, Zone.GRAVEYARD, source, game);
return true;
}
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class ExplosiveRevelationEffect 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) {
if (controller.getLibrary().hasCards()) {
CardsImpl toReveal = new CardsImpl();
Library library = controller.getLibrary();
Card nonLandCard = null;
for (Card card : library.getCards(game)) {
toReveal.add(card);
if (!card.isLand(game)) {
nonLandCard = card;
break;
}
}
// reveal cards
controller.revealCards(sourceObject.getIdName(), toReveal, game);
// the nonland card
int damage = nonLandCard == null ? 0 : nonLandCard.getManaValue();
// assign damage to target
for (UUID targetId : targetPointer.getTargets(game, source)) {
Permanent targetedCreature = game.getPermanent(targetId);
if (targetedCreature != null) {
targetedCreature.damage(damage, source.getSourceId(), source, game, false, true);
} else {
Player targetedPlayer = game.getPlayer(targetId);
if (targetedPlayer != null) {
targetedPlayer.damage(damage, source.getSourceId(), source, game);
}
}
}
if (nonLandCard != null) {
// move nonland card to hand
controller.moveCards(nonLandCard, Zone.HAND, source, game);
toReveal.remove(nonLandCard);
}
// put the rest of the cards on the bottom of the library in any order
return controller.putCardsOnBottomOfLibrary(toReveal, game, source, true);
}
return true;
}
return false;
}
use of mage.players.Library in project mage by magefree.
the class BlessedReincarnationEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
if (permanent != null && controller != null) {
controller.moveCards(permanent, Zone.EXILED, source, game);
game.getState().processAction(game);
Player permanentController = game.getPlayer(permanent.getControllerId());
if (permanentController != null) {
Library library = permanentController.getLibrary();
if (library.hasCards()) {
Cards toReveal = new CardsImpl();
for (Card card : library.getCards(game)) {
toReveal.add(card);
if (card.isCreature(game)) {
permanentController.moveCards(card, Zone.BATTLEFIELD, source, game);
break;
}
}
permanentController.revealCards(source, toReveal, game);
if (toReveal.size() > 1) {
permanentController.shuffleLibrary(source, game);
}
}
}
return true;
}
return false;
}
Aggregations