Search in sources :

Example 21 with ServerRequest

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

the class Inventories method updateInventories.

/**
	 * Updates the inventories with the latest data.
	 *
	 * @param forceUpdate For a full update if true
	 * @return the response to the update message
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public GetInventoryResponse updateInventories(boolean forceUpdate) throws RequestFailedException {
    if (forceUpdate) {
        lastInventoryUpdate = 0;
        itemBag.reset();
        pokebank.reset();
        candyjar.reset();
        pokedex.reset();
        synchronized (this.lock) {
            incubators.clear();
        }
        hatchery.reset();
    }
    GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder().setLastTimestampMs(lastInventoryUpdate).build();
    ServerRequest inventoryRequest = new ServerRequest(RequestTypeOuterClass.RequestType.GET_INVENTORY, invReqMsg);
    api.getRequestHandler().sendServerRequests(inventoryRequest);
    GetInventoryResponse response;
    try {
        response = GetInventoryResponse.parseFrom(inventoryRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    return response;
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) GetInventoryMessage(POGOProtos.Networking.Requests.Messages.GetInventoryMessageOuterClass.GetInventoryMessage) ServerRequest(com.pokegoapi.main.ServerRequest) GetInventoryResponse(POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse)

Example 22 with ServerRequest

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

the class ItemBag method useLuckyEgg.

/**
	 * use a lucky egg
	 *
	 * @return the xp boost response
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public UseItemXpBoostResponse useLuckyEgg() throws RequestFailedException {
    UseItemXpBoostMessage xpMsg = UseItemXpBoostMessage.newBuilder().setItemId(ItemId.ITEM_LUCKY_EGG).build();
    ServerRequest req = new ServerRequest(RequestType.USE_ITEM_XP_BOOST, xpMsg);
    api.getRequestHandler().sendServerRequests(req, true);
    try {
        UseItemXpBoostResponse response = UseItemXpBoostResponse.parseFrom(req.getData());
        Log.i("Main", "Use incense result: " + response.getResult());
        return response;
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) UseItemXpBoostResponse(POGOProtos.Networking.Responses.UseItemXpBoostResponseOuterClass.UseItemXpBoostResponse) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) UseItemXpBoostMessage(POGOProtos.Networking.Requests.Messages.UseItemXpBoostMessageOuterClass.UseItemXpBoostMessage)

Example 23 with ServerRequest

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

the class Pokemon method evolve.

/**
	 * Evolves pokemon with evolution item
	 *
	 * @param evolutionItem the evolution item to evolve with
	 * @return the evolution result
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public EvolutionResult evolve(ItemId evolutionItem) throws RequestFailedException {
    EvolvePokemonMessage.Builder messageBuilder = EvolvePokemonMessage.newBuilder().setPokemonId(getId());
    if (evolutionItem != null) {
        messageBuilder.setEvolutionItemRequirement(evolutionItem);
    }
    ServerRequest serverRequest = new ServerRequest(RequestType.EVOLVE_POKEMON, messageBuilder.build());
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    EvolvePokemonResponse response;
    try {
        response = EvolvePokemonResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        return null;
    }
    return new EvolutionResult(api, response);
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) EvolvePokemonResponse(POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass.EvolvePokemonResponse) EvolutionResult(com.pokegoapi.api.map.pokemon.EvolutionResult) ServerRequest(com.pokegoapi.main.ServerRequest) EvolvePokemonMessage(POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage)

Example 24 with ServerRequest

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

the class Gym method details.

private GetGymDetailsResponse details() throws RequestFailedException {
    if (details == null) {
        GetGymDetailsMessage reqMsg = GetGymDetailsMessage.newBuilder().setGymId(this.getId()).setGymLatitude(this.getLatitude()).setGymLongitude(this.getLongitude()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).build();
        ServerRequest serverRequest = new ServerRequest(RequestType.GET_GYM_DETAILS, reqMsg);
        api.getRequestHandler().sendServerRequests(serverRequest, true);
        try {
            details = GetGymDetailsResponse.parseFrom(serverRequest.getData());
        } catch (InvalidProtocolBufferException e) {
            throw new RequestFailedException();
        }
    }
    return details;
}
Also used : GetGymDetailsMessage(POGOProtos.Networking.Requests.Messages.GetGymDetailsMessageOuterClass.GetGymDetailsMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 25 with ServerRequest

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

the class Gym method deployPokemonAsync.

/**
	 * Deploy pokemon
	 *
	 * @param pokemon The pokemon to deploy
	 * @return Result of attempt to deploy pokemon
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public Observable<FortDeployPokemonResponse.Result> deployPokemonAsync(Pokemon pokemon) throws RequestFailedException {
    FortDeployPokemonMessage reqMsg = FortDeployPokemonMessage.newBuilder().setFortId(getId()).setPlayerLatitude(api.getLatitude()).setPlayerLongitude(api.getLongitude()).setPokemonId(pokemon.getId()).build();
    ServerRequest asyncServerRequest = new ServerRequest(RequestType.FORT_DEPLOY_POKEMON, reqMsg);
    return api.getRequestHandler().sendAsyncServerRequests(asyncServerRequest).map(new Func1<ByteString, FortDeployPokemonResponse.Result>() {

        @Override
        public FortDeployPokemonResponse.Result call(ByteString response) {
            try {
                return FortDeployPokemonResponse.parseFrom(response).getResult();
            } catch (InvalidProtocolBufferException e) {
                throw Exceptions.propagate(e);
            }
        }
    });
}
Also used : ByteString(com.google.protobuf.ByteString) FortDeployPokemonMessage(POGOProtos.Networking.Requests.Messages.FortDeployPokemonMessageOuterClass.FortDeployPokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) 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