Search in sources :

Example 1 with GetHoloInventoryResponse

use of POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse 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
 * @deprecated Inventory is updated as a common request
 */
@Deprecated
public GetHoloInventoryResponse updateInventories(boolean forceUpdate) throws RequestFailedException {
    if (forceUpdate) {
        lastInventoryUpdate = 0;
        itemBag.reset();
        pokebank.reset();
        candyjar.reset();
        pokedex.reset();
        synchronized (this.lock) {
            incubators.clear();
        }
        hatchery.reset();
    }
    GetHoloInventoryMessage invReqMsg = GetHoloInventoryMessage.newBuilder().setLastTimestampMs(lastInventoryUpdate).build();
    ServerRequest inventoryRequest = new ServerRequest(RequestType.GET_HOLOHOLO_INVENTORY, invReqMsg);
    api.requestHandler.sendServerRequests(inventoryRequest, false);
    GetHoloInventoryResponse response;
    try {
        response = GetHoloInventoryResponse.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) GetHoloInventoryMessage(POGOProtos.Networking.Requests.Messages.GetHoloInventoryMessageOuterClass.GetHoloInventoryMessage) ServerRequest(com.pokegoapi.main.ServerRequest) GetHoloInventoryResponse(POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)

Example 2 with GetHoloInventoryResponse

use of POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse in project PokeGOAPI-Java by Grover-c13.

the class PokeBank method releasePokemon.

/**
 * Releases multiple pokemon in a single request
 *
 * @param releasePokemon the pokemon to release
 * @return the amount of candies for each pokemon family
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public Map<PokemonFamilyId, Integer> releasePokemon(Pokemon... releasePokemon) throws RequestFailedException {
    ReleasePokemonMessage.Builder releaseBuilder = ReleasePokemonMessage.newBuilder();
    for (Pokemon pokemon : releasePokemon) {
        if (!pokemon.isDeployed() && !pokemon.isFavorite()) {
            releaseBuilder.addPokemonIds(pokemon.getId());
        }
    }
    ServerRequest releaseRequest = new ServerRequest(RequestType.RELEASE_POKEMON, releaseBuilder.build());
    ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(releaseRequest, api);
    Map<PokemonFamilyId, Integer> lastCandies = new HashMap<>(api.inventories.candyjar.getCandies());
    ServerResponse response = api.requestHandler.sendServerRequests(envelope);
    try {
        ByteString inventoryData = response.get(RequestType.GET_HOLOHOLO_INVENTORY);
        GetHoloInventoryResponse inventoryResponse = GetHoloInventoryResponse.parseFrom(inventoryData);
        ReleasePokemonResponse releaseResponse = ReleasePokemonResponse.parseFrom(releaseRequest.getData());
        Map<PokemonFamilyId, Integer> candyCount = new HashMap<>();
        if (releaseResponse.getResult() == Result.SUCCESS && inventoryResponse.getSuccess()) {
            synchronized (this.lock) {
                this.pokemons.removeAll(Arrays.asList(releasePokemon));
            }
            for (Pokemon pokemon : releasePokemon) {
                api.inventories.pokebank.removePokemon(pokemon);
            }
            List<InventoryItem> items = inventoryResponse.getInventoryDelta().getInventoryItemsList();
            for (InventoryItem item : items) {
                InventoryItemData data = item.getInventoryItemData();
                if (data != null && data.hasCandy()) {
                    Candy candy = data.getCandy();
                    PokemonFamilyId family = candy.getFamilyId();
                    Integer lastCandy = lastCandies.get(family);
                    if (lastCandy == null) {
                        lastCandy = 0;
                    }
                    candyCount.put(family, candy.getCandy() - lastCandy);
                }
            }
            api.inventories.updateInventories(inventoryResponse);
        }
        return candyCount;
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : ServerResponse(com.pokegoapi.main.ServerResponse) InventoryItem(POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem) HashMap(java.util.HashMap) ByteString(com.google.protobuf.ByteString) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) PokemonFamilyId(POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId) ServerRequestEnvelope(com.pokegoapi.main.ServerRequestEnvelope) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) ReleasePokemonMessage(POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage) Candy(POGOProtos.Inventory.CandyOuterClass.Candy) ReleasePokemonResponse(POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse) Pokemon(com.pokegoapi.api.pokemon.Pokemon) ServerRequest(com.pokegoapi.main.ServerRequest) InventoryItemData(POGOProtos.Inventory.InventoryItemDataOuterClass.InventoryItemData) GetHoloInventoryResponse(POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)

Example 3 with GetHoloInventoryResponse

use of POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse in project PokeGOAPI-Java by Grover-c13.

the class CommonRequests method handleCommons.

/**
 * Handles all commons in a ServerResponse
 * @param api the current api
 * @param response the response to handle
 * @throws InvalidProtocolBufferException if an invalid response is parsed
 * @throws RequestFailedException if a request fails while sending a request
 */
public static void handleCommons(PokemonGo api, ServerResponse response) throws InvalidProtocolBufferException, RequestFailedException {
    if (response.has(RequestType.DOWNLOAD_SETTINGS)) {
        ByteString data = response.get(RequestType.DOWNLOAD_SETTINGS);
        DownloadSettingsResponse settings = DownloadSettingsResponse.parseFrom(data);
        api.settings.updateSettings(settings);
    }
    if (response.has(RequestType.CHECK_CHALLENGE)) {
        ByteString data = response.get(RequestType.CHECK_CHALLENGE);
        CheckChallengeResponse checkChallenge = CheckChallengeResponse.parseFrom(data);
        api.updateChallenge(checkChallenge.getChallengeUrl(), checkChallenge.getShowChallenge());
    }
    if (response.has(RequestType.GET_HOLOHOLO_INVENTORY)) {
        ByteString data = response.get(RequestType.GET_HOLOHOLO_INVENTORY);
        GetHoloInventoryResponse inventory = GetHoloInventoryResponse.parseFrom(data);
        api.inventories.updateInventories(inventory);
    }
    if (response.has(RequestType.CHECK_AWARDED_BADGES)) {
        ByteString data = response.get(RequestType.CHECK_AWARDED_BADGES);
        CheckAwardedBadgesResponse awardedBadges = CheckAwardedBadgesResponse.parseFrom(data);
        api.playerProfile.updateAwardedMedals(awardedBadges);
    }
    if (response.has(RequestType.GET_HATCHED_EGGS)) {
        ByteString data = response.get(RequestType.GET_HATCHED_EGGS);
        GetHatchedEggsResponse hatchedEggs = GetHatchedEggsResponse.parseFrom(data);
        api.inventories.hatchery.updateHatchedEggs(hatchedEggs);
    }
    if (response.has(RequestType.GET_BUDDY_WALKED)) {
        ByteString data = response.get(RequestType.GET_BUDDY_WALKED);
        GetBuddyWalkedResponse buddyWalked = GetBuddyWalkedResponse.parseFrom(data);
        int candies = buddyWalked.getCandyEarnedCount();
        if (buddyWalked.getSuccess() && candies > 0) {
            List<PokemonListener> listeners = api.getListeners(PokemonListener.class);
            for (PokemonListener listener : listeners) {
                listener.onBuddyFindCandy(api, buddyWalked.getFamilyCandyId(), candies);
            }
        }
    }
    if (response.has(RequestType.GET_INCENSE_POKEMON)) {
        ByteString data = response.get(RequestType.GET_INCENSE_POKEMON);
        GetIncensePokemonResponse incense = GetIncensePokemonResponse.parseFrom(data);
        api.getMap().mapObjects.addIncensePokemon(incense);
    }
}
Also used : DownloadSettingsResponse(POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse) GetHatchedEggsResponse(POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse) GetBuddyWalkedResponse(POGOProtos.Networking.Responses.GetBuddyWalkedResponseOuterClass.GetBuddyWalkedResponse) ByteString(com.google.protobuf.ByteString) GetIncensePokemonResponse(POGOProtos.Networking.Responses.GetIncensePokemonResponseOuterClass.GetIncensePokemonResponse) CheckChallengeResponse(POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse) PokemonListener(com.pokegoapi.api.listener.PokemonListener) CheckAwardedBadgesResponse(POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse) GetHoloInventoryResponse(POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)

Aggregations

GetHoloInventoryResponse (POGOProtos.Networking.Responses.GetHoloInventoryResponseOuterClass.GetHoloInventoryResponse)3 ByteString (com.google.protobuf.ByteString)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)2 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)2 ServerRequest (com.pokegoapi.main.ServerRequest)2 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 Candy (POGOProtos.Inventory.CandyOuterClass.Candy)1 InventoryItemData (POGOProtos.Inventory.InventoryItemDataOuterClass.InventoryItemData)1 InventoryItem (POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem)1 GetHoloInventoryMessage (POGOProtos.Networking.Requests.Messages.GetHoloInventoryMessageOuterClass.GetHoloInventoryMessage)1 ReleasePokemonMessage (POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage)1 CheckAwardedBadgesResponse (POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse)1 CheckChallengeResponse (POGOProtos.Networking.Responses.CheckChallengeResponseOuterClass.CheckChallengeResponse)1 DownloadSettingsResponse (POGOProtos.Networking.Responses.DownloadSettingsResponseOuterClass.DownloadSettingsResponse)1 GetBuddyWalkedResponse (POGOProtos.Networking.Responses.GetBuddyWalkedResponseOuterClass.GetBuddyWalkedResponse)1 GetHatchedEggsResponse (POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass.GetHatchedEggsResponse)1 GetIncensePokemonResponse (POGOProtos.Networking.Responses.GetIncensePokemonResponseOuterClass.GetIncensePokemonResponse)1 ReleasePokemonResponse (POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse)1 PokemonListener (com.pokegoapi.api.listener.PokemonListener)1 Pokemon (com.pokegoapi.api.pokemon.Pokemon)1