Skip to content

Commit

Permalink
Merge pull request #1578 from simplyphp/master
Browse files Browse the repository at this point in the history
Resolved issue with default value of zero for a couple config values
  • Loading branch information
NecronomiconCoding authored Jul 31, 2016
2 parents ff6337f + 530b564 commit e6e8ed4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
54 changes: 54 additions & 0 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
using PokemonGo.RocketAPI.Enums;
using POGOProtos.Enums;
using POGOProtos.Inventory.Item;
using System.ComponentModel;
using System.Reflection;
using System.Collections;

#endregion

Expand Down Expand Up @@ -437,6 +440,27 @@ public static GlobalSettings Load(string path)
jsonSettings.DefaultValueHandling = DefaultValueHandling.Populate;

settings = JsonConvert.DeserializeObject<GlobalSettings>(input, jsonSettings);

// One day we might be able to better do this so its automatic
/*
FieldInfo[] fi = typeof(GlobalSettings).GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach (FieldInfo info in fi)
{
if (info.GetValue(Default) is int || info.GetValue(Default) is bool ||
info.GetValue(Default) is float)
{
}
if (info.GetValue(Default) is double)
{
Logger.Write($"{info.Name}={info.GetValue(Default)}", LogLevel.Error);
Type type = settings.GetType();
PropertyInfo propertyInfo = type.GetProperty(info.Name, BindingFlags.Instance | BindingFlags.Public);
propertyInfo.SetValue(settings, info.GetValue(Default));
}
}
*/
}
catch (JsonReaderException exception)
{
Expand All @@ -449,6 +473,21 @@ public static GlobalSettings Load(string path)
settings = new GlobalSettings();
}

if (settings.DefaultAltitude <= 0)
{
settings.DefaultAltitude = Default.DefaultAltitude;
}

if (settings.DefaultLatitude <= 0)
{
settings.DefaultLatitude = Default.DefaultLatitude;
}

if (settings.DefaultLongitude <= 0)
{
settings.DefaultLongitude = Default.DefaultLongitude;
}

if (settings.WebSocketPort == 0)
{
settings.WebSocketPort = 14251;
Expand All @@ -469,6 +508,21 @@ public static GlobalSettings Load(string path)
settings.SnipeLocationServer = Default.SnipeLocationServer;
}

if (settings.SnipingScanOffset <= 0)
{
settings.SnipingScanOffset = Default.SnipingScanOffset;
}

if (settings.RecycleInventoryAtUsagePercentage <= 0)
{
settings.RecycleInventoryAtUsagePercentage = Default.RecycleInventoryAtUsagePercentage;
}

if (settings.WalkingSpeedInKilometerPerHour <= 0)
{
settings.WalkingSpeedInKilometerPerHour = Default.WalkingSpeedInKilometerPerHour;
}

settings.ProfilePath = profilePath;
settings.ProfileConfigPath = profileConfigPath;
settings.GeneralConfigPath = Path.Combine(Directory.GetCurrentDirectory(), "config");
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ private static ScanResult SnipeScanForPokemon(ISession session, Location locatio

var offset = session.LogicSettings.SnipingScanOffset;
// 0.003 = half a mile; maximum 0.06 is 10 miles
if (offset<0.001 || offset>0.06) offset=0.003;
if (offset<0.001) offset=0.003;
if (offset>0.06) offset = 0.06;

var bound_lower_left_lat = location.Latitude - offset;
var bound_lower_left_lng = location.Longitude - offset;
Expand Down

0 comments on commit e6e8ed4

Please sign in to comment.