Skip to content

Commit

Permalink
Merge pull request #2548 from Codecamv/master
Browse files Browse the repository at this point in the history
Customizable throws
  • Loading branch information
BornSupercharged authored Aug 3, 2016
2 parents 7a1e93b + 423254f commit 289680a
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 2 deletions.
10 changes: 10 additions & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public interface ILogicSettings
double UseMasterBallBelowCatchProbability { get; }
double UseUltraBallBelowCatchProbability { get; }
double UseGreatBallBelowCatchProbability { get; }
bool EnableHumanizedThrows { get; }
int NiceThrowChance { get; }
int GreatThrowChance { get; }
int ExcellentThrowChance { get; }
int CurveThrowChance { get; }
double ForceGreatThrowOverIv { get; }
double ForceExcellentThrowOverIv { get; }
int ForceGreatThrowOverCp { get; }
int ForceExcellentThrowOverCp { get; }

int DelayBetweenPokemonCatch { get; }
bool AutomaticallyLevelUpPokemon { get; }
string LevelUpByCPorIv { get; }
Expand Down
28 changes: 28 additions & 0 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,25 @@ public class GlobalSettings
public double UseUltraBallBelowCatchProbability;
[DefaultValue(0.05)]
public double UseMasterBallBelowCatchProbability;
//customizable catch
[DefaultValue(false)]
public bool EnableHumanizedThrows;
[DefaultValue(40)]
public int NiceThrowChance;
[DefaultValue(30)]
public int GreatThrowChance;
[DefaultValue(10)]
public int ExcellentThrowChance;
[DefaultValue(90)]
public int CurveThrowChance;
[DefaultValue(90.00)]
public double ForceGreatThrowOverIv;
[DefaultValue(95.00)]
public double ForceExcellentThrowOverIv;
[DefaultValue(1000)]
public int ForceGreatThrowOverCp;
[DefaultValue(1500)]
public int ForceExcellentThrowOverCp;
//transfer
[DefaultValue(false)]
public bool TransferWeakPokemon;
Expand Down Expand Up @@ -750,6 +769,15 @@ public LogicSettings(GlobalSettings settings)
public double UseMasterBallBelowCatchProbability => _settings.UseMasterBallBelowCatchProbability;
public double UseUltraBallBelowCatchProbability => _settings.UseUltraBallBelowCatchProbability;
public double UseGreatBallBelowCatchProbability => _settings.UseGreatBallBelowCatchProbability;
public bool EnableHumanizedThrows => _settings.EnableHumanizedThrows;
public int NiceThrowChance => _settings.NiceThrowChance;
public int GreatThrowChance => _settings.GreatThrowChance;
public int ExcellentThrowChance => _settings.ExcellentThrowChance;
public int CurveThrowChance => _settings.CurveThrowChance;
public double ForceGreatThrowOverIv => _settings.ForceGreatThrowOverIv;
public double ForceExcellentThrowOverIv => _settings.ForceExcellentThrowOverIv;
public int ForceGreatThrowOverCp => _settings.ForceGreatThrowOverCp;
public int ForceExcellentThrowOverCp => _settings.ForceExcellentThrowOverCp;
public int DelayBetweenPokemonCatch => _settings.DelayBetweenPokemonCatch;
public int DelayBetweenPlayerActions => _settings.DelayBetweenPlayerActions;
public bool UsePokemonToNotCatchFilter => _settings.UsePokemonToNotCatchFilter;
Expand Down
67 changes: 65 additions & 2 deletions PoGo.NecroBot.Logic/Tasks/CatchPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@
using POGOProtos.Map.Pokemon;
using POGOProtos.Networking.Responses;
using System.Threading;
using PoGo.NecroBot.Logic.Logging;

#endregion

namespace PoGo.NecroBot.Logic.Tasks
{
public static class CatchPokemonTask
{
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)
{
Expand All @@ -28,7 +31,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
// If the encounter is null nothing will work below, so exit now
if (encounter == null) return;

float probability = encounter?.CaptureProbability?.CaptureProbability_[0];
float probability = encounter.CaptureProbability?.CaptureProbability_[0];

// Check for pokeballs before proceeding
var pokeball = await GetBestBall(session, encounter, probability);
Expand Down Expand Up @@ -94,14 +97,74 @@ encounter is EncounterResponse || encounter is IncenseEncounterResponse
return;
}

//default to excellent throw
var normalizedRecticleSize = 1.95;
//default spin
var spinModifier = 1.0;

//Humanized throws
if (session.LogicSettings.EnableHumanizedThrows)
{
//thresholds: https://gist.github.com/anonymous/077d6dea82d58b8febde54ae9729b1bf
var spinTxt = "Curve";
var hitTxt = "Excellent";
if (pokemonCp > session.LogicSettings.ForceExcellentThrowOverCp ||
pokemonIv > session.LogicSettings.ForceExcellentThrowOverIv)
{
normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.7) + 1.7;
}
else if (pokemonCp >= session.LogicSettings.ForceGreatThrowOverCp ||
pokemonIv >= session.LogicSettings.ForceGreatThrowOverIv)
{
normalizedRecticleSize = Random.NextDouble() * (1.95 - 1.3) + 1.3;
hitTxt = "Great";
}
else
{
var regularThrow = 100 - (session.LogicSettings.ExcellentThrowChance +
session.LogicSettings.GreatThrowChance +
session.LogicSettings.NiceThrowChance);
var rnd = Random.Next(1 , 101);

if (rnd <= regularThrow)
{
normalizedRecticleSize = Random.NextDouble() * (1 - 0.1) + 0.1;
hitTxt = "Ordinary";
}
else if (rnd <= regularThrow + session.LogicSettings.NiceThrowChance)
{
normalizedRecticleSize = Random.NextDouble() * (1.3 - 1) + 1;
hitTxt = "Nice";
}
else if (rnd <=
regularThrow + session.LogicSettings.NiceThrowChance +
session.LogicSettings.GreatThrowChance)
{
normalizedRecticleSize = Random.NextDouble() * (1.7 - 1.3) + 1.3;
hitTxt = "Great";
}

if (Random.NextDouble() * 100 > session.LogicSettings.CurveThrowChance)
{
spinModifier = 0.0;
spinTxt = "Straight";
}
}

//round to 2 decimals
normalizedRecticleSize = Math.Round(normalizedRecticleSize, 2);

Logger.Write($"(Threw ball) {hitTxt} hit. {spinTxt}-ball...", LogLevel.Debug);
}

caughtPokemonResponse =
await session.Client.Encounter.CatchPokemon(
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.EncounterId
: encounterId,
encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.SpawnPointId
: currentFortData.Id, pokeball);
: currentFortData.Id, pokeball, normalizedRecticleSize, spinModifier);

var lat = encounter is EncounterResponse || encounter is IncenseEncounterResponse
? pokemon.Latitude : currentFortData.Latitude;
Expand Down

0 comments on commit 289680a

Please sign in to comment.