Search in sources :

Example 26 with ExileZone

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

the class AshioksErasureReplacementEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (event.getPlayerId().equals(source.getControllerId())) {
        return false;
    }
    Card card = game.getCard(event.getSourceId());
    if (sourcePermanent == null || card == null) {
        return false;
    }
    UUID exileZone = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    ExileZone exile = game.getExile().getExileZone(exileZone);
    if (exile == null) {
        // try without ZoneChangeCounter - that is useful for tokens
        exileZone = CardUtil.getCardExileZoneId(game, source);
        exile = game.getExile().getExileZone(exileZone);
    }
    if (exile == null) {
        return false;
    }
    Set<Card> cards = exile.getCards(game);
    if (cards.isEmpty()) {
        return false;
    }
    Card exiledCard = cards.iterator().next();
    if (exiledCard != null) {
        return CardUtil.haveSameNames(exiledCard, card);
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 27 with ExileZone

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

the class AsmodeusTheArchfiendReturnEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    UUID exileZoneId = (UUID) this.getValue("exileZoneId");
    if (controller != null && exileZoneId != null) {
        ExileZone exileZone = game.getExile().getExileZone(exileZoneId);
        if (exileZone != null) {
            int numCards = exileZone.size();
            if (numCards > 0) {
                controller.moveCards(exileZone, Zone.HAND, source, game);
                controller.loseLife(numCards, game, source, false);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) ExileZone(mage.game.ExileZone) UUID(java.util.UUID)

Example 28 with ExileZone

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

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

Example 29 with ExileZone

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

the class KheruMindEaterLookAtCardEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    if (affectedControllerId.equals(source.getControllerId())) {
        Card card = game.getCard(objectId);
        if (card != null) {
            MageObject sourceObject = game.getObject(source.getSourceId());
            if (sourceObject == null) {
                return false;
            }
            UUID exileId = CardUtil.getCardExileZoneId(game, source);
            ExileZone exile = game.getExile().getExileZone(exileId);
            return exile != null && exile.contains(objectId);
        }
    }
    return false;
}
Also used : MageObject(mage.MageObject) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 30 with ExileZone

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

the class LivingLoreSacrificeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    int zcc = game.getState().getZoneChangeCounter(source.getSourceId());
    if (permanent == null) {
        permanent = game.getPermanentEntering(source.getSourceId());
        zcc++;
    }
    if (permanent == null) {
        return true;
    }
    UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), zcc);
    if (exileId != null) {
        ExileZone exileZone = game.getExile().getExileZone(exileId);
        if (exileZone == null) {
            return false;
        }
        Card exiledCard = null;
        for (Card card : exileZone.getCards(game)) {
            exiledCard = card;
            break;
        }
        if (exiledCard != null) {
            int value = exiledCard.getManaValue();
            permanent.getPower().setValue(value);
            permanent.getToughness().setValue(value);
        }
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) Card(mage.cards.Card)

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