Skip to content

Commit ba979f3

Browse files
author
Matthew J. Mjelde
committed
Added Pokedex handling
1 parent 1f79f38 commit ba979f3

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

src/main/java/com/pokegoapi/api/inventory/Inventories.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class Inventories {
4444
private PokeBank pokebank;
4545
@Getter
4646
private CandyJar candyjar;
47+
@Getter
48+
private Pokedex pokedex;
4749

4850
private long lastInventoryUpdate = 0;
4951

@@ -58,6 +60,7 @@ public Inventories(PokemonGo api) throws LoginFailedException, RemoteServerExcep
5860
itemBag = new ItemBag(api);
5961
pokebank = new PokeBank(api);
6062
candyjar = new CandyJar(api);
63+
pokedex = new Pokedex(api);
6164
updateInventories();
6265
}
6366

@@ -82,6 +85,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException,
8285
itemBag = new ItemBag(api);
8386
pokebank = new PokeBank(api);
8487
candyjar = new CandyJar(api);
88+
pokedex = new Pokedex(api);
8589
}
8690
GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder()
8791
.setLastTimestampMs(lastInventoryUpdate)
@@ -120,6 +124,10 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException,
120124
api.getPlayerProfile().setStats(inventoryItem.getInventoryItemData().getPlayerStats());
121125
}
122126

127+
if (itemData.hasPokedexEntry()) {
128+
pokedex.add(itemData.getPokedexEntry());
129+
}
130+
123131
lastInventoryUpdate = System.currentTimeMillis();
124132
}
125133
}

src/main/java/com/pokegoapi/api/inventory/Pokedex.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,37 @@
1515

1616
package com.pokegoapi.api.inventory;
1717

18+
import POGOProtos.Data.PokedexEntryOuterClass.PokedexEntry;
19+
import POGOProtos.Enums.PokemonIdOuterClass.PokemonId;
20+
import com.pokegoapi.api.PokemonGo;
21+
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
1825
public class Pokedex {
1926

27+
private final PokemonGo api;
28+
private Map<PokemonId, PokedexEntry> pokedexMap = new HashMap();
29+
30+
public Pokedex(PokemonGo api) {
31+
this.api = api;
32+
}
33+
34+
/**
35+
* Add/Update a PokdexEntry.
36+
* @param entry The entry to add or update
37+
*/
38+
public void add(PokedexEntry entry) {
39+
PokemonId id = PokemonId.forNumber(entry.getPokedexEntryNumber());
40+
pokedexMap.put(id, entry);
41+
}
42+
43+
/**
44+
* Get a pokedex entry value.
45+
* @param pokemonId the ID of the pokemon to get
46+
* @return Entry if in pokedex or null if it doesn't
47+
*/
48+
public PokedexEntry getPokedexEntry(PokemonId pokemonId) {
49+
return pokedexMap.get(pokemonId);
50+
}
2051
}

0 commit comments

Comments
 (0)