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

[WIP] new api #1237

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
22f2364
[WIP] new API
jabbink Aug 22, 2016
5449e28
merge with develop
jabbink Aug 23, 2016
013d3d0
move all tasks over to the new API
jabbink Aug 23, 2016
98fc6b7
add helper functions in PokemonData.kt
jabbink Aug 24, 2016
95126be
fully restore export task
jabbink Aug 24, 2016
f4c61ca
Merge remote-tracking branch 'origin/develop' into wip/newAPI
jabbink Aug 25, 2016
cfacd89
migrate BotController to new API
jabbink Aug 25, 2016
e5619cd
it compiles
jabbink Aug 25, 2016
8e6a40b
make bot work
jabbink Aug 25, 2016
0239c57
update API and fix /pokemon api call
jabbink Aug 26, 2016
ac50928
hopefully fix evolving
jabbink Aug 26, 2016
9b625b7
remove countdownlatches and remove getAltitude calls
jabbink Aug 26, 2016
dcbd973
remove altitude cache
jabbink Aug 26, 2016
46c9fc6
fix compiler warnings
jabbink Aug 26, 2016
af58a55
properly check if API is ready
jabbink Aug 26, 2016
279d689
properly print last saved location
jabbink Aug 26, 2016
db3c5fe
update api to not crash when the server returns garbage
jabbink Aug 26, 2016
880dada
fix pokestop names and REST actions
jabbink Aug 26, 2016
0a1758b
update API (proper fort names, hopefully)
jabbink Aug 26, 2016
a37efb7
more logging on error
jabbink Aug 26, 2016
2950c59
update API; add debug logging
jabbink Sep 2, 2016
bd85e4f
Merge develop changes in new API branch (#1278)
Sieberkev Sep 6, 2016
1ab16ea
Revert "Merge develop changes in new API branch" (#1281)
Sieberkev Sep 7, 2016
616c64b
fix bot
jabbink Nov 8, 2016
ce24b8c
version bump
jabbink Nov 8, 2016
66c8363
update new API and don't log incorrect level rewards
jabbink Nov 9, 2016
d838e4a
bump version
jabbink Nov 9, 2016
39daf59
remove lure spam
jabbink Nov 9, 2016
4516880
update for iOS 1.15
jabbink Nov 12, 2016
3ab0e1c
fix catch rate
jabbink Nov 12, 2016
0ba1d20
fixed lures in range output (#1306)
Cypherke Nov 12, 2016
510db85
fix "MISSINGNO" hatch messages
jabbink Nov 12, 2016
128df29
merge with develop
jabbink Nov 14, 2016
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
11 changes: 10 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,17 @@ configurations {
dependencies {
//compile files('../PokeGOAPI-Java/library/build/libs/PokeGOAPI-library-all-0.3.0.jar')

compile files('lib/api-0.0.1.jar')

// TODO: Wait for jitpack to fix itself...
compile 'com.github.Grover-c13:PokeGOAPI-Java:Development-SNAPSHOT'
//compile 'com.github.Grover-c13:PokeGOAPI-Java:Development-SNAPSHOT'

compile 'com.squareup.okhttp3:okhttp:3.4.1'
compile 'io.reactivex:rxkotlin:0.60.0'
compile 'svarzee.gps:gpsoauth:0.3'
compile 'com.squareup.moshi:moshi:1.2.0'
compile 'net.jpountz.lz4:lz4:1.3.0'
compile 'com.google.protobuf:protobuf-java:3.0.0-beta-3'

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile "com.corundumstudio.socketio:netty-socketio:1.7.7"
Expand Down
Binary file added lib/api-0.0.1.jar
Binary file not shown.
94 changes: 35 additions & 59 deletions src/main/kotlin/ink/abb/pogo/scraper/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,14 @@ package ink.abb.pogo.scraper
import com.fasterxml.jackson.databind.ObjectMapper
import com.google.common.util.concurrent.AtomicDouble
import com.google.maps.GeoApiContext
import com.pokegoapi.api.PokemonGo
import com.pokegoapi.api.map.MapObjects
import com.pokegoapi.api.map.fort.Pokestop
import com.pokegoapi.api.player.PlayerProfile
import com.pokegoapi.api.pokemon.Pokemon
import ink.abb.pogo.api.PoGoApi
import ink.abb.pogo.api.cache.BagPokemon
import ink.abb.pogo.api.cache.Pokestop
import ink.abb.pogo.scraper.controllers.ProgramController
import ink.abb.pogo.scraper.gui.SocketServer
import ink.abb.pogo.scraper.tasks.*
import ink.abb.pogo.scraper.util.Log
import ink.abb.pogo.scraper.util.cachedInventories
import ink.abb.pogo.scraper.util.directions.RouteProviderEnum
import ink.abb.pogo.scraper.util.inventory.size
import ink.abb.pogo.scraper.util.pokemon.getIv
import ink.abb.pogo.scraper.util.pokemon.getIvPercentage
import java.io.File
Expand All @@ -37,7 +33,7 @@ import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong
import kotlin.concurrent.thread

class Bot(val api: PokemonGo, val settings: Settings) {
class Bot(val api: PoGoApi, val settings: Settings) {

private var runningLatch = CountDownLatch(0)
var prepareWalkBack = AtomicBoolean(false)
Expand All @@ -52,10 +48,9 @@ class Bot(val api: PokemonGo, val settings: Settings) {
lateinit private var phaser: Phaser
var ctx = Context(
api,
api.playerProfile,
AtomicDouble(settings.latitude),
AtomicDouble(settings.longitude),
AtomicLong(api.playerProfile.stats.experience),
AtomicLong(api.inventory.playerStats.experience),
LocalDateTime.now(),
Pair(AtomicInteger(0), AtomicInteger(0)),
AtomicInteger(0),
Expand All @@ -78,32 +73,36 @@ class Bot(val api: PokemonGo, val settings: Settings) {
fun start() {
if (isRunning()) return

if (settings.saveLocationOnShutdown && settings.savedLatitude!=0.0 && settings.savedLongitude!=0.0) {
if (settings.saveLocationOnShutdown && settings.savedLatitude != 0.0 && settings.savedLongitude != 0.0) {
ctx.lat.set(settings.savedLatitude)
ctx.lng.set(settings.savedLongitude)
Log.normal("Loaded last saved location (${settings.savedLatitude}, ${settings.savedLatitude})")
Log.normal("Loaded last saved location (${settings.savedLatitude}, ${settings.savedLongitude})")
}

ctx.walking.set(false)

Log.normal("Name: ${ctx.profile.playerData.username} - Team: ${ctx.profile.playerData.team.name}")
Log.normal("Level ${ctx.profile.stats.level}, Experience ${ctx.profile.stats.experience}; Pokecoin: ${ctx.profile.currencies[PlayerProfile.Currency.POKECOIN]}")
Log.normal("Pokebank ${ctx.api.cachedInventories.pokebank.pokemons.size + ctx.api.inventories.hatchery.eggs.size}/${ctx.profile.playerData.maxPokemonStorage}; Stardust: ${ctx.profile.currencies[PlayerProfile.Currency.STARDUST]}; Inventory ${ctx.api.cachedInventories.itemBag.size()}/${ctx.profile.playerData.maxItemStorage}")
Log.normal("Name: ${api.playerData.username} - Team: ${api.playerData.team.name}")
Log.normal("Level ${api.inventory.playerStats.level} - " +
"Experience ${api.inventory.playerStats.experience}; " +
"Pokecoin: ${api.inventory.currencies.getOrPut("POKECOIN", { AtomicInteger(0) }).get()}")
Log.normal("Pokebank ${api.inventory.pokemon.size + api.inventory.eggs.size}/${api.playerData.maxPokemonStorage}; " +
"Stardust: ${api.inventory.currencies.getOrPut("STARDUST", { AtomicInteger(0) }).get()}; " +
"Inventory ${api.inventory.size}/${api.playerData.maxItemStorage}")

val compareName = Comparator<Pokemon> { a, b ->
a.pokemonId.name.compareTo(b.pokemonId.name)
val compareName = Comparator<BagPokemon> { a, b ->
a.pokemonData.pokemonId.name.compareTo(b.pokemonData.pokemonId.name)
}
val compareIv = Comparator<Pokemon> { a, b ->
val compareIv = Comparator<BagPokemon> { a, b ->
// compare b to a to get it descending
if (settings.sortByIv) {
b.getIv().compareTo(a.getIv())
b.pokemonData.getIv().compareTo(a.pokemonData.getIv())
} else {
b.cp.compareTo(a.cp)
b.pokemonData.cp.compareTo(a.pokemonData.cp)
}
}
api.cachedInventories.pokebank.pokemons.sortedWith(compareName.thenComparing(compareIv)).map {
val pnickname = if (!it.nickname.isEmpty()) " (${it.nickname})" else ""
"Have ${it.pokemonId.name}$pnickname with ${it.cp}/${it.maxCpForPlayer} ${it.cpInPercentageActualPlayerLevel}% CP and IV (${it.individualAttack}-${it.individualDefense}-${it.individualStamina}) ${it.getIvPercentage()}% "
api.inventory.pokemon.map { it.value }.sortedWith(compareName.thenComparing(compareIv)).map {
val pnickname = if (!it.pokemonData.nickname.isEmpty()) " (${it.pokemonData.nickname})" else ""
"Have ${it.pokemonData.pokemonId.name}$pnickname with ${it.pokemonData.cp} CP and IV (${it.pokemonData.individualAttack}-${it.pokemonData.individualDefense}-${it.pokemonData.individualStamina}) ${it.pokemonData.getIvPercentage()}%"
}.forEach { Log.normal(it) }

val keepalive = GetMapRandomDirection()
Expand All @@ -121,34 +120,11 @@ class Bot(val api: PokemonGo, val settings: Settings) {
task(keepalive)
Log.normal("Getting initial pokestops...")

val sleepTimeout = 10L
val originalInitialMapSize = settings.initialMapSize
var retries = 0
var reply: MapObjects?
do {
reply = api.map.getMapObjects(settings.initialMapSize)
Log.normal("Got ${reply.pokestops.size} pokestops")
if (reply == null || reply.pokestops.size == 0) {
retries++
if (retries % 3 == 0) {
if (settings.initialMapSize > 1) {
settings.initialMapSize -= 2
Log.red("Decreasing initialMapSize to ${settings.initialMapSize}")
} else {
Log.red("Cannot decrease initialMapSize even further. Are your sure your latitude/longitude is correct?")
Log.yellow("This is what I am trying to fetch: " +
"https://www.google.com/maps/@${settings.latitude},${settings.longitude},15z")
}
}
Log.red("Retrying in $sleepTimeout seconds...")
Thread.sleep(sleepTimeout * 1000)
}
} while (reply == null || reply.pokestops.size == 0)
if (originalInitialMapSize != settings.initialMapSize) {
Log.red("Too high initialMapSize ($originalInitialMapSize) found, " +
"please change the setting in your config to ${settings.initialMapSize}")
while (api.map.getPokestops(api.latitude, api.longitude, settings.initialMapSize).size == 0) {
Thread.sleep(1000)
}
val process = ProcessPokestops(reply.pokestops)

val process = ProcessPokestops(api.map.getPokestops(api.latitude, api.longitude, settings.initialMapSize))

runningLatch = CountDownLatch(1)
phaser = Phaser(1)
Expand Down Expand Up @@ -183,7 +159,7 @@ class Bot(val api: PokemonGo, val settings: Settings) {
task(process)
else if (!ctx.walking.get())
task(WalkToStartPokestop(process.startPokestop as Pokestop))
if(checkForPlannedStop()){
if (checkForPlannedStop()) {
stop()
}
}
Expand Down Expand Up @@ -280,25 +256,25 @@ class Bot(val api: PokemonGo, val settings: Settings) {
task.run(this, ctx, settings)
}

fun checkForPlannedStop():Boolean {
val timeDiff:Long = ChronoUnit.MINUTES.between(ctx.startTime, LocalDateTime.now())
val pokemonCatched:Int = ctx.pokemonStats.first.get()
val pokestopsVisited:Int = ctx.pokestops.get()
fun checkForPlannedStop(): Boolean {
val timeDiff: Long = ChronoUnit.MINUTES.between(ctx.startTime, LocalDateTime.now())
val pokemonCatched: Int = ctx.pokemonStats.first.get()
val pokestopsVisited: Int = ctx.pokestops.get()
//Log.red("time: ${timeDiff}, pokemon: ${pokemonCatched}, pokestops: ${pokestopsVisited}")
if(settings.botTimeoutAfterMinutes <= timeDiff && settings.botTimeoutAfterMinutes != -1){
if (settings.botTimeoutAfterMinutes <= timeDiff && settings.botTimeoutAfterMinutes != -1) {
Log.red("Bot timed out as declared in the settings (after ${settings.botTimeoutAfterMinutes} minutes)")
return true
} else if(settings.botTimeoutAfterCatchingPokemon <= pokemonCatched && settings.botTimeoutAfterCatchingPokemon != -1){
} else if (settings.botTimeoutAfterCatchingPokemon <= pokemonCatched && settings.botTimeoutAfterCatchingPokemon != -1) {
Log.red("Bot timed out as declared in the settings (after catching ${settings.botTimeoutAfterCatchingPokemon} pokemon)")
return true
} else if(settings.botTimeoutAfterVisitingPokestops <= pokestopsVisited && settings.botTimeoutAfterVisitingPokestops != -1){
} else if (settings.botTimeoutAfterVisitingPokestops <= pokestopsVisited && settings.botTimeoutAfterVisitingPokestops != -1) {
Log.red("Bot timed out as declared in the settings (after visiting ${settings.botTimeoutAfterVisitingPokestops} pokestops)")
return true
}
return false
}

fun terminateApplication(){
fun terminateApplication() {
phaser.forceTermination()
ProgramController.stopAllApplications()
}
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/ink/abb/pogo/scraper/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,16 @@
package ink.abb.pogo.scraper

import com.google.common.util.concurrent.AtomicDouble
import ink.abb.pogo.api.PoGoApi
import com.google.maps.GeoApiContext
import com.pokegoapi.api.PokemonGo
import com.pokegoapi.api.player.PlayerProfile
import ink.abb.pogo.scraper.gui.SocketServer
import java.time.LocalDateTime
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import java.util.concurrent.atomic.AtomicLong

data class Context(
val api: PokemonGo,
val profile: PlayerProfile,
val api: PoGoApi,
val lat: AtomicDouble,
val lng: AtomicDouble,

Expand Down
Loading