Skip to content

Commit

Permalink
Merge pull request Necrobot-Private#84 from Necrobot-Private/master
Browse files Browse the repository at this point in the history
v1.0.0.96
  • Loading branch information
Furtif committed Feb 8, 2017
2 parents b732203 + 141c242 commit a95dfe0
Show file tree
Hide file tree
Showing 19 changed files with 548 additions and 82 deletions.
4 changes: 2 additions & 2 deletions PoGo.NecroBot.CLI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// [assembly: AssemblyVersion1("0.9.9.5")]


[assembly: AssemblyVersion("1.0.0.95")]
[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.95")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]

6 changes: 3 additions & 3 deletions PoGo.NecroBot.GUI/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.0.95")]
// [assembly: AssemblyVersion("1.0.0.96")]


[assembly: AssemblyVersion("1.0.0.95")]
[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.95")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]
26 changes: 24 additions & 2 deletions PoGo.NecroBot.Logic/Model/Settings/BaseConfig.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using System.ComponentModel;
using POGOProtos.Enums;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;

namespace PoGo.NecroBot.Logic.Model.Settings
Expand All @@ -11,8 +14,27 @@ public BaseConfig()
foreach (PropertyInfo prop in props)
{
var d = prop.GetCustomAttribute<DefaultValueAttribute>();

if (d != null)
prop.SetValue(this, d.Value);
{

if (prop.PropertyType == typeof(List<PokemonId>))
{
var arr = d.Value.ToString().Split(new char[] { ';' });
var list = new List<PokemonId>();
foreach (var pname in arr)
{
PokemonId pi = PokemonId.Missingno;
if (Enum.TryParse<PokemonId>(pname, true, out pi))
{
list.Add(pi);
}
}
prop.SetValue(this, list);
}
else
prop.SetValue(this, d.Value);
}
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions PoGo.NecroBot.Logic/Model/Settings/GymConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ internal enum TeamColor
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate)]
public bool UsePokemonToAttackOnlyByCp { get; set; }

[NecrobotConfig(Description = "List of pokemon bot won't use in gym batle, deploy", Position = 24)]
[DefaultValue("Kangaskhan;Tauros;MrMime;Farfetchd")]
[JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Ignore)]

public List<PokemonId> ExcludeForGyms { get; set; }

private static ICollection<KeyValuePair<PokemonId, PokemonMove>> GetDefaults()
{
return new List<KeyValuePair<PokemonId, PokemonMove>>()
Expand Down
1 change: 0 additions & 1 deletion PoGo.NecroBot.Logic/MultiAccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ public BotAccount GetSwitchableAccount(BotAccount bot = null)

public void SwitchAccountTo(BotAccount account)
{
Logging.Logger.Write($"{account}");
this.requestedAccount = account;
}

Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.Logic/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
// [assembly: AssemblyVersion1("0.9.9.5")]
//

[assembly: AssemblyVersion("1.0.0.95")]
[assembly: AssemblyVersion("1.0.0.96")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("v1.0.0.95")]
[assembly: AssemblyInformationalVersion("v1.0.0.96")]
79 changes: 50 additions & 29 deletions PoGo.NecroBot.Logic/State/SessionStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ public class SessionStats
public bool IsSnipping { get; internal set; }

private ISession ownerSession;
private LiteDatabase db;
private LiteCollection<PokeStopTimestamp> pokestopTimestampCollection;
private LiteCollection<PokemonTimestamp> pokemonTimestampCollection;


class PokeStopTimestamp
{
public Int64 Timestamp { get; set; }
Expand Down Expand Up @@ -138,67 +135,91 @@ public SessionStats(ISession session)

public void InitializeDatabase(ISession session)
{
string username = session.Settings.AuthType == AuthType.Ptc
? session.Settings.PtcUsername
: session.Settings.GoogleUsername;
string username = GetUsername();
if (string.IsNullOrEmpty(username))
{
//firsttime setup , don't need to initial database
return;
}
var path = Path.Combine(session.LogicSettings.ProfileConfigPath, username);

using (var db = new LiteDatabase(GetDBPath(username)))
{
db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION).EnsureIndex(s => s.Timestamp);
db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION).EnsureIndex(s => s.Timestamp);
}
}

public string GetUsername()
{
string username = ownerSession.Settings.AuthType == AuthType.Ptc
? ownerSession.Settings.PtcUsername
: ownerSession.Settings.GoogleUsername;
return username;
}

public string GetDBPath(string username)
{
var path = Path.Combine(ownerSession.LogicSettings.ProfileConfigPath, username);

if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

path = Path.Combine(path, DB_NAME);

db = new LiteDatabase(path);
pokestopTimestampCollection = db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION);
pokemonTimestampCollection = db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION);

// Add index
pokestopTimestampCollection.EnsureIndex(s => s.Timestamp);
pokemonTimestampCollection.EnsureIndex(s => s.Timestamp);
return path;
}

public void AddPokestopTimestamp(Int64 ts)
{
if (!pokestopTimestampCollection.Exists(s => s.Timestamp == ts))
using (var db = new LiteDatabase(GetDBPath(GetUsername())))
{
var stat = new PokeStopTimestamp {Timestamp = ts};
pokestopTimestampCollection.Insert(stat);
if (!db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION).Exists(s => s.Timestamp == ts))
{
var stat = new PokeStopTimestamp { Timestamp = ts };
db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION).Insert(stat);
}
}
}

public void AddPokemonTimestamp(Int64 ts)
{
if (!pokemonTimestampCollection.Exists(s => s.Timestamp == ts))
using (var db = new LiteDatabase(GetDBPath(GetUsername())))
{
var stat = new PokemonTimestamp {Timestamp = ts};
pokemonTimestampCollection.Insert(stat);
if (!db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION).Exists(s => s.Timestamp == ts))
{
var stat = new PokemonTimestamp { Timestamp = ts };
db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION).Insert(stat);
}
}
}

public void CleanOutExpiredStats()
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
pokestopTimestampCollection.Delete(s => s.Timestamp < TSminus24h);
pokemonTimestampCollection.Delete(s => s.Timestamp < TSminus24h);
using (var db = new LiteDatabase(GetDBPath(GetUsername())))
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION).Delete(s => s.Timestamp < TSminus24h);
db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION).Delete(s => s.Timestamp < TSminus24h);
}
}

public int GetNumPokestopsInLast24Hours()
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
return pokestopTimestampCollection.Count(s => s.Timestamp >= TSminus24h);
using (var db = new LiteDatabase(GetDBPath(GetUsername())))
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
return db.GetCollection<PokeStopTimestamp>(POKESTOP_STATS_COLLECTION).Count(s => s.Timestamp >= TSminus24h);
}
}

public int GetNumPokemonsInLast24Hours()
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
return pokemonTimestampCollection.Count(s => s.Timestamp >= TSminus24h);
using (var db = new LiteDatabase(GetDBPath(GetUsername())))
{
var TSminus24h = DateTime.Now.AddHours(-24).Ticks;
return db.GetCollection<PokemonTimestamp>(POKEMON_STATS_COLLECTION).Count(s => s.Timestamp >= TSminus24h);
}
}

public void LoadLegacyData(ISession session)
Expand Down
1 change: 0 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ private static async Task Evolve(ISession session, List<PokemonData> pokemonToEv
int sequence = 1;
foreach (var pokemon in pokemonToEvolve)
{
TinyIoC.TinyIoCContainer.Current.Resolve<MultiAccountManager>().ThrowIfSwitchAccountRequested();
if (await session.Inventory.CanEvolvePokemon(pokemon))
{
try
Expand Down
52 changes: 46 additions & 6 deletions PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
using POGOProtos.Networking.Responses;
using System.Text.RegularExpressions;
using PoGo.NecroBot.Logic.Logging;
using System.Linq;
using System.Collections.Generic;
using POGOProtos.Data;

#endregion

Expand All @@ -24,7 +27,44 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
cancellationToken.ThrowIfCancellationRequested();
TinyIoC.TinyIoCContainer.Current.Resolve<MultiAccountManager>().ThrowIfSwitchAccountRequested();
var pokemons = session.Inventory.GetPokemons();
if (session.LogicSettings.TransferDuplicatePokemon)
{
var duplicatePokemons =
await
session.Inventory.GetDuplicatePokemonToTransfer(
session.LogicSettings.PokemonsNotToTransfer,
session.LogicSettings.PokemonsToEvolve,
session.LogicSettings.KeepPokemonsThatCanEvolve,
session.LogicSettings.PrioritizeIvOverCp);

pokemons = pokemons.Where(x => !duplicatePokemons.Any(p => p.Id == x.Id));
}

if (session.LogicSettings.TransferWeakPokemon)
{

var pokemonsFiltered =
pokemons.Where(pokemon => !session.LogicSettings.PokemonsNotToTransfer.Contains(pokemon.PokemonId) &&
pokemon.Favorite == 0 &&
pokemon.DeployedFortId == string.Empty)
.ToList().OrderBy(poke => poke.Cp);


var weakPokemons = new List<PokemonData>();
foreach (var pokemon in pokemonsFiltered)
{
cancellationToken.ThrowIfCancellationRequested();
if ((pokemon.Cp >= session.LogicSettings.KeepMinCp) ||
(PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage &&
session.LogicSettings.PrioritizeIvOverCp) ||
(PokemonInfo.GetLevel(pokemon) >= session.LogicSettings.KeepMinLvl && session.LogicSettings.UseKeepMinLvl) ||
pokemon.Favorite == 1)
continue;

weakPokemons.Add(pokemon);
}
pokemons = pokemons.Where(x => !weakPokemons.Any(p => p.Id == x.Id));
}
foreach (var pokemon in pokemons)
{
cancellationToken.ThrowIfCancellationRequested();
Expand All @@ -34,22 +74,22 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
var pokemonName = session.Translation.GetPokemonTranslation(pokemon.PokemonId);
var cp = PokemonInfo.CalculateCp(pokemon);
// iv number + templating part + pokemonName <= 12

var newNickname = session.LogicSettings.RenameTemplate.ToUpper();
newNickname = newNickname.Replace("{IV}", Math.Round(perfection, 0).ToString());
newNickname = newNickname.Replace("{LEVEL}", Math.Round(level, 0).ToString());
newNickname = newNickname.Replace("{CP}",cp.ToString());
newNickname = newNickname.Replace("{CP}", cp.ToString());

var nameLength = 18 - newNickname.Length;
if (pokemonName.Length > nameLength && nameLength >0)
if (pokemonName.Length > nameLength && nameLength > 0)
{
pokemonName = pokemonName.Substring(0, nameLength);
}

newNickname = newNickname.Replace("{NAME}", pokemonName);

//verify
if(Regex.IsMatch(newNickname, @"[^a-zA-Z0-9-_.%]") || nameLength <=0 )
//verify
if (Regex.IsMatch(newNickname, @"[^a-zA-Z0-9-_.%/\\]") || nameLength <= 0)
{
Logger.Write($"Your rename template : {session.LogicSettings.RenameTemplate} incorrect. : {pokemonName} / {newNickname}");
continue;
Expand Down Expand Up @@ -81,4 +121,4 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
}
}
}
}
}
2 changes: 0 additions & 2 deletions PoGo.NecroBot.Logic/Tasks/TransferWeakPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
var totalEggs = session.Inventory.GetEggs();
if ((maxStorage - totalEggs.Count() - buff) > pokemons.Count()) return;



var pokemonDatas = pokemons as IList<PokemonData> ?? pokemons.ToList();

var buddy = session.Profile.PlayerData.BuddyPokemon;
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/UseGymBattleTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,10 +1326,11 @@ private static async Task<PokemonData> GetDeployablePokemon(ISession session)
{
PokemonData pokemon = null;
List<ulong> excluded = new List<ulong>();
var pokemonList = session.Inventory.GetPokemons().ToList();
pokemonList.RemoveAll(x => session.LogicSettings.GymConfig.ExcludeForGyms.Contains(x.PokemonId));

while (pokemon == null)
{
var pokemonList = session.Inventory.GetPokemons().ToList();
pokemonList = pokemonList
.Where(w => !excluded.Contains(w.Id) && w.Id != session.Profile.PlayerData.BuddyPokemon?.Id)
.OrderByDescending(p => p.Cp)
Expand Down
12 changes: 12 additions & 0 deletions PoGo.Necrobot.Window/AppConfigWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,18 @@ private UIElement GetInputControl(PropertyInfo item, object source)
BindingOperations.SetBinding(numberTextbox, TextBox.TextProperty, binding);
return numberTextbox;
}

if(item.PropertyType == typeof(List<PokemonId>))
{
var txt = new TextBox()
{
MinWidth = 600,
HorizontalAlignment = HorizontalAlignment.Left
};
binding.Converter = new ListPokemonIdConverter();
BindingOperations.SetBinding(txt, TextBox.TextProperty, binding);
return txt;
}
return new TextBox();
}

Expand Down
8 changes: 4 additions & 4 deletions PoGo.Necrobot.Window/Behaviors/DataGridBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public static void SetDisplayRowNumber(DependencyObject target, bool value)

private static void OnDisplayRowNumberChanged(DependencyObject target, DependencyPropertyChangedEventArgs e)
{
FilteringDataGrid dataGrid = target as FilteringDataGrid;
DataGrid dataGrid = target as DataGrid;
if ((bool)e.NewValue == true)
{
EventHandler< Microsoft.Windows.Controls.DataGridRowEventArgs> loadedRowHandler = null;
loadedRowHandler = (object sender, Microsoft.Windows.Controls.DataGridRowEventArgs ea) =>
EventHandler<DataGridRowEventArgs> loadedRowHandler = null;
loadedRowHandler = (object sender, DataGridRowEventArgs ea) =>
{
if (GetDisplayRowNumber(dataGrid) == false)
{
Expand Down Expand Up @@ -63,7 +63,7 @@ private static void OnDisplayRowNumberChanged(DependencyObject target, Dependenc

private static void DataGrid_LoadingRow(object sender, Microsoft.Windows.Controls.DataGridRowEventArgs e)
{
throw new NotImplementedException();

}

#endregion // DisplayRowNumber
Expand Down

0 comments on commit a95dfe0

Please sign in to comment.