Search in sources :

Example 1 with EggPokemon

use of com.pokegoapi.api.pokemon.EggPokemon in project PokeGOAPI-Java by Grover-c13.

the class Inventories method updateInventories.

/**
	 * Updates the inventories with the latest data.
	 *
	 * @param response the get inventory response
	 */
public void updateInventories(GetInventoryResponse response) {
    lastInventoryUpdate = api.currentTimeMillis();
    for (InventoryItemOuterClass.InventoryItem inventoryItem : response.getInventoryDelta().getInventoryItemsList()) {
        InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData();
        // hatchery
        PokemonData pokemonData = itemData.getPokemonData();
        if (pokemonData.getPokemonId() == PokemonId.MISSINGNO && pokemonData.getIsEgg()) {
            hatchery.addEgg(new EggPokemon(pokemonData));
        }
        // pokebank
        if (pokemonData.getPokemonId() != PokemonId.MISSINGNO) {
            pokebank.addPokemon(new Pokemon(api, inventoryItem.getInventoryItemData().getPokemonData()));
        }
        // items
        if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) {
            ItemData item = itemData.getItem();
            if (item.getCount() > 0) {
                itemBag.addItem(new Item(api, item, itemBag));
            }
        }
        // candyjar
        if (itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED && itemData.getCandy().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) {
            candyjar.setCandy(itemData.getCandy().getFamilyId(), itemData.getCandy().getCandy());
        }
        // player stats
        if (itemData.hasPlayerStats()) {
            api.getPlayerProfile().setStats(new Stats(itemData.getPlayerStats()));
        }
        // pokedex
        if (itemData.hasPokedexEntry()) {
            pokedex.add(itemData.getPokedexEntry());
        }
        if (itemData.hasEggIncubators()) {
            EggIncubators eggIncubators = itemData.getEggIncubators();
            for (EggIncubatorOuterClass.EggIncubator incubator : eggIncubators.getEggIncubatorList()) {
                EggIncubator eggIncubator = new EggIncubator(api, incubator);
                synchronized (this.lock) {
                    incubators.remove(eggIncubator);
                    incubators.add(eggIncubator);
                }
            }
        }
        if (itemData.hasAppliedItems()) {
            AppliedItems appliedItems = itemData.getAppliedItems();
            for (AppliedItem appliedItem : appliedItems.getItemList()) {
                this.appliedItems.put(appliedItem.getItemId(), appliedItem);
            }
        }
        Set<ItemId> stale = new HashSet<>();
        for (Map.Entry<ItemId, AppliedItem> entry : appliedItems.entrySet()) {
            ItemId itemId = entry.getKey();
            AppliedItem applied = entry.getValue();
            if (api.currentTimeMillis() >= applied.getExpireMs()) {
                stale.add(itemId);
            } else {
                Item item = itemBag.getItem(itemId);
                item.setApplied(applied);
                itemBag.addItem(item);
            }
        }
        for (ItemId item : stale) {
            appliedItems.remove(item);
            itemBag.getItem(item).removeApplied();
        }
    }
}
Also used : InventoryItemOuterClass(POGOProtos.Inventory.InventoryItemOuterClass) EggIncubators(POGOProtos.Inventory.EggIncubatorsOuterClass.EggIncubators) EggIncubatorOuterClass(POGOProtos.Inventory.EggIncubatorOuterClass) ItemId(POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId) AppliedItem(POGOProtos.Inventory.AppliedItemOuterClass.AppliedItem) EggPokemon(com.pokegoapi.api.pokemon.EggPokemon) InventoryItemDataOuterClass(POGOProtos.Inventory.InventoryItemDataOuterClass) AppliedItems(POGOProtos.Inventory.AppliedItemsOuterClass.AppliedItems) EggPokemon(com.pokegoapi.api.pokemon.EggPokemon) Pokemon(com.pokegoapi.api.pokemon.Pokemon) PokemonData(POGOProtos.Data.PokemonDataOuterClass.PokemonData) HashMap(java.util.HashMap) Map(java.util.Map) AppliedItem(POGOProtos.Inventory.AppliedItemOuterClass.AppliedItem) ItemData(POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData) HashSet(java.util.HashSet)

Aggregations

PokemonData (POGOProtos.Data.PokemonDataOuterClass.PokemonData)1 AppliedItem (POGOProtos.Inventory.AppliedItemOuterClass.AppliedItem)1 AppliedItems (POGOProtos.Inventory.AppliedItemsOuterClass.AppliedItems)1 EggIncubatorOuterClass (POGOProtos.Inventory.EggIncubatorOuterClass)1 EggIncubators (POGOProtos.Inventory.EggIncubatorsOuterClass.EggIncubators)1 InventoryItemDataOuterClass (POGOProtos.Inventory.InventoryItemDataOuterClass)1 InventoryItemOuterClass (POGOProtos.Inventory.InventoryItemOuterClass)1 ItemData (POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData)1 ItemId (POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId)1 EggPokemon (com.pokegoapi.api.pokemon.EggPokemon)1 Pokemon (com.pokegoapi.api.pokemon.Pokemon)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1