From 8fe3285fef5abfe4516062129a6d2a7180fcbb0a Mon Sep 17 00:00:00 2001 From: Grover-c13 Date: Sat, 23 Jul 2016 17:27:44 +0800 Subject: [PATCH] Eggs --- .../com/pokegoapi/api/inventory/Hatchery.java | 22 ++++ .../pokegoapi/api/inventory/Inventories.java | 19 ++- .../com/pokegoapi/api/pokemon/EggPokemon.java | 112 ++++++++++++++++++ 3 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java diff --git a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java index 7b8990c6..22b3cd89 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Hatchery.java +++ b/src/main/java/com/pokegoapi/api/inventory/Hatchery.java @@ -15,6 +15,28 @@ package com.pokegoapi.api.inventory; +import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.pokemon.EggPokemon; +import com.pokegoapi.api.pokemon.Pokemon; +import lombok.Getter; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + public class Hatchery { + @Getter + Set eggs = new HashSet(); + @Getter + PokemonGo instance; + + public Hatchery(PokemonGo instance) { + this.instance = instance; + } + + public void addEgg(EggPokemon egg) { + eggs.add(egg); + } } diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index b5926fd5..974d486e 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -17,6 +17,7 @@ import POGOProtos.Enums.PokemonFamilyIdOuterClass; import POGOProtos.Enums.PokemonIdOuterClass; +import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; import POGOProtos.Inventory.InventoryItemDataOuterClass; import POGOProtos.Inventory.InventoryItemOuterClass; import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData; @@ -26,6 +27,7 @@ import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse; import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.pokemon.EggPokemon; import com.pokegoapi.api.pokemon.Pokemon; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.RemoteServerException; @@ -44,6 +46,8 @@ public class Inventories { private CandyJar candyjar; @Getter private Pokedex pokedex; + @Getter + private Hatchery hatchery; private long lastInventoryUpdate = 0; @@ -60,6 +64,7 @@ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerExcep pokebank = new PokeBank(api); candyjar = new CandyJar(api); pokedex = new Pokedex(api); + hatchery = new Hatchery(api); updateInventories(); } @@ -105,14 +110,24 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, : response.getInventoryDelta().getInventoryItemsList()) { InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData(); - if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { + // hatchery + if (itemData.getPokemonData().getPokemonId() == PokemonId.MISSINGNO && itemData.getPokemonData().getIsEgg()) { + hatchery.addEgg(new EggPokemon(itemData.getPokemonData())); + } + + // pokebank + if (itemData.getPokemonData().getPokemonId() != PokemonId.MISSINGNO) { pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); } + + // items if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) { ItemData item = inventoryItem.getInventoryItemData().getItem(); itemBag.addItem(new Item(item)); } + + // candyjar if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED && itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) { candyjar.setCandy( @@ -120,10 +135,12 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() ); } + // player stats if (itemData.hasPlayerStats()) { api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats()); } + // pokedex if (itemData.hasPokedexEntry()) { pokedex.add(itemData.getPokedexEntry()); } diff --git a/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java new file mode 100644 index 00000000..82c8e044 --- /dev/null +++ b/src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java @@ -0,0 +1,112 @@ +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/* + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.pokegoapi.api.pokemon; + +import POGOProtos.Data.PokemonDataOuterClass.PokemonData; +import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; +import POGOProtos.Enums.PokemonIdOuterClass; +import POGOProtos.Enums.PokemonMoveOuterClass; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; +import POGOProtos.Networking.Requests.Messages.EvolvePokemonMessageOuterClass.EvolvePokemonMessage; +import POGOProtos.Networking.Requests.Messages.NicknamePokemonMessageOuterClass.NicknamePokemonMessage; +import POGOProtos.Networking.Requests.Messages.ReleasePokemonMessageOuterClass.ReleasePokemonMessage; +import POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType; +import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass.EvolvePokemonResponse; +import POGOProtos.Networking.Responses.NicknamePokemonResponseOuterClass.NicknamePokemonResponse; +import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse; +import POGOProtos.Networking.Responses.ReleasePokemonResponseOuterClass.ReleasePokemonResponse.Result; +import com.google.protobuf.InvalidProtocolBufferException; +import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.map.pokemon.EvolutionResult; +import com.pokegoapi.exceptions.LoginFailedException; +import com.pokegoapi.exceptions.RemoteServerException; +import com.pokegoapi.main.ServerRequest; +import com.pokegoapi.util.Log; +import lombok.Setter; + +/** + * The egg pokemon. + */ +public class EggPokemon { + + private static final String TAG = EggPokemon.class.getSimpleName(); + @Setter + PokemonGo pgo; + private PokemonData proto; + + // API METHODS // + + // DELEGATE METHODS BELOW // + public EggPokemon(PokemonData proto) { + this.proto = proto; + } + + public long getId() { + return proto.getId(); + } + + public boolean getIsEgg() { + return proto.getIsEgg(); + } + + public double getEggKmWalkedTarget() { + return proto.getEggKmWalkedTarget(); + } + + public double getEggKmWalkedStart() { + return proto.getEggKmWalkedStart(); + } + + public long getCapturedCellId() { + return proto.getCapturedCellId(); + } + + public long getCreationTimeMs() { + return proto.getCreationTimeMs(); + } + + + @Override + public int hashCode() { + return proto.getPokemonId().hashCode(); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof EggPokemon) { + EggPokemon other = (EggPokemon) obj; + return (this.getId() == other.getId()); + } + + return false; + } + // TODO: add wrapper objects for encubators and allow to be got. +}