Skip to content
This repository was archived by the owner on Jul 22, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 4 additions & 1 deletion src/main/kotlin/ink/abb/pogo/scraper/Context.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ data class Context(

val walking: AtomicBoolean = AtomicBoolean(false),

val pauseWalking: AtomicBoolean = AtomicBoolean(false)
val pauseWalking: AtomicBoolean = AtomicBoolean(false),

val snipeLat: AtomicDouble = AtomicDouble(0.0),
val snipeLong: AtomicDouble = AtomicDouble(0.0),
val snipeName: String = ""
)
138 changes: 138 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/SnipePokemon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**
* Pokemon Go Bot Copyright (C) 2016 PokemonGoBot-authors (see authors.md for more information)
* This program comes with ABSOLUTELY NO WARRANTY;
* This is free software, and you are welcome to redistribute it under certain conditions.
*
* For more information, refer to the LICENSE file in this repositories root directory
*/

package ink.abb.pogo.scraper.tasks

import POGOProtos.Networking.Responses.CatchPokemonResponseOuterClass.CatchPokemonResponse
import POGOProtos.Networking.Responses.EncounterResponseOuterClass.EncounterResponse.Status
import com.pokegoapi.api.inventory.Pokeball
import com.pokegoapi.api.map.pokemon.encounter.DiskEncounterResult
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.cachedInventories
import ink.abb.pogo.scraper.util.inventory.hasPokeballs
import ink.abb.pogo.scraper.util.map.getCatchablePokemon
import ink.abb.pogo.scraper.util.pokemon.catch
import ink.abb.pogo.scraper.util.pokemon.getIvPercentage
import ink.abb.pogo.scraper.util.pokemon.getStatsFormatted
import ink.abb.pogo.scraper.util.pokemon.shouldTransfer

class SnipePokemon : Task {
override fun run(bot: Bot, ctx: Context, settings: Settings) {
// STOP WALKING
ctx.pauseWalking.set(true)
val hasPokeballs = ctx.api.cachedInventories.itemBag.hasPokeballs()
if (!hasPokeballs) {
ctx.pauseWalking.set(false)
return
}

ctx.api.setLocation(ctx.snipeLat.get(), ctx.snipeLong.get(), 0.0)
val pokemon = ctx.api.map.getCatchablePokemon(ctx.blacklistedEncounters)

val catchablePokemon = pokemon.find { it.pokemonId.toString().toLowerCase().equals(ctx.snipeName.toLowerCase()) }

/*Pokeball.values().forEach {
Log.yellow("${it.ballType}: ${ctx.api.cachedInventories.itemBag.getItem(it.ballType).count}")
}*/



if (null != catchablePokemon) {
if (settings.obligatoryTransfer.contains(catchablePokemon.pokemonId) && settings.desiredCatchProbabilityUnwanted == -1.0) {
ctx.blacklistedEncounters.add(catchablePokemon.encounterId)
Log.normal("Found pokemon ${catchablePokemon.pokemonId}; blacklisting because it's unwanted")
ctx.pauseWalking.set(false)
return
}
Log.green("Found pokemon ${catchablePokemon.pokemonId}")
ctx.api.setLocation(ctx.snipeLat.get(), ctx.snipeLong.get(), 0.0)

val encounterResult = catchablePokemon.encounterPokemon()
val wasFromLure = encounterResult is DiskEncounterResult
if (encounterResult.wasSuccessful()) {
val pokemonData = encounterResult.pokemonData
Log.green("Encountered pokemon ${catchablePokemon.pokemonId} " +
"with CP ${pokemonData.cp} and IV ${pokemonData.getIvPercentage()}%")
ctx.api.setLocation(ctx.lat.get(), ctx.lng.get(), 0.0)
val (shouldRelease, reason) = pokemonData.shouldTransfer(settings)
val desiredCatchProbability = if (shouldRelease) {
Log.yellow("Using desired_catch_probability_unwanted because $reason")
settings.desiredCatchProbabilityUnwanted
} else {
settings.desiredCatchProbability
}
if (desiredCatchProbability == -1.0) {
ctx.blacklistedEncounters.add(catchablePokemon.encounterId)
Log.normal("CP/IV of encountered pokemon ${catchablePokemon.pokemonId} turns out to be too low; blacklisting encounter")
ctx.pauseWalking.set(false)
return
}
val result = catchablePokemon.catch(
encounterResult.captureProbability,
ctx.api.cachedInventories.itemBag,
desiredCatchProbability,
settings.alwaysCurve,
!settings.neverUseBerries,
-1)

if (result == null) {
// prevent trying it in the next iteration
ctx.blacklistedEncounters.add(catchablePokemon.encounterId)
Log.red("No Pokeballs in your inventory; blacklisting Pokemon")
ctx.pauseWalking.set(false)
return
}

// TODO: temp fix for server timing issues regarding GetMapObjects
ctx.blacklistedEncounters.add(catchablePokemon.encounterId)
if (result.status == CatchPokemonResponse.CatchStatus.CATCH_SUCCESS) {
ctx.pokemonStats.first.andIncrement
if (wasFromLure) {
ctx.luredPokemonStats.andIncrement
}
val iv = (pokemonData.individualAttack + pokemonData.individualDefense + pokemonData.individualStamina) * 100 / 45
var message = "Caught a ${catchablePokemon.pokemonId} " +
"with CP ${pokemonData.cp} and IV $iv%"
message += "\r\n ${pokemonData.getStatsFormatted()}"
if (settings.displayIfPokemonFromLure) {
if (encounterResult is DiskEncounterResult)
message += " (lured pokemon) "
else
message += " (wild pokemon) "
}
if (settings.displayPokemonCatchRewards)
message += ": [${result.xpList.sum()}x XP, ${result.candyList.sum()}x " +
"Candy, ${result.stardustList.sum()}x Stardust]"
Log.cyan(message)

ctx.server.newPokemon(catchablePokemon.latitude, catchablePokemon.longitude, pokemonData)
ctx.server.sendProfile()
} else {
Log.red("Capture of ${catchablePokemon.pokemonId} failed with status : ${result.status}")
if (result.status == CatchPokemonResponse.CatchStatus.CATCH_ERROR) {
Log.red("Blacklisting pokemon to prevent infinite loop")
}
}
} else {
Log.red("Encounter failed with result: ${encounterResult.status}")
if (encounterResult.status == Status.POKEMON_INVENTORY_FULL) {
Log.red("Disabling catching of Pokemon")

ctx.pokemonInventoryFullStatus.second.set(true)

settings.catchPokemon = false
}
}
}
ctx.pauseWalking.set(false)
}
}