Search in sources :

Example 1 with DownloadItemTemplatesResponse

use of POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse in project PokeGOAPI-Java by Grover-c13.

the class ItemTemplates method updatePage.

/**
 * Updates {@link ItemTemplate} pages recursively
 *
 * @param api the current api
 * @param page the current page index
 * @param timestamp the timestamp of this page
 * @param loadTime the time at which the templates started loading
 * @throws RequestFailedException if the page update is not successfully sent
 */
private void updatePage(PokemonGo api, int page, long timestamp, long loadTime) throws RequestFailedException {
    DownloadItemTemplatesMessage message = DownloadItemTemplatesMessage.newBuilder().setPaginate(true).setPageOffset(page).setPageTimestamp(timestamp).build();
    ServerRequest request = new ServerRequest(RequestType.DOWNLOAD_ITEM_TEMPLATES, message);
    api.requestHandler.sendServerRequests(request, true);
    try {
        DownloadItemTemplatesResponse response = DownloadItemTemplatesResponse.parseFrom(request.getData());
        provider.updateTemplates(response, loadTime);
        if (response.getResult() == Result.PAGE) {
            updatePage(api, response.getPageOffset(), response.getTimestampMs(), loadTime);
        }
    } catch (IOException e) {
        throw new RequestFailedException(e);
    }
}
Also used : RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) DownloadItemTemplatesMessage(POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage) DownloadItemTemplatesResponse(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse) IOException(java.io.IOException) ServerRequest(com.pokegoapi.main.ServerRequest)

Example 2 with DownloadItemTemplatesResponse

use of POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse in project PokeGOAPI-Java by Grover-c13.

the class PokemonMeta method update.

/**
	 * Updates the PokemonMeta from the response to DownloadItemTemplatesResponse and caches it
	 *
	 * @param data the data from the response
	 * @param write if this should write the data to the cache
	 * @throws IOException if writing fails
	 */
public static void update(ByteString data, boolean write) throws IOException {
    DownloadItemTemplatesResponse templatesResponse = DownloadItemTemplatesResponse.parseFrom(data);
    if (write) {
        data.writeTo(new FileOutputStream(Utils.createTempFile("templates")));
    }
    List<ItemTemplate> templates = templatesResponse.getItemTemplatesList();
    PokemonMeta.templates.clear();
    PokemonMeta.templates.addAll(templates);
    for (ItemTemplate template : templates) {
        if (template.hasPokemonSettings()) {
            PokemonSettings pokemonSettings = template.getPokemonSettings();
            PokemonMeta.pokemonSettings.put(pokemonSettings.getPokemonId(), pokemonSettings);
        } else if (template.hasMoveSettings()) {
            MoveSettings moveSettings = template.getMoveSettings();
            PokemonMeta.moveSettings.put(moveSettings.getMovementId(), moveSettings);
        } else if (template.hasBadgeSettings()) {
            BadgeSettings badgeSettings = template.getBadgeSettings();
            PokemonMeta.badgeSettings.put(badgeSettings.getBadgeType(), badgeSettings);
        } else if (template.hasItemSettings()) {
            ItemSettings itemSettings = template.getItemSettings();
            PokemonMeta.itemSettings.put(itemSettings.getItemId(), itemSettings);
        } else if (template.hasBattleSettings()) {
            battleSettings = template.getBattleSettings();
        } else if (template.hasPokemonUpgrades()) {
            upgradeSettings = template.getPokemonUpgrades();
        }
    }
    Evolutions.initialize(templates);
    PokemonCpUtils.initialize(templates);
}
Also used : BadgeSettings(POGOProtos.Settings.Master.BadgeSettingsOuterClass.BadgeSettings) PokemonSettings(POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings) ItemSettings(POGOProtos.Settings.Master.ItemSettingsOuterClass.ItemSettings) ItemTemplate(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate) FileOutputStream(java.io.FileOutputStream) DownloadItemTemplatesResponse(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse) MoveSettings(POGOProtos.Settings.Master.MoveSettingsOuterClass.MoveSettings)

Aggregations

DownloadItemTemplatesResponse (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse)2 DownloadItemTemplatesMessage (POGOProtos.Networking.Requests.Messages.DownloadItemTemplatesMessageOuterClass.DownloadItemTemplatesMessage)1 ItemTemplate (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate)1 BadgeSettings (POGOProtos.Settings.Master.BadgeSettingsOuterClass.BadgeSettings)1 ItemSettings (POGOProtos.Settings.Master.ItemSettingsOuterClass.ItemSettings)1 MoveSettings (POGOProtos.Settings.Master.MoveSettingsOuterClass.MoveSettings)1 PokemonSettings (POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings)1 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)1 ServerRequest (com.pokegoapi.main.ServerRequest)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1