use of mage.cards.Card in project mage by magefree.
the class TheBiblioplexEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
player.lookAtCards("Top of library", card, game);
if (card.isInstantOrSorcery(game) && player.chooseUse(Outcome.DrawCard, "Reveal that card and put it into your hand?", source, game)) {
player.revealCards(source, new CardsImpl(card), game);
player.moveCards(card, Zone.HAND, source, game);
} else if (player.chooseUse(Outcome.Discard, "Put that card into your graveyard?", source, game)) {
player.moveCards(card, Zone.GRAVEYARD, source, game);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class TransmuteArtifactEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
// Sacrifice an artifact.
int manaValue = 0;
boolean sacrifice = false;
TargetControlledPermanent targetArtifact = new TargetControlledPermanent(new FilterControlledArtifactPermanent());
if (controller.chooseTarget(Outcome.Sacrifice, targetArtifact, source, game)) {
Permanent permanent = game.getPermanent(targetArtifact.getFirstTarget());
if (permanent != null) {
manaValue = permanent.getManaValue();
sacrifice = permanent.sacrifice(source, game);
}
} else {
return true;
}
// If you do, search your library for an artifact card.
if (sacrifice && controller.searchLibrary(target, source, game)) {
if (!target.getTargets().isEmpty()) {
for (UUID cardId : target.getTargets()) {
Card card = controller.getLibrary().getCard(cardId, game);
if (card != null) {
// If that card's converted mana cost is less than or equal to the sacrificed artifact's converted mana cost, put it onto the battlefield.
if (card.getManaValue() <= manaValue) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
// If it's greater, you may pay {X}, where X is the difference. If you do, put it onto the battlefield.
Cost cost = ManaUtil.createManaCost(card.getManaValue() - manaValue, true);
boolean payed = false;
if (controller.chooseUse(Outcome.Benefit, "Do you want to pay " + cost.getText() + " to put it onto the battlefield?", source, game) && cost.pay(source, game, source, source.getControllerId(), false)) {
payed = true;
}
if (payed) {
controller.moveCards(card, Zone.BATTLEFIELD, source, game);
} else {
// If you don't, put it into its owner's graveyard. Then shuffle your library
controller.moveCards(card, Zone.GRAVEYARD, source, game);
}
}
}
}
}
controller.shuffleLibrary(source, game);
return true;
}
controller.shuffleLibrary(source, game);
return false;
}
use of mage.cards.Card in project mage by magefree.
the class TrackDownEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source.getSourceId());
if (sourceObject == null || controller == null) {
return false;
}
if (!controller.getLibrary().hasCards()) {
return false;
}
Card card = controller.getLibrary().getFromTop(game);
if (card == null) {
return false;
}
CardsImpl cards = new CardsImpl();
cards.add(card);
controller.revealCards(sourceObject.getName(), cards, game);
if (card.isLand(game) || card.isCreature(game)) {
controller.drawCards(1, source, game);
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class VaevictisAsmadiTheDireEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
List<Player> playersToFlip = new ArrayList<>();
for (Target target : source.getTargets()) {
for (UUID permId : target.getTargets()) {
Permanent permanent = game.getPermanent(permId);
if (permanent == null || !permanent.sacrifice(source, game)) {
continue;
}
Player player = game.getPlayer(permanent.getControllerId());
if (player != null) {
playersToFlip.add(player);
}
}
}
for (Player player : playersToFlip) {
if (player == null) {
return false;
}
Card card = player.getLibrary().getFromTop(game);
if (card == null) {
continue;
}
player.revealCards(source, new CardsImpl(card), game);
if (card.isPermanent(game)) {
player.moveCards(card, Zone.BATTLEFIELD, source, game);
}
}
return true;
}
use of mage.cards.Card in project mage by magefree.
the class ExileAllCardsFromAllGraveyards method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject Valki = game.getObject(source.getSourceId());
Set<Card> cardsToExile = new LinkedHashSet<>();
if (controller != null && Valki != null) {
UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + Valki.getZoneChangeCounter(game), game);
for (UUID opponentId : game.getOpponents(controller.getId())) {
Player opponent = game.getPlayer(opponentId);
if (opponent != null) {
opponent.revealCards(source, opponent.getHand(), game);
TargetCard targetToExile = new TargetCard(Zone.HAND, StaticFilters.FILTER_CARD_CREATURE);
targetToExile.withChooseHint("card to exile");
targetToExile.setNotTarget(true);
if (controller.choose(Outcome.Exile, opponent.getHand(), targetToExile, game)) {
Card targetedCardToExile = game.getCard(targetToExile.getFirstTarget());
if (targetedCardToExile != null && game.getState().getZone(source.getSourceId()) == Zone.BATTLEFIELD) {
cardsToExile.add(targetedCardToExile);
}
}
}
}
// exile all cards at one time
controller.moveCardsToExile(cardsToExile, source, game, true, exileId, Valki.getName());
game.addDelayedTriggeredAbility(new ValkiGodOfLiesReturnExiledCardAbility(), source);
return true;
}
return false;
}
Aggregations