Skip to content

Commit

Permalink
Merge pull request #3243 from cawk/master
Browse files Browse the repository at this point in the history
Use berry when pokemon escape and choose how many berries to use per pokemon
  • Loading branch information
GrimmGringo committed Aug 8, 2016
2 parents 436787a + e19e897 commit 53dae8e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public interface ILogicSettings

int GetMinStarDustForLevelUp { get; }
bool UseLuckyEggConstantly { get; }
int MaxBerriesToUsePerPokemon { get; }
bool UseIncenseConstantly { get; }
int UseBerriesMinCp { get; }
float UseBerriesMinIv { get; }
Expand Down
4 changes: 4 additions & 0 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,9 @@ public class GlobalSettings
public int AmountOfPokemonToDisplayOnStart;
[DefaultValue(true)]
public bool DetailedCountsBeforeRecycling;

[DefaultValue(3)]
public int MaxBerriesToUsePerPokemon;
//pokemon
[DefaultValue(true)]
public bool CatchPokemon;
Expand Down Expand Up @@ -1204,6 +1207,7 @@ public LogicSettings(GlobalSettings settings)
public bool CatchPokemon => _settings.CatchPokemon;
public bool TransferWeakPokemon => _settings.TransferWeakPokemon;
public bool DisableHumanWalking => _settings.DisableHumanWalking;
public int MaxBerriesToUsePerPokemon => _settings.MaxBerriesToUsePerPokemon;
public float KeepMinIvPercentage => _settings.KeepMinIvPercentage;
public string KeepMinOperator => _settings.KeepMinOperator;
public int KeepMinCp => _settings.KeepMinCp;
Expand Down
54 changes: 31 additions & 23 deletions PoGo.NecroBot.Logic/Tasks/CatchPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ namespace PoGo.NecroBot.Logic.Tasks
{
public static class CatchPokemonTask
{
public static int AmountOfBerries;
private static Random Random => new Random((int)DateTime.Now.Ticks);

public static async Task Execute(ISession session, CancellationToken cancellationToken, dynamic encounter, MapPokemon pokemon,
FortData currentFortData = null, ulong encounterId = 0)
{
AmountOfBerries = 0;
cancellationToken.ThrowIfCancellationRequested();

// If the encounter is null nothing will work below, so exit now
Expand All @@ -45,26 +47,6 @@ public static class CatchPokemonTask
? encounter.WildPokemon?.PokemonData
: encounter?.PokemonData);

// Determine whether to use berries or not
if ((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") &&
pokemonIv >= session.LogicSettings.UseBerriesMinIv &&
pokemonCp >= session.LogicSettings.UseBerriesMinCp &&
probability < session.LogicSettings.UseBerriesBelowCatchProbability) ||
(session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && (
pokemonIv >= session.LogicSettings.UseBerriesMinIv ||
pokemonCp >= session.LogicSettings.UseBerriesMinCp ||
probability < session.LogicSettings.UseBerriesBelowCatchProbability)))
{
await
UseBerry(session,
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.EncounterId
: encounterId,
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.SpawnPointId
: currentFortData?.Id);
}

// Calculate distance away
var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
session.Client.CurrentLongitude,
Expand All @@ -79,7 +61,7 @@ public static class CatchPokemonTask
var attemptCounter = 1;
do
{
if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 &&
if ((session.LogicSettings.MaxPokeballsPerPokemon > 0 &&
attemptCounter > session.LogicSettings.MaxPokeballsPerPokemon))
break;

Expand All @@ -97,6 +79,32 @@ public static class CatchPokemonTask
return;
}

// Determine whether to use berries or not
if ((session.LogicSettings.UseBerriesOperator.ToLower().Equals("and") &&
pokemonIv >= session.LogicSettings.UseBerriesMinIv &&
pokemonCp >= session.LogicSettings.UseBerriesMinCp &&
probability < session.LogicSettings.UseBerriesBelowCatchProbability) ||
(session.LogicSettings.UseBerriesOperator.ToLower().Equals("or") && (
pokemonIv >= session.LogicSettings.UseBerriesMinIv ||
pokemonCp >= session.LogicSettings.UseBerriesMinCp ||
probability < session.LogicSettings.UseBerriesBelowCatchProbability)))
{

AmountOfBerries++;
if (AmountOfBerries < session.LogicSettings.MaxBerriesToUsePerPokemon)
{
await
UseBerry(session,
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.EncounterId
: encounterId,
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.SpawnPointId
: currentFortData?.Id);
}

}

//default to excellent throw
var normalizedRecticleSize = 1.95;
//default spin
Expand Down Expand Up @@ -124,7 +132,7 @@ public static class CatchPokemonTask
var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance +
session.LogicSettings.GreatThrowChance +
session.LogicSettings.NiceThrowChance);
var rnd = Random.Next(1 , 101);
var rnd = Random.Next(1, 101);

if (rnd <= regularThrow)
{
Expand Down Expand Up @@ -312,7 +320,7 @@ private static async Task UseBerry(ISession session, ulong encounterId, string s

await session.Client.Encounter.UseCaptureItem(encounterId, ItemId.ItemRazzBerry, spawnPointId);
berry.Count -= 1;
session.EventDispatcher.Send(new UseBerryEvent {BerryType = ItemId.ItemRazzBerry, Count = berry.Count});
session.EventDispatcher.Send(new UseBerryEvent { BerryType = ItemId.ItemRazzBerry, Count = berry.Count });
}
}
}

0 comments on commit 53dae8e

Please sign in to comment.