Fight in Gym - always fail
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 ee28406d5a0f87dc2b16429f7b19e31fbac30a95
So is this gym attack thing working and what does it do?
at the moment i think that's not usable, but i can be wrong.
i got timeout during attack
yeah gym battles are complicated and this deff needs more work
Timeouts for me after half a Minute battling
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.
@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.
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.

@sarbajitsaha Great Work !
very interesting indeed, ill try to "translate" your code into C# and use it with the FeroxApi
@sarbajitsaha @tw88 - you can set Team Color with following (just pass the color as arg) https://github.com/AeonLucid/POGOProtos/blob/master/src/POGOProtos/Networking/Requests/Messages/SetPlayerTeamMessage.proto
https://github.com/sarbajitsaha I have the same code. Get the result state unset and error: invalid defender?
Timed out now.
@ScaryEnderman are you using fixed64 for your defender protobuf struct?
for me, the code on Battle class it's not working at all. some consideration after looking at code
-
we send multiple attack at once, all with 500 of costs. not all move1 cost 500ms
-
sending multiple attacks without sleep (for the TOTAL of time) before sending an attack will make the server think that we will send the attack from the future :)
-
attack sum only 100, but the cost of attack it's 500 (and, it's wrong) this can't work, standing on vmarchaud dump (posted above), each attach start when the previous finish so... 0 (setActionStartMs) 500 (attack move) 2nd attack should be 510 (setActionStartMs) 500 (attack move) 3rd 1020 500
and so on... currently it's all +100 that is wrong.
- the blank action it's send immediately after request, i don't think it's right, there should be a delay..
The last setActionStartMs should be send in the present, not in the past i think, but i haven't a dumo with timestamp unfortunately to check :(
@vmarchaud will be great if you can add another dump of a battle, as you give to us before, but this time with timestamp for each request/response, i don't know if the proxy that you use support that
@ScaryEnderman please try to user another ID for the defender.
the standart getDefenderId() return the Number of the Pkmn, 150 for Mewto etc. but i think what it needs is the Unique ID of the Trainers Pokemon which sits in the Arena.
In C# my Call looks like this: startGymBattle = await session.Client.Fort.StartGymBattle(arena.Id, fortInfo.GymState.Memberships[0].PokemonData.Id, myTeamPkmnIds);
The part what im atalking about is: fortInfo.GymState.Memberships[0].PokemonData.Id which returns the long unique(?) id of the pokmon on fist slot of the arena.
Edit: In the Log file posted earlier, the defenderPkmnId does not exist....
@Nostrademous how do I alter it?
@ScaryEnderman talk to @Grover-c13 - it's his library - I don't use it. Not sure how he wants user to modify their own protos.
any idea what FAILED:UNSET means? Gym battles definitely work, I won one, lost three, but some gyms are showing that error.
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 :)
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);
}
}
}