From 02b54d9196aa39ea7d40202977d8d5b0720a8dba Mon Sep 17 00:00:00 2001 From: udnp Date: Mon, 15 Jun 2020 03:31:15 +0900 Subject: [PATCH] [C] improve detection Galarian and evolution line including Galarian forms. --- .../pogoiv/scanlogic/PokeInfoCalculator.java | 25 +++-- .../kamron/pogoiv/scanlogic/PokemonBase.java | 93 +++++++++++++++++++ .../scanlogic/PokemonNameCorrector.java | 46 +++++++-- 3 files changed, 149 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java index 6feded1e2..797e7d7dc 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokeInfoCalculator.java @@ -27,6 +27,12 @@ public class PokeInfoCalculator { private List formVariantPokemons; private String[] pokeNamesWithForm = {}; + public static final int MELTAN_INDEX_OFFSET = 5; + public static final int MELMETAL_INDEX_OFFSET = 4; + public static final int OBSTAGOON_INDEX_OFFSET = 3; + public static final int PERRSERKER_INDEX_OFFSET = 2; + public static final int SIRFETCHD_INDEX_OFFSET = 1; + /** * Pokemons who's name appears as a type of candy. * For most, this is the basePokemon (ie: Pidgey candies) @@ -177,13 +183,18 @@ private void populatePokemon(@NonNull GoIVSettings settings, @NonNull Resources int pokeListSize = names.length; ArrayList formVariantPokemons = new ArrayList<>(); - // quick hardcoded patch for Meltan and Melmetal - // Tentatively use pokedex list size until supporting discontinuous pokedex numbers, - // like as #493 Arceus, #808 Meltan, #809 Melmetal. - candyNamesArray[pokeListSize - 2] = pokeListSize - 2; - candyNamesArray[pokeListSize - 1] = pokeListSize - 2; - devolution[pokeListSize - 1] = pokeListSize - 2; - // END patch for Meltan and Melmetal + // quick hardcoded patch for supporting discontinuous pokedex number pokemons followings + // #808 Meltan + // #809 Melmetal + // #862 Obstagoon, + // #863 Perrserker, + // #865 Sirfetch'd + // currently GoIV logic expects that pokedex numbers are continuous and less than pokeListSize. + // so this patch shifts these to dummy indexes, with pokeListSize offset. + candyNamesArray[pokeListSize - MELTAN_INDEX_OFFSET] = pokeListSize - MELTAN_INDEX_OFFSET; + candyNamesArray[pokeListSize - MELMETAL_INDEX_OFFSET] = pokeListSize - MELTAN_INDEX_OFFSET; + devolution[pokeListSize - MELMETAL_INDEX_OFFSET] = pokeListSize - MELTAN_INDEX_OFFSET; + // END patch for supporting discontinuous pokedex number pokemons for (int i = 0; i < pokeListSize; i++) { PokemonBase p = new PokemonBase(names[i], displayNames[i], i, devolution[i], evolutionCandyCost[i]); diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonBase.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonBase.java index afb61f42d..bb6da7e12 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonBase.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonBase.java @@ -70,6 +70,99 @@ public Pokemon getForm(@NonNull Pokemon otherForm) { // In that case return the first one, which can be done in any case if this base has multiple forms (because // then we know that the other form is the single one). But if the other form has multiple forms it also needs // to verify that the other form is actually the first one. + + final int pokeListSize = PokeInfoCalculator.getInstance().getPokedex().size(); + + if (number == 51) { // #52 Meowth + // check #863 Perrserker with its index number in pokemons.xml + if (otherForm.number == pokeListSize - PokeInfoCalculator.PERRSERKER_INDEX_OFFSET) { + // return Galarian forms + return forms.get(2); + } else { + return getForm(otherForm.formName); + } + } + if (number == 52) { // #53 Persian + return getForm(otherForm.formName); + } + if (number == 82) { // #83 Farfetch'd + // check #865 Sirfetch'd with its index number in pokemons.xml + if (otherForm.number == pokeListSize - PokeInfoCalculator.SIRFETCHD_INDEX_OFFSET) { + // return Galarian forms + return forms.get(1); + } else { + return getForm(otherForm.formName); + } + } + if (number == 262 || number == 263) { // #263 ZIGZAGOON or #264 LINOONE + // check #862 OBSTAGOON with its index number in pokemons.xml + if (otherForm.number == pokeListSize - PokeInfoCalculator.OBSTAGOON_INDEX_OFFSET) { + // return Galarian forms + return forms.get(1); + } else { + return getForm(otherForm.formName); + } + } + if (number == 553) { // #554 Darumaka + // check #555 Darmanitan + if (otherForm.number == 554 && otherForm.base.forms.get(0) == otherForm) { + // return Normal Form + return forms.get(0); + } + // check #555 Darmanitan Galarian + if (otherForm.number == 554 && otherForm.base.forms.get(2) == otherForm) { + // return Galarian Form + return forms.get(1); + } else { + return getForm(otherForm.formName); + } + } + if (number == 554) { // #555 Darmanitan + // check #554 Darumaka Normal + if (otherForm.number == 553 && otherForm.base.forms.get(0) == otherForm) { + // return Standard Form + return forms.get(0); + } + // check #554 Darumaka Galarian + if (otherForm.number == 553 && otherForm.base.forms.get(1) == otherForm) { + // return Galarian Standard Form + return forms.get(2); + } else { + return getForm(otherForm.formName); + } + } + if (number == pokeListSize + - PokeInfoCalculator.OBSTAGOON_INDEX_OFFSET) { // #862 OBSTAGOON index number in pokemons.xml + // check #263 ZIGZAGOON Galarian + if (otherForm.number == 262 && otherForm.base.forms.get(1) == otherForm) { + return forms.get(0); + } + // check #264 LINOONE Galarian + if (otherForm.number == 263 && otherForm.base.forms.get(1) == otherForm) { + return forms.get(0); + } else { + return getForm(otherForm.formName); + } + } + if (number == pokeListSize + - PokeInfoCalculator.PERRSERKER_INDEX_OFFSET) { // #863 Perrserker index number in pokemons.xml + // check #52 Meowth Galarian + if (otherForm.number == 51 && otherForm.base.forms.get(2) == otherForm) { + return forms.get(0); + } else { + return getForm(otherForm.formName); + } + } + if (number == pokeListSize + - PokeInfoCalculator.SIRFETCHD_INDEX_OFFSET) { // #865 Sirfetch'd index number in pokemons.xml + // check #83 Farfetch'd Galarian + if (otherForm.number == 82 && otherForm.base.forms.get(1) == otherForm) { + return forms.get(0); + } else { + return getForm(otherForm.formName); + } + } + if ((otherForm.base.forms.size() == 1 && forms.size() > 1) || (forms.size() == 1 && otherForm.base.forms.size() > 1 && otherForm.base.forms.get(0) == otherForm)) { return forms.get(0); diff --git a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java index 73f231c3b..b16d429a1 100644 --- a/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java +++ b/app/src/main/java/com/kamron/pogoiv/scanlogic/PokemonNameCorrector.java @@ -181,11 +181,11 @@ public PokeDist getPossiblePokemon(@NonNull ScanData scanData) { } - //6. Check if the found pokemon should be alolan variant or not. + //6. Check if the found pokemon should be its variant(e.g. Alolan, Galarian, or its specific form) or not. if (scanData != null && scanData.getPokemonType() != null) { - PokeDist alolanGuess = checkAlolanVariant(guess, scanData); - if (alolanGuess != null) { - guess = alolanGuess; + PokeDist variantGuess = checkVariant(guess, scanData); + if (variantGuess != null) { + guess = variantGuess; } } @@ -289,7 +289,7 @@ private PokeDist createFormPokeDistances(PokeDist guess, ScanData scanData, Type return null; } - private PokeDist checkAlolanVariant(PokeDist guess, ScanData scanData) { + private PokeDist checkVariant(PokeDist guess, ScanData scanData) { try { switch (guess.pokemon.number) { case (102): // Exeggutor (dex 103) @@ -323,8 +323,7 @@ private PokeDist checkAlolanVariant(PokeDist guess, ScanData scanData) { // check types including steel return createFormPokeDist(guess, scanData, Type.STEEL, 1); case (51): // Meowth - // check types including dark - return createFormPokeDist(guess, scanData, Type.DARK, 1); + return createFormPokeDistances(guess, scanData, Type.NORMAL, Type.DARK, Type.STEEL); case (52): // Persian // check types including dark return createFormPokeDist(guess, scanData, Type.DARK, 1); @@ -337,6 +336,8 @@ private PokeDist checkAlolanVariant(PokeDist guess, ScanData scanData) { case (75): // Golem // check types including electric return createFormPokeDist(guess, scanData, Type.ELECTRIC, 1); + case (82): // Farfetch'd + return createFormPokeDist(guess, scanData, Type.FIGHTING, 1); case (87): // Grimer // check types including dark return createFormPokeDist(guess, scanData, Type.DARK, 1); @@ -346,6 +347,12 @@ private PokeDist checkAlolanVariant(PokeDist guess, ScanData scanData) { case (104): // Marowak // check types including fire return createFormPokeDist(guess, scanData, Type.FIRE, 1); + case (109): // Weezing + return createFormPokeDist(guess, scanData, Type.FAIRY, 1); + case (262): // Zigzagoon + return createFormPokeDist(guess, scanData, Type.DARK, 1); + case (263): // Linoone + return createFormPokeDist(guess, scanData, Type.DARK, 1); case (412): // Wormadam return createFormPokeDistances(guess, scanData, Type.DARK, Type.GROUND, Type.STEEL); case (478): // Rotom @@ -357,10 +364,33 @@ private PokeDist checkAlolanVariant(PokeDist guess, ScanData scanData) { dist = new PokeDist(guess.pokemon.base.forms.get(0), 0); } return dist; - case (492): // Rotom + case (492): // Arceus return createFormPokeDistances(guess, scanData, Type.NORMAL, Type.FIGHTING, Type.FLYING, Type.POISON, Type.GROUND, Type.ROCK, Type.BUG, Type.GHOST, Type.STEEL, Type.FIRE, Type.WATER, Type.GRASS, Type.ELECTRIC, Type.PSYCHIC, Type.ICE, Type.DRAGON, Type.DARK, Type.FAIRY); + case (553): // Darumaka + return createFormPokeDist(guess, scanData, Type.ICE, 1); + case (554): // Darmanitan + dist = createFormPokeDist(guess, scanData, Type.PSYCHIC, 1); + // check Zen Form + if (dist == null) { + // check Standard Form + if (createFormPokeDist(guess, scanData, Type.ICE, 1) == null) { + dist = createFormPokeDist(guess, scanData, Type.FIRE, 0); + } + // check Galarian Standard Form + else if (createFormPokeDist(guess, scanData, Type.FIRE, 1) == null) { + dist = createFormPokeDist(guess, scanData, Type.ICE, 2); + } + // Galarian Zen Form + else { + dist = createFormPokeDist(guess, scanData, Type.ICE, 3); + } + } + return dist; + case (617): // Stunfisk + return createFormPokeDist(guess, scanData, Type.STEEL, 1); + default: // do nothing