Skip to content

Commit

Permalink
Merge pull request Grover-c13#173 from Hindi/inventoryForceUpdate
Browse files Browse the repository at this point in the history
Inventory force update
  • Loading branch information
Grover-c13 authored Jul 24, 2016
2 parents f91890a + 995313a commit 4a91a97
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 20 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/pokegoapi/api/inventory/CandyJar.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public class CandyJar {
private HashMap<PokemonFamilyId, Integer> candies;

public CandyJar(PokemonGo pgo) {
reset(pgo);
}

public void reset(PokemonGo pgo) {
this.pgo = pgo;
candies = new HashMap<>();
}
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/pokegoapi/api/inventory/Hatchery.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@ public class Hatchery {
@Getter
PokemonGo instance;

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

public void reset(PokemonGo pgo) {
this.instance = pgo;
}

public void addEgg(EggPokemon egg) {
Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/pokegoapi/api/inventory/Inventories.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ public void updateInventories() throws LoginFailedException, RemoteServerExcepti
public void updateInventories(boolean forceUpdate) throws LoginFailedException, RemoteServerException {
if (forceUpdate) {
lastInventoryUpdate = 0;
itemBag = new ItemBag(api);
pokebank = new PokeBank(api);
candyjar = new CandyJar(api);
pokedex = new Pokedex(api);
itemBag.reset(api);
pokebank.reset(api);
candyjar.reset(api);
pokedex.reset(api);
incubators = new ArrayList<>();
hatchery = new Hatchery(api);
hatchery.reset(api);
}
GetInventoryMessage invReqMsg = GetInventoryMessage.newBuilder()
.setLastTimestampMs(lastInventoryUpdate)
Expand All @@ -125,7 +125,7 @@ public void updateInventories(boolean forceUpdate) throws LoginFailedException,

// pokebank
if (itemData.getPokemonData().getPokemonId() != PokemonId.MISSINGNO) {
pokebank.addPokemon(new Pokemon(inventoryItem.getInventoryItemData().getPokemonData()));
pokebank.addPokemon(new Pokemon(api, inventoryItem.getInventoryItemData().getPokemonData()));
}

// items
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/pokegoapi/api/inventory/ItemBag.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public class ItemBag {
private HashMap<ItemId, Item> items;

public ItemBag(PokemonGo pgo) {
reset(pgo);
}

public void reset(PokemonGo pgo) {
this.pgo = pgo;
items = new HashMap<>();
}
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/pokegoapi/api/inventory/PokeBank.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@ public class PokeBank {
@Getter
PokemonGo instance;

public PokeBank(PokemonGo instance) {
this.instance = instance;
public PokeBank(PokemonGo pgo) {
reset(pgo);
}

public void reset(PokemonGo pgo) {
this.instance = pgo;
}

/**
* Add a pokemon to the pokebank inventory. Will not add duplicates (pokemon with same id).
* @param pokemon Pokemon to add to the inventory
*/
public void addPokemon(final Pokemon pokemon) {
pokemon.setPgo(instance);
List<Pokemon> alreadyAdded = Stream.of(pokemons).filter(new Predicate<Pokemon>() {
@Override
public boolean test(Pokemon testPokemon) {
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/pokegoapi/api/inventory/Pokedex.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@

public class Pokedex {

private final PokemonGo api;
private PokemonGo api;
private Map<PokemonId, PokedexEntry> pokedexMap = new HashMap();

public Pokedex(PokemonGo api) {
this.api = api;
public Pokedex(PokemonGo pgo) {
reset(pgo);
}

public void reset(PokemonGo pgo) {
this.api = pgo;
}

/**
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/pokegoapi/api/map/pokemon/EvolutionResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@
package com.pokegoapi.api.map.pokemon;

import POGOProtos.Networking.Responses.EvolvePokemonResponseOuterClass;
import com.pokegoapi.api.PokemonGo;
import com.pokegoapi.api.pokemon.Pokemon;

public class EvolutionResult {

private EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto;
private Pokemon pokemon;

public EvolutionResult(EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) {
/**
* The evolution result.
* @param api PokemonGo api
* @param proto Pokemon proto
*/
public EvolutionResult(PokemonGo api, EvolvePokemonResponseOuterClass.EvolvePokemonResponse proto) {
this.proto = proto;
this.pokemon = new Pokemon(proto.getEvolvedPokemonData());
this.pokemon = new Pokemon(api, proto.getEvolvedPokemonData());
}

public EvolvePokemonResponseOuterClass.EvolvePokemonResponse.Result getResult() {
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/pokegoapi/api/pokemon/Pokemon.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@
public class Pokemon {

private static final String TAG = Pokemon.class.getSimpleName();
@Setter
PokemonGo pgo;
private final PokemonGo pgo;
private PokemonData proto;
private PokemonMeta meta;

// API METHODS //

// DELEGATE METHODS BELOW //
public Pokemon(PokemonData proto) {
public Pokemon(PokemonGo api, PokemonData proto) {
this.pgo = api;
this.proto = proto;
}

Expand Down Expand Up @@ -137,7 +137,7 @@ public EvolutionResult evolve() throws LoginFailedException, RemoteServerExcepti
return null;
}

EvolutionResult result = new EvolutionResult(response);
EvolutionResult result = new EvolutionResult(pgo, response);

pgo.getInventories().getPokebank().removePokemon(this);

Expand Down

0 comments on commit 4a91a97

Please sign in to comment.