use of mage.game.ExileZone in project mage by magefree.
the class VoltaicVisionaryWatcher method watch.
@Override
public void watch(GameEvent event, Game game) {
if (event.getType() != GameEvent.EventType.ZONE_CHANGE || ((ZoneChangeEvent) event).getToZone() != Zone.EXILED) {
return;
}
Card card = game.getCard(event.getTargetId());
UUID exileId = game.getExile().getExileZones().stream().filter(exileZone -> exileZone.contains(card)).map(ExileZone::getId).findFirst().orElse(null);
if (exileId == null) {
return;
}
map.computeIfAbsent(exileId, x -> new HashSet<>()).add(new MageObjectReference(card, game));
}
use of mage.game.ExileZone in project mage by magefree.
the class ReturnExiledPermanentsEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = source.getSourceObject(game);
if (sourceObject != null && controller != null) {
ExileZone exile = getExileIfPossible(game, source);
if (exile != null) {
return controller.moveCards(new LinkedHashSet<>(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 ReturnToBattlefieldUnderYourControlSourceEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId());
if (controller == null) {
return false;
}
UUID exileZoneId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
if (exileZone != null && exileZone.contains(source.getSourceId())) {
Card card = game.getCard(source.getSourceId());
if (card != null && controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
return true;
}
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class EpicExperimentEffect 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) {
// move cards from library to exile
controller.moveCardsToExile(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX()), source, game, true, source.getSourceId(), sourceObject.getIdName());
// cast the possible cards without paying the mana
ExileZone epicExperimentExileZone = game.getExile().getExileZone(source.getSourceId());
FilterCard filter = new FilterInstantOrSorceryCard();
filter.add(new ManaValuePredicate(ComparisonType.FEWER_THAN, source.getManaCostsToPay().getX() + 1));
filter.setMessage("instant and sorcery cards with mana value " + source.getManaCostsToPay().getX() + " or less");
Cards cardsToCast = new CardsImpl();
if (epicExperimentExileZone == null) {
return true;
}
cardsToCast.addAll(epicExperimentExileZone.getCards(filter, source.getSourceId(), source.getControllerId(), game));
while (controller.canRespond() && !cardsToCast.isEmpty()) {
if (!controller.chooseUse(Outcome.PlayForFree, "Cast (another) a card exiled with " + sourceObject.getLogName() + " without paying its mana cost?", source, game)) {
break;
}
TargetCard targetCard = new TargetCard(1, Zone.EXILED, new FilterCard("instant or sorcery card to cast for free"));
if (controller.choose(Outcome.PlayForFree, cardsToCast, targetCard, game)) {
Card card = game.getCard(targetCard.getFirstTarget());
if (card != null) {
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
Boolean cardWasCast = controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
if (!cardWasCast) {
game.informPlayer(controller, "You're not able to cast " + card.getIdName() + " or you canceled the casting.");
}
cardsToCast.remove(card);
} else {
break;
}
} else {
break;
}
}
// move cards not cast to graveyard
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
if (exileZone != null) {
controller.moveCards(exileZone.getCards(game), Zone.GRAVEYARD, source, game);
}
return true;
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class IdolOfEnduranceWatcher method applies.
@Override
public boolean applies(UUID sourceId, Ability source, UUID affectedControllerId, Game game) {
if (!IdolOfEnduranceWatcher.checkPermission(affectedControllerId, source, game)) {
return false;
}
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
if (exileZone == null || !exileZone.contains(sourceId)) {
return false;
}
Card card = game.getCard(sourceId);
if (card == null || !card.isCreature(game) || card.isLand(game)) {
return false;
}
return allowCardToPlayWithoutMana(sourceId, source, affectedControllerId, game);
}
Aggregations