From 43d909161557290c4579b6502fe906f5fa1a2cea Mon Sep 17 00:00:00 2001 From: Bryan Muschter Date: Tue, 16 Aug 2016 01:00:34 -0400 Subject: [PATCH 1/4] Added thresholds for looted pokestop and catching pokemon --- config.properties.template | 6 ++++++ src/main/kotlin/ink/abb/pogo/scraper/Context.kt | 3 +++ src/main/kotlin/ink/abb/pogo/scraper/Settings.kt | 11 +++++++++-- .../abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt | 8 ++++++++ .../abb/pogo/scraper/tasks/LootOneNearbyPokestop.kt | 2 ++ .../ink/abb/pogo/scraper/tasks/ProcessPokestops.kt | 5 +++++ 6 files changed, 33 insertions(+), 2 deletions(-) diff --git a/config.properties.template b/config.properties.template index 8703b2765..dbd9d8b77 100644 --- a/config.properties.template +++ b/config.properties.template @@ -201,6 +201,12 @@ wait_chance=0.0 wait_time_min=0 wait_time_max=0 +# Maximum of times to loot Pokestops and catch Pokemon (24hr period): +# Recommended pokestops threshold is 1500 +# Recommended pokemon threshold is 1000 +pokestop_threshold=1500 +pokemon_threshold=1000 + # List of pokemon names #MISSINGNO #BULBASAUR diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt index ef802ed15..6f2923ea8 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt @@ -29,6 +29,9 @@ data class Context( val luredPokemonStats: AtomicInteger, val itemStats: Pair, + val lootedPokestops: AtomicInteger, + val caughtPokemon: AtomicInteger, + val blacklistedEncounters: MutableSet, val server: SocketServer, diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt index 9c3e2cb90..3ec73400b 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt @@ -131,7 +131,11 @@ class SettingsParser(val properties: Properties) { waitTimeMin = getPropertyIfSet("Minimal time to wait", "wait_time_min", defaults.waitTimeMin, String::toInt), - waitTimeMax = getPropertyIfSet("Maximal time to wait", "wait_time_max", defaults.waitTimeMax, String::toInt) + waitTimeMax = getPropertyIfSet("Maximal time to wait", "wait_time_max", defaults.waitTimeMax, String::toInt), + + pokestopThreshold = getPropertyIfSet("The maximum amount of pokestops to loot before stopping", "pokestop_threshold", defaults.pokestopThreshold, String::toInt), + + pokemonThreshold = getPropertyIfSet("The maximum amount of pokemon to catch before stopping", "pokemon_threshold", defaults.pokemonThreshold, String::toInt) ) } @@ -266,7 +270,10 @@ data class Settings( val waitChance: Double = 0.0, val waitTimeMin: Int = 0, - val waitTimeMax: Int = 0 + val waitTimeMax: Int = 0, + + val pokestopThreshold: Int = 1500, + val pokemonThreshold: Int = 1000 ) { fun withName(name: String): Settings { this.name = name diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt index aab95a63b..9e7e18d59 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt @@ -28,6 +28,13 @@ import ink.abb.pogo.scraper.util.pokemon.shouldTransfer class CatchOneNearbyPokemon : Task { override fun run(bot: Bot, ctx: Context, settings: Settings) { // STOP WALKING + + if (ctx.caughtPokemon.get() > settings.pokemonThreshold) { + Thread.sleep(3600 * 12000) + ctx.caughtPokemon.set(0) + return + } + ctx.pauseWalking.set(true) val pokemon = ctx.api.map.getCatchablePokemon(ctx.blacklistedEncounters) @@ -96,6 +103,7 @@ class CatchOneNearbyPokemon : Task { // TODO: temp fix for server timing issues regarding GetMapObjects ctx.blacklistedEncounters.add(catchablePokemon.encounterId) if (result.status == CatchPokemonResponse.CatchStatus.CATCH_SUCCESS) { + ctx.caughtPokemon.andIncrement ctx.pokemonStats.first.andIncrement if (wasFromLure) { ctx.luredPokemonStats.andIncrement diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/LootOneNearbyPokestop.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/LootOneNearbyPokestop.kt index 3eae8b7b5..0d2fbe112 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/LootOneNearbyPokestop.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/LootOneNearbyPokestop.kt @@ -26,6 +26,7 @@ class LootOneNearbyPokestop(val sortedPokestops: List, val lootTimeout override fun run(bot: Bot, ctx: Context, settings: Settings) { // STOP WALKING! until loot is done + ctx.pauseWalking.set(true) ctx.api.setLocation(ctx.lat.get(), ctx.lng.get(), 0.0) val nearbyPokestops = sortedPokestops.filter { @@ -60,6 +61,7 @@ class LootOneNearbyPokestop(val sortedPokestops: List, val lootTimeout when (result.result) { Result.SUCCESS -> { + ctx.lootedPokestops.andIncrement ctx.server.sendPokestop(closest) ctx.server.sendProfile() var message = "Looted pokestop $pokestopID; +${result.experience} XP" diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt index c8349bf54..4dc5dfaae 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt @@ -50,6 +50,11 @@ class ProcessPokestops(var pokestops: MutableCollection) : Task { if (startPokestop == null) startPokestop = sortedPokestops.first() + if (ctx.lootedPokestops.get() > settings.pokestopThreshold) { + Thread.sleep(3600 * 12000) + ctx.lootedPokestops.set(0) + } + if (settings.lootPokestop) { val loot = LootOneNearbyPokestop(sortedPokestops, lootTimeouts) try { From 562029739b46bb307faf6ad9504fb489b37e8f46 Mon Sep 17 00:00:00 2001 From: Bryan Muschter Date: Tue, 16 Aug 2016 01:01:35 -0400 Subject: [PATCH 2/4] Added missing return --- src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt index 4dc5dfaae..e6277a941 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt @@ -53,6 +53,7 @@ class ProcessPokestops(var pokestops: MutableCollection) : Task { if (ctx.lootedPokestops.get() > settings.pokestopThreshold) { Thread.sleep(3600 * 12000) ctx.lootedPokestops.set(0) + return } if (settings.lootPokestop) { From 83c9dc6077f63f34342534076101615e0a87701a Mon Sep 17 00:00:00 2001 From: Bryan Muschter Date: Tue, 16 Aug 2016 01:09:05 -0400 Subject: [PATCH 3/4] Fix build errors with misplaced values and non-set values --- src/main/kotlin/ink/abb/pogo/scraper/Context.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt index 6f2923ea8..19059c9f5 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt @@ -29,9 +29,6 @@ data class Context( val luredPokemonStats: AtomicInteger, val itemStats: Pair, - val lootedPokestops: AtomicInteger, - val caughtPokemon: AtomicInteger, - val blacklistedEncounters: MutableSet, val server: SocketServer, @@ -42,6 +39,9 @@ data class Context( val walking: AtomicBoolean = AtomicBoolean(false), - val pauseWalking: AtomicBoolean = AtomicBoolean(false) + val pauseWalking: AtomicBoolean = AtomicBoolean(false), + + val lootedPokestops: AtomicInteger = AtomicInteger(0), + val caughtPokemon: AtomicInteger = AtomicInteger(0) ) From 62310fc9826896a0c1f6c3fe29d01525adaa8e5b Mon Sep 17 00:00:00 2001 From: Bryan Muschter Date: Wed, 17 Aug 2016 08:39:25 -0400 Subject: [PATCH 4/4] Remove thread.sleep for timestamp checking --- config.properties.template | 3 +++ src/main/kotlin/ink/abb/pogo/scraper/Context.kt | 5 ++++- src/main/kotlin/ink/abb/pogo/scraper/Settings.kt | 7 +++++-- .../abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt | 12 ++++++++++-- .../ink/abb/pogo/scraper/tasks/ProcessPokestops.kt | 12 ++++++++++-- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/config.properties.template b/config.properties.template index dbd9d8b77..e3355c256 100644 --- a/config.properties.template +++ b/config.properties.template @@ -207,6 +207,9 @@ wait_time_max=0 pokestop_threshold=1500 pokemon_threshold=1000 +# Threshold delay time in hours: +threshold_wait_time=12 + # List of pokemon names #MISSINGNO #BULBASAUR diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt index 19059c9f5..2968a0946 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt @@ -42,6 +42,9 @@ data class Context( val pauseWalking: AtomicBoolean = AtomicBoolean(false), val lootedPokestops: AtomicInteger = AtomicInteger(0), - val caughtPokemon: AtomicInteger = AtomicInteger(0) + val caughtPokemon: AtomicInteger = AtomicInteger(0), + + var pokemonLockTime: Long = 0L, + var pokestopLockTime: Long = 0L ) diff --git a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt index 3ec73400b..9a685151c 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt @@ -135,7 +135,9 @@ class SettingsParser(val properties: Properties) { pokestopThreshold = getPropertyIfSet("The maximum amount of pokestops to loot before stopping", "pokestop_threshold", defaults.pokestopThreshold, String::toInt), - pokemonThreshold = getPropertyIfSet("The maximum amount of pokemon to catch before stopping", "pokemon_threshold", defaults.pokemonThreshold, String::toInt) + pokemonThreshold = getPropertyIfSet("The maximum amount of pokemon to catch before stopping", "pokemon_threshold", defaults.pokemonThreshold, String::toInt), + + thresholdWaitTime = getPropertyIfSet("Threshold delay time in hours", "threshold_wait_time", defaults.thresholdWaitTime, String::toInt) ) } @@ -237,7 +239,7 @@ data class Settings( val displayPokemonCatchRewards: Boolean = true, val displayIfPokemonFromLure: Boolean = true, - val lootPokestop: Boolean = true, + var lootPokestop: Boolean = true, var catchPokemon: Boolean = true, val autoFillIncubator: Boolean = true, @@ -272,6 +274,7 @@ data class Settings( val waitTimeMin: Int = 0, val waitTimeMax: Int = 0, + val thresholdWaitTime: Int = 12, val pokestopThreshold: Int = 1500, val pokemonThreshold: Int = 1000 ) { diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt index 9e7e18d59..b9aa5764c 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/CatchOneNearbyPokemon.kt @@ -29,9 +29,17 @@ class CatchOneNearbyPokemon : Task { override fun run(bot: Bot, ctx: Context, settings: Settings) { // STOP WALKING - if (ctx.caughtPokemon.get() > settings.pokemonThreshold) { - Thread.sleep(3600 * 12000) + if (ctx.pokemonLockTime != 0L && bot.api.currentTimeMillis() > ctx.pokemonLockTime) + { + settings.catchPokemon = true ctx.caughtPokemon.set(0) + } + + if (ctx.caughtPokemon.get() > settings.pokemonThreshold) { + if (settings.catchPokemon) { + settings.catchPokemon = false + ctx.pokemonLockTime = bot.api.currentTimeMillis() + (3600 * settings.thresholdWaitTime.toLong()) + } return } diff --git a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt index e6277a941..e1eaa345e 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/tasks/ProcessPokestops.kt @@ -50,9 +50,17 @@ class ProcessPokestops(var pokestops: MutableCollection) : Task { if (startPokestop == null) startPokestop = sortedPokestops.first() - if (ctx.lootedPokestops.get() > settings.pokestopThreshold) { - Thread.sleep(3600 * 12000) + if (ctx.pokestopLockTime != 0L && bot.api.currentTimeMillis() > ctx.pokestopLockTime) + { + settings.lootPokestop = true ctx.lootedPokestops.set(0) + } + + if (ctx.lootedPokestops.get() > settings.pokestopThreshold) { + if (settings.lootPokestop) { + settings.lootPokestop = false + ctx.pokestopLockTime = bot.api.currentTimeMillis() + (3600 * settings.thresholdWaitTime.toLong()) + } return }