Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to Enable/Disable Pokemon catching #298

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions PoGo.PokeMobBot.CLI/ConsoleEventListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ public void HandleEvent(NoPokeballEvent evt, ISession session)
LogLevel.Caught);
}

public void HandleEvent(CatchPokemonDisabledEvent evt, ISession session)
{
Logger.Write(session.Translation.GetTranslation(TranslationString.CatchPokemonDisabled, session.Translation.GetPokemonName(evt.Id)),
LogLevel.Warning);
}

public void HandleEvent(UseBerryEvent evt, ISession session)
{
Logger.Write(session.Translation.GetTranslation(TranslationString.UseBerry, evt.Count),
Expand Down
3 changes: 3 additions & 0 deletions PoGo.PokeMobBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public enum TranslationString
EventNoPokeballs,
CatchStatusAttempt,
CatchStatus,
CatchPokemonDisabled,
Candies,
UnhandledGpxData,
DisplayHighestsHeader,
Expand Down Expand Up @@ -189,6 +190,8 @@ public class Translation : ITranslation
"({0}) | {2}, Lvl: {3} | CP: ({4}/{5}) | IV: {6}% | Type: {1} | Chance: {7}% | Dist: {8}m | Used: {9} ({10} left) | XP: {11} | {12}"),
new KeyValuePair<TranslationString, string>(TranslationString.EventNoPokeballs,
"No Pokeballs - We missed a {0} with CP {1}"),
new KeyValuePair<TranslationString, string>(TranslationString.CatchPokemonDisabled,
"Catch Pokemon Disabled - We ignored a {0}"),
new KeyValuePair<TranslationString, string>(TranslationString.CatchStatusAttempt, "{0} Attempt #{1}"),
new KeyValuePair<TranslationString, string>(TranslationString.CatchStatus, "{0}"),
new KeyValuePair<TranslationString, string>(TranslationString.Candies, "Candies: {0}"),
Expand Down
13 changes: 13 additions & 0 deletions PoGo.PokeMobBot.Logic/Event/CatchPokemonDisabledEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#region using directives

using POGOProtos.Enums;

#endregion

namespace PoGo.PokeMobBot.Logic.Event
{
public class CatchPokemonDisabledEvent : IEvent
{
public PokemonId Id;
}
}
1 change: 1 addition & 0 deletions PoGo.PokeMobBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public interface ILogicSettings

//coords and movement
bool Teleport { get; }
bool CatchPokemon { get; }
double WalkingSpeedInKilometerPerHour { get; }
int MaxTravelDistanceInMeters { get; }
bool UseGpxPathing { get; }
Expand Down
1 change: 1 addition & 0 deletions PoGo.PokeMobBot.Logic/PoGo.PokeMobBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
<Compile Include="DataDumper\Dumper.cs" />
<Compile Include="Common\Translations.cs" />
<Compile Include="Event\DebugEvent.cs" />
<Compile Include="Event\CatchPokemonDisabledEvent.cs" />
<Compile Include="Event\UseLuckyEggMinPokemonEvent.cs" />
<Compile Include="Event\DisplayHighestsPokemonEvent.cs" />
<Compile Include="Event\EggHatchedEvent.cs" />
Expand Down
2 changes: 2 additions & 0 deletions PoGo.PokeMobBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ public class GlobalSettings
public int WebSocketPort = 14251;

//coords and movement
public bool CatchPokemon = true;
public bool Teleport = false;
public double DefaultLatitude = 40.785091;
public double DefaultLongitude = -73.968285;
Expand Down Expand Up @@ -704,6 +705,7 @@ public LogicSettings(GlobalSettings settings)
public int TotalAmountOfRevivesToKeep => _settings.TotalAmountOfRevivesToKeep;
public int TotalAmountOfMaxRevivesToKeep => _settings.TotalAmountOfRevivesToKeep;
public bool Teleport => _settings.Teleport;
public bool CatchPokemon => _settings.CatchPokemon;
public int DelayCatchIncensePokemon => _settings.DelayCatchIncensePokemon;
public int DelayCatchNearbyPokemon => _settings.DelayCatchNearbyPokemon;
public int DelayPositionCheckState => _settings.DelayPositionCheckState;
Expand Down
7 changes: 7 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/CatchIncensePokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
Message = session.Translation.GetTranslation(TranslationString.PokemonIgnoreFilter,session.Translation.GetPokemonName(pokemon.PokemonId))
});
}
else if (!session.LogicSettings.CatchPokemon)
{
session.EventDispatcher.Send(new CatchPokemonDisabledEvent
{
Id = pokemon.PokemonId
});
}
else
{
var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
Expand Down
7 changes: 7 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/CatchLurePokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ public static async Task Execute(ISession session, FortData currentFortData, Can
Message = session.Translation.GetTranslation(TranslationString.PokemonSkipped, session.Translation.GetPokemonName(pokemonId))
});
}
else if (!session.LogicSettings.CatchPokemon)
{
session.EventDispatcher.Send(new CatchPokemonDisabledEvent
{
Id = pokemonId
});
}
else
{
var encounterId = currentFortData.LureInfo.EncounterId;
Expand Down
77 changes: 44 additions & 33 deletions PoGo.PokeMobBot.Logic/Tasks/CatchNearbyPokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,50 +58,61 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
});
continue;
}

var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
await Task.Delay(distance > 100 ? 3000 : 500, cancellationToken);

var encounter =
await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId);

if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
else if (!session.LogicSettings.CatchPokemon)
{
await CatchPokemonTask.Execute(session, encounter, pokemon);
session.EventDispatcher.Send(new CatchPokemonDisabledEvent
{
Id = pokemon.PokemonId
});
}
else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
else
{
if (session.LogicSettings.TransferDuplicatePokemon)


var distance = LocationUtils.CalculateDistanceInMeters(session.Client.CurrentLatitude,
session.Client.CurrentLongitude, pokemon.Latitude, pokemon.Longitude);
await Task.Delay(distance > 100 ? 3000 : 500, cancellationToken);

var encounter =
await session.Client.Encounter.EncounterPokemon(pokemon.EncounterId, pokemon.SpawnPointId);

if (encounter.Status == EncounterResponse.Types.Status.EncounterSuccess)
{
session.EventDispatcher.Send(new WarnEvent
await CatchPokemonTask.Execute(session, encounter, pokemon);
}
else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
{
if (session.LogicSettings.TransferDuplicatePokemon)
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
});
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
});
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
else
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
});
}
else
{
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferManually)
Message =
session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
});
}
else
{
session.EventDispatcher.Send(new WarnEvent
{
Message =
session.Translation.GetTranslation(TranslationString.EncounterProblem, encounter.Status)
});
}
}

// If pokemon is not last pokemon in list, create delay between catches, else keep moving.
if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
{
if(session.LogicSettings.Teleport)
await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
else
await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
// If pokemon is not last pokemon in list, create delay between catches, else keep moving.
if (!Equals(pokemons.ElementAtOrDefault(pokemons.Count() - 1), pokemon))
{
if (session.LogicSettings.Teleport)
await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch);
else
await Task.Delay(session.LogicSettings.DelayBetweenPokemonCatch, cancellationToken);
}
}
}
}
Expand Down
Loading