Search in sources :

Example 1 with Emblem

use of mage.game.command.Emblem in project mage by magefree.

the class TibaltCosmicImpostorPlayFromExileEffect method applies.

@Override
public boolean applies(UUID objectId, Ability source, UUID affectedControllerId, Game game) {
    Emblem tibaltEmblem = (Emblem) game.getEmblem(source.getSourceId());
    if (tibaltEmblem == null) {
        return false;
    }
    // the exile zone of the Tibalt, Cosmic Impostor that spawned the emblem only
    UUID exileId = CardUtil.getExileZoneId(tibaltEmblem.getSourceObject().getId().toString(), game);
    if (exileId == null) {
        return false;
    }
    ExileZone exile = game.getState().getExile().getExileZone(exileId);
    if (exile == null) {
        return false;
    }
    if (exile.isEmpty()) {
        return false;
    }
    Card cardInExile = game.getCard(objectId);
    if (cardInExile == null) {
        return false;
    }
    UUID mainCardId = cardInExile.getMainCard().getId();
    if (exile.contains(mainCardId) && affectedControllerId.equals(source.getControllerId()) && game.getState().getZone(mainCardId).equals(Zone.EXILED)) {
        CardUtil.makeCardPlayable(game, source, cardInExile, Duration.Custom, true);
        return true;
    }
    return false;
}
Also used : Emblem(mage.game.command.Emblem) ExileZone(mage.game.ExileZone) UUID(java.util.UUID) Card(mage.cards.Card)

Example 2 with Emblem

use of mage.game.command.Emblem in project mage by magefree.

the class AbilityImpl method isInUseableZone.

/**
 * @param game
 * @param source
 * @return
 */
@Override
public boolean isInUseableZone(Game game, MageObject source, GameEvent event) {
    if (!this.hasSourceObjectAbility(game, source, event)) {
        return false;
    }
    if (zone == Zone.COMMAND) {
        if (this.getSourceId() == null) {
            // commander effects
            return true;
        }
        MageObject object = game.getObject(this.getSourceId());
        // emblem/planes are always actual
        if (object instanceof Emblem || object instanceof Dungeon || object instanceof Plane) {
            return true;
        }
    }
    UUID parameterSourceId;
    // so will use the sourceId of the object itself that came as a parameter if it is not null
    if (this instanceof MageSingleton && source != null) {
        parameterSourceId = source.getId();
    } else {
        parameterSourceId = getSourceId();
    }
    // check against shortLKI for effects that move multiple object at the same time (e.g. destroy all)
    if (game.getShortLivingLKI(getSourceId(), getZone())) {
        return true;
    }
    // check against current state
    Zone test = game.getState().getZone(parameterSourceId);
    return zone.match(test);
}
Also used : Plane(mage.game.command.Plane) Emblem(mage.game.command.Emblem) Dungeon(mage.game.command.Dungeon) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 3 with Emblem

use of mage.game.command.Emblem in project mage by magefree.

the class MageBook method loadTokens.

public List<Object> loadTokens() {
    List<Object> res = new ArrayList<>();
    // tokens
    List<CardDownloadData> allTokens = getTokenCardUrls();
    for (CardDownloadData token : allTokens) {
        if (token.getSet().equals(currentSet)) {
            try {
                String className = token.getName();
                className = className.replaceAll("[^a-zA-Z0-9]", "");
                className = "mage.game.permanent.token." + className + "Token";
                if (token.getTokenClassName() != null && token.getTokenClassName().length() > 0) {
                    if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*token.*")) {
                        className = token.getTokenClassName();
                        className = "mage.game.permanent.token." + className;
                    } else if (token.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
                        continue;
                    }
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newToken = cons.newInstance();
                if (newToken instanceof Token) {
                    ((Token) newToken).setOriginalExpansionSetCode(currentSet);
                    ((Token) newToken).setExpansionSetCodeForImage(currentSet);
                    ((Token) newToken).setTokenType(token.getType());
                    res.add(newToken);
                }
            } catch (ClassNotFoundException | NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) {
            // Swallow exception
            }
        }
    }
    // emblems
    List<CardDownloadData> allEmblems = getTokenCardUrls();
    for (CardDownloadData emblem : allEmblems) {
        if (emblem.getSet().equals(currentSet)) {
            try {
                String className = emblem.getName();
                if (emblem.getTokenClassName() != null && emblem.getTokenClassName().length() > 0) {
                    if (emblem.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*emblem.*")) {
                        className = emblem.getTokenClassName();
                        className = "mage.game.command.emblems." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newEmblem = cons.newInstance();
                if (newEmblem instanceof Emblem) {
                    ((Emblem) newEmblem).setExpansionSetCodeForImage(currentSet);
                    res.add(newEmblem);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    // planes
    List<CardDownloadData> allPlanes = getTokenCardUrls();
    for (CardDownloadData plane : allPlanes) {
        if (plane.getSet().equals(currentSet)) {
            try {
                String className = plane.getName();
                if (plane.getTokenClassName() != null && plane.getTokenClassName().length() > 0) {
                    if (plane.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*plane.*")) {
                        className = plane.getTokenClassName();
                        className = "mage.game.command.planes." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newPlane = cons.newInstance();
                if (newPlane instanceof Plane) {
                    ((Plane) newPlane).setExpansionSetCodeForImage(currentSet);
                    res.add(newPlane);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    // dungeons
    List<CardDownloadData> allDungeons = getTokenCardUrls();
    for (CardDownloadData dungeon : allDungeons) {
        if (dungeon.getSet().equals(currentSet)) {
            try {
                String className = dungeon.getName();
                if (dungeon.getTokenClassName() != null && dungeon.getTokenClassName().length() > 0) {
                    if (dungeon.getTokenClassName().toLowerCase(Locale.ENGLISH).matches(".*dungeon.*")) {
                        className = dungeon.getTokenClassName();
                        className = "mage.game.command.dungeons." + className;
                    }
                } else {
                    continue;
                }
                Class<?> c = Class.forName(className);
                Constructor<?> cons = c.getConstructor();
                Object newDungeon = cons.newInstance();
                if (newDungeon instanceof Dungeon) {
                    ((Dungeon) newDungeon).setExpansionSetCodeForImage(currentSet);
                    res.add(newDungeon);
                }
            } catch (ClassNotFoundException | InvocationTargetException | IllegalArgumentException | IllegalAccessException | InstantiationException | SecurityException | NoSuchMethodException ex) {
            // Swallow exception
            }
        }
    }
    return res;
}
Also used : CardDownloadData(org.mage.plugins.card.images.CardDownloadData) Plane(mage.game.command.Plane) ArrayList(java.util.ArrayList) PermanentToken(mage.game.permanent.PermanentToken) Token(mage.game.permanent.token.Token) InvocationTargetException(java.lang.reflect.InvocationTargetException) Emblem(mage.game.command.Emblem) Dungeon(mage.game.command.Dungeon)

Aggregations

Emblem (mage.game.command.Emblem)3 UUID (java.util.UUID)2 Dungeon (mage.game.command.Dungeon)2 Plane (mage.game.command.Plane)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 MageObject (mage.MageObject)1 Card (mage.cards.Card)1 ExileZone (mage.game.ExileZone)1 PermanentToken (mage.game.permanent.PermanentToken)1 Token (mage.game.permanent.token.Token)1 CardDownloadData (org.mage.plugins.card.images.CardDownloadData)1