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

Automatically power up your highest IV pokemon #967

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
4 changes: 4 additions & 0 deletions config.properties.template
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ export=
# Initial map size (S2 tiles) to fetch (max. 9: ~3*3km area)
initial_map_size=9

auto_power_up=false
power_up_iv_threshold=90
power_up_only_best=true

# List of pokemon names
#MISSINGNO
#BULBASAUR
Expand Down
3 changes: 3 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/Bot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ class Bot(val api: PokemonGo, val settings: Settings) {
val release = ReleasePokemon()
val hatchEggs = HatchEggs()
val export = Export()
val powerUp = PowerUp()

if (settings.export.length > 0)
task(export)
Expand Down Expand Up @@ -137,6 +138,8 @@ class Bot(val api: PokemonGo, val settings: Settings) {
task(hatchEggs)
if (settings.export.length > 0)
task(export)
if (settings.autoPowerUp)
task(powerUp)
}

runLoop(TimeUnit.SECONDS.toMillis(5), "BotLoop") {
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class SettingsParser(val properties: Properties) {

transferIvThreshold = getPropertyIfSet("Minimum IV percentage to keep a pokemon", "transfer_iv_threshold", defaults.transferIvThreshold, String::toInt),

autoPowerUp = getPropertyIfSet("Automatically powerup pokemon that meet the threshold", "auto_power_up", defaults.autoPowerUp, String::toBoolean),
powerUpIvThreshold = getPropertyIfSet("Minimum IV percentage to powerup a pokemon", "power_up_iv_threshold", defaults.transferIvThreshold, String::toInt),
powerUpOnlyBest = getPropertyIfSet("Power up only the best of each species", "power_up_only_best", defaults.powerUpOnlyBest, String::toBoolean),

ignoredPokemon = getPropertyIfSet("Never transfer these Pokemon", "ignored_pokemon", defaults.ignoredPokemon.map { it.name }.joinToString(","), String::toString).split(",").filter { it.isNotBlank() }.map { PokemonId.valueOf(it) },

obligatoryTransfer = getPropertyIfSet("list of pokemon you always want to transfer regardless of CP", "obligatory_transfer", defaults.obligatoryTransfer.map { it.name }.joinToString(","), String::toString).split(",").filter { it.isNotBlank() }.map { PokemonId.valueOf(it) },
Expand Down Expand Up @@ -211,6 +215,10 @@ data class Settings(
val transferIvThreshold: Int = 80,
val ignoredPokemon: List<PokemonId> = listOf(PokemonId.EEVEE, PokemonId.MEWTWO, PokemonId.CHARMANDER),

val autoPowerUp: Boolean = false,
val powerUpIvThreshold: Int = 90,
val powerUpOnlyBest: Boolean = true,

val obligatoryTransfer: List<PokemonId> = listOf(PokemonId.DODUO, PokemonId.RATTATA, PokemonId.CATERPIE, PokemonId.PIDGEY),

val export: String = "",
Expand Down
54 changes: 54 additions & 0 deletions src/main/kotlin/ink/abb/pogo/scraper/tasks/PowerUp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package ink.abb.pogo.scraper.tasks

import com.pokegoapi.api.player.PlayerProfile
import com.pokegoapi.api.pokemon.Pokemon
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.pokemon.getIvPercentage

class PowerUp : Task {
override fun run(bot: Bot, ctx: Context, settings: Settings) {
// TODO exclude those where a better poke in the same family exists that be evolved to here
var eligiblePokemon = ctx.api.cachedInventories.pokebank.pokemons.filter {
it.getIvPercentage() >= settings.powerUpIvThreshold &&
it.candiesToEvolve == 0
}.sortedByDescending {
it.ivRatio
}

if (settings.powerUpOnlyBest) {
eligiblePokemon = eligiblePokemon.groupBy {
it.pokemonId
}.flatMap {
listOf(it.value[0])
}
}

val poke = eligiblePokemon.filter { it.level < ctx.profile.stats.level + 2 }[0]
Log.blue("Attempting to PowerUp ${poke.pokemonId.name} IV ${poke.getIvPercentage()}%")
// Use stardust on best possible only
powerUp(poke, ctx)
}

fun powerUp(pokemon: Pokemon, ctx: Context) {
while (pokemon.level < ctx.profile.stats.level + 2) {
Log.red("${ctx.api.cachedInventories.candyjar.getCandies(pokemon.pokemonFamily)}/${pokemon.candyCostsForPowerup} candy")
Log.red("${ctx.profile.currencies.get(PlayerProfile.Currency.STARDUST)!!}/${pokemon.stardustCostsForPowerup} stardust")
if (pokemon.candyCostsForPowerup <= ctx.api.cachedInventories.candyjar.getCandies(pokemon.pokemonFamily) &&
pokemon.stardustCostsForPowerup <= ctx.profile.currencies.get(PlayerProfile.Currency.STARDUST)!!) {
Log.blue("PowerUp ${pokemon.pokemonId.name} IV ${pokemon.getIvPercentage()}% ${pokemon.cp} cp -> ${pokemon.cpAfterPowerup}")
val powerUpCostCandies = pokemon.candyCostsForPowerup
val powerUpCostStardust = pokemon.stardustCostsForPowerup
pokemon.powerUp()
ctx.api.cachedInventories.candyjar.removeCandy(pokemon.pokemonFamily, powerUpCostCandies)
ctx.api.playerProfile.currencies.put(PlayerProfile.Currency.STARDUST, ctx.profile.currencies.get(PlayerProfile.Currency.STARDUST)!! - powerUpCostStardust)
} else {
return
}
}
}
}