Search in sources :

Example 6 with ItemTemplate

use of POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate 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)

Example 7 with ItemTemplate

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

the class FileTemplateProvider method load.

private void load() throws IOException {
    File timestampFile = getTimestampFile();
    File templatesFile = getTemplatesFile();
    if (timestampFile.exists() && templatesFile.exists()) {
        try (DataInputStream in = new DataInputStream(new FileInputStream(timestampFile))) {
            timestamp = in.readLong();
        }
        try (DataInputStream in = new DataInputStream(new FileInputStream(templatesFile))) {
            while (in.available() > 0) {
                int length = in.readUnsignedShort();
                byte[] templateBytes = new byte[length];
                for (int i = 0; i < length; i++) {
                    templateBytes[i] = in.readByte();
                }
                ItemTemplate template = ItemTemplate.parseFrom(templateBytes);
                templates.put(template.getTemplateId(), template);
            }
        }
    }
}
Also used : ItemTemplate(POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Aggregations

ItemTemplate (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate)7 PokemonSettings (POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings)3 BadgeSettings (POGOProtos.Settings.Master.BadgeSettingsOuterClass.BadgeSettings)2 ItemSettings (POGOProtos.Settings.Master.ItemSettingsOuterClass.ItemSettings)2 MoveSettings (POGOProtos.Settings.Master.MoveSettingsOuterClass.MoveSettings)2 FileOutputStream (java.io.FileOutputStream)2 PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)1 DownloadItemTemplatesResponse (POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse)1 PlayerLevelSettingsOuterClass (POGOProtos.Settings.Master.PlayerLevelSettingsOuterClass)1 PlayerLevelSettings (POGOProtos.Settings.Master.PlayerLevelSettingsOuterClass.PlayerLevelSettings)1 Evolutions (com.pokegoapi.api.pokemon.Evolutions)1 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1