Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fight in Gym - always fail #252

Closed
Lasek opened this issue Jul 26, 2016 · 63 comments
Closed

Fight in Gym - always fail #252

Lasek opened this issue Jul 26, 2016 · 63 comments

Comments

@Lasek
Copy link

Lasek commented Jul 26, 2016

Description:
When I start battle, status of start battle is always UNSET

Steps to reproduce:

Battle battle = gym.battle(attackers);
StartGymBattleResponseOuterClass.StartGymBattleResponse.Result result = battle.start();
if(result == StartGymBattleResponseOuterClass.StartGymBattleResponse.Result.SUCCESS){
    ...
}else{
    new throw Exception(result);
}

Expected behavior:
Status should be SUCCESS

Actual behavior:
Status always is UNSET

Version:
Last commit ee28406

@Grover-c13
Copy link
Owner

i had this issue when i had dead pokemon in my attacking team, need to add some checks to it at some point.

@Lasek
Copy link
Author

Lasek commented Jul 27, 2016

My all pokemons in team have max stamina. I still have a problem.

@apottere
Copy link

I'm seeing the same issue.

@apottere
Copy link

I tried the code in FightGymExample.java, (substituting my username and password), and this was the outcome:

D/RequestHandler: Authenticated with static token
D/RequestHandler: Authenticated with static token
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET
FAILED:UNSET

@twdnhfr
Copy link

twdnhfr commented Jul 27, 2016

im not using this api/bot because im a c# guy, but i think we have the same issue.

If you look at the IDs of you attacker Team - they are ulong and something like "6068907423423435111511".
But the GuardPokemonId returns a PokemonId (Flareon = 143 or whatever). GuardPokemonCP is also always 0. So we maybe need the pkmn-unique id of the defender pkmn, same as we use these unique ids for attackerTeam.

It could be that this is an issue of pogoprotos.dll

@apottere
Copy link

Are you talking about the ID of the gym pokemon when the battle start request is sent? This API is sending the UID of the defending pokemon just fine AFAICT.

@vmarchaud
Copy link
Contributor

From my testing, when building with the java api, you should get a different status_code in the ResponseEnvelope.
As i discussed with someone over slack, when you start a fight, the server will switch you to another one (like the first packet send) with the status_code 53 or 2.
In reality we got 3, thats a bad request status from my testing again, so dont know if the proto are wrong but the definitely dont want us to make that request.

@Grover-c13 told me that he succeed for sending that packet, any more info ?

@Grover-c13
Copy link
Owner

My apologies guys, i must of modified the proto when developing it and forgot to submit a PR to AeonLucids, if you change the defender_id to fixed64 this will work correctly. AeonLucid/POGOProtos#97

@apottere
Copy link

@Grover-c13 I fixed the proto locally, and now I'm getting ERROR_INVALID_DEFENDER. It looks like the logic for selecting the first defender is working correctly, so I'm not sure what's going wrong.

@Grover-c13
Copy link
Owner

hmmm, i was assuming the defenders that are on gyms are sorted on the server, but maybe i was lucky and we should sort for the lowest defender CP first before selecting the initial defender ID (which has to be the lowest CP defender pretty sure)

@apottere
Copy link

It looks like it is selecting the lowest CP defender, that was the first thing I checked.

@Grover-c13
Copy link
Owner

Is it an offensive attack (team vs another team) or a training attack (same team vs same team)?

@Lasek
Copy link
Author

Lasek commented Jul 28, 2016

If you asked me, this problem is in attack and trening too.

@apottere
Copy link

This is an offensive attack

@apottere
Copy link

Seems to be working this morning, but I didn't change anything. It's possible my account was soft banned. Now I'm getting INVALID_ATTACK_ACTIONS

@vmarchaud
Copy link
Contributor

vmarchaud commented Jul 28, 2016

Yes, you should check on how work battling, since the parameters are actually super important on the result of the action, read this dump and try to understand how it works, its not easy i warn you : http://pastebin.com/enDzFvUN

@apottere
Copy link

That's just what I was looking for - thanks!

@twdnhfr
Copy link

twdnhfr commented Jul 29, 2016

did anyone manage to do this yet?

@Nostrademous
Copy link

So my issue with this is that it works for me sometimes... (I have applied the fixed64 proto fix to defender). it seems like it fails if the defender_id is larger than an int64 but smaller than uint64. I had the same exact issue when capturing Incense generated Pokemon. Perhaps it's a python 2.7 issue on my end or something stupid.

@hmate9
Copy link

hmate9 commented Jul 30, 2016

Any updates on this? I've fixed the proto manually but attacking an enemy gym still does not work. My attacks are not being registered. I can see my pokemon's health going down but the enemy's health stays exactly the same (even though I have a higher CP) meaning my attacks aren't registered.

I followed the code in the example provided.

@mt247
Copy link

mt247 commented Aug 1, 2016

So is this gym attack thing working and what does it do?

@ramarro123
Copy link
Contributor

at the moment i think that's not usable, but i can be wrong.

i got timeout during attack

@Grover-c13
Copy link
Owner

yeah gym battles are complicated and this deff needs more work

@ScaryEnderman
Copy link

ScaryEnderman commented Aug 2, 2016

Timeouts for me after half a Minute battling

@sarbajitsaha
Copy link

any idea how to set a team (mystic, instinct etc.) automatically? I did try the gym battle out, and it actually succeeded. I check in the PokemonGo app and in the badge part, it shows I won one gym battle, but team isn't set, and since the app doesn't work where I stay, I can't check if it actually worked.

@twdnhfr
Copy link

twdnhfr commented Aug 3, 2016

@sarbajitsaha can you post example code you used?

I dont know if its possile to set your Team via the API, i dont think this is implemented yet.

@sarbajitsaha
Copy link

sarbajitsaha commented Aug 3, 2016

   try {
            List<Pokemon> pokemons = PokeMaticApplication.pogo.getInventories().getPokebank().getPokemons();

            Pokemon[] attackers = new Pokemon[6];
            str = "Pokemons being used:\n";

            for (int i = 0; i < 6; i++) {
                attackers[i] = pokemons.get(i);
                str+=(attackers[i].getOwnerName()+" CP: "+attackers[i].getCp()+"\n");
            }

            result = true;
            publishProgress();
            Log.e("result",str);

            List<Gym> gyms = PokeMaticApplication.pogo.getMap().getGyms();
            Log.e("gyms", String.valueOf(gyms.size()));

            for (Gym gym : gyms) {
                PokeMaticApplication.pogo.setLocation(gym.getLatitude(),gym.getLongitude(),20);
                if (gym.isAttackable()) {
                    Battle battle = gym.battle(attackers);
                    // start the battle
                    StartGymBattleResponseOuterClass.StartGymBattleResponse.Result result = battle.start();

                    if (result == StartGymBattleResponseOuterClass.StartGymBattleResponse.Result.SUCCESS) {
                        // started battle successfully
                        str += "\nGym Battle Started";
                        Log.e("result",str);
                        publishProgress();

                        // loop while battle is not finished
                        while (!battle.isConcluded()) {
                            results+="Attack:" + battle.attack(5)+"\n";
                            Log.e("result",results);
                            publishProgress();
                            Thread.sleep(500);
                        }
                        results+="Battle result:" + battle.getOutcome()+"\n";
                        Log.e("result",results);
                        publishProgress();

                    } else {
                        results+="Failed:" + result+"\n";
                        Log.e("result",results);
                    }
                }

            }
            result = true;

        } catch (Exception e) {
            e.printStackTrace();
            result = false;
        }

This is in an Async task for an android app. I did not get the battle conclusion and it also reported INVALID_ATTACK_OPTIONS a few times in the log, but I was kinda surprised to see that I have won a gym battle in the app.

Also note this is with the latest version; earlier I was getting UNSET, and you also need to change your location close to the gym to start the battle or else it will show out of range.

Battle

@john086
Copy link

john086 commented Aug 3, 2016

@sarbajitsaha Great Work !

@ramarro123
Copy link
Contributor

well, battle doesn't definitely work.... they 'randomly' work :) as you say, sometimes you got errors.

the problem it's that with the current code config, you can play only with pokemon that have move1 of time 500ms i think.

anyway, we should wait for @Grover-c13 support i presume :)

@kaynab
Copy link

kaynab commented Aug 4, 2016

I had it working pretty consistently with the below code prior to the api change. This includes joining a team if you never did as well as adding a pokemon to a friendly gym. My test account was rather weak and my local gym rather strong so everything ended in a defeated status but it never threw any errors and everything flowed consistently.

I got the basic logic from the FightGymExample.java file.

Pokemon[] attackers = getBiggestAvailableByCP(pokemons,0,6);
            for (Gym gym : go.getMap().getGyms()) {
                Thread.sleep(1000);
                System.out.println(gym.getDescription()+" @ "+gym.getLatitude()+", "+gym.getLongitude() + " - "+gym.getOwnedByTeam());
                System.out.println("In range: "+gym.inRange()+" Enabled: "+gym.getEnabled());
                List<PokemonData> dataList = gym.getDefendingPokemon();
                for(PokemonData d : dataList)
                {
                    System.out.println("    "+d.getCp()+" - "+d.getPokemonId()+ " - "+d.getOwnerName());
                }

                if(gym.isAttackable()&&gym.inRange())
                {
                    if(go.getPlayerProfile().getPlayerData().getTeam()==TeamColor.NEUTRAL)
                    {
                        SetPlayerTeamMessage msg = SetPlayerTeamMessage.newBuilder().setTeam(TeamColor.RED).build();
                        ServerRequest serverRequest = new ServerRequest(RequestType.SET_PLAYER_TEAM,msg);
                        go.getRequestHandler().sendServerRequests(serverRequest);
                        SetPlayerTeamResponse res = null;
                        try
                        {
                            res = SetPlayerTeamResponse.parseFrom(serverRequest.getData());
                            System.out.println(res);
                            break;
                        }
                        catch(Exception e)
                        {
                            System.out.println(e);
                        }
                    }
                    if(gym.getOwnedByTeam()==TeamColor.NEUTRAL || gym.getOwnedByTeam()==playerTeam)
                    {
                        System.out.println("Gym join logic... "+gym.getPoints());
                        Pokemon[] da = getBiggestAvailableByCP(pokemons, 0, 1);
                        if(da!=null && da.length>0)
                        {
                            Pokemon d = da[0];
                            System.out.println("Chose: "+d.getPokemonId()+" - "+d.getCp());
                            FortDeployPokemonMessage msg = FortDeployPokemonMessage.newBuilder().setPokemonId(d.getId()).setFortId(gym.getId()).build();
                            ServerRequest serverRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON,msg);
                            go.getRequestHandler().sendServerRequests(serverRequest);
                            FortDeployPokemonResponse res = null;
                            try
                            {
                                res = FortDeployPokemonResponse.parseFrom(serverRequest.getData());
                                System.out.println(res);
                            }
                            catch(Exception e)
                            {
                                System.out.println(e);
                            }
                                                      //Doing this because previous biggest might have just joined gym
                            attackers = getBiggestAvailableByCP(pokemons, 0, 1);
                        }
                    }
                    Battle battle = gym.battle(attackers);
                    // start the battle
                    Thread.sleep(1000);
                    Result result = battle.start();
                    Thread.sleep(1000);
                    if (result == Result.SUCCESS) {
                        // started battle successfully
                        System.out.println("Battling...");
                        // loop while battle is not finished
                        while (!battle.isConcluded()) {
                            battle.attack(5);
                            Thread.sleep(500);
                        }

                        System.out.println("Battle result:" + battle.getOutcome());

                    } else {
                        System.out.println("FAILED:" + result);
                    }
                }

            }

@mjmjelde
Copy link
Contributor

mjmjelde commented Aug 4, 2016

Are you only getting this today? If so, all API's are broken right now is probably why you are getting this. Niantic changed the way requests need to be sent. Wait until there is a fix for that and see if this problem still exists then

@stanleykerr
Copy link

stanleykerr commented Aug 9, 2016

Using any of the above code, I get FAILED:UNSET or ERROR_INVALID_ATTACK_ACTIONS

@kaynab
Copy link

kaynab commented Aug 9, 2016

I haven't tried it since the api change but I'll take a look in a bit.

I just gave it a try and it appears to be working:
D/RequestHandler: Authenticated with static token
Level: 7
Adding 183 - DROWZEE - 41
Adding 162 - EEVEE - 40
Adding 152 - DROWZEE - 40
Adding 144 - CLEFAIRY - 42
Adding 137 - SHELLDER - 22
Adding 124 - JYNX - 31
@ 42.30063, -73.999677 - RED
In range: true Enabled: true
905 - LAPRAS - skullforlife
1068 - VAPOREON - tazjojo
1314 - FLAREON - Sistaqueen
1618 - NIDOKING - JaredTots
Gym join logic... 10208
Adding 183 - DROWZEE - 41
Chose: DROWZEE - 183
result: ERROR_NOT_IN_RANGE

Adding 183 - DROWZEE - 41
Attackers: 1
FAILED:ERROR_NOT_IN_RANGE

@ 42.299666, -74.002315 - BLUE
In range: true Enabled: true
629 - VAPOREON - KINGBOBY1265
1113 - VAPOREON - Swift1234
1294 - DRAGONITE - ThomasLewis
Attackers: 1
Battling...
Battle result:DEFEATED

If you're getting UNSET it means you're passing a null value somewhere. I'd double check your pokemon list.

@Nostrademous
Copy link

IT IS VERY IMPORTANT THAT YOU:

  • don't send pokemon to fight gyms that are not full health
  • don't send pokemon to fight gyms that are deployed to a gym

@kaynab
Copy link

kaynab commented Aug 9, 2016

That's a good point. My find highest CP method only returns available full health, not fainted pokemon.

That's also why I run it again if gym join was successful.

Also make sure that if it's a friendly gym that you only have 1 attacker instead of 6.

@uz19ibyd
Copy link

Although my messsages appear to be alright, my pkmn in good shape and not in gym, i still get success=0 without even an error. does somebody have a hint?

@eraofchaos
Copy link

eraofchaos commented Aug 10, 2016

Current code in Battle is wrong and does not work correctly.
@ramarro123:

  1. The attack time is not always 500! You must use code like
    PokemonMoveMeta pmm = PokemonMoveMetaRegistry.getMeta(pokemon.getMove1());
    int attackTime = pmm.getTime();

to get correct time for "simple" pokemon attack...

  1. The sleep outside attack code... but main issue -> we need to wait until Battle is begin... between battle.start() and attack(5)... waiting time depends on your attack speed....

  2. ok

  3. right.

more critical:
You need to send more information:
BattleAction action = BattleAction
.newBuilder()
.setType(BattleActionTypeOuterClass.BattleActionType.ACTION_ATTACK) // may be ACTION_SPECIAL_ATTACK | ACTION_DODGE
.setActionStartMs(myTime /_currentDelayPerAction 100_times */)
.setDurationMs(attackTime)
.setAttackerIndex(-1)
.setTargetIndex(-1)
.setActivePokemonId(pok.getId())
// TBD.setTargetPokemonId(value) <-- did not get it in the battle log... looks like only with BattleActionType.ACTION_FAINT
// TBD optional .setEnergyDelta(value)
.setDamageWindowsStartTimestampMss(myTime+attackTime-200)
.setDamageWindowsEndTimestampMss(myTime+attackTime)
.build();

also, ACTION_ATTACK is just simple one... we need at least 2 more:
ACTION_SPECIAL_ATTACK + ACTION_FAINT

the SPECIAL_ATTACK is required ".setTargetPokemonId(value)"

With Best Regards

@vmarchaud: Would be nice to get more BATTLEs for current "0.33.0" version.
Thanks,

@Nostrademous
Copy link

Nostrademous commented Aug 11, 2016

@firexball does it work for you? I'm writing my own battle bot and am finding that I don't need to set "activePokemonId", or the "DamageWindow..." or "AttackerIndex" when attacking. The server replies with SUCCESS result without these... however, I seem to take damage while the defender takes no damage currently...

@firebolt55439
Copy link

@Nostrademous I have the same result - the server "accepts" all my requests, but I essentially sit there and take attacks without executing any of my own.

@firebolt55439
Copy link

firebolt55439 commented Aug 11, 2016

Never mind, I got it working (though I really need to get better pokemon lol). The opponent finally takes damage.

@Nostrademous
Copy link

Nostrademous commented Aug 11, 2016

@firebolt55439 are you sending any extra info besides "target_index", "duration_ms", "action_start_ms" and "type"?

If not, then I'm guessing it's a timing thing on my side.

@firebolt55439
Copy link

@Nostrademous I don't send attacker_index, but I do send the damage window and the active pokemon information, and I make sure that I'm sending strictly past actions (e.g. no future timestamps relative to server_time_ms)

@Nostrademous
Copy link

@firebolt55439 thank you, that fixed it for me too. Doing damage now.

How does Dodging work? I send dodge actions but I still seem to take damage... I figured a bot would be able to dodge perfectly by adding a dodge_action between the damage window of the defending pokemon for every one of their attacks, no?

Perhaps special attacks cannot be dodged?

@firebolt55439
Copy link

@Nostrademous Still haven't figured out why I can't really dodge anything - I just stick to doing fast attacks and the occasional special attack.

@firebolt55439
Copy link

firebolt55439 commented Aug 12, 2016

I have an iPhone and can't disable the SSL cert pinning - by any chance, do any of you have access to a recent MITM log for a gym battle? I know there's one posted here earlier, but it's pre-unknown6 and not entirely accurate. It would be very much appreciated :)

@Nostrademous
Copy link

@firebolt55439 nope, that's the only one I know of.

@firebolt55439
Copy link

@Nostrademous I'm going to jailbreak it just for PoGo now haha (the things I do for love...)

@BadChoicesZ
Copy link

@firebolt55439 Thanks for your help here, what you posted will fix most peoples problems, i now have Attack Gyms working in C# ( I only recently seen this page. ).

Legend 👍

@firebolt55439
Copy link

@FaezeOner No problem - happy to help :).

On Thu, Aug 25, 2016 at 4:50 AM, FaezeOner [email protected] wrote:

@firebolt55439 https://github.com/firebolt55439 Thanks for your help
here, what you posted will fix most peoples problems, i now have Attack
Gyms working in C# ( I only recently seen this page. ).

Legend 👍


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#252 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABO7p6OF9uxkjRmSpn2WEeNd8PayNukWks5qjYGigaJpZM4JVSIN
.

-Sumer

@pokeplayer2
Copy link

@FaezeOner Hi, can you share the C# code for Attack Gyms? I like to play with it. Thanks a lot!

This was referenced Nov 29, 2016
@Gegy
Copy link
Collaborator

Gegy commented Dec 11, 2016

I've been working on a fixed and improved Battle class, but I'm getting the same problem that a few others have gotten. The defender doesn't take any damage. (Although, in my case, it does occasionally)

I'm currently sending action_start_ms, target_index, active_pokemon_id, damage_windows_start_timestamp_ms, damage_windows_end_timestamp_ms and type, and I am making sure I do not send any timestamps greater than server_time_ms.

You can see the updated Battle class here: https://github.com/gegy1000/PokeGOAPI-Java/commit/d7802bdb663685a5f9ad09efe9784637c1b22e70

@firebolt55439 From what you've said above, it looks like the only fields that need to be set on the BattleAction being sent to the server are the ones I mentioned above. Could the required fields have changed in a newer version? Any idea what I'm doing wrong here?

Thanks.

EDIT: Okay, I made a silly mistake. I was performing special attacks when I didn't have enough energy and normal attacks when I did. My problem now is that after my first pokemon faints, the server will continue to send this faint action.

@samuraitruong
Copy link

hi @BadChoicesZ

I am working on fixing Gymbattle in Rocket API C# too. Hope you can share your experience to solve the issue, for you I learn how to do delay between 2 action since I debug and GymAttack work, but when run without debug it got BAD request, I believe that we need delay properly.

Thanks

@ziomber
Copy link

ziomber commented Jan 27, 2017

If you have any clues how to use ACTION_SWAP_POKEMON it will be great to know that to. What i'll do i've got always the same result: ERROR_INVALID_ATTACK_ACTIONS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests