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();
}
Aggregations