PokemonGoBot icon indicating copy to clipboard operation
PokemonGoBot copied to clipboard

[SUGGESTION] revise CatchablePokemon to use pokeball based on CP

Open cleftfairy opened this issue 10 years ago • 2 comments

Description: With the newest revision, CatchablePokemon uses different balls and raspberries randomly it seems. Not based on CP or other characteristics. Since CatchOneNearbyPokemon.kt knows the CP of the encountered pokemon before calling

result = catchablePokemon.catch( encounterResult.captureProbability, ctx.api.inventories.itemBag, settings.desiredCatchProbability)

it seems as if .catch could use the CP to choose balls based on that. I'm trying to make this work but my programming skills in this language are not yet up to par.

Version: 0.4.0

cleftfairy avatar Jul 24 '16 21:07 cleftfairy

Had it working in version 0.3 Sharing a code here, don't have a time to port it. Catching code:

                    val pokemonData = encounterResult.wildPokemon.pokemonData;
                    val usedPokeball = findPreferredBall(ctx, settings, pokemonData)

                    if(useBerry(settings, pokemonData) && hasBerry(ctx)) {
                        Log.green("Use Berry")
                        val result = catchablePokemon.useItem(ItemId.ITEM_RAZZ_BERRY);
                    }
                    val result = catchablePokemon.catchPokemon(usedPokeball)

Additional functions:

    fun hasItem(ctx: Context, id:ItemId):Boolean {
        var item = ctx.api.inventories.itemBag.getItem(id)
        if (item == null || item.count == 0) {
            return false
        }
        return true
    }

    fun hasBerry(ctx: Context) : Boolean {
        return hasItem(ctx, ItemId.ITEM_RAZZ_BERRY);
    }

    fun hasAnyBall(ctx: Context, settings: Settings):Boolean {
        for (pokeball in settings.pokeballItems) {
            if(hasItem(ctx, pokeball.key))
                return true
        }
        return false
    }

    fun findPreferredBall(ctx: Context, settings: Settings, pokemonData: PokemonDataOuterClass.PokemonData) : Pokeball? {

        try {
            var preferred_ball: ItemId? = null
            if(hasItem(ctx, ItemId.ITEM_POKE_BALL)) {
                preferred_ball = ItemId.ITEM_POKE_BALL
            }
            if(hasItem(ctx, ItemId.ITEM_GREAT_BALL) && (preferred_ball == null || pokemonData.cp >= settings.useGreatBallCP) ) {
                preferred_ball = ItemId.ITEM_GREAT_BALL
            }
            if(hasItem(ctx, ItemId.ITEM_ULTRA_BALL) && (preferred_ball == null || pokemonData.cp >= settings.useUltraBallCP) ) {
                preferred_ball = ItemId.ITEM_ULTRA_BALL
            }
            if(hasItem(ctx, ItemId.ITEM_MASTER_BALL) && (preferred_ball == null || pokemonData.cp >= settings.useMasterBallCP) ) {
                preferred_ball = ItemId.ITEM_MASTER_BALL
            }

            Log.green("Prefer to use ball ${preferred_ball}")

            if(preferred_ball != null) {
                return settings.pokeballItems.get(preferred_ball)
            }
        } catch (e: Exception) {
            throw e
        }
        return null
    }

    fun useBerry(settings: Settings, pokemonData: PokemonDataOuterClass.PokemonData) : Boolean {
        if(pokemonData.cp >= settings.useBerriesCP){
            return true;
        }
        return false;
    }

evaldasguogis avatar Jul 24 '16 21:07 evaldasguogis

Implemented since 0.4.2

jabbink avatar Jul 26 '16 22:07 jabbink