diff --git a/build.gradle b/build.gradle index 83c73d11..649a4407 100644 --- a/build.gradle +++ b/build.gradle @@ -31,7 +31,7 @@ sourceSets { main { proto { // Need to use custom dir cause Gradle doesn't like us otherwise :( - srcDir 'src/resources/protobuf/pogo' + srcDir 'src/resources/protobuf/src' include '**/*.proto' } } diff --git a/src/main/java/com/pokegoapi/api/inventory/Inventories.java b/src/main/java/com/pokegoapi/api/inventory/Inventories.java index 11542879..b5926fd5 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Inventories.java +++ b/src/main/java/com/pokegoapi/api/inventory/Inventories.java @@ -15,13 +15,12 @@ package com.pokegoapi.api.inventory; -import POGOProtos.Data.Player.PlayerStatsOuterClass; import POGOProtos.Enums.PokemonFamilyIdOuterClass; import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Inventory.InventoryItemDataOuterClass; import POGOProtos.Inventory.InventoryItemOuterClass; -import POGOProtos.Inventory.ItemIdOuterClass; -import POGOProtos.Inventory.ItemOuterClass; +import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Networking.Requests.Messages.GetInventoryMessageOuterClass.GetInventoryMessage; import POGOProtos.Networking.Requests.RequestTypeOuterClass; import POGOProtos.Networking.Responses.GetInventoryResponseOuterClass.GetInventoryResponse; @@ -44,14 +43,15 @@ public class Inventories { @Getter private CandyJar candyjar; @Getter - private PlayerStatsOuterClass.PlayerStats stats; + private Pokedex pokedex; private long lastInventoryUpdate = 0; /** * Creates Inventories and initializes content. + * * @param api PokemonGo api - * @throws LoginFailedException the login failed exception + * @throws LoginFailedException the login failed exception * @throws RemoteServerException the remote server exception */ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerException { @@ -59,12 +59,14 @@ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerExcep itemBag = new ItemBag(api); pokebank = new PokeBank(api); candyjar = new CandyJar(api); + pokedex = new Pokedex(api); updateInventories(); } /** * Updates the inventories with latest data. - * @throws LoginFailedException the login failed exception + * + * @throws LoginFailedException the login failed exception * @throws RemoteServerException the remote server exception */ public void updateInventories() throws LoginFailedException, RemoteServerException { @@ -73,8 +75,9 @@ public void updateInventories() throws LoginFailedException, RemoteServerExcepti /** * Updates the inventories with the latest data. + * * @param forceUpdate For a full update if true - * @throws LoginFailedException the login failed exception + * @throws LoginFailedException the login failed exception * @throws RemoteServerException the remote server exception */ public void updateInventories(boolean forceUpdate) throws LoginFailedException, RemoteServerException { @@ -83,13 +86,13 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, itemBag = new ItemBag(api); pokebank = new PokeBank(api); candyjar = new CandyJar(api); + pokedex = new Pokedex(api); } GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder() .setLastTimestampMs(lastInventoryUpdate) .build(); ServerRequest inventoryRequest = new ServerRequest(RequestTypeOuterClass.RequestType.GET_INVENTORY, invReqMsg); - api.getRequestHandler().request(inventoryRequest); - api.getRequestHandler().sendServerRequests(); + api.getRequestHandler().sendServerRequests(inventoryRequest); GetInventoryResponse response = null; try { @@ -101,37 +104,28 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException, for (InventoryItemOuterClass.InventoryItem inventoryItem : response.getInventoryDelta().getInventoryItemsList()) { InventoryItemDataOuterClass.InventoryItemData itemData = inventoryItem.getInventoryItemData(); - if (inventoryItem.getDeletedItemKey() > 0) { - if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { - pokebank.removePokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); - } - if (itemData.getItem().getItemId() != ItemIdOuterClass.ItemId.UNRECOGNIZED) { - ItemOuterClass.Item item = inventoryItem.getInventoryItemData().getItem(); - itemBag.removeItem(inventoryItem.getInventoryItemData().getItem().getItemId(), item.getCount()); - } - if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED) { - candyjar.removeCandy( - inventoryItem.getInventoryItemData().getPokemonFamily().getFamilyId(), - inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() - ); - } - } else { - if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { - pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); - } - if (itemData.getItem().getItemId() != ItemIdOuterClass.ItemId.UNRECOGNIZED) { - ItemOuterClass.Item item = inventoryItem.getInventoryItemData().getItem(); - itemBag.addItem(new Item(item)); - } - if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED) { - candyjar.addCandy( - inventoryItem.getInventoryItemData().getPokemonFamily().getFamilyId(), - inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() - ); - } - if (itemData.hasPlayerStats()) { - stats = inventoryItem.getInventoryItemData().getPlayerStats(); - } + + if (itemData.getPokemonData().getPokemonId() != PokemonIdOuterClass.PokemonId.MISSINGNO) { + pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData())); + } + if (itemData.getItem().getItemId() != ItemId.UNRECOGNIZED + && itemData.getItem().getItemId() != ItemId.ITEM_UNKNOWN) { + ItemData item = inventoryItem.getInventoryItemData().getItem(); + itemBag.addItem(new Item(item)); + } + if (itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.UNRECOGNIZED + && itemData.getPokemonFamily().getFamilyId() != PokemonFamilyIdOuterClass.PokemonFamilyId.FAMILY_UNSET) { + candyjar.setCandy( + inventoryItem.getInventoryItemData().getPokemonFamily().getFamilyId(), + inventoryItem.getInventoryItemData().getPokemonFamily().getCandy() + ); + } + if (itemData.hasPlayerStats()) { + api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats()); + } + + if (itemData.hasPokedexEntry()) { + pokedex.add(itemData.getPokedexEntry()); } lastInventoryUpdate = System.currentTimeMillis(); diff --git a/src/main/java/com/pokegoapi/api/inventory/Item.java b/src/main/java/com/pokegoapi/api/inventory/Item.java index 2787fb48..584d7dbb 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Item.java +++ b/src/main/java/com/pokegoapi/api/inventory/Item.java @@ -15,14 +15,14 @@ package com.pokegoapi.api.inventory; -import POGOProtos.Inventory.ItemIdOuterClass.ItemId; - +import POGOProtos.Inventory.Item.ItemDataOuterClass; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; public class Item { - private POGOProtos.Inventory.ItemOuterClass.Item proto; + private ItemDataOuterClass.ItemData proto; private int count; - public Item(POGOProtos.Inventory.ItemOuterClass.Item proto) { + public Item(ItemDataOuterClass.ItemData proto) { this.proto = proto; this.count = proto.getCount(); } diff --git a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java index e7b08d7d..f2dad7dc 100644 --- a/src/main/java/com/pokegoapi/api/inventory/ItemBag.java +++ b/src/main/java/com/pokegoapi/api/inventory/ItemBag.java @@ -16,8 +16,9 @@ package com.pokegoapi.api.inventory; -import POGOProtos.Inventory.ItemIdOuterClass.ItemId; -import POGOProtos.Inventory.ItemOuterClass; +import POGOProtos.Inventory.Item.ItemDataOuterClass; +import POGOProtos.Inventory.Item.ItemDataOuterClass.ItemData; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Networking.Requests.Messages.RecycleInventoryItemMessageOuterClass.RecycleInventoryItemMessage; import POGOProtos.Networking.Requests.RequestTypeOuterClass; import POGOProtos.Networking.Responses.RecycleInventoryItemResponseOuterClass; @@ -96,7 +97,7 @@ public Item getItem(ItemId type) { // prevent returning null if (!items.containsKey(type)) { - return new Item(ItemOuterClass.Item.newBuilder().setCount(0).setItemId(type).build()); + return new Item(ItemData.newBuilder().setCount(0).setItemId(type).build()); } return items.get(type); diff --git a/src/main/java/com/pokegoapi/api/inventory/Pokeball.java b/src/main/java/com/pokegoapi/api/inventory/Pokeball.java index 8ab106be..12c2a5c6 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Pokeball.java +++ b/src/main/java/com/pokegoapi/api/inventory/Pokeball.java @@ -15,18 +15,19 @@ package com.pokegoapi.api.inventory; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import lombok.Getter; public enum Pokeball { - POKEBALL(1), - GREATBALL(2), - ULTRABALL(3), - MASTERBALL(4); + POKEBALL(ItemId.ITEM_POKE_BALL), + GREATBALL(ItemId.ITEM_GREAT_BALL), + ULTRABALL(ItemId.ITEM_ULTRA_BALL), + MASTERBALL(ItemId.ITEM_MASTER_BALL); @Getter - private final int balltype; + private final ItemId ballType; - Pokeball(int type) { - balltype = type; + Pokeball(ItemId type) { + ballType = type; } } diff --git a/src/main/java/com/pokegoapi/api/inventory/Pokedex.java b/src/main/java/com/pokegoapi/api/inventory/Pokedex.java index 373818eb..8f342942 100644 --- a/src/main/java/com/pokegoapi/api/inventory/Pokedex.java +++ b/src/main/java/com/pokegoapi/api/inventory/Pokedex.java @@ -15,6 +15,37 @@ package com.pokegoapi.api.inventory; +import POGOProtos.Data.PokedexEntryOuterClass.PokedexEntry; +import POGOProtos.Enums.PokemonIdOuterClass.PokemonId; +import com.pokegoapi.api.PokemonGo; + +import java.util.HashMap; +import java.util.Map; + public class Pokedex { + private final PokemonGo api; + private Map pokedexMap = new HashMap(); + + public Pokedex(PokemonGo api) { + this.api = api; + } + + /** + * Add/Update a PokdexEntry. + * @param entry The entry to add or update + */ + public void add(PokedexEntry entry) { + PokemonId id = PokemonId.forNumber(entry.getPokemonId().getNumber()); + pokedexMap.put(id, entry); + } + + /** + * Get a pokedex entry value. + * @param pokemonId the ID of the pokemon to get + * @return Entry if in pokedex or null if it doesn't + */ + public PokedexEntry getPokedexEntry(PokemonId pokemonId) { + return pokedexMap.get(pokemonId); + } } diff --git a/src/main/java/com/pokegoapi/api/map/Map.java b/src/main/java/com/pokegoapi/api/map/Map.java index 67100be9..bad8ce0e 100644 --- a/src/main/java/com/pokegoapi/api/map/Map.java +++ b/src/main/java/com/pokegoapi/api/map/Map.java @@ -15,6 +15,7 @@ package com.pokegoapi.api.map; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; import POGOProtos.Map.Fort.FortDataOuterClass.FortData; import POGOProtos.Map.Fort.FortTypeOuterClass.FortType; import POGOProtos.Map.MapCellOuterClass; @@ -103,6 +104,13 @@ public List getCatchablePokemon() throws LoginFailedException, catchablePokemons.add(new CatchablePokemon(api, wildPokemon)); } + // TODO: Check if this code is correct; merged because this contains many other fixes + /*for (Pokestop pokestop : objects.getPokestops()) { + if (pokestop.inRange() && pokestop.hasLurePokemon()) { + catchablePokemons.add(new CatchablePokemon(api, pokestop.getFortData())); + } + }*/ + return catchablePokemons; } @@ -408,7 +416,7 @@ public EncounterResponse encounterPokemon(MapPokemon catchablePokemon) .setEncounterId(catchablePokemon.getEncounterId()) .setPlayerLatitude(api.getLatitude()) .setPlayerLongitude(api.getLongitude()) - .setSpawnpointId(catchablePokemon.getSpawnpointId()) + .setSpawnPointId(catchablePokemon.getSpawnPointId()) .build(); ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); @@ -440,7 +448,7 @@ public CatchPokemonResponse catchPokemon( double normalizedHitPosition, double normalizedReticleSize, double spinModifier, - int pokeball) + ItemId pokeball) throws LoginFailedException, RemoteServerException { CatchPokemonMessage reqMsg = CatchPokemonMessage.newBuilder() @@ -448,7 +456,7 @@ public CatchPokemonResponse catchPokemon( .setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(catchablePokemon.getSpawnpointId()) + .setSpawnPointGuid(catchablePokemon.getSpawnPointId()) .setSpinModifier(spinModifier) .setPokeball(pokeball) .build(); diff --git a/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java b/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java index fabca72f..4b8b3e39 100644 --- a/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java +++ b/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java @@ -35,6 +35,7 @@ public class Pokestop { private final PokemonGo api; + @Getter private final FortDataOuterClass.FortData fortData; @Getter private long cooldownCompleteTimestampMs; @@ -52,6 +53,21 @@ public Pokestop(PokemonGo api, FortDataOuterClass.FortData fortData) { this.cooldownCompleteTimestampMs = fortData.getCooldownCompleteTimestampMs(); } + /** + * Returns whether or not a pokestop is in range. + * @return true when in range of player + */ + public boolean inRange() { + S2LatLng pokestop = S2LatLng.fromDegrees(getLatitude(), getLongitude()); + S2LatLng player = S2LatLng.fromDegrees(api.getLatitude(), api.getLongitude()); + double distance = pokestop.getEarthDistance(player); + return distance < 30; + } + + /** + * can user loot this from current position. + * @return true when lootable + */ public boolean canLoot() { return canLoot(false); } @@ -63,10 +79,11 @@ public boolean canLoot() { * @return the boolean */ public boolean canLoot(boolean ignoreDistance) { - S2LatLng pokestop = S2LatLng.fromDegrees(getLatitude(), getLongitude()); - S2LatLng player = S2LatLng.fromDegrees(api.getLatitude(), api.getLongitude()); - double distance = pokestop.getEarthDistance(player); - return (ignoreDistance || distance < 30) && cooldownCompleteTimestampMs < System.currentTimeMillis(); + boolean active = cooldownCompleteTimestampMs < System.currentTimeMillis(); + if (!ignoreDistance) { + return active && inRange(); + } + return active; } public String getId() { @@ -134,5 +151,11 @@ public FortDetails getDetails() throws LoginFailedException, RemoteServerExcepti return new FortDetails(response); } - + /** + * Returns whether this pokestop has an active lure. + * @return lure status + */ + public boolean hasLurePokemon() { + return fortData.hasLureInfo() && fortData.getLureInfo().getLureExpiresTimestampMs() < System.currentTimeMillis(); + } } diff --git a/src/main/java/com/pokegoapi/api/map/fort/PokestopLootResult.java b/src/main/java/com/pokegoapi/api/map/fort/PokestopLootResult.java index cc7cbf63..613aee6c 100644 --- a/src/main/java/com/pokegoapi/api/map/fort/PokestopLootResult.java +++ b/src/main/java/com/pokegoapi/api/map/fort/PokestopLootResult.java @@ -15,7 +15,7 @@ package com.pokegoapi.api.map.fort; -import POGOProtos.Inventory.ItemAwardOuterClass; +import POGOProtos.Inventory.Item.ItemAwardOuterClass.ItemAward; import POGOProtos.Networking.Responses.FortSearchResponseOuterClass; import POGOProtos.Networking.Responses.FortSearchResponseOuterClass.FortSearchResponse.Result; @@ -40,7 +40,7 @@ public Result getResult() { return response.getResult(); } - public List getItemsAwarded() { + public List getItemsAwarded() { return response.getItemsAwardedList(); } diff --git a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java index e47c6997..3036984d 100644 --- a/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java +++ b/src/main/java/com/pokegoapi/api/map/pokemon/CatchablePokemon.java @@ -16,7 +16,8 @@ package com.pokegoapi.api.map.pokemon; import POGOProtos.Enums.PokemonIdOuterClass; -import POGOProtos.Inventory.ItemIdOuterClass; +import POGOProtos.Inventory.Item.ItemIdOuterClass.ItemId; +import POGOProtos.Map.Fort.FortDataOuterClass.FortData; import POGOProtos.Map.Pokemon.MapPokemonOuterClass.MapPokemon; import POGOProtos.Map.Pokemon.WildPokemonOuterClass.WildPokemon; import POGOProtos.Networking.Requests.Messages.CatchPokemonMessageOuterClass.CatchPokemonMessage; @@ -27,6 +28,7 @@ import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse; import com.google.protobuf.InvalidProtocolBufferException; import com.pokegoapi.api.PokemonGo; +import com.pokegoapi.api.inventory.ItemBag; import com.pokegoapi.api.inventory.Pokeball; import com.pokegoapi.exceptions.LoginFailedException; import com.pokegoapi.exceptions.RemoteServerException; @@ -43,7 +45,7 @@ public class CatchablePokemon { private final PokemonGo api; @Getter - private final String spawnpointId; + private final String spawnPointId; @Getter private final long encounterId; @Getter @@ -67,7 +69,7 @@ public class CatchablePokemon { public CatchablePokemon(PokemonGo api, MapPokemon proto) { this.api = api; - this.spawnpointId = proto.getSpawnpointId(); + this.spawnPointId = proto.getSpawnPointId(); this.encounterId = proto.getEncounterId(); this.pokemonId = proto.getPokemonId(); this.expirationTimestampMs = proto.getExpirationTimestampMs(); @@ -84,7 +86,7 @@ public CatchablePokemon(PokemonGo api, MapPokemon proto) { */ public CatchablePokemon(PokemonGo api, WildPokemon proto) { this.api = api; - this.spawnpointId = proto.getSpawnpointId(); + this.spawnPointId = proto.getSpawnPointId(); this.encounterId = proto.getEncounterId(); this.pokemonId = proto.getPokemonData().getPokemonId(); this.expirationTimestampMs = proto.getTimeTillHiddenMs(); @@ -92,6 +94,25 @@ public CatchablePokemon(PokemonGo api, WildPokemon proto) { this.longitude = proto.getLongitude(); } + /** + * Instantiates a new Catchable pokemon. + * + * @param api the api + * @param proto the proto + */ + public CatchablePokemon(PokemonGo api, FortData proto) { + if (!proto.hasLureInfo()) { + throw new IllegalArgumentException("Fort does not have lure"); + } + this.api = api; + // TODO: does this work? + this.spawnPointId = null; + this.encounterId = proto.getLureInfo().getEncounterId(); + this.pokemonId = proto.getLureInfo().getActivePokemonId(); + this.expirationTimestampMs = proto.getLureInfo().getLureExpiresTimestampMs(); + this.latitude = proto.getLatitude(); + this.longitude = proto.getLongitude(); + } /** * Encounter pokemon encounter result. @@ -105,7 +126,7 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer .setEncounterId(getEncounterId()) .setPlayerLatitude(api.getLatitude()) .setPlayerLongitude(api.getLongitude()) - .setSpawnpointId(getSpawnpointId()) + .setSpawnPointId(getSpawnPointId()) .build(); ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.ENCOUNTER, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); @@ -127,15 +148,20 @@ public EncounterResult encounterPokemon() throws LoginFailedException, RemoteSer * @throws RemoteServerException if the server failed to respond */ public CatchResult catchPokemon() throws LoginFailedException, RemoteServerException { - Pokeball ball = Pokeball.POKEBALL; - if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_POKE_BALL).getCount() == 0) { - ball = Pokeball.GREATBALL; - } else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_GREAT_BALL).getCount() == 0) { - ball = Pokeball.ULTRABALL; - } else if (api.getInventories().getItemBag().getItem(ItemIdOuterClass.ItemId.ITEM_ULTRA_BALL).getCount() == 0) { - ball = Pokeball.MASTERBALL; + Pokeball pokeball; + + ItemBag bag = api.getInventories().getItemBag(); + if (bag.getItem(ItemId.ITEM_POKE_BALL).getCount() > 0) { + pokeball = Pokeball.POKEBALL; + } else if (bag.getItem(ItemId.ITEM_GREAT_BALL).getCount() > 0) { + pokeball = Pokeball.GREATBALL; + } else if (bag.getItem(ItemId.ITEM_ULTRA_BALL).getCount() > 0) { + pokeball = Pokeball.ULTRABALL; + } else { + pokeball = Pokeball.MASTERBALL; } - return catchPokemon(ball); + + return catchPokemon(pokeball); } @@ -191,9 +217,9 @@ public CatchResult catchPokemon( .setHitPokemon(true) .setNormalizedHitPosition(normalizedHitPosition) .setNormalizedReticleSize(normalizedReticleSize) - .setSpawnPointGuid(getSpawnpointId()) + .setSpawnPointGuid(getSpawnPointId()) .setSpinModifier(spinModifier) - .setPokeball(type.getBalltype()) + .setPokeball(type.getBallType()) .build(); ServerRequest serverRequest = new ServerRequest(RequestTypeOuterClass.RequestType.CATCH_POKEMON, reqMsg); api.getRequestHandler().sendServerRequests(serverRequest); @@ -217,5 +243,4 @@ public CatchResult catchPokemon( return new CatchResult(response); } - } diff --git a/src/main/java/com/pokegoapi/api/player/PlayerProfile.java b/src/main/java/com/pokegoapi/api/player/PlayerProfile.java index 903b55d5..6d36d4d7 100644 --- a/src/main/java/com/pokegoapi/api/player/PlayerProfile.java +++ b/src/main/java/com/pokegoapi/api/player/PlayerProfile.java @@ -37,16 +37,26 @@ public class PlayerProfile { private static final String TAG = PlayerProfile.class.getSimpleName(); private final PokemonGo api; + @Getter private long creationTime; + @Getter private String username; + @Getter private Team team; + @Getter private int pokemonStorage; + @Getter private int itemStorage; + @Getter private EquippedBadgeOuterClass.EquippedBadge badge; + @Getter private PlayerAvatar avatar; + @Getter private DailyBonus dailyBonus; + @Getter private ContactSettings contactSettings; + @Getter private Map currencies = new HashMap(); @Getter @Setter @@ -59,14 +69,14 @@ public PlayerProfile(PokemonGo api) throws LoginFailedException, RemoteServerExc /** * Updates the player profile with the latest data. - * @throws LoginFailedException the login failed exception + * + * @throws LoginFailedException the login failed exception * @throws RemoteServerException the remote server exception */ public void updateProfile() throws LoginFailedException, RemoteServerException { GetPlayerMessage getPlayerReqMsg = GetPlayerMessage.newBuilder().build(); ServerRequest getPlayerServerRequest = new ServerRequest(RequestType.GET_PLAYER, getPlayerReqMsg); - api.getRequestHandler().request(getPlayerServerRequest); - api.getRequestHandler().sendServerRequests(); + api.getRequestHandler().sendServerRequests(getPlayerServerRequest); GetPlayerResponseOuterClass.GetPlayerResponse playerResponse = null; try { @@ -116,7 +126,6 @@ public void updateProfile() throws LoginFailedException, RemoteServerException { dailyBonus = bonusApi; - } /** diff --git a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java index 91b75b85..b9591eef 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java +++ b/src/main/java/com/pokegoapi/api/pokemon/Pokemon.java @@ -19,6 +19,8 @@ import POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId; import POGOProtos.Enums.PokemonIdOuterClass; import POGOProtos.Enums.PokemonMoveOuterClass; +import POGOProtos.Inventory.Item.ItemIdOuterClass; +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; @@ -73,6 +75,12 @@ public Result transferPokemon() throws LoginFailedException, RemoteServerExcepti return ReleasePokemonResponse.Result.FAILED; } + if (response.getResult() == Result.SUCCESS) { + pgo.getInventories().getPokebank().removePokemon(this); + } + + pgo.getInventories().getPokebank().removePokemon(this); + pgo.getInventories().updateInventories(); return response.getResult(); @@ -103,6 +111,7 @@ public NicknamePokemonResponse.Result renamePokemon(String nickname) throw new RemoteServerException(e); } + pgo.getInventories().getPokebank().removePokemon(this); pgo.getInventories().updateInventories(); return response.getResult(); @@ -130,6 +139,8 @@ public EvolutionResult evolve() throws LoginFailedException, RemoteServerExcepti EvolutionResult result = new EvolutionResult(response); + pgo.getInventories().getPokebank().removePokemon(this); + pgo.getInventories().updateInventories(); return result; @@ -223,7 +234,7 @@ public float getCpMultiplier() { return proto.getCpMultiplier(); } - public int getPokeball() { + public ItemId getPokeball() { return proto.getPokeball(); } @@ -239,7 +250,7 @@ public int getBattlesDefended() { return proto.getBattlesDefended(); } - public int getEggIncubatorId() { + public String getEggIncubatorId() { return proto.getEggIncubatorId(); } diff --git a/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java b/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java index 9a9edef6..354150a8 100644 --- a/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java +++ b/src/main/java/com/pokegoapi/api/pokemon/PokemonFamilyMap.java @@ -30,7 +30,7 @@ public class PokemonFamilyMap { familys.put(PokemonId.IVYSAUR, PokemonFamilyId.FAMILY_BULBASAUR); familys.put(PokemonId.VENUSAUR, PokemonFamilyId.FAMILY_BULBASAUR); highestForFamily.put(PokemonFamilyId.FAMILY_BULBASAUR, PokemonId.VENUSAUR); - familys.put(PokemonId.CHARMENDER, PokemonFamilyId.FAMILY_CHARMANDER); + familys.put(PokemonId.CHARMANDER, PokemonFamilyId.FAMILY_CHARMANDER); familys.put(PokemonId.CHARMELEON, PokemonFamilyId.FAMILY_CHARMANDER); familys.put(PokemonId.CHARIZARD, PokemonFamilyId.FAMILY_CHARMANDER); highestForFamily.put(PokemonFamilyId.FAMILY_CHARMANDER, PokemonId.CHARIZARD); @@ -63,17 +63,17 @@ public class PokemonFamilyMap { familys.put(PokemonId.RAICHU, PokemonFamilyId.FAMILY_PIKACHU); highestForFamily.put(PokemonFamilyId.FAMILY_PIKACHU, PokemonId.RAICHU); familys.put(PokemonId.SANDSHREW, PokemonFamilyId.FAMILY_SANDSHREW); - familys.put(PokemonId.SANDLASH, PokemonFamilyId.FAMILY_SANDSHREW); - highestForFamily.put(PokemonFamilyId.FAMILY_SANDSHREW, PokemonId.SANDLASH); - familys.put(PokemonId.NIDORAN_FEMALE, PokemonFamilyId.FAMILY_NIDORAN); - familys.put(PokemonId.NIDORINA, PokemonFamilyId.FAMILY_NIDORAN); - familys.put(PokemonId.NIDOQUEEN, PokemonFamilyId.FAMILY_NIDORAN); - highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN, PokemonId.NIDOQUEEN); - familys.put(PokemonId.NIDORAN_MALE, PokemonFamilyId.FAMILY_NIDORAN2); - familys.put(PokemonId.NIDORINO, PokemonFamilyId.FAMILY_NIDORAN2); - familys.put(PokemonId.NIDOKING, PokemonFamilyId.FAMILY_NIDORAN2); - highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN2, PokemonId.NIDOKING); - familys.put(PokemonId.CLEFARY, PokemonFamilyId.FAMILY_CLEFAIRY); + familys.put(PokemonId.SANDSLASH, PokemonFamilyId.FAMILY_SANDSHREW); + highestForFamily.put(PokemonFamilyId.FAMILY_SANDSHREW, PokemonId.SANDSLASH); + familys.put(PokemonId.NIDORAN_FEMALE, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + familys.put(PokemonId.NIDORINA, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + familys.put(PokemonId.NIDOQUEEN, PokemonFamilyId.FAMILY_NIDORAN_FEMALE); + highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN_FEMALE, PokemonId.NIDOQUEEN); + familys.put(PokemonId.NIDORAN_MALE, PokemonFamilyId.FAMILY_NIDORAN_MALE); + familys.put(PokemonId.NIDORINO, PokemonFamilyId.FAMILY_NIDORAN_MALE); + familys.put(PokemonId.NIDOKING, PokemonFamilyId.FAMILY_NIDORAN_MALE); + highestForFamily.put(PokemonFamilyId.FAMILY_NIDORAN_MALE, PokemonId.NIDOKING); + familys.put(PokemonId.CLEFAIRY, PokemonFamilyId.FAMILY_CLEFAIRY); familys.put(PokemonId.CLEFABLE, PokemonFamilyId.FAMILY_CLEFAIRY); highestForFamily.put(PokemonFamilyId.FAMILY_CLEFAIRY, PokemonId.CLEFABLE); familys.put(PokemonId.VULPIX, PokemonFamilyId.FAMILY_VULPIX); @@ -116,20 +116,20 @@ public class PokemonFamilyMap { highestForFamily.put(PokemonFamilyId.FAMILY_POLIWAG, PokemonId.POLIWRATH); familys.put(PokemonId.ABRA, PokemonFamilyId.FAMILY_ABRA); familys.put(PokemonId.KADABRA, PokemonFamilyId.FAMILY_ABRA); - familys.put(PokemonId.ALAKHAZAM, PokemonFamilyId.FAMILY_ABRA); - highestForFamily.put(PokemonFamilyId.FAMILY_ABRA, PokemonId.ALAKHAZAM); + familys.put(PokemonId.ALAKAZAM, PokemonFamilyId.FAMILY_ABRA); + highestForFamily.put(PokemonFamilyId.FAMILY_ABRA, PokemonId.ALAKAZAM); familys.put(PokemonId.MACHOP, PokemonFamilyId.FAMILY_MACHOP); familys.put(PokemonId.MACHOKE, PokemonFamilyId.FAMILY_MACHOP); familys.put(PokemonId.MACHAMP, PokemonFamilyId.FAMILY_MACHOP); highestForFamily.put(PokemonFamilyId.FAMILY_MACHOP, PokemonId.MACHAMP); familys.put(PokemonId.BELLSPROUT, PokemonFamilyId.FAMILY_BELLSPROUT); familys.put(PokemonId.WEEPINBELL, PokemonFamilyId.FAMILY_BELLSPROUT); - familys.put(PokemonId.VICTREEBELL, PokemonFamilyId.FAMILY_BELLSPROUT); - highestForFamily.put(PokemonFamilyId.FAMILY_BELLSPROUT, PokemonId.VICTREEBELL); + familys.put(PokemonId.VICTREEBEL, PokemonFamilyId.FAMILY_BELLSPROUT); + highestForFamily.put(PokemonFamilyId.FAMILY_BELLSPROUT, PokemonId.VICTREEBEL); familys.put(PokemonId.TENTACOOL, PokemonFamilyId.FAMILY_TENTACOOL); familys.put(PokemonId.TENTACRUEL, PokemonFamilyId.FAMILY_TENTACOOL); highestForFamily.put(PokemonFamilyId.FAMILY_TENTACOOL, PokemonId.TENTACRUEL); - familys.put(PokemonId.GEODUGE, PokemonFamilyId.FAMILY_GEODUDE); + familys.put(PokemonId.GEODUDE, PokemonFamilyId.FAMILY_GEODUDE); familys.put(PokemonId.GRAVELER, PokemonFamilyId.FAMILY_GEODUDE); familys.put(PokemonId.GOLEM, PokemonFamilyId.FAMILY_GEODUDE); highestForFamily.put(PokemonFamilyId.FAMILY_GEODUDE, PokemonId.GOLEM); diff --git a/src/main/java/com/pokegoapi/main/RequestHandler.java b/src/main/java/com/pokegoapi/main/RequestHandler.java index 1e9559cb..7520bf3a 100644 --- a/src/main/java/com/pokegoapi/main/RequestHandler.java +++ b/src/main/java/com/pokegoapi/main/RequestHandler.java @@ -246,8 +246,8 @@ private void resetBuilder() { private void resetBuilder(RequestEnvelopeOuterClass.RequestEnvelope.Builder builder) { builder.setStatusCode(2); builder.setRequestId(8145806132888207460L); - if (lastAuth != null - && lastAuth.getExpireTimestampMs() > 0 + if (lastAuth != null + && lastAuth.getExpireTimestampMs() > 0 && lastAuth.getExpireTimestampMs() > System.currentTimeMillis()) { builder.setAuthTicket(lastAuth); } else { diff --git a/src/resources/protobuf b/src/resources/protobuf index 1b124cdb..eeccbb12 160000 --- a/src/resources/protobuf +++ b/src/resources/protobuf @@ -1 +1 @@ -Subproject commit 1b124cdbdd271a9cd6953949a74db3865a5f42a8 +Subproject commit eeccbb121b126aa51fc4eebae8d2f23d013e1cb8