Skip to content
This repository has been archived by the owner on Jul 22, 2019. It is now read-only.

Commit

Permalink
fully implement hatching eggs
Browse files Browse the repository at this point in the history
closes #2
  • Loading branch information
jabbink committed Jul 24, 2016
1 parent cfdfb56 commit ad9efae
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[submodule "lib/PokeGOAPI-Java"]
path = lib/PokeGOAPI-Java
url = https://github.com/Grover-c13/PokeGOAPI-Java.git
branch = Development
25 changes: 23 additions & 2 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/HatchEggs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,46 @@

package ink.abb.pogo.scraper.tasks

import ink.abb.pogo.scraper.util.Log
import POGOProtos.Enums.PokemonIdOuterClass
import POGOProtos.Networking.Responses.UseItemEggIncubatorResponseOuterClass
import ink.abb.pogo.scraper.Bot
import ink.abb.pogo.scraper.Context
import ink.abb.pogo.scraper.Settings
import ink.abb.pogo.scraper.Task
import ink.abb.pogo.scraper.util.Log
import ink.abb.pogo.scraper.util.pokemon.getIvPercentage

class HatchEggs : Task {

override fun run(bot: Bot, ctx: Context, settings: Settings) {
val freeIncubators = ctx.api.inventories.incubators.filter { !it.isInUse }
val eggs = ctx.api.inventories.hatchery.eggs.filter { it.eggIncubatorId == null || it.eggIncubatorId.isBlank() }
val eggs = ctx.api.inventories.hatchery.eggs
.filter { it.eggIncubatorId == null || it.eggIncubatorId.isBlank() }
.sortedByDescending { it.eggKmWalkedTarget }
if (freeIncubators.isNotEmpty() && eggs.isNotEmpty()) {
val result = freeIncubators.first().hatchEgg(eggs.first())
if (result == UseItemEggIncubatorResponseOuterClass.UseItemEggIncubatorResponse.Result.SUCCESS) {
Log.green("Put egg ${eggs.first().id} in unused incubator")
} else {
Log.red("Failed to put egg in incubator; error: $result")
}
} else {
val result = ctx.api.inventories.hatchery.queryHatchedEggs()
if (result.isNotEmpty()) {
result.forEachIndexed { index, it ->
// TODO: That proto is probably wrong and this fails.
val newPokemon = ctx.api.inventories.pokebank.getPokemonById(it.id)
println(newPokemon)
println(it.id)
val stats = "+${it.candy} candy; +${it.experience} XP; +${it.stardust} stardust"
if (newPokemon == null) {
Log.green("Hatched pokemon; $stats")
} else {
Log.green("Hatched ${newPokemon.pokemonId.name} with ${newPokemon.cp} CP " +
"and ${newPokemon.getIvPercentage()}% IV; $stats")
}
}
}
}

This comment has been minimized.

Copy link
@johnnyslt

johnnyslt Jul 24, 2016

I've got an error when I started the bot with this patch:

24 Jul 18:45:14: Walking to (44.433358, 26.143442) in 93.49042399026696 steps. Exception in thread "Thread-4" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3 at java.util.ArrayList.rangeCheck(ArrayList.java:653) at java.util.ArrayList.get(ArrayList.java:429) at java.util.Collections$UnmodifiableList.get(Collections.java:1309) at POGOProtos.Networking.Responses.GetHatchedEggsResponseOuterClass$GetHatchedEggsResponse.getExperienceAwarded(GetHatchedEggsResponseOuterClass.java:292) at com.pokegoapi.api.inventory.Hatchery.queryHatchedEggs(Hatchery.java:73) at ink.abb.pogo.scraper.tasks.HatchEggs.run(HatchEggs.kt:35) at ink.abb.pogo.scraper.Bot.task(Bot.kt:83) at ink.abb.pogo.scraper.Bot$run$$inlined$fixedRateTimer$lambda$lambda$2.invoke(Bot.kt:77) at ink.abb.pogo.scraper.Bot$run$$inlined$fixedRateTimer$lambda$lambda$2.invoke(Bot.kt:21) at kotlin.concurrent.ThreadsKt$thread$thread$1.run(Thread.kt:18) 24 Jul 18:45:17: Getting map of (44.43303336961298, 26.14327091662373)

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ReleasePokemon : Task {
if (pokemon.cp < minCP || minCP == -1) {
cpTooLow = true
}
reason = "CP < $minCP and IV < $minIVPercentage"
reason = "CP < $minCP and IV < $minIVPercentage%"
shouldRelease = ivTooLow && cpTooLow
}
if (shouldRelease) {
Expand Down

0 comments on commit ad9efae

Please sign in to comment.