Search in sources :

Example 16 with Zone

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

the class FactOrFictionEffect 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(sourceObject.getName(), 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"));
        List<Card> pile1 = new ArrayList<>();
        if (opponent.choose(Outcome.Neutral, cards, target, game)) {
            List<UUID> targets = target.getTargets();
            for (UUID targetId : targets) {
                Card card = cards.get(targetId, game);
                if (card != null) {
                    pile1.add(card);
                    cards.remove(card);
                }
            }
        }
        List<Card> pile2 = new ArrayList<>();
        pile2.addAll(cards.getCards(game));
        boolean choice = controller.choosePile(outcome, "Choose a pile to put into your hand.", pile1, pile2, game);
        Zone pile1Zone = Zone.GRAVEYARD;
        Zone pile2Zone = Zone.HAND;
        if (choice) {
            pile1Zone = Zone.HAND;
            pile2Zone = Zone.GRAVEYARD;
        }
        StringBuilder sb = new StringBuilder("Pile 1, going to ").append(pile1Zone == Zone.HAND ? "Hand" : "Graveyard").append(": ");
        int i = 0;
        for (Card card : pile1) {
            i++;
            sb.append(card.getName());
            if (i < pile1.size()) {
                sb.append(", ");
            }
        }
        cards.clear();
        cards.addAll(pile1);
        controller.moveCards(cards, pile1Zone, source, game);
        game.informPlayers(sb.toString());
        sb = new StringBuilder("Pile 2, going to ").append(pile2Zone == Zone.HAND ? "Hand" : "Graveyard").append(':');
        i = 0;
        for (Card card : pile2) {
            i++;
            sb.append(' ').append(card.getName());
            if (i < pile2.size()) {
                sb.append(", ");
            }
        }
        cards.clear();
        cards.addAll(pile2);
        controller.moveCards(cards, 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 17 with Zone

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

the class RunedCrownEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = null;
    Zone zone = null;
    if (controller.chooseUse(Outcome.Neutral, "Search your graveyard for a Rune card?", source, game)) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(filter);
        target.setNotTarget(true);
        if (controller.choose(Outcome.PutCardInPlay, controller.getGraveyard(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.GRAVEYARD;
            }
        }
    }
    if (card == null && controller.chooseUse(Outcome.Neutral, "Search your hand for a Rune card?", source, game)) {
        TargetCardInHand target = new TargetCardInHand(filter);
        if (controller.choose(Outcome.PutCardInPlay, controller.getHand(), target, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.HAND;
            }
        }
    }
    if (card == null) {
        TargetCardInLibrary target = new TargetCardInLibrary(filter);
        if (controller.searchLibrary(target, source, game)) {
            card = game.getCard(target.getFirstTarget());
            if (card != null) {
                zone = Zone.LIBRARY;
            }
        }
        controller.shuffleLibrary(source, game);
    }
    // aura card found - attach it
    if (card == null) {
        return true;
    }
    Permanent permanent = source.getSourcePermanentIfItStillExists(game);
    if (permanent != null) {
        game.getState().setValue("attachTo:" + card.getId(), permanent);
    }
    controller.moveCards(card, Zone.BATTLEFIELD, source, game);
    if (permanent != null) {
        return permanent.addAttachment(card.getId(), source, game);
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCardInHand(mage.target.common.TargetCardInHand) Zone(mage.constants.Zone) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) TargetCardInLibrary(mage.target.common.TargetCardInLibrary) FilterCard(mage.filter.FilterCard) Card(mage.cards.Card)

Example 18 with Zone

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

the class RevealAndShuffleIntoLibrarySourceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObject sourceObject = source.getSourceObjectIfItStillExists(game);
    Player controller = game.getPlayer(source.getControllerId());
    if (sourceObject != null && controller != null) {
        Player owner = null;
        Cards cards = new CardsImpl();
        Permanent permanent = null;
        if (sourceObject instanceof Spell) {
            sourceObject = ((Spell) sourceObject).getCard();
        }
        if (sourceObject instanceof Permanent) {
            permanent = (Permanent) sourceObject;
            owner = game.getPlayer(permanent.getOwnerId());
            if (sourceObject instanceof PermanentCard) {
                cards.add(permanent);
            }
        } else if (sourceObject instanceof Card) {
            owner = game.getPlayer(((Card) sourceObject).getOwnerId());
            cards.add((Card) sourceObject);
        }
        if (owner != null) {
            Zone fromZone = game.getState().getZone(sourceObject.getId());
            if (!cards.isEmpty()) {
                controller.revealCards(sourceObject.getName(), cards, game);
            }
            if (permanent != null) {
                controller.moveCardToLibraryWithInfo(permanent, source, game, fromZone, true, true);
            } else {
                controller.moveCardToLibraryWithInfo((Card) sourceObject, source, game, fromZone, true, true);
            }
            if (!cards.isEmpty()) {
                controller.shuffleLibrary(source, game);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Zone(mage.constants.Zone) MageObject(mage.MageObject) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Spell(mage.game.stack.Spell) PermanentCard(mage.game.permanent.PermanentCard) PermanentCard(mage.game.permanent.PermanentCard) Card(mage.cards.Card)

Example 19 with Zone

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

the class KickerAbility method getActivationKey.

/**
 * Return activation zcc key for searching spell's settings in source object
 *
 * @param source
 * @param game
 * @return
 */
public static String getActivationKey(Ability source, Game game) {
    // Kicker activates in STACK zone so all zcc must be from "stack moment"
    // Use cases:
    // * resolving spell have same zcc (example: check kicker status in sorcery/instant);
    // * copied spell have same zcc as source spell (see Spell.copySpell and zcc sync);
    // * creature/token from resolved spell have +1 zcc after moved to battlefield (example: check kicker status in ETB triggers/effects);
    // find object info from the source ability (it can be a permanent or a spell on stack, on the moment of trigger/resolve)
    MageObject sourceObject = source.getSourceObject(game);
    Zone sourceObjectZone = game.getState().getZone(sourceObject.getId());
    int zcc = CardUtil.getActualSourceObjectZoneChangeCounter(game, source);
    // * spells and copied spells resolves on STACK (zcc not changes)
    if (sourceObjectZone != Zone.STACK) {
        --zcc;
    }
    return zcc + "";
}
Also used : Zone(mage.constants.Zone) MageObject(mage.MageObject)

Example 20 with Zone

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

the class HauntEffect method isInUseableZone.

@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
    boolean fromOK = true;
    Permanent sourcePermanent = (Permanent) game.getLastKnownInformation(sourceId, Zone.BATTLEFIELD);
    if (creatureHaunt && sourcePermanent == null) {
        // check it was previously on battlefield
        fromOK = false;
    }
    if (!this.hasSourceObjectAbility(game, sourcePermanent, event)) {
        return false;
    }
    // check now it is in graveyard
    Zone after = game.getState().getZone(sourceId);
    return fromOK && after != null && Zone.GRAVEYARD.match(after);
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) 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