diff --git a/config.properties.template b/config.properties.template index f3b899c5b..ef8d21d38 100644 --- a/config.properties.template +++ b/config.properties.template @@ -202,6 +202,15 @@ 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 + +# 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 ef802ed15..2968a0946 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Context.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Context.kt @@ -39,6 +39,12 @@ 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), + + 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 f30c630b0..eb477937a 100644 --- a/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt +++ b/src/main/kotlin/ink/abb/pogo/scraper/Settings.kt @@ -132,7 +132,13 @@ 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), + + thresholdWaitTime = getPropertyIfSet("Threshold delay time in hours", "threshold_wait_time", defaults.thresholdWaitTime, String::toInt) ) } @@ -235,7 +241,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, @@ -268,7 +274,11 @@ data class Settings( val waitChance: Double = 0.0, val waitTimeMin: Int = 0, - val waitTimeMax: Int = 0 + val waitTimeMax: Int = 0, + + val thresholdWaitTime: Int = 12, + 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 fc8929a41..d9225b016 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,21 @@ import ink.abb.pogo.scraper.util.pokemon.shouldTransfer class CatchOneNearbyPokemon : Task { override fun run(bot: Bot, ctx: Context, settings: Settings) { // STOP WALKING + + 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 + } + ctx.pauseWalking.set(true) val pokemon = ctx.api.map.getCatchablePokemon(ctx.blacklistedEncounters) @@ -96,6 +111,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..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,6 +50,20 @@ class ProcessPokestops(var pokestops: MutableCollection) : Task { if (startPokestop == null) startPokestop = sortedPokestops.first() + 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 + } + if (settings.lootPokestop) { val loot = LootOneNearbyPokestop(sortedPokestops, lootTimeouts) try {