Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Eggs #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2016
Merged

Eggs #145

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/com/pokegoapi/api/inventory/Hatchery.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<EggPokemon> eggs = new HashSet<EggPokemon>();
@Getter
PokemonGo instance;

public Hatchery(PokemonGo instance) {
this.instance = instance;
}

public void addEgg(EggPokemon egg) {
eggs.add(egg);
}

}
19 changes: 18 additions & 1 deletion src/main/java/com/pokegoapi/api/inventory/Inventories.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -44,6 +46,8 @@ public class Inventories {
private CandyJar candyjar;
@Getter
private Pokedex pokedex;
@Getter
private Hatchery hatchery;

private long lastInventoryUpdate = 0;

Expand All @@ -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();
}

Expand Down Expand Up @@ -105,25 +110,37 @@ 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(
inventoryItem.getInventoryItemData().getPokemonFamily().getFamilyId(),
inventoryItem.getInventoryItemData().getPokemonFamily().getCandy()
);
}
// player stats
if (itemData.hasPlayerStats()) {
api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats());
}

// pokedex
if (itemData.hasPokedexEntry()) {
pokedex.add(itemData.getPokedexEntry());
}
Expand Down
112 changes: 112 additions & 0 deletions src/main/java/com/pokegoapi/api/pokemon/EggPokemon.java
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
*/

/*
* 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 <http://www.gnu.org/licenses/>.
*/

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.
}