Search in sources :

Example 21 with Zone

use of mage.constants.Zone in project mage by magefree.

the class EpiphanyAtTheDrownyardEffect 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) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, source.getManaCostsToPay().getX() + 1));
    controller.revealCards(sourceObject.getIdName(), cards, game);
    Player opponent;
    Set<UUID> opponents = game.getOpponents(controller.getId());
    if (opponents.size() == 1) {
        opponent = game.getPlayer(opponents.iterator().next());
    } else {
        Target target = new TargetOpponent(true);
        controller.chooseTarget(Outcome.Detriment, target, source, game);
        opponent = game.getPlayer(target.getFirstTarget());
    }
    if (opponent != null) {
        TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
        List<Card> pile1 = new ArrayList<>();
        Cards pile1CardsIds = new CardsImpl();
        target.setRequired(false);
        if (controller.choose(Outcome.Neutral, cards, target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = game.getCard(targetId);
                if (card != null) {
                    pile1.add(card);
                    pile1CardsIds.add(card.getId());
                }
            }
        }
        List<Card> pile2 = new ArrayList<>();
        Cards pile2CardsIds = new CardsImpl();
        for (UUID cardId : cards) {
            Card card = game.getCard(cardId);
            if (card != null && !pile1.contains(card)) {
                pile2.add(card);
                pile2CardsIds.add(card.getId());
            }
        }
        boolean choice = opponent.choosePile(Outcome.Detriment, "Choose a pile to put into " + controller.getName() + "'s hand.", pile1, pile2, game);
        Zone pile1Zone = Zone.GRAVEYARD;
        Zone pile2Zone = Zone.HAND;
        if (choice) {
            pile1Zone = Zone.HAND;
            pile2Zone = Zone.GRAVEYARD;
        }
        StringBuilder sb = new StringBuilder(sourceObject.getLogName() + ": Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
        int i = 0;
        for (UUID cardUuid : pile1CardsIds) {
            i++;
            Card card = game.getCard(cardUuid);
            if (card != null) {
                sb.append(GameLog.getColoredObjectName(card));
                if (i < pile1CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(new CardsImpl(pile1CardsIds), pile1Zone, source, game);
        game.informPlayers(sb.toString());
        sb = new StringBuilder(sourceObject.getLogName() + ": Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
        i = 0;
        for (UUID cardUuid : pile2CardsIds) {
            Card card = game.getCard(cardUuid);
            if (card != null) {
                i++;
                sb.append(' ').append(GameLog.getColoredObjectName(card));
                if (i < pile2CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(new CardsImpl(pile2CardsIds), pile2Zone, source, game);
        game.informPlayers(sb.toString());
    }
    return true;
}
Also used : Player(mage.players.Player) TargetOpponent(mage.target.common.TargetOpponent) Zone(mage.constants.Zone) MageObject(mage.MageObject) ArrayList(java.util.ArrayList) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID)

Example 22 with Zone

use of mage.constants.Zone in project mage by magefree.

the class ExileTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Set<Card> toExile = new LinkedHashSet<>();
        if (multitargetHandling && targetPointer instanceof FirstTargetPointer && (source.getTargets().size() > 1 || (source.getTargets().size() > 0 && source.getTargets().get(0).getTargets().size() > 1))) {
            for (Target target : source.getTargets()) {
                for (UUID targetId : target.getTargets()) {
                    Permanent permanent = game.getPermanent(targetId);
                    if (permanent != null && permanent.isPhasedIn()) {
                        Zone currentZone = game.getState().getZone(permanent.getId());
                        if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == Zone.BATTLEFIELD)) {
                            toExile.add(permanent);
                        }
                    } else {
                        Card card = game.getCard(targetId);
                        if (card != null) {
                            Zone currentZone = game.getState().getZone(card.getId());
                            if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == currentZone)) {
                                toExile.add(card);
                            }
                        } else {
                            StackObject stackObject = game.getStack().getStackObject(targetId);
                            if (stackObject instanceof Spell) {
                                toExile.add((Spell) stackObject);
                            }
                        }
                    }
                }
            }
        } else {
            for (UUID targetId : getTargetPointer().getTargets(game, source)) {
                Permanent permanent = game.getPermanent(targetId);
                if (permanent != null && permanent.isPhasedIn()) {
                    Zone currentZone = game.getState().getZone(permanent.getId());
                    if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == Zone.BATTLEFIELD)) {
                        toExile.add(permanent);
                    }
                } else {
                    Card card = game.getCard(targetId);
                    if (card != null) {
                        Zone currentZone = game.getState().getZone(card.getId());
                        if (currentZone != Zone.EXILED && (onlyFromZone == null || onlyFromZone == currentZone)) {
                            toExile.add(card);
                        }
                    } else {
                        StackObject stackObject = game.getStack().getStackObject(targetId);
                        if (stackObject instanceof Spell) {
                            toExile.add((Spell) stackObject);
                        }
                    }
                }
            }
        }
        if (toSourceExileZone) {
            MageObject sourceObject = source.getSourceObject(game);
            exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
            if (sourceObject != null) {
                exileZone = sourceObject.getIdName();
            }
        }
        controller.moveCardsToExile(toExile, source, game, withName, exileId, exileZone);
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Target(mage.target.Target) Permanent(mage.game.permanent.Permanent) Zone(mage.constants.Zone) StackObject(mage.game.stack.StackObject) MageObject(mage.MageObject) FirstTargetPointer(mage.target.targetpointer.FirstTargetPointer) UUID(java.util.UUID) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 23 with Zone

use of mage.constants.Zone in project mage by magefree.

the class SplitCard method moveToExile.

@Override
public boolean moveToExile(UUID exileId, String name, Ability source, Game game, List<UUID> appliedEffects) {
    if (super.moveToExile(exileId, name, source, game, appliedEffects)) {
        Zone currentZone = game.getState().getZone(getId());
        game.getState().setZone(getLeftHalfCard().getId(), currentZone);
        game.getState().setZone(getRightHalfCard().getId(), currentZone);
        return true;
    }
    return false;
}
Also used : Zone(mage.constants.Zone)

Example 24 with Zone

use of mage.constants.Zone in project mage by magefree.

the class JaceMindseekerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cardsToCast = new CardsImpl();
    Player targetOpponent = game.getPlayer(targetPointer.getFirst(game, source));
    if (targetOpponent != null) {
        Set<Card> allCards = targetOpponent.millCards(5, source, game).getCards(game);
        for (Card card : allCards) {
            if (filter.match(card, game)) {
                Zone zone = game.getState().getZone(card.getId());
                // you can cast one of those instant or sorcery cards from that zone.
                if (zone == Zone.GRAVEYARD || zone == Zone.EXILED) {
                    cardsToCast.add(card);
                }
            }
        }
        // cast an instant or sorcery for free
        if (!cardsToCast.isEmpty()) {
            Player controller = game.getPlayer(source.getControllerId());
            if (controller != null) {
                // zone should be ignored here
                TargetCard target = new TargetCard(Zone.GRAVEYARD, filter);
                target.setNotTarget(true);
                if (controller.chooseUse(outcome, "Cast an instant or sorcery card from among them for free?", source, game) && controller.choose(Outcome.PlayForFree, cardsToCast, target, game)) {
                    Card card = cardsToCast.get(target.getFirstTarget(), game);
                    if (card != null) {
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), Boolean.TRUE);
                        controller.cast(controller.chooseAbilityForCast(card, game, true), game, true, new ApprovingObject(source, game));
                        game.getState().setValue("PlayFromNotOwnHandZone" + card.getId(), null);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ApprovingObject(mage.ApprovingObject) Zone(mage.constants.Zone) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard)

Example 25 with Zone

use of mage.constants.Zone in project mage by magefree.

the class CopySpellTest method cardsMustHaveSameZoneAndZCC.

private void cardsMustHaveSameZoneAndZCC(Card originalCard, Card copiedCard, String infoPrefix) {
    // zcc and zone are not copied, so you don't need it here yet
    Zone zone1 = currentGame.getState().getZone(originalCard.getId());
    Zone zone2 = currentGame.getState().getZone(copiedCard.getId());
    int zcc1 = currentGame.getState().getZoneChangeCounter(originalCard.getId());
    int zcc2 = currentGame.getState().getZoneChangeCounter(copiedCard.getId());
    if (zone1 != zone2 || zcc1 != zcc2) {
        Assert.fail(infoPrefix + " - " + "cards must have same zone and zcc: " + zcc1 + " - " + zone1 + " != " + zcc2 + " - " + zone2);
    }
}
Also used : Zone(mage.constants.Zone)

Aggregations

Zone (mage.constants.Zone)31 Player (mage.players.Player)18 Card (mage.cards.Card)15 MageObject (mage.MageObject)13 Permanent (mage.game.permanent.Permanent)12 FilterCard (mage.filter.FilterCard)11 TargetCard (mage.target.TargetCard)9 UUID (java.util.UUID)7 Target (mage.target.Target)7 TargetOpponent (mage.target.common.TargetOpponent)6 ArrayList (java.util.ArrayList)5 CardsImpl (mage.cards.CardsImpl)5 Cards (mage.cards.Cards)4 PermanentCard (mage.game.permanent.PermanentCard)4 ZoneChangeEvent (mage.game.events.ZoneChangeEvent)3 java.util (java.util)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 Matcher (java.util.regex.Matcher)2 Ability (mage.abilities.Ability)2