Example #1
0
 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Ball"))
     {
         isCatching = false;
         if (ball.IsFree)
         {
             OnCatch?.Invoke();
             StartCoroutine(ResetPosition());
         }
     }
 }
Example #2
0
        private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon, Client client)
        {
            CatchPokemonResponse caughtPokemonResponse;

            do
            {
                if (encounter?.CaptureProbability.CaptureProbability_.First() < 0.40)
                {
                    _logger.Write("Using berry", LogLevel.INFO);
                    await _pokemonItems.UseBerry(pokemon.EncounterId, pokemon.SpawnPointId, client);
                }

                var pokeball = await _pokemonItems.GetBestBall(encounter?.WildPokemon, client.Inventory);

                await Task.Delay(1000);

                caughtPokemonResponse =
                    await client.Encounter.CatchPokemon(pokemon.EncounterId, pokemon.SpawnPointId, pokeball);

                await Task.Delay(500);
            } while (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchMissed ||
                     caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape);

            if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess)
            {
                var wildPokemon = encounter?.WildPokemon.PokemonData;
                if (wildPokemon != null)
                {
                    OnCatch?.Invoke(wildPokemon);
                    OnExperienceAwarded?.Invoke(caughtPokemonResponse.CaptureAward.Xp.Sum(x => x));

                    var iv = wildPokemon.IndividualAttack + wildPokemon.IndividualDefense +
                             wildPokemon.IndividualStamina;

                    _logger.Write($"Gotcha! {pokemon.PokemonId} - CP: {wildPokemon.Cp}, " +
                                  $"IV {iv}", LogLevel.SUCC);

                    if (_settings.Settings.QuickTransfer)
                    {
                        if (_pokemonHelper.ShouldTranferPokemon(wildPokemon, _settings.Settings.IvPercentageDiscart,
                                                                _settings.Settings.KeepMinCp, _settings.Settings.IvOverCp))
                        {
                            await _transferPokemonHandler.TransferPokemon(client, wildPokemon, true);
                        }
                    }
                }
                else
                {
                    _logger.Write($"Caught status: {caughtPokemonResponse.Status}", LogLevel.WARN);
                }
            }
        }