PokeGOAPI-Java icon indicating copy to clipboard operation
PokeGOAPI-Java copied to clipboard

Commit cca2a1c finds pokemon only once after running.

Open jsl303 opened this issue 10 years ago • 30 comments

In Commit cca2a1c, go.getMap().getCatchablePokemon() only seems to find pokemons only once after launching. After catching pokemon, I have to terminate and rerun in order to find more.

jsl303 avatar Aug 01 '16 23:08 jsl303

this commit doesn´t changed the logic. You have to wait 5sec after every scan since the server update.

FabianTerhorst avatar Aug 01 '16 23:08 FabianTerhorst

If I run my same code with commit 82fefdb6, it finds pokemons without any problem except getting stuck at cp.catchPokemon() once in a while. In cca2a1c, are you suggesting to run Thread.sleep(5000) before catchablePokemon = go.getMap().getCatchablePokemon();? Thanks,

On 8/1/2016 7:50 PM, Fabian Terhorst wrote:

this commit doesn´t changed the logic. You have to wait 5sec after every scan since the server update.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Grover-c13/PokeGOAPI-Java/issues/438#issuecomment-236745502, or mute the thread https://github.com/notifications/unsubscribe-auth/ALDSx1mndUMFxKtnz9h6wwQE1PnKkaCsks5qboZggaJpZM4JaG68.

jsl303 avatar Aug 02 '16 00:08 jsl303

There are logic changes from @jabbink in this commit.

FabianTerhorst avatar Aug 02 '16 00:08 FabianTerhorst

from #426

FabianTerhorst avatar Aug 02 '16 00:08 FabianTerhorst

does this is breaking the scan in your app?

FabianTerhorst avatar Aug 02 '16 00:08 FabianTerhorst

Well, it finds once in the beginning. Then it breaks. I'm not sure exactly what the sequence is supposed to be. Here's my code for catching loop. This code works fine in commit  82fefdb except it hangs once in a while at cp.catchPokemon();. In  cca2a1c , it only finds once in the beginning, and I have to terminate and rerun in order to find more. It'd be great if you could write a catching loop in the example.

    while (true) {
        int size = 0;
        while (size == 0) {
            Thread.sleep(1000);
            catchablePokemon = go.getMap().getCatchablePokemon();
            size = catchablePokemon.size();
        }
        System.out.println("Catching " + size + " Pokemons");
        for (CatchablePokemon cp : catchablePokemon) {
            PokemonId id = cp.getPokemonId();
            EncounterResult encResult = cp.encounterPokemon();
            System.out.println("Encountered: " + id + " " + encResult.getStatus());
            if (!encResult.wasSuccessful()) continue;
            CatchResult result = cp.catchPokemon();
            System.out.println("Attempt to catch: " + id + " " + result.getStatus());
        }
    }

jsl303 avatar Aug 02 '16 00:08 jsl303

you need to change the sleep time to 5000 or otherwise it will only work once

stefan-karger avatar Aug 02 '16 07:08 stefan-karger

and you may also need to add a Thread.sleep(5000) after encounterPokemon() and catchPokemon() for the same reason, but I'm not 100% sure about that one

stefan-karger avatar Aug 02 '16 07:08 stefan-karger

I only know that 5 seconds is the minimum for scanning. Many people are saying there are using 6 seconds to be 100% sure.

FabianTerhorst avatar Aug 02 '16 07:08 FabianTerhorst

The api currently implements this (it will use cached object for 5 seconds and request new one), im looking into an issue with the cache of catchable pokemon now, but looks like its running fine for me.

Grover-c13 avatar Aug 02 '16 07:08 Grover-c13

Is the wait before or after the first request?

FabianTerhorst avatar Aug 02 '16 07:08 FabianTerhorst

it will use a fresh copy on the first request, then store it, and then any call for the next 5 seconds will return the cache copy, and then will request a new copy again for calls after that 5 seconds.

Grover-c13 avatar Aug 02 '16 07:08 Grover-c13

I thought about saving 50 pokemongo object references that are using 50 different accounts so that i can send a request every 0,1seconds.

FabianTerhorst avatar Aug 02 '16 07:08 FabianTerhorst

If the api returns cache copy, wouldn't my loop eventually get a new scan every 5 seconds? It shouldn't break forever until restart though.

jsl303 avatar Aug 02 '16 09:08 jsl303

Yes you are correct, unless there is a flaw in the cache logic. Can you give me the long/lat so i can do some testing at that area to see if i can reproduce?

Grover-c13 avatar Aug 02 '16 09:08 Grover-c13

I'm just doing Central Park, New York.

On 8/2/2016 5:03 AM, Grover-c13 wrote:

Yes you are correct, unless there is a flaw in the cache logic. Can you give me the long/lat so i can do some testing at that area to see if i can reproduce?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/Grover-c13/PokeGOAPI-Java/issues/438#issuecomment-236846414, or mute the thread https://github.com/notifications/unsubscribe-auth/ALDSx3rLbuhcvK8jeOXAlJcwzVnBKPicks5qbwfTgaJpZM4JaG68.

jsl303 avatar Aug 02 '16 09:08 jsl303

There's a flaw in the cache logic. If you call getCatchablePokemon for the first time, everything works. cachedCatchable is set to something not null. If you after this, do any call on getting the map and the timeout has expired, map objects are reloaded and cache timeout is reset. If you then get catchable pokemon, timeout is not expired and cachedCatchable is not null, so cachedCatchable is returned which by this time most likely is empty.

Setting cachedCatchable to null in the getMapObjectsAsync call will solve this.

pvanassen avatar Aug 02 '16 12:08 pvanassen

yeah i think i did this in the latest PR, let me check

Grover-c13 avatar Aug 02 '16 12:08 Grover-c13

Here's a PR if it's still broken

pvanassen avatar Aug 02 '16 12:08 pvanassen

https://github.com/Grover-c13/PokeGOAPI-Java/blob/0d9857633b92ebce4c7c8bc5c1b52bb891999b74/library/src/main/java/com/pokegoapi/api/map/Map.java#L98

https://github.com/Grover-c13/PokeGOAPI-Java/blob/0d9857633b92ebce4c7c8bc5c1b52bb891999b74/library/src/main/java/com/pokegoapi/api/map/Map.java#L378

yep did it

Grover-c13 avatar Aug 02 '16 12:08 Grover-c13