Search in sources :

Example 36 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Pokemon method renamePokemon.

/**
	 * Rename pokemon nickname pokemon response . result.
	 *
	 * @param nickname the nickname
	 * @return the nickname pokemon response . result
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public NicknamePokemonResponse.Result renamePokemon(String nickname) throws RequestFailedException {
    NicknamePokemonMessage reqMsg = NicknamePokemonMessage.newBuilder().setPokemonId(getId()).setNickname(nickname).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.NICKNAME_POKEMON, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    NicknamePokemonResponse response;
    try {
        response = NicknamePokemonResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == NicknamePokemonResponse.Result.SUCCESS) {
            this.nickname = nickname;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.getInventories().getPokebank().removePokemon(this);
    return response.getResult();
}
Also used : NicknamePokemonMessage(POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage) NicknamePokemonResponse(POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 37 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Map method requestMapObjects.

/**
	 * Requests and returns MapObjects from the server.
	 *
	 * @return the returned MapObjects
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
protected MapObjects requestMapObjects() throws RequestFailedException {
    List<Long> cells = getDefaultCells();
    GetMapObjectsMessage.Builder builder = GetMapObjectsMessage.newBuilder();
    builder.setLatitude(api.getLatitude());
    builder.setLongitude(api.getLongitude());
    for (Long cell : cells) {
        builder.addCellId(cell);
        builder.addSinceTimestampMs(0);
    }
    ServerRequest request = new ServerRequest(RequestType.GET_MAP_OBJECTS, builder.build());
    api.getRequestHandler().sendServerRequests(request, true);
    try {
        GetMapObjectsResponse response = GetMapObjectsResponse.parseFrom(request.getData());
        MapObjects mapObjects = new MapObjects(api);
        for (MapCell cell : response.getMapCellsList()) {
            mapObjects.addCell(cell);
        }
        return mapObjects;
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) GetMapObjectsResponse(POGOProtos.Networking.Responses.GetMapObjectsResponseOuterClass.GetMapObjectsResponse) ServerRequest(com.pokegoapi.main.ServerRequest) GetMapObjectsMessage(POGOProtos.Networking.Requests.Messages.GetMapObjectsMessageOuterClass.GetMapObjectsMessage) MapCell(POGOProtos.Map.MapCellOuterClass.MapCell)

Example 38 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Pokestop method getDetailsAsync.

/**
	 * Get more detailed information about a pokestop.
	 *
	 * @return FortDetails
	 */
public Observable<FortDetails> getDetailsAsync() {
    FortDetailsMessage reqMsg = FortDetailsMessage.newBuilder().setFortId(getId()).setLatitude(getLatitude()).setLongitude(getLongitude()).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_DETAILS, reqMsg);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, FortDetails>() {

        @Override
        public FortDetails call(ByteString result) {
            FortDetailsResponseOuterClass.FortDetailsResponse response = null;
            try {
                response = FortDetailsResponseOuterClass.FortDetailsResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            return new FortDetails(response);
        }
    });
}
Also used : FortDetailsMessage(POGOProtos.Networking.Requests.Messages.FortDetailsMessageOuterClass.FortDetailsMessage) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 39 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Pokestop method lootAsync.

/**
	 * Loots a pokestop for pokeballs and other items.
	 *
	 * @return PokestopLootResult
	 */
public Observable<PokestopLootResult> lootAsync() {
    FortSearchMessage searchMessage = FortSearchMessage.newBuilder().setFortId(getId()).setFortLatitude(getLatitude()).setFortLongitude(getLongitude()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.FORT_SEARCH, searchMessage);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest, true).map(new Func1<ByteString, PokestopLootResult>() {

        @Override
        public PokestopLootResult call(ByteString result) {
            FortSearchResponseOuterClass.FortSearchResponse response;
            try {
                response = FortSearchResponseOuterClass.FortSearchResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            cooldownCompleteTimestampMs = response.getCooldownCompleteTimestampMs();
            PokestopLootResult lootResult = new PokestopLootResult(response);
            List<PokestopListener> listeners = api.getListeners(PokestopListener.class);
            for (PokestopListener listener : listeners) {
                // listener.onLoot(lootResult);
                // return the pokestop, also change in listener
                listener.onLoot(lootResult, Pokestop.this);
            }
            return lootResult;
        }
    });
}
Also used : PokestopListener(com.pokegoapi.api.listener.PokestopListener) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) List(java.util.List) FortSearchMessage(POGOProtos.Networking.Requests.Messages.FortSearchMessageOuterClass.FortSearchMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 40 with ServerRequest

use of com.pokegoapi.main.ServerRequest in project PokeGOAPI-Java by Grover-c13.

the class Pokestop method addModifierAsync.

/**
	 * Adds a modifier to this pokestop. (i.e. add a lure module)
	 *
	 * @param item the modifier to add to this pokestop
	 * @return true if success
	 */
public Observable<Boolean> addModifierAsync(ItemId item) {
    AddFortModifierMessage msg = AddFortModifierMessage.newBuilder().setModifierType(item).setFortId(getId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
    ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ADD_FORT_MODIFIER, msg);
    return api.getRequestHandler().sendAsyncServerRequests(serverRequest).map(new Func1<ByteString, Boolean>() {

        @Override
        public Boolean call(ByteString result) {
            try {
                //sadly the server response does not contain any information to verify if the request was
                // successful
                AddFortModifierResponseOuterClass.AddFortModifierResponse.parseFrom(result);
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
            return Boolean.TRUE;
        }
    });
}
Also used : ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) AddFortModifierMessage(POGOProtos.Networking.Requests.Messages.AddFortModifierMessageOuterClass.AddFortModifierMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)42 ServerRequest (com.pokegoapi.main.ServerRequest)42 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)35 ByteString (com.google.protobuf.ByteString)13 GetPlayerMessage (POGOProtos.Networking.Requests.Messages.GetPlayerMessageOuterClass.GetPlayerMessage)3 Item (com.pokegoapi.api.inventory.Item)3 ItemBag (com.pokegoapi.api.inventory.ItemBag)3 TutorialListener (com.pokegoapi.api.listener.TutorialListener)3 FortDeployPokemonMessage (POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage)2 LevelUpRewardsMessage (POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage)2 ReleasePokemonMessage (POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage)2 UseItemEncounterMessage (POGOProtos.Networking.Requests.Messages.UseItemEncounterMessageOuterClass.UseItemEncounterMessage)2 LevelUpRewardsResponse (POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse)2 UseItemEncounterResponse (POGOProtos.Networking.Responses.UseItemEncounterResponseOuterClass.UseItemEncounterResponse)2 EvolutionResult (com.pokegoapi.api.map.pokemon.EvolutionResult)2 BattleAction (POGOProtos.Data.Battle.BattleActionOuterClass.BattleAction)1 PlayerBadge (POGOProtos.Data.PlayerBadgeOuterClass.PlayerBadge)1 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 TutorialState (POGOProtos.Enums.TutorialStateOuterClass.TutorialState)1 Candy (POGOProtos.Inventory.CandyOuterClass.Candy)1