Search in sources :

Example 1 with AppliedItems

use of POGOProtos.Inventory.AppliedItemsOuterClass.AppliedItems 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)

Example 2 with AppliedItems

use of POGOProtos.Inventory.AppliedItemsOuterClass.AppliedItems 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
 * @throws RequestFailedException if a request fails while sending a request
 */
public void updateInventories(GetHoloInventoryResponse response) throws RequestFailedException {
    lastInventoryUpdate = api.currentTimeMillis();
    for (InventoryItem inventoryItem : response.getInventoryDelta().getInventoryItemsList()) {
        // Remove released Pokemon from bag.
        if (inventoryItem.getDeletedItem().getPokemonId() != 0) {
            pokebank.removePokemon(inventoryItem.getDeletedItem().getPokemonId());
        }
        InventoryItemData itemData = inventoryItem.getInventoryItemData();
        if (itemData.hasPokemonData()) {
            PokemonData pokemonData = itemData.getPokemonData();
            if (pokemonData.getPokemonId() == PokemonId.MISSINGNO && pokemonData.getIsEgg()) {
                hatchery.addEgg(new EggPokemon(pokemonData));
            }
            if (pokemonData.getPokemonId() != PokemonId.MISSINGNO) {
                pokebank.addPokemon(new Pokemon(api, pokemonData));
            }
        }
        if (itemData.hasItem()) {
            ItemData item = itemData.getItem();
            if (item.getCount() > 0) {
                itemBag.addItem(new Item(api, item, itemBag));
            }
        }
        if (itemData.hasCandy()) {
            Candy candy = itemData.getCandy();
            if (candy.getFamilyId() != PokemonFamilyId.UNRECOGNIZED && candy.getFamilyId() != PokemonFamilyId.FAMILY_UNSET) {
                candyjar.setCandy(candy.getFamilyId(), candy.getCandy());
            }
        }
        // player stats
        if (itemData.hasPlayerStats()) {
            api.playerProfile.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 : InventoryItem(POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem) EggIncubators(POGOProtos.Inventory.EggIncubatorsOuterClass.EggIncubators) EggIncubatorOuterClass(POGOProtos.Inventory.EggIncubatorOuterClass) ItemId(POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId) AppliedItem(POGOProtos.Inventory.AppliedItemOuterClass.AppliedItem) InventoryItem(POGOProtos.Inventory.InventoryItemOuterClass.InventoryItem) EggPokemon(com.pokegoapi.api.pokemon.EggPokemon) Candy(POGOProtos.Inventory.CandyOuterClass.Candy) AppliedItems(POGOProtos.Inventory.AppliedItemsOuterClass.AppliedItems) InventoryItemData(POGOProtos.Inventory.InventoryItemDataOuterClass.InventoryItemData) 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) InventoryItemData(POGOProtos.Inventory.InventoryItemDataOuterClass.InventoryItemData) HashSet(java.util.HashSet)

Aggregations

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