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

Enhanced pokeball-management for sniping #1428

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ public enum TranslationString
MissingCredentialsPtc,
SnipeScan,
NoPokemonToSnipe,
NotEnoughPokeballsToSnipe,
}

public class Translation : ITranslation
Expand Down Expand Up @@ -224,6 +225,7 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(Common.TranslationString.MissingCredentialsPtc, "You need to fill out PtcUsername and PtcPassword in auth.json!"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.SnipeScan, "[Sniper] Scanning for Snipeable Pokemon at {0}..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.NoPokemonToSnipe, "[Sniper] No Pokemon found to snipe!"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.NotEnoughPokeballsToSnipe, "Not enough Pokeballs to start sniping! ({0}/{1})"),
};

public string GetTranslation(TranslationString translationString, params object[] data)
Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public interface ILogicSettings
string GeneralConfigPath { get; }
bool SnipeAtPokestops { get; }
int MinPokeballsToSnipe { get; }
int MinPokeballsWhileSnipe { get; }
string SnipeLocationServer { get; }
int SnipeLocationServerPort { get; }
bool UseSnipeLocationServer { get; }
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public class GlobalSettings
public bool StartupWelcomeDelay = true;
public bool SnipeAtPokestops = false;
public int MinPokeballsToSnipe = 20;
public int MinPokeballsWhileSnipe = 0;
public string SnipeLocationServer = "localhost";
public int SnipeLocationServerPort = 16969;
public bool UseSnipeLocationServer = false;
Expand Down Expand Up @@ -595,6 +596,7 @@ public LogicSettings(GlobalSettings settings)
public bool StartupWelcomeDelay => _settings.StartupWelcomeDelay;
public bool SnipeAtPokestops => _settings.SnipeAtPokestops;
public int MinPokeballsToSnipe => _settings.MinPokeballsToSnipe;
public int MinPokeballsWhileSnipe => _settings.MinPokeballsWhileSnipe;
public SnipeSettings PokemonToSnipe => _settings.PokemonToSnipe;
public string SnipeLocationServer => _settings.SnipeLocationServer;
public int SnipeLocationServerPort => _settings.SnipeLocationServerPort;
Expand Down
31 changes: 23 additions & 8 deletions PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
}
}
}
else

else if (await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsToSnipe, session, cancellationToken))
{
foreach (var location in session.LogicSettings.PokemonToSnipe.Locations)
{
session.EventDispatcher.Send(new SnipeScanEvent() { Bounds = location });
Expand All @@ -264,12 +264,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
lastSnipe = DateTime.Now;
foreach (var pokemonLocation in locationsToSnipe)
{
var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall);
var greatBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall);
var ultraBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall);
var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall);

if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount < session.LogicSettings.MinPokeballsToSnipe)
if (!await CheckPokeballsToSnipe(session.LogicSettings.MinPokeballsWhileSnipe + 1, session, cancellationToken))
return;

locsVisited.Add(pokemonLocation);
Expand All @@ -285,6 +280,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
});
}
}
}
}

}
Expand Down Expand Up @@ -317,5 +313,24 @@ private static ScanResult SnipeScanForPokemon(Location location)
}
return scanResult;
}

public static async Task<bool> CheckPokeballsToSnipe(int minPokeballs, ISession session, CancellationToken cancellationToken)
{
var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall);
pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall);
pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall);
pokeBallsCount += await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall);

if (pokeBallsCount < minPokeballs)
{
session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(Common.TranslationString.NotEnoughPokeballsToSnipe, pokeBallsCount, minPokeballs)
});
return false;
}

return true;
}
}
}