Search in sources :

Example 61 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class SkyshipWeatherlightEffect2 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 exZone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
        if (exZone != null) {
            controller.moveCards(exZone.getRandom(game), Zone.HAND, source, game);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) ExileZone(mage.game.ExileZone)

Example 62 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class SynodSanctumEffect2 method apply.

@Override
public boolean apply(Game game, Ability source) {
    UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    ExileZone exileZone = game.getExile().getExileZone(exileId);
    if (exileZone == null) {
        return true;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        return controller.moveCards(exileZone, Zone.BATTLEFIELD, source, game);
    }
    return false;
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID)

Example 63 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class WatcherForTomorrowEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    Permanent permanentLeftBattlefield = (Permanent) getValue("permanentLeftBattlefield");
    if (permanentLeftBattlefield == null) {
        return false;
    }
    ExileZone zone = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanentLeftBattlefield.getZoneChangeCounter(game)));
    if (zone == null) {
        return false;
    }
    Cards cards = new CardsImpl(zone.getCards(game));
    return player.moveCards(cards, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 64 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class AdventureCastFromExileEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    UUID targetId = getTargetPointer().getFirst(game, source);
    ExileZone adventureExileZone = game.getExile().getExileZone(ExileAdventureSpellEffect.adventureExileId(affectedControllerId, game));
    if (targetId == null) {
        this.discard();
    } else if (objectId.equals(targetId) && affectedControllerId.equals(source.getControllerId()) && adventureExileZone.contains(objectId)) {
        Card card = game.getCard(objectId);
        return card != null;
    }
    return false;
}
Also used : ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 65 with ExileZone

use of mage.game.ExileZone in project mage by magefree.

the class GrimoireThiefCounterspellEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Cards cards = new CardsImpl();
    MageObject sourceObject = game.getObject(source.getSourceId());
    Set<UUID> exileZones = (Set<UUID>) game.getState().getValue(GrimoireThief.VALUE_PREFIX + source.getSourceId().toString());
    if (exileZones != null && sourceObject != null) {
        for (ExileZone exileZone : game.getExile().getExileZones()) {
            if (!exileZone.isEmpty()) {
                cards.addAll(exileZone.getCards(game));
            }
        }
        // set face up first
        for (Card card : cards.getCards(game)) {
            card.setFaceDown(false, game);
        }
        // then counter any with the same name as the card exiled with Grimoire Thief
        for (Card card : cards.getCards(game)) {
            for (Iterator<StackObject> iterator = game.getStack().iterator(); iterator.hasNext(); ) {
                StackObject stackObject = iterator.next();
                MageObject mageObject = game.getObject(card.getId());
                String name1;
                String name2;
                if (mageObject instanceof SplitCard) {
                    name1 = ((SplitCard) mageObject).getLeftHalfCard().getName();
                    name2 = ((SplitCard) mageObject).getRightHalfCard().getName();
                } else {
                    // modal double faces cards, adventure cards -- all have one name in non stack/battlefield zone
                    name1 = mageObject.getName();
                    name2 = name1;
                }
                if (CardUtil.haveSameNames(stackObject, name1, game) || CardUtil.haveSameNames(stackObject, name2, game)) {
                    Spell spell = (Spell) stackObject;
                    game.getStack().counter(stackObject.getId(), source, game);
                    game.informPlayers(sourceObject.getLogName() + ": spell " + spell.getIdName() + " was countered.");
                }
            }
        }
        return true;
    }
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) MageObject(mage.MageObject) StackObject(mage.game.stack.StackObject) ExileZone(mage.game.ExileZone) Spell(mage.game.stack.Spell) UUID(java.util.UUID)

Aggregations

ExileZone (mage.game.ExileZone)92 Player (mage.players.Player)61 UUID (java.util.UUID)44 Card (mage.cards.Card)44 MageObject (mage.MageObject)24 Permanent (mage.game.permanent.Permanent)23 FilterCard (mage.filter.FilterCard)15 HashSet (java.util.HashSet)11 ApprovingObject (mage.ApprovingObject)9 CardsImpl (mage.cards.CardsImpl)9 TargetCard (mage.target.TargetCard)9 Cards (mage.cards.Cards)7 MageObjectReference (mage.MageObjectReference)6 Ability (mage.abilities.Ability)5 Spell (mage.game.stack.Spell)5 SimpleStaticAbility (mage.abilities.common.SimpleStaticAbility)3 TransformSourceEffect (mage.abilities.effects.common.TransformSourceEffect)3 TargetPlayer (mage.target.TargetPlayer)3 Objects (java.util.Objects)2 Set (java.util.Set)2