use of mage.game.ExileZone in project mage by magefree.
the class TibaltsTrickeryEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Spell spell = game.getStack().getSpell(targetPointer.getFirst(game, source));
if (spell != null) {
String spellName = spell.getName();
Player controller = game.getPlayer(spell.getControllerId());
game.getStack().counter(spell.getId(), source, game);
if (controller != null) {
int random = RandomUtil.nextInt(3) + 1;
game.informPlayers(random + " was chosen at random");
controller.millCards(random, source, game);
Card cardToCast = null;
Set<Card> cardsToExile = new HashSet<>();
FilterCard filter = new FilterCard();
filter.add(Predicates.not(CardType.LAND.getPredicate()));
filter.add(Predicates.not(new NamePredicate(spellName)));
for (Card card : controller.getLibrary().getCards(game)) {
cardsToExile.add(card);
if (filter.match(card, game)) {
cardToCast = card;
break;
}
}
controller.moveCardsToExile(cardsToExile, source, game, true, source.getSourceId(), CardUtil.createObjectRealtedWindowTitle(source, game, null));
if (cardToCast != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Cast " + cardToCast.getLogName() + " for free?", source, game)) {
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), Boolean.TRUE);
controller.cast(controller.chooseAbilityForCast(cardToCast, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + cardToCast.getId(), null);
}
}
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null) {
controller.putCardsOnBottomOfLibrary(exile, game, source, false);
}
}
return true;
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class WizardsSpellbookEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
Card card = game.getCard(getTargetPointer().getFirst(game, source));
if (player == null || card == null) {
return false;
}
UUID exileId = CardUtil.getExileZoneId(game, source);
player.moveCardsToExile(card, source, game, true, exileId, CardUtil.getSourceName(game, source));
if (level < 3) {
Card copiedCard = game.copyCard(card, source, source.getControllerId());
if (!player.chooseUse(Outcome.Benefit, "Cast " + copiedCard.getName() + (level == 1 ? "?" : " by paying {1}?"), source, game)) {
return false;
}
SpellAbility spellAbility = player.chooseAbilityForCast(copiedCard, game, level == 2);
if (spellAbility == null) {
return false;
}
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
if (level == 2) {
player.setCastSourceIdWithAlternateMana(copiedCard.getId(), new ManaCostsImpl<>("{1}"), null);
}
player.cast(spellAbility, game, false, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
return true;
}
ExileZone exile = game.getExile().getExileZone(exileId);
if (exile == null || exile.isEmpty()) {
return true;
}
Set<Card> cards = new HashSet<>();
for (Card exiledCard : exile.getCards(game)) {
cards.add(game.copyCard(exiledCard, source, source.getControllerId()));
}
while (!cards.isEmpty()) {
for (Card copiedCard : cards) {
if (!player.chooseUse(Outcome.PlayForFree, "Cast " + copiedCard.getName() + " without paying its mana cost?", source, game)) {
continue;
}
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), Boolean.TRUE);
player.cast(player.chooseAbilityForCast(copiedCard, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + copiedCard.getId(), null);
}
if (!player.chooseUse(Outcome.Neutral, "Continue casting exiled cards?", source, game)) {
break;
}
cards.removeIf(c -> game.getState().getZone(c.getId()) != Zone.EXILED);
}
return true;
}
use of mage.game.ExileZone in project mage by magefree.
the class WorldgorgerDragonLeavesEffect 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) {
int zoneChangeCounter = (sourceObject instanceof PermanentToken) ? source.getSourceObjectZoneChangeCounter() : source.getSourceObjectZoneChangeCounter() - 1;
ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), zoneChangeCounter));
if (exile != null) {
return controller.moveCards(exile.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null);
}
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class ReturnFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
Player controller = game.getPlayer(source.getControllerId());
if (controller == null || exile == null) {
return false;
}
if (zone == Zone.LIBRARY) {
return controller.putCardsOnTopOfLibrary(exile, game, source, false);
}
return controller.moveCards(exile.getCards(game), zone, source, game, tapped, false, true, null);
}
use of mage.game.ExileZone in project mage by magefree.
the class ReturnCreaturesFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ExileZone exile = game.getExile().getExileZone(exileId);
Player controller = game.getPlayer(source.getControllerId());
if (controller != null && exile != null) {
controller.moveCards(exile.getCards(new FilterCreatureCard(), game), Zone.BATTLEFIELD, source, game, false, false, this.byOwner, null);
return true;
}
return false;
}
Aggregations