Search in sources :

Example 6 with Zone

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

the class GristTheHungerTideTest method testGristInHandBattlefieldGraveLibrary.

@Test
public void testGristInHandBattlefieldGraveLibrary() {
    addCard(Zone.HAND, playerA, grist);
    addCard(Zone.BATTLEFIELD, playerA, grist);
    addCard(Zone.GRAVEYARD, playerA, grist);
    addCard(Zone.LIBRARY, playerA, grist);
    setStrictChooseMode(true);
    setStopAt(1, PhaseStep.END_TURN);
    execute();
    assertAllCommandsUsed();
    for (Card card : currentGame.getCards()) {
        if (!card.getName().equals(grist)) {
            continue;
        }
        Zone zone = currentGame.getState().getZone(card.getId());
        if (zone == Zone.BATTLEFIELD) {
            Assert.assertFalse("Not a creature on the battlefield", card.isCreature(currentGame));
        } else {
            Assert.assertTrue("Should be a creature when zone is " + zone, card.isCreature(currentGame));
        }
    }
}
Also used : Zone(mage.constants.Zone) Card(mage.cards.Card) Test(org.junit.Test)

Example 7 with Zone

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

the class EmeriaShepherdReturnToHandTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent triggeringLand = ((LandfallAbility) source).getTriggeringPermanent();
    if (controller == null || triggeringLand == null) {
        return false;
    }
    Zone toZone = Zone.HAND;
    if (triggeringLand.hasSubtype(SubType.PLAINS, game) && controller.chooseUse(Outcome.PutCardInPlay, "Put the card to battlefield instead?", source, game)) {
        toZone = Zone.BATTLEFIELD;
    }
    return controller.moveCards(new CardsImpl(targetPointer.getTargets(game, source)), toZone, source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Zone(mage.constants.Zone) LandfallAbility(mage.abilities.common.LandfallAbility) CardsImpl(mage.cards.CardsImpl)

Example 8 with Zone

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

the class SteamAuguryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    Set<Card> cardsToGraveyard = new LinkedHashSet<>();
    Set<Card> cardsToHand = new LinkedHashSet<>();
    if (controller == null || sourceObject == null) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    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(", ");
                }
                cardsToGraveyard.add(card);
            }
        }
        controller.moveCards(cardsToGraveyard, 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(", ");
                }
                cardsToHand.add(card);
            }
        }
        controller.moveCards(cardsToHand, pile2Zone, source, game);
        game.informPlayers(sb.toString());
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) 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) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 9 with Zone

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

the class MageTestBase method parseLine.

private void parseLine(String line) {
    if (parserState == ParserState.EXPECTED) {
        // just remember for future use
        expectedResults.add(line);
        return;
    }
    Matcher m = pattern.matcher(line);
    if (m.matches()) {
        String zone = m.group(1);
        String nickname = m.group(2);
        if (nickname.equals("ComputerA") || nickname.equals("ComputerB")) {
            List<Card> cards = null;
            List<PermanentCard> perms = null;
            Zone gameZone;
            if ("hand".equalsIgnoreCase(zone)) {
                gameZone = Zone.HAND;
                cards = nickname.equals("ComputerA") ? handCardsA : handCardsB;
            } else if ("battlefield".equalsIgnoreCase(zone)) {
                gameZone = Zone.BATTLEFIELD;
                perms = nickname.equals("ComputerA") ? battlefieldCardsA : battlefieldCardsB;
            } else if ("graveyard".equalsIgnoreCase(zone)) {
                gameZone = Zone.GRAVEYARD;
                cards = nickname.equals("ComputerA") ? graveyardCardsA : graveyardCardsB;
            } else if ("library".equalsIgnoreCase(zone)) {
                gameZone = Zone.LIBRARY;
                cards = nickname.equals("ComputerA") ? libraryCardsA : libraryCardsB;
            } else if ("player".equalsIgnoreCase(zone)) {
                String command = m.group(3);
                if ("life".equals(command)) {
                    if (nickname.equals("ComputerA")) {
                        commandsA.put(Zone.OUTSIDE, "life:" + m.group(4));
                    } else {
                        commandsB.put(Zone.OUTSIDE, "life:" + m.group(4));
                    }
                }
                return;
            } else {
                // go parse next line
                return;
            }
            String cardName = m.group(3);
            Integer amount = Integer.parseInt(m.group(4));
            boolean tapped = m.group(5) != null && m.group(5).equals(":{tapped}");
            if (cardName.equals("clear")) {
                if (nickname.equals("ComputerA")) {
                    commandsA.put(gameZone, "clear");
                } else {
                    commandsB.put(gameZone, "clear");
                }
            } else {
                for (int i = 0; i < amount; i++) {
                    CardInfo cardInfo = CardRepository.instance.findCard(cardName);
                    Card newCard = cardInfo != null ? cardInfo.getCard() : null;
                    if (newCard != null) {
                        if (gameZone == Zone.BATTLEFIELD) {
                            Card permCard = CardUtil.getDefaultCardSideForBattlefield(currentGame, newCard);
                            PermanentCard p = new PermanentCard(permCard, null, currentGame);
                            p.setTapped(tapped);
                            perms.add(p);
                        } else {
                            cards.add(newCard);
                        }
                    } else {
                        logger.fatal("Couldn't find a card: " + cardName);
                        logger.fatal("line: " + line);
                    }
                }
            }
        } else {
            logger.warn("Unknown player: " + nickname);
        }
    } else {
        logger.warn("Init string wasn't parsed: " + line);
    }
}
Also used : Matcher(java.util.regex.Matcher) Zone(mage.constants.Zone) CardInfo(mage.cards.repository.CardInfo) Card(mage.cards.Card) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard)

Example 10 with Zone

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

the class SphinxOfUthuunEffect 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) {
        return false;
    }
    Cards cards = new CardsImpl(controller.getLibrary().getTopCards(game, 5));
    controller.revealCards(source, cards, game);
    Set<UUID> opponents = game.getOpponents(source.getControllerId());
    if (!opponents.isEmpty()) {
        Player opponent = game.getPlayer(opponents.iterator().next());
        if (opponents.size() > 1) {
            Target targetOpponent = new TargetOpponent(true);
            if (controller.chooseTarget(Outcome.Neutral, targetOpponent, source, game)) {
                opponent = game.getPlayer(targetOpponent.getFirstTarget());
                game.informPlayers(controller.getLogName() + " chose " + opponent.getLogName() + " to separate the revealed cards");
            }
        }
        TargetCard target = new TargetCard(0, cards.size(), Zone.LIBRARY, new FilterCard("cards to put in the first pile"));
        target.setRequired(false);
        List<Card> pile1 = new ArrayList<>();
        Cards pile1CardsIds = new CardsImpl();
        if (opponent.choose(Outcome.Neutral, cards, target, game)) {
            pile1CardsIds.addAll(target.getTargets());
            pile1.addAll(pile1CardsIds.getCards(game));
        }
        List<Card> pile2 = new ArrayList<>();
        Cards pile2CardsIds = new CardsImpl(cards);
        pile2CardsIds.removeAll(pile1CardsIds);
        pile2.addAll(pile2CardsIds.getCards(game));
        boolean choice = controller.choosePile(Outcome.DestroyPermanent, "Choose a pile to put into 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()).append(": 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(card.getName());
                if (i < pile1CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(pile1CardsIds, pile1Zone, source, game);
        game.informPlayers(sb.toString());
        sb = new StringBuilder(sourceObject.getLogName()).append(": 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(card.getName());
                if (i < pile2CardsIds.size()) {
                    sb.append(", ");
                }
            }
        }
        controller.moveCards(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) TargetCard(mage.target.TargetCard) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard) FilterCard(mage.filter.FilterCard) Target(mage.target.Target) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

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