Search in sources :

Example 1 with SetAvatarMessage

use of POGOProtos.Networking.Requests.Messages.SetAvatarMessageOuterClass.SetAvatarMessage in project PokeGOAPI-Java by Grover-c13.

the class PlayerProfile method setupAvatar.

/**
 * Setup an avatar for the current account
 *
 * @throws RequestFailedException if an exception occurred while sending requests
 */
public void setupAvatar() throws RequestFailedException {
    SecureRandom random = new SecureRandom();
    PlayerGender gender = random.nextInt(100) % 2 == 0 ? PlayerGender.FEMALE : PlayerGender.MALE;
    PlayerAvatar avatar = new PlayerAvatar(gender, random.nextInt(PlayerAvatar.getAvailableSkins()), random.nextInt(PlayerAvatar.getAvailableHair()), random.nextInt(PlayerAvatar.getAvailableShirts(gender)), random.nextInt(PlayerAvatar.getAvailablePants(gender)), random.nextInt(PlayerAvatar.getAvailableHats()), random.nextInt(PlayerAvatar.getAvailableShoes()), random.nextInt(PlayerAvatar.getAvailableEyes()), random.nextInt(PlayerAvatar.getAvailableBags(gender)));
    List<TutorialListener> listeners = api.getListeners(TutorialListener.class);
    for (TutorialListener listener : listeners) {
        PlayerAvatar listenerAvatar = listener.selectAvatar(api);
        if (listenerAvatar != null) {
            avatar = listenerAvatar;
            break;
        }
    }
    final SetAvatarMessage setAvatarMessage = SetAvatarMessage.newBuilder().setPlayerAvatar(avatar.avatar).build();
    ServerRequest request = new ServerRequest(RequestType.SET_AVATAR, setAvatarMessage);
    api.requestHandler.sendServerRequests(request, true);
    try {
        SetAvatarResponse setAvatarResponse = SetAvatarResponse.parseFrom(request.getData());
        playerData = setAvatarResponse.getPlayerData();
        updateProfile(playerData);
    } catch (InvalidProtocolBufferException e) {
        throw new RequestFailedException(e);
    }
    markTutorial(TutorialStateOuterClass.TutorialState.AVATAR_SELECTION);
    api.getAssetDigest();
}
Also used : TutorialListener(com.pokegoapi.api.listener.TutorialListener) SetAvatarMessage(POGOProtos.Networking.Requests.Messages.SetAvatarMessageOuterClass.SetAvatarMessage) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) SecureRandom(java.security.SecureRandom) ServerRequest(com.pokegoapi.main.ServerRequest) SetAvatarResponse(POGOProtos.Networking.Responses.SetAvatarResponseOuterClass.SetAvatarResponse)

Aggregations

SetAvatarMessage (POGOProtos.Networking.Requests.Messages.SetAvatarMessageOuterClass.SetAvatarMessage)1 SetAvatarResponse (POGOProtos.Networking.Responses.SetAvatarResponseOuterClass.SetAvatarResponse)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 TutorialListener (com.pokegoapi.api.listener.TutorialListener)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 SecureRandom (java.security.SecureRandom)1