use of POGOProtos.Networking.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage in project PokeGOAPI-Java by Grover-c13.
the class PokemonGo method initialize.
private void initialize() throws RequestFailedException {
if (requestHandler != null) {
requestHandler.exit();
}
requestHandler = new RequestHandler(this, client);
requestHandler.sendServerRequests(ServerRequestEnvelope.create());
playerProfile.updateProfile();
ServerRequest downloadConfigRequest = new ServerRequest(RequestType.DOWNLOAD_REMOTE_CONFIG_VERSION, CommonRequests.getDownloadRemoteConfigVersionMessageRequest(this));
requestHandler.sendServerRequests(downloadConfigRequest, true);
getAssetDigest();
try {
ByteString configVersionData = downloadConfigRequest.getData();
if (itemTemplates.requiresUpdate(DownloadRemoteConfigVersionResponse.parseFrom(configVersionData))) {
itemTemplates.update(this);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
playerProfile.getProfile();
try {
LevelUpRewardsMessage rewardsMessage = LevelUpRewardsMessage.newBuilder().setLevel(playerProfile.getStats().getLevel()).build();
ServerRequest request = new ServerRequest(RequestType.LEVEL_UP_REWARDS, rewardsMessage);
ServerRequestEnvelope envelope = ServerRequestEnvelope.createCommons(request, this);
requestHandler.sendServerRequests(envelope);
LevelUpRewardsResponse levelUpRewardsResponse = LevelUpRewardsResponse.parseFrom(request.getData());
if (levelUpRewardsResponse.getResult() == Result.SUCCESS) {
inventories.itemBag.addAwardedItems(levelUpRewardsResponse);
}
} catch (InvalidProtocolBufferException e) {
throw new RequestFailedException(e);
}
ByteString getStoreItems = GetStoreItemsRequest.newBuilder().build().toByteString();
ServerRequestEnvelope envelope = ServerRequestEnvelope.create();
envelope.addPlatform(new ServerPlatformRequest(PlatformRequestType.GET_STORE_ITEMS, getStoreItems));
requestHandler.sendServerRequests(envelope);
try {
FetchAllNewsMessageOuterClass.FetchAllNewsMessage msg = FetchAllNewsMessageOuterClass.FetchAllNewsMessage.newBuilder().build();
ServerRequest request = new ServerRequest(RequestType.FETCH_ALL_NEWS, msg);
envelope = ServerRequestEnvelope.create(request);
requestHandler.sendServerRequests(envelope);
FetchAllNewsResponseOuterClass.FetchAllNewsResponse response = FetchAllNewsResponseOuterClass.FetchAllNewsResponse.parseFrom(request.getData());
if (response.getResult() == FetchAllNewsResponseOuterClass.FetchAllNewsResponse.Result.SUCCESS) {
Log.i(TAG, "FetchAllNewsMessage Success: total News=" + response.getCurrentNews().getNewsArticlesCount());
this.news.setCurrentNews(response.getCurrentNews());
// mark all un-read new to read
this.news.markUnreadNews();
} else {
Log.d(TAG, "FetchAllNewsMessage Failed. Result=" + response.getResult());
}
} catch (Exception e) {
Log.d(TAG, "Exceptions FetchAllNew");
}
List<LoginListener> loginListeners = getListeners(LoginListener.class);
for (LoginListener listener : loginListeners) {
listener.onLogin(this);
}
loggingIn = false;
active = true;
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 = playerProfile.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.Requests.Messages.LevelUpRewardsMessageOuterClass.LevelUpRewardsMessage 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.requestHandler.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.inventories.itemBag;
bag.addAwardedItems(response);
// Build a new rewards object and return it
return new PlayerLevelUpRewards(response);
}
Aggregations