Search in sources :

Example 31 with ServerRequest

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

the class PlayerProfile method markTutorial.

private void markTutorial(TutorialStateOuterClass.TutorialState state) throws RequestFailedException {
    final MarkTutorialCompleteMessage tutorialMessage = MarkTutorialCompleteMessage.newBuilder().addTutorialsCompleted(state).setSendMarketingEmails(false).setSendPushNotifications(false).build();
    ServerRequest request = new ServerRequest(RequestType.MARK_TUTORIAL_COMPLETE, tutorialMessage);
    api.getRequestHandler().sendServerRequests(request);
    try {
        playerData = MarkTutorialCompleteResponse.parseFrom(request.getData()).getPlayerData();
        updateProfile(playerData);
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) MarkTutorialCompleteMessage(POGOProtos.Networking.Requests.Messages.MarkTutorialCompleteMessageOuterClass.MarkTutorialCompleteMessage) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 32 with ServerRequest

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

the class PlayerProfile method getProfile.

/**
	 * Performs a GET_PLAYER_PROFILE request.
	 *
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public void getProfile() throws RequestFailedException {
    GetPlayerProfileMessage profileMessage = GetPlayerProfileMessage.newBuilder().setPlayerName("").build();
    ServerRequest profileRequest = new ServerRequest(RequestType.GET_PLAYER_PROFILE, profileMessage);
    api.getRequestHandler().sendServerRequests(profileRequest, true);
    try {
        GetPlayerProfileResponse response = GetPlayerProfileResponse.parseFrom(profileRequest.getData());
        if (response.getResult() == GetPlayerProfileResponse.Result.SUCCESS) {
            medals.clear();
            List<PlayerBadge> badges = response.getBadgesList();
            for (PlayerBadge badge : badges) {
                medals.put(badge.getBadgeType(), new Medal(badge));
            }
            this.startTime = response.getStartTime();
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : GetPlayerProfileMessage(POGOProtos.Networking.Requests.Messages.GetPlayerProfileMessageOuterClass.GetPlayerProfileMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) GetPlayerProfileResponse(POGOProtos.Networking.Responses.GetPlayerProfileResponseOuterClass.GetPlayerProfileResponse) PlayerBadge(POGOProtos.Data.PlayerBadgeOuterClass.PlayerBadge)

Example 33 with ServerRequest

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

the class PlayerProfile method checkAndEquipBadges.

/**
	 * Check and equip badges.
	 *
	 * @throws RequestFailedException if an exception occurred while sending requests
	 * @deprecated use getMedals, which uses common requests to check for badges
	 */
@Deprecated
public void checkAndEquipBadges() throws RequestFailedException {
    CheckAwardedBadgesMessage msg = CheckAwardedBadgesMessage.newBuilder().build();
    ServerRequest serverRequest = new ServerRequest(RequestType.CHECK_AWARDED_BADGES, msg);
    api.getRequestHandler().sendServerRequests(serverRequest);
    CheckAwardedBadgesResponse response;
    try {
        response = CheckAwardedBadgesResponse.parseFrom(serverRequest.getData());
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    this.updateAwardedMedals(response);
}
Also used : CheckAwardedBadgesMessage(POGOProtos.Networking.Requests.Messages.CheckAwardedBadgesMessageOuterClass.CheckAwardedBadgesMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest) CheckAwardedBadgesResponse(POGOProtos.Networking.Responses.CheckAwardedBadgesResponseOuterClass.CheckAwardedBadgesResponse)

Example 34 with ServerRequest

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

the class Pokemon method setFavoritePokemon.

/**
	 * Function to mark the pokemon as favorite or not.
	 *
	 * @param markFavorite Mark Pokemon as Favorite?
	 * @return the SetFavoritePokemonResponse.Result
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public SetFavoritePokemonResponse.Result setFavoritePokemon(boolean markFavorite) throws RequestFailedException {
    SetFavoritePokemonMessage reqMsg = SetFavoritePokemonMessage.newBuilder().setPokemonId(getId()).setIsFavorite(markFavorite).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.SET_FAVORITE_POKEMON, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    SetFavoritePokemonResponse response;
    try {
        response = SetFavoritePokemonResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == SetFavoritePokemonResponse.Result.SUCCESS) {
            favorite = markFavorite ? 1 : 0;
        }
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    api.getInventories().getPokebank().removePokemon(this);
    return response.getResult();
}
Also used : SetFavoritePokemonResponse(POGOProtos.Networking.Responses.SetFavoritePokemonResponseOuterClass.SetFavoritePokemonResponse) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) SetFavoritePokemonMessage(POGOProtos.Networking.Requests.Messages.SetFavoritePokemonMessageOuterClass.SetFavoritePokemonMessage) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 35 with ServerRequest

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

the class Pokemon method useRevive.

/**
	 * Use a revive item on the pokemon. Will check if there is enough revive &amp; if the pokemon need
	 * to be revived.
	 *
	 * @param itemId {@link ItemId} of the Revive to use.
	 * @return Result, ERROR_CANNOT_USE if the requirements aren't met
	 * @throws RequestFailedException if an exception occurred while sending requests
	 */
public UseItemReviveResponse.Result useRevive(ItemId itemId) throws RequestFailedException {
    Item item = api.getInventories().getItemBag().getItem(itemId);
    if (!item.isRevive() || item.getCount() < 1 || !isFainted())
        return UseItemReviveResponse.Result.ERROR_CANNOT_USE;
    UseItemReviveMessage reqMsg = UseItemReviveMessage.newBuilder().setItemId(itemId).setPokemonId(getId()).build();
    ServerRequest serverRequest = new ServerRequest(RequestType.USE_ITEM_REVIVE, reqMsg);
    api.getRequestHandler().sendServerRequests(serverRequest, true);
    UseItemReviveResponse response;
    try {
        response = UseItemReviveResponse.parseFrom(serverRequest.getData());
        if (response.getResult() == UseItemReviveResponse.Result.SUCCESS) {
            item.setCount(item.getCount() - 1);
            setStamina(response.getStamina());
        }
        return response.getResult();
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
}
Also used : Item(com.pokegoapi.api.inventory.Item) UseItemReviveMessage(POGOProtos.Networking.Requests.Messages.UseItemReviveMessageOuterClass.UseItemReviveMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) UseItemReviveResponse(POGOProtos.Networking.Responses.UseItemReviveResponseOuterClass.UseItemReviveResponse) 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