use of mage.game.ExileZone in project mage by magefree.
the class HideawayPlayEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
ExileZone zone = null;
Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
if (permanent != null) {
zone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanent.getZoneChangeCounter(game)));
}
if (zone == null) {
return true;
}
Set<Card> cards = zone.getCards(game);
if (cards.isEmpty()) {
return true;
}
Card card = cards.iterator().next();
Player controller = game.getPlayer(source.getControllerId());
if (card != null && controller != null) {
if (controller.chooseUse(Outcome.PlayForFree, "Play " + card.getIdName() + " for free?", source, game)) {
card.setFaceDown(false, game);
int zcc = card.getZoneChangeCounter(game);
/* 702.74. Hideaway, rulings:
* If the removed card is a land, you may play it as a result of the last ability only if it's your turn
* and you haven't already played a land that turn. This counts as your land play for the turn.
*/
if (card.isLand(game)) {
UUID playerId = controller.getId();
if (!game.isActivePlayer(playerId) || !game.getPlayer(playerId).canPlayLand()) {
return false;
}
}
if (!controller.playCard(card, game, true, new ApprovingObject(source, game))) {
if (card.getZoneChangeCounter(game) == zcc) {
card.setFaceDown(true, game);
}
}
}
return true;
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class IdolOfEnduranceWatcher method apply.
@Override
public boolean apply(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return false;
}
ExileZone exileZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source));
return exileZone != null && !exileZone.isEmpty() && player.moveCards(exileZone, Zone.GRAVEYARD, source, game);
}
use of mage.game.ExileZone in project mage by magefree.
the class PlanarGuideReturnFromExileEffect method apply.
@Override
public boolean apply(Game game, Ability source) {
MageObject sourceObject = game.getObject(source.getSourceId());
Player controller = game.getPlayer(source.getControllerId());
if (sourceObject != null && controller != null) {
Set<Card> toExile = new HashSet<>();
toExile.addAll(game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game));
controller.moveCardsToExile(toExile, source, game, true, source.getSourceId(), sourceObject.getIdName());
ExileZone exile = game.getExile().getExileZone(source.getSourceId());
if (exile != null && !exile.isEmpty()) {
// Create delayed triggered ability
AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new PlanarGuideReturnFromExileEffect());
game.addDelayedTriggeredAbility(delayedAbility, source);
return true;
}
return true;
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class ScrollRackEffect 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 && sourceObject != null) {
FilterCard filter = new FilterCard("card in your hand to exile");
TargetCardInHand target = new TargetCardInHand(0, controller.getHand().size(), filter);
target.setRequired(false);
int amountExiled = 0;
if (target.canChoose(source.getSourceId(), source.getControllerId(), game) && target.choose(Outcome.Neutral, source.getControllerId(), source.getSourceId(), game)) {
if (!target.getTargets().isEmpty()) {
for (UUID targetId : target.getTargets()) {
Card card = game.getCard(targetId);
if (card != null) {
card.setFaceDown(true, game);
amountExiled++;
}
}
controller.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, false, source.getSourceId(), sourceObject.getIdName());
ExileZone exileZone = game.getExile().getExileZone(source.getSourceId());
if (exileZone != null) {
for (Card card : exileZone.getCards(game)) {
card.setFaceDown(true, game);
}
}
}
}
// Put that many cards from the top of your library into your hand.
if (amountExiled > 0) {
controller.moveCards(controller.getLibrary().getTopCards(game, amountExiled), Zone.HAND, source, game);
}
// Then look at the exiled cards and put them on top of your library in any order
controller.putCardsOnTopOfLibrary(game.getExile().getExileZone(source.getSourceId()), game, source, true);
return true;
}
return false;
}
use of mage.game.ExileZone in project mage by magefree.
the class SharedFateLookEffect method applies.
@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
if (game.getState().getZone(objectId) == Zone.EXILED) {
Permanent sourcePermanent = game.getPermanent(source.getSourceId());
UUID exileId = CardUtil.getExileZoneId(source.getSourceId().toString() + sourcePermanent.getZoneChangeCounter(game) + affectedControllerId.toString(), game);
ExileZone exileZone = game.getExile().getExileZone(exileId);
if (exileZone != null && exileZone.contains(objectId)) {
Card card = game.getCard(objectId);
return card != null && game.getState().getZone(objectId) == Zone.EXILED;
}
}
return false;
}
Aggregations