Skip to content

Commit

Permalink
Merged in changes from master
Browse files Browse the repository at this point in the history
  • Loading branch information
kaeus committed Jul 26, 2016
2 parents 8ffb13c + 4ad24b5 commit f8303db
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
2 changes: 1 addition & 1 deletion PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private static void Main()

machine.SetFailureState(new LoginState());

GlobalSettings settings = GlobalSettings.Load("\\configs\\config.json");
GlobalSettings settings = GlobalSettings.Load("\\config\\config.json");

var context = new Context(new ClientSettings(settings), new LogicSettings(settings));
context.Client.Login.GoogleDeviceCodeEvent += LoginWithGoogle;
Expand Down
28 changes: 14 additions & 14 deletions PoGo.NecroBot.CLI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ namespace PoGo.NecroBot.CLI
{
internal class AuthSettings
{
//Default Auth Settings
public AuthType AuthType = AuthType.Google;
public string GoogleRefreshToken = "";
public string PtcPassword = "username2";
public string PtcUsername = "pw";

[JsonIgnore]
private string _filePath;
private string FilePath;

public void Load(string path)
{
_filePath = path;
FilePath = path;

if (File.Exists(_filePath))
if (File.Exists(FilePath))
{
var input = File.ReadAllText(_filePath);
//if the file exists, load the settings
var input = File.ReadAllText(FilePath);

JsonSerializerSettings settings = new JsonSerializerSettings();
settings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
Expand All @@ -43,7 +43,7 @@ public void Load(string path)
}
else
{
Save(_filePath);
Save(FilePath);
}
}

Expand All @@ -62,9 +62,9 @@ public void Save(string path)

public void Save()
{
if(!string.IsNullOrEmpty(_filePath))
if(!string.IsNullOrEmpty(FilePath))
{
Save(_filePath);
Save(FilePath);
}
}
}
Expand All @@ -73,9 +73,6 @@ public class GlobalSettings
{
public static GlobalSettings Default => new GlobalSettings();

[JsonIgnore]
internal AuthSettings Auth = new AuthSettings();

private static string GetAuthPath(string path)
{
var fullPath = Directory.GetCurrentDirectory() + path;
Expand All @@ -92,6 +89,7 @@ public static GlobalSettings Load(string path)
GlobalSettings settings = null;
if (File.Exists(fullPath))
{
//if the file exists, load the settings
var input = File.ReadAllText(fullPath);

JsonSerializerSettings jsonSettings = new JsonSerializerSettings();
Expand Down Expand Up @@ -125,7 +123,6 @@ public void Save(string path)
File.WriteAllText(fullPath, output);
}

//Default Global Settings
public double DefaultAltitude = 10;
public double DefaultLatitude = 52.379189;
public double DefaultLongitude = 4.899431;
Expand All @@ -146,6 +143,9 @@ public void Save(string path)
public bool UsePokemonToNotCatchFilter = false;
public double WalkingSpeedInKilometerPerHour = 50;
public bool RenameAboveIv = false;

[JsonIgnore]
internal AuthSettings Auth = new AuthSettings();

public List<KeyValuePair<ItemId, int>> ItemRecycleFilter = new List<KeyValuePair<ItemId, int>>
{
Expand Down Expand Up @@ -209,7 +209,7 @@ public void Save(string path)

public class ClientSettings : ISettings
{
private readonly GlobalSettings _settings;
private GlobalSettings _settings;

public ClientSettings(GlobalSettings settings)
{
Expand Down Expand Up @@ -239,7 +239,7 @@ public string GoogleRefreshToken

public class LogicSettings : ILogicSettings
{
private readonly GlobalSettings _settings;
private GlobalSettings _settings;

public LogicSettings(GlobalSettings settings)
{
Expand Down
16 changes: 13 additions & 3 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,9 +209,19 @@ public async Task<IEnumerable<PlayerStats>> GetPlayerStats()
public async Task<IEnumerable<PokemonFamily>> GetPokemonFamilies()
{
var inventory = await GetCachedInventory();
return
inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.PokemonFamily)
.Where(p => p != null && p.FamilyId != PokemonFamilyId.FamilyUnset);

var families = from item in inventory.InventoryDelta.InventoryItems
where item.InventoryItemData?.PokemonFamily != null
where item.InventoryItemData?.PokemonFamily.FamilyId != PokemonFamilyId.FamilyUnset
group item by item.InventoryItemData?.PokemonFamily.FamilyId into family
select new PokemonFamily
{
FamilyId = family.First().InventoryItemData.PokemonFamily.FamilyId,
Candy = family.First().InventoryItemData.PokemonFamily.Candy
};


return families;
}

public async Task<IEnumerable<PokemonData>> GetPokemons()
Expand Down
9 changes: 8 additions & 1 deletion PoGo.NecroBot.Logic/State/LoginState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ public IState Execute(Context ctx, StateMachine machine)
switch (ctx.Settings.AuthType)
{
case AuthType.Ptc:
ctx.Client.Login.DoPtcLogin(ctx.Settings.PtcUsername, ctx.Settings.PtcPassword).Wait();
try
{
ctx.Client.Login.DoPtcLogin(ctx.Settings.PtcUsername, ctx.Settings.PtcPassword).Wait();
}
catch (System.AggregateException ae)
{
throw ae.Flatten().InnerException;
}
break;
case AuthType.Google:
ctx.Client.Login.DoGoogleLogin().Wait();
Expand Down
15 changes: 11 additions & 4 deletions PoGo.NecroBot.Logic/Tasks/CatchPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,19 @@ public static void Execute(Context ctx, StateMachine machine, EncounterResponse
var pokemonSettings = ctx.Inventory.GetPokemonSettings().Result;
var pokemonFamilies = ctx.Inventory.GetPokemonFamilies().Result;

var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId);
var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);
var setting = pokemonSettings.FirstOrDefault(q => q.PokemonId == pokemon.PokemonId);
var family = pokemonFamilies.FirstOrDefault(q => q.FamilyId == setting.FamilyId);

family.Candy += 3;
if (family != null)
{
family.Candy += caughtPokemonResponse.CaptureAward.Candy.Sum();

evt.FamilyCandies = family.Candy;
evt.FamilyCandies = family.Candy;
}
else
{
evt.FamilyCandies = caughtPokemonResponse.CaptureAward.Candy.Sum();
}
}


Expand Down

0 comments on commit f8303db

Please sign in to comment.