use of POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse in project PokeGOAPI-Java by Grover-c13.
the class PokemonGo method initialize.
private void initialize() throws RequestFailedException {
if (getRequestHandler() != null) {
getRequestHandler().exit();
}
requestHandler = new RequestHandler(this, client);
getRequestHandler().sendServerRequests(ServerRequestEnvelope.create());
playerProfile.updateProfile();
ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
getRequestHandler().sendServerRequests(downloadConfigRequest, true, RequestType.GET_BUDDY_WALKED, RequestType.GET_INCENSE_POKEMON);
getAssetDigest();
try {
ByteString configVersionData = downloadConfigRequest.getData();
if (PokemonMeta.checkVersion(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
DownloadItemTemplatesMessage message = CommonRequests.getDownloadItemTemplatesRequest();
ServerRequest request = new ServerRequest(RequestType.DOWNLOAD_ITEM_TEMPLATES, message);
PokemonMeta.update(getRequestHandler().sendServerRequests(request, true), true);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
playerProfile.getProfile();
try {
LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getLevel()).build();
ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons();
ServerRequest request = envelope.add(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
getRequestHandler().sendServerRequests(envelope);
LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
inventories.getItemBag().addAwardedItems(levelUpRewardsResponse);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
List<LoginListener> loginListeners = getListeners(LoginListener.class);
for (LoginListener listener : loginListeners) {
listener.onLogin(this);
}
loggingIn = false;
active = true;
// From now one we will start to check our accounts is ready to fire requests.
// Actually, we can receive valid responses even with this first check,
// that mark the tutorial state into LEGAL_SCREEN.
// Following, we are going to check if the account binded to this session
// have an avatar, a nickname, and all the other things that are usually filled
// on the official client BEFORE sending any requests such as the getMapObject etc.
ArrayList<TutorialState> tutorialStates = playerProfile.getTutorialState().getTutorialStates();
if (tutorialStates.isEmpty()) {
playerProfile.activateAccount();
}
if (!tutorialStates.contains(TutorialState.AVATAR_SELECTION)) {
playerProfile.setupAvatar();
}
heartbeat.start();
if (!tutorialStates.contains(TutorialState.POKEMON_CAPTURE)) {
playerProfile.encounterTutorialComplete();
}
int remainingCodenameClaims = getPlayerProfile().getPlayerData().getRemainingCodenameClaims();
if (!tutorialStates.contains(TutorialState.NAME_SELECTION) && remainingCodenameClaims > 0) {
playerProfile.claimCodeName();
}
if (!tutorialStates.contains(TutorialState.FIRST_TIME_EXPERIENCE_COMPLETE)) {
playerProfile.firstTimeExperienceComplete();
}
}
use of POGOProtos.Networking.Responses.LevelUpRewardsResponseOuterClass.LevelUpRewardsResponse in project PokeGOAPI-Java by Grover-c13.
the class PlayerProfile method acceptLevelUpRewards.
/**
* Accept the rewards granted and the items unlocked by gaining a trainer level up. Rewards are retained by the
* server until a player actively accepts them.
* The rewarded items are automatically inserted into the players item bag.
*
* @param level the trainer level that you want to accept the rewards for
* @return a PlayerLevelUpRewards object containing information about the items rewarded and unlocked for this level
* @throws RequestFailedException if an exception occurred while sending requests
* @throws InsufficientLevelException if you have not yet reached the desired level
* @see PlayerLevelUpRewards
*/
public PlayerLevelUpRewards acceptLevelUpRewards(int level) throws RequestFailedException {
// Check if we even have achieved this level yet
if (level > stats.getLevel()) {
throw new InsufficientLevelException();
}
LevelUpRewardsMessage msg = LevelUpRewardsMessage.newBuilder().setLevel(level).build();
ServerRequest serverRequest = new ServerRequest(RequestType.LEVEL_UP_REWARDS, msg);
api.getRequestHandler().sendServerRequests(serverRequest, true);
LevelUpRewardsResponse response;
try {
response = LevelUpRewardsResponse.parseFrom(serverRequest.getData());
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
// Add the awarded items to our bag
ItemBag bag = api.getInventories().getItemBag();
bag.addAwardedItems(response);
// Build a new rewards object and return it
return new PlayerLevelUpRewards(response);
}
Aggregations