Search in sources :

Example 1 with LevelingEvolution

use of com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.types.LevelingEvolution in project PixelmonPlaceholders by happyzleaf.

the class ParserUtility method parsePokedexInfo.

public static Object parsePokedexInfo(EnumPokemon pokemon, String[] values) throws NoValueException {
    if (values.length == 1) {
        return pokemon.name;
    }
    BaseStats stats = DatabaseStats.getBaseStats(pokemon.name).orElse(null);
    if (stats == null) {
        throw new RuntimeException("Could not find BaseStats for pokémon " + pokemon.name + ".");
    }
    switch(values[1]) {
        case "name":
            return pokemon.name;
        case "catchrate":
            return stats.catchRate;
        case "nationalid":
            return stats.nationalPokedexNumber;
        case "rarity":
            if (values.length == 3) {
                int rarity;
                switch(values[2]) {
                    case "day":
                        rarity = stats.rarity.day;
                        break;
                    case "night":
                        rarity = stats.rarity.night;
                        break;
                    case "dawndusk":
                        rarity = stats.rarity.dawndusk;
                        break;
                    default:
                        throw new NoValueException();
                }
                return rarity <= 0 ? EnumPokemon.legendaries.contains(pokemon.name) ? 0 : 1 : rarity;
            }
            break;
        case "postevolutions":
            /*
				 * "postevolutions" does not work how you might think.
				 * The post evolution of Bulbasaur is only Ivysaur, while the post evolutions of Eevee are all the eevolutions.
				 * The problem is that even if i'd like to add Venusaur to the post evolutions of Bulbasaur, after Ivysaur,
				 * i can't know it programmatically without doing any kind of human sacrifice,
				 * and i wound't know if i'd have to add them (the evolutions of an evolution) only if the post evolutions is one or so,
				 * cause, even if i'm sure that Umbreon does not have a post evolution,
				 * i'm putting a big limit to the OOP which should work regardless of the poke.
				 *
				 * Yeah, i'm sure no one will understand what i've wrote, but don't worry, i'm the choosen, i'm gonna fix it myself and you won't even notice.
				 */
            return asReadableList(values, 2, Arrays.stream(stats.evolutions).map(evolution -> evolution.to.name).toArray());
        case "preevolutions":
            return asReadableList(values, 2, stats.preEvolutions);
        case // Evolutions in order since 1.3.0
        "evolutions":
            // WHAT AM I DOING
            return asReadableList(values, 2, ArrayUtils.addAll(ArrayUtils.add(ArrayUtils.addAll(new Object[] {}, stats.preEvolutions), pokemon.name), Arrays.stream(stats.evolutions).map(evolution -> evolution.to.name).toArray()));
        case "ability":
            if (values.length == 3) {
                String value1 = values[2];
                int ability = value1.equals("1") ? 0 : value1.equals("2") ? 1 : value1.equalsIgnoreCase("h") ? 2 : -1;
                if (ability != -1) {
                    String result = stats.abilities[ability];
                    return result == null ? PPConfig.noneText : result;
                }
            }
            break;
        case "abilities":
            return asReadableList(values, 2, stats.abilities);
        // Since 1.2.0
        case "biomes":
            return asReadableList(values, 2, Arrays.stream(stats.biomeIDs).map(id -> Biome.getBiome(id).getBiomeName()).toArray());
        case "spawnlocations":
            return asReadableList(values, 2, stats.spawnLocations);
        case // 1.2.2
        "doesevolve":
            return stats.evolutions.length != 0;
        case // 1.2.2
        "evolutionscount":
            return stats.evolutions.length;
        case // Modified in 1.2.2
        "evolution":
            if (values.length >= 3) {
                int evolution;
                try {
                    evolution = Integer.parseInt(values[2]) - 1;
                } catch (NumberFormatException e) {
                    throw new NoValueException();
                }
                if (stats.evolutions.length <= 0) {
                    throw new NoValueException();
                }
                if (stats.evolutions.length <= evolution) {
                    return "Does not evolve.";
                } else {
                    Evolution evol = stats.evolutions[evolution];
                    if (values.length < 4) {
                        return stats.evolutions[evolution].to.name;
                    } else {
                        // Drastically changed since 1.3.0
                        String choice = values[3];
                        if (choice.equals("list")) {
                            // TODO write better
                            List<String> conditions = new ArrayList<>();
                            for (Map.Entry<String, EvoParser> entry : evoParsers.entrySet()) {
                                for (EvoCondition cond : evol.conditions) {
                                    if (cond.getClass().equals(entry.getValue().clazz)) {
                                        conditions.add(entry.getKey());
                                    }
                                }
                            }
                            if (!conditions.contains("level") && evol instanceof LevelingEvolution) {
                                conditions.add("level");
                            }
                            return asReadableList(values, 4, conditions.toArray());
                        } else {
                            try {
                                EvoParser parser = evoParsers.get(values[3]);
                                if (parser == null)
                                    throw new NoValueException();
                                EvoCondition cond = null;
                                for (EvoCondition c : evol.conditions) {
                                    if (c.getClass().equals(parser.clazz)) {
                                        cond = c;
                                    }
                                }
                                if (cond == null) {
                                    if (values[3].equals("level") && evol instanceof LevelingEvolution) {
                                        return ((LevelingEvolution) evol).level;
                                    }
                                    throw new NoValueException();
                                }
                                try {
                                    // noinspection unchecked
                                    return parser.parse(cond, values, 4);
                                } catch (IllegalAccessException e) {
                                    e.printStackTrace();
                                }
                            } catch (NoValueException e) {
                                return PPConfig.evolutionNotAvailableText;
                            }
                        }
                    }
                }
            }
            break;
        case "type":
            return asReadableList(values, 2, stats.getTypeList().toArray());
        case "basestats":
            if (values.length >= 3) {
                switch(values[2]) {
                    case "hp":
                        return stats.hp;
                    case "atk":
                        return stats.attack;
                    case "def":
                        return stats.defence;
                    case "spa":
                        return stats.spAtt;
                    case "spd":
                        return stats.spDef;
                    case "spe":
                        return stats.speed;
                    case "yield":
                        if (values.length >= 4) {
                            EVsStore yield = stats.evGain;
                            switch(values[3]) {
                                case "hp":
                                    return yield.HP;
                                case "atk":
                                    return yield.Attack;
                                case "def":
                                    return yield.Defence;
                                case "spa":
                                    return yield.SpecialAttack;
                                case "spd":
                                    return yield.SpecialDefence;
                                case "spe":
                                    return yield.Speed;
                            }
                        }
                        break;
                    case "yields":
                        EVsStore yield = stats.evGain;
                        return yield.HP + yield.Attack + yield.Defence + yield.SpecialAttack + yield.SpecialDefence + yield.Speed;
                }
            }
            break;
        case "drops":
            if (values.length >= 3) {
                PokemonDropInformation drops = pokemonDrops.get(pokemon);
                if (drops == null) {
                    return PPConfig.noneText;
                } else {
                    try {
                        switch(values[2]) {
                            case "main":
                                return getItemStackInfo((ItemStack) mainDrop.get(drops));
                            case "rare":
                                return getItemStackInfo((ItemStack) rareDrop.get(drops));
                            case "optional1":
                                return getItemStackInfo((ItemStack) optDrop1.get(drops));
                            case "optional2":
                                return getItemStackInfo((ItemStack) optDrop2.get(drops));
                        }
                    } catch (IllegalAccessException e) {
                        e.printStackTrace();
                    }
                }
            }
            break;
        case "egggroups":
            return asReadableList(values, 2, stats.eggGroups);
        case // Since 1.2.3
        "texturelocation":
            return "pixelmon:sprites/pokemon/" + String.format("%03d", stats.nationalPokedexNumber);
        case // Since 1.3.0
        "move":
            if (values.length >= 3) {
                try {
                    List<Attack> attacks = DatabaseMoves.getAllAttacks(stats.nationalPokedexNumber);
                    int attack = Integer.parseInt(values[2]) - 1;
                    if (attack >= 0 && attack < attacks.size()) {
                        return attacks.get(attack);
                    } else {
                        return PPConfig.moveNotAvailableText;
                    }
                } catch (NumberFormatException ignored) {
                }
            }
            break;
        case "moves":
            return asReadableList(values, 2, DatabaseMoves.getAllAttacks(stats.nationalPokedexNumber).stream().map(attack -> attack.baseAttack.getLocalizedName()).toArray());
    }
    throw new NoValueException();
}
Also used : java.util(java.util) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NoValueException(me.rojo8399.placeholderapi.NoValueException) com.pixelmonmod.pixelmon.entities.pixelmon.stats(com.pixelmonmod.pixelmon.entities.pixelmon.stats) PPConfig(com.github.happyzleaf.pixelmonplaceholders.PPConfig) ItemStack(net.minecraft.item.ItemStack) DatabaseMoves(com.pixelmonmod.pixelmon.database.DatabaseMoves) Attack(com.pixelmonmod.pixelmon.battles.attacks.Attack) WeatherType(com.pixelmonmod.pixelmon.api.world.WeatherType) PokemonDropInformation(com.pixelmonmod.pixelmon.entities.npcs.registry.PokemonDropInformation) Nullable(javax.annotation.Nullable) DatabaseStats(com.pixelmonmod.pixelmon.database.DatabaseStats) LevelingEvolution(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.types.LevelingEvolution) World(net.minecraft.world.World) DecimalFormat(java.text.DecimalFormat) EnumPokemon(com.pixelmonmod.pixelmon.enums.EnumPokemon) EnumType(com.pixelmonmod.pixelmon.enums.EnumType) Evolution(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution) Field(java.lang.reflect.Field) EntityPixelmon(com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon) PlayerStorage(com.pixelmonmod.pixelmon.storage.PlayerStorage) DropItemRegistry(com.pixelmonmod.pixelmon.entities.npcs.registry.DropItemRegistry) Player(org.spongepowered.api.entity.living.player.Player) com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.conditions(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.conditions) Biome(net.minecraft.world.biome.Biome) LevelingEvolution(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.types.LevelingEvolution) PokemonDropInformation(com.pixelmonmod.pixelmon.entities.npcs.registry.PokemonDropInformation) Attack(com.pixelmonmod.pixelmon.battles.attacks.Attack) NoValueException(me.rojo8399.placeholderapi.NoValueException) LevelingEvolution(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.types.LevelingEvolution) Evolution(com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution)

Aggregations

PPConfig (com.github.happyzleaf.pixelmonplaceholders.PPConfig)1 WeatherType (com.pixelmonmod.pixelmon.api.world.WeatherType)1 Attack (com.pixelmonmod.pixelmon.battles.attacks.Attack)1 DatabaseMoves (com.pixelmonmod.pixelmon.database.DatabaseMoves)1 DatabaseStats (com.pixelmonmod.pixelmon.database.DatabaseStats)1 DropItemRegistry (com.pixelmonmod.pixelmon.entities.npcs.registry.DropItemRegistry)1 PokemonDropInformation (com.pixelmonmod.pixelmon.entities.npcs.registry.PokemonDropInformation)1 EntityPixelmon (com.pixelmonmod.pixelmon.entities.pixelmon.EntityPixelmon)1 com.pixelmonmod.pixelmon.entities.pixelmon.stats (com.pixelmonmod.pixelmon.entities.pixelmon.stats)1 Evolution (com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.Evolution)1 com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.conditions (com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.conditions)1 LevelingEvolution (com.pixelmonmod.pixelmon.entities.pixelmon.stats.evolution.types.LevelingEvolution)1 EnumPokemon (com.pixelmonmod.pixelmon.enums.EnumPokemon)1 EnumType (com.pixelmonmod.pixelmon.enums.EnumType)1 PlayerStorage (com.pixelmonmod.pixelmon.storage.PlayerStorage)1 Field (java.lang.reflect.Field)1 DecimalFormat (java.text.DecimalFormat)1 java.util (java.util)1 Nullable (javax.annotation.Nullable)1 NoValueException (me.rojo8399.placeholderapi.NoValueException)1