diff --git a/PokeRoadie/Context.cs b/PokeRoadie/Context.cs index e826533..a8e370e 100644 --- a/PokeRoadie/Context.cs +++ b/PokeRoadie/Context.cs @@ -1,33 +1,6 @@ #region " Imports " -using System; -using System.IO; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using System.Net; - -using PokemonGo.RocketAPI; -using PokemonGo.RocketAPI.Enums; -using PokemonGo.RocketAPI.Extensions; -using PokemonGo.RocketAPI.Helpers; -using PokemonGo.RocketAPI.Logging; -using PokemonGo.RocketAPI.Exceptions; -using PokemonGo.RocketAPI.Rpc; - -using POGOProtos.Inventory; -using POGOProtos.Inventory.Item; -using POGOProtos.Networking.Responses; -using POGOProtos.Data; -using POGOProtos.Enums; -using POGOProtos.Map.Fort; -using POGOProtos.Data.Player; -using POGOProtos.Map.Pokemon; -using POGOProtos.Data.Capture; - -using PokeRoadie.Extensions; using PokeRoadie.Utils; -//using PokeRoadie.Logging; using System.ComponentModel; #endregion @@ -47,11 +20,13 @@ public class Context public Player PlayerState { get; set; } public Directories Directories { get; set; } public ISynchronizeInvoke Invoker { get; set; } + public Utility Utility { get; set; } public Context(PokeRoadieSettings settings) { Settings = settings; Directories = new Directories(); + Utility = new Utility(this); ApiFailureStrategy = new ApiFailureStrategy(this); Client = new PokeRoadieClient(this); ApiFailureStrategy.Client = Client; @@ -65,5 +40,6 @@ public Context(PokeRoadieSettings settings, ISynchronizeInvoke form) : this(sett { Invoker = form; } + } } diff --git a/PokeRoadie/PokeRoadie.csproj b/PokeRoadie/PokeRoadie.csproj index cbe4d76..31f4ef3 100644 --- a/PokeRoadie/PokeRoadie.csproj +++ b/PokeRoadie/PokeRoadie.csproj @@ -131,6 +131,7 @@ True UserSettings.settings + diff --git a/PokeRoadie/PokeRoadieExtensions.cs b/PokeRoadie/PokeRoadieExtensions.cs index f01d9f1..b1c718c 100644 --- a/PokeRoadie/PokeRoadieExtensions.cs +++ b/PokeRoadie/PokeRoadieExtensions.cs @@ -85,196 +85,199 @@ public static double GetCP(this PokemonData pokemon) } - public static string GetStats(this PokemonData pokemon) - { - return $"{((pokemon.Favorite == 1 ? "*" : "") + pokemon.PokemonId.ToString()).PadRight(19,' ')} {pokemon.CalculatePokemonValue().ToString().PadRight(3, ' ')} V | {pokemon.Cp.ToString().PadLeft(4, ' ')} Cp | {pokemon.GetPerfection().ToString("0.00").PadLeft(6, ' ')}% IV | Lvl {pokemon.GetLevel().ToString("00")} | {(pokemon.Stamina.ToString() + "/" + pokemon.StaminaMax.ToString() + " Hp").PadLeft(10,' ')} | {pokemon.IndividualAttack.ToString("00").PadLeft(2)} A | {pokemon.IndividualDefense.ToString("00").PadLeft(2)} D | {pokemon.IndividualStamina.ToString("00").PadLeft(2)} S | {pokemon.Move1.GetMoveName().PadRight(14, ' ')}{CalculateMoveValue(pokemon.Move1.GetMoveName())} | {pokemon.Move2.GetMoveName().PadRight(14, ' ')}{CalculateMoveValue(pokemon.Move2.GetMoveName())}"; - } - - public static string GetMinStats(this PokemonData pokemon) - { - var name = pokemon.PokemonId.ToString(); - if (name.Length > 10) name = name.Substring(0, 10); - return $"{pokemon.PokemonId.ToString()} " + $"({pokemon.CalculatePokemonValue()}V-{pokemon.Cp.ToString()}Cp-{pokemon.GetPerfection().ToString("0.00")}%-Lv{pokemon.GetLevel().ToString("00")}-{pokemon.StaminaMax.ToString()}Hp)"; - } - - #endregion - #region " Move Extensions " - public static MoveData GetMove(this ICollection list, string name) - { - var filteredName = name.ToLower(); - var move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); - if (move == null) - { - if (filteredName.EndsWith("fast")) - filteredName = filteredName.Substring(0, filteredName.Length - 4); - move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); - } - if (move == null) - { - Logger.Write($"Pokemon move '{name}' could not be found in the PokemonMoveDatas.xml file, using default move.", LogLevel.Error); - move = new MoveData(); - move.Name = name; - move.Power = 50; - move.PP = 20; - move.Type = "Normal"; - move.Category = "Physical"; - move.Effect = "Unknown"; - move.Accuracy = 75; - } - - return move; - } + ////The following code was moved to the new Utility class. It can be accessed off Context.Utility. - public static string GetMoveName(this PokemonMove move) - { - var val = move.ToString(); - if (val.ToLower().EndsWith("fast")) val = val.Substring(0, val.Length - 4); - return val; - } - #endregion - #region " True Value Extensions " + //public static string GetStats(this PokemonData pokemon) + //{ + // return $"{((pokemon.Favorite == 1 ? "*" : "") + pokemon.PokemonId.ToString()).PadRight(19,' ')} {pokemon.CalculatePokemonValue().ToString().PadRight(3, ' ')} V | {pokemon.Cp.ToString().PadLeft(4, ' ')} Cp | {pokemon.GetPerfection().ToString("0.00").PadLeft(6, ' ')}% IV | Lvl {pokemon.GetLevel().ToString("00")} | {(pokemon.Stamina.ToString() + "/" + pokemon.StaminaMax.ToString() + " Hp").PadLeft(10,' ')} | {pokemon.IndividualAttack.ToString("00").PadLeft(2)} A | {pokemon.IndividualDefense.ToString("00").PadLeft(2)} D | {pokemon.IndividualStamina.ToString("00").PadLeft(2)} S | {pokemon.Move1.GetMoveName().PadRight(14, ' ')}{CalculateMoveValue(pokemon.Move1.GetMoveName())} | {pokemon.Move2.GetMoveName().PadRight(14, ' ')}{CalculateMoveValue(pokemon.Move2.GetMoveName())}"; + //} - public static double CalculatePokemonValue(this PokemonData pokemon) - { - var p = System.Convert.ToInt32(PokemonInfo.CalculatePokemonPerfection(pokemon) * 1.5); - var cp = Convert.ToInt32(pokemon.Cp == 0 ? 0 : pokemon.Cp / twoThousand * oneHundred); - var m1 = CalculateMoveValue(pokemon.Move1.GetMoveName()) * .5; - var m2 = CalculateMoveValue(pokemon.Move2.GetMoveName()) * .5; - var l = (pokemon.GetLevel() == 0 ? 0 : pokemon.GetLevel() * 3.5); - return Math.Round(p + cp + m1 + m2 + l, 0); - } - private static int CalculateMoveValue(string moveName) - { - var m1a = 100; - var move1 = PokeRoadieSettings.Current.PokemonMoves.GetMove(moveName); - if (move1 == null) return 20; - m1a = move1.Power + move1.Accuracy + move1.Hit; - m1a = m1a < 51 ? 50 : m1a > 200 ? 200 : m1a; - double m1b = (move1.PP > 0 && move1.PP < 15) ? - 3.0d : 4.0d; - return Convert.ToInt32(m1a / m1b); - } - - #endregion - #region " Xlo Extesnions " - - public static void Save(this FortDetailsResponse fortInfo, string filePath, double currentAltitude) - { - try - { - var data = new Xml.Pokestop(); - data.Id = fortInfo.FortId; - data.Latitude = fortInfo.Latitude; - data.Longitude = fortInfo.Longitude; - data.Altitude = currentAltitude; - data.Name = fortInfo.Name; - data.Description = fortInfo.Description; - data.Fp = fortInfo.Fp; - foreach (var img in fortInfo.ImageUrls) - { - data.ImageUrls.Add(img); - } - Xml.Serializer.SerializeToFile(data, filePath); - } - catch// (Exception e) - { - //Logger.Write($"Could not save the pokestop information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); - } - } - - public static void Save(this GetGymDetailsResponse fortDetails, FortDetailsResponse fortInfo, string filePath, double currentAltitude) - { - //write data file - try - { - var data = new Xml.Gym2(); - data.Id = fortInfo.FortId; - data.Latitude = fortDetails.GymState.FortData.Latitude; - data.Longitude = fortDetails.GymState.FortData.Longitude; - data.Altitude = currentAltitude; - data.Name = fortDetails.Name; - data.Description = fortDetails.Description; - data.Fp = fortInfo.Fp; - data.CooldownCompleteTimestampMs = fortDetails.GymState.FortData.CooldownCompleteTimestampMs; - data.GymPoints = fortDetails.GymState.FortData.GymPoints; - data.LastModifiedTimestampMs = fortDetails.GymState.FortData.LastModifiedTimestampMs; - data.Sponsor = fortDetails.GymState.FortData.Sponsor.ToString(); - data.Team = fortDetails.GymState.FortData.OwnedByTeam.ToString(); - if (fortDetails.GymState.Memberships != null && fortDetails.GymState.Memberships.Count() > 0) - { - foreach (var membership in fortDetails.GymState.Memberships) - { - var m = new Xml.Membership2(); - m.Player.Name = membership.TrainerPublicProfile.Name; - m.Player.Level = membership.TrainerPublicProfile.Level; - m.Pokemon.BattlesAttacked = membership.PokemonData.BattlesAttacked; - m.Pokemon.BattlesDefended = membership.PokemonData.BattlesDefended; - m.Pokemon.Cp = membership.PokemonData.Cp; - m.Pokemon.Hp = membership.PokemonData.StaminaMax; - m.Pokemon.HeightM = membership.PokemonData.HeightM; - m.Pokemon.WeightKg = membership.PokemonData.WeightKg; - m.Pokemon.Id = membership.PokemonData.Id; - m.Pokemon.IndividualAttack = membership.PokemonData.IndividualAttack; - m.Pokemon.IndividualDefense = membership.PokemonData.IndividualDefense; - m.Pokemon.IndividualStamina = membership.PokemonData.IndividualStamina; - m.Pokemon.PlayerLevel = membership.TrainerPublicProfile.Level; - m.Pokemon.PlayerTeam = fortDetails.GymState.FortData.OwnedByTeam.ToString(); - m.Pokemon.IV = membership.PokemonData.GetPerfection(); - m.Pokemon.Nickname = membership.PokemonData.Nickname; - m.Pokemon.V = membership.PokemonData.CalculatePokemonValue(); - m.Pokemon.Move1 = membership.PokemonData.Move1.ToString(); - m.Pokemon.Move2 = membership.PokemonData.Move2.ToString(); - m.Pokemon.Nickname = membership.PokemonData.Nickname; - m.Pokemon.Level = membership.PokemonData.NumUpgrades; - m.Pokemon.Origin = membership.PokemonData.Origin; - m.Pokemon.Type = membership.PokemonData.PokemonId.ToString(); - data.Memberships.Add(m); - } - } - - foreach (var img in fortInfo.ImageUrls) - { - data.ImageUrls.Add(img); - } - Xml.Serializer.SerializeToFile(data, filePath); - - } - catch// (Exception e) - { - //Logger.Write($"Could not save the gym information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); - } - } - - public static void Save(this PokeRoadieInventory inventory, PokemonData pokemon, GeoCoordinate geo, string playerName, int playerLevel, string playerTeam, ulong encounterId, EncounterSourceTypes encounterType, string filePath) - { - try - { - var data = new Xml.PokemonEncounter() - { - EncounterId = encounterId, - EncounterType = Convert.ToInt32(encounterType), - Latitude = geo.Latitude, - Longitude = geo.Longitude, - Altitude = geo.Altitude, - Player = playerName, - PlayerLevel = playerLevel, - PlayerTeam = playerTeam, - Cp = pokemon.Cp, - IV = pokemon.GetPerfection(), - V = pokemon.CalculatePokemonValue(), - NumberOfUpgrades = System.Convert.ToInt32(pokemon.GetLevel()), - Type = pokemon.PokemonId.ToString() - }; - Xml.Serializer.SerializeToFile(data, filePath); - } - catch// (Exception e) - { - //Logger.Write($"Could not save the encounter information file for {encounterId} - {e.ToString()}", LogLevel.Error); - } - } + //public static string GetMinStats(this PokemonData pokemon) + //{ + // var name = pokemon.PokemonId.ToString(); + // if (name.Length > 10) name = name.Substring(0, 10); + // return $"{pokemon.PokemonId.ToString()} " + $"({pokemon.CalculatePokemonValue()}V-{pokemon.Cp.ToString()}Cp-{pokemon.GetPerfection().ToString("0.00")}%-Lv{pokemon.GetLevel().ToString("00")}-{pokemon.StaminaMax.ToString()}Hp)"; + //} #endregion + //#region " Move Extensions " + //public static MoveData GetMove(this ICollection list, string name) + //{ + // var filteredName = name.ToLower(); + // var move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); + // if (move == null) + // { + // if (filteredName.EndsWith("fast")) + // filteredName = filteredName.Substring(0, filteredName.Length - 4); + // move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); + // } + // if (move == null) + // { + // Logger.Write($"Pokemon move '{name}' could not be found in the PokemonMoveDatas.xml file, using default move.", LogLevel.Error); + // move = new MoveData(); + // move.Name = name; + // move.Power = 50; + // move.PP = 20; + // move.Type = "Normal"; + // move.Category = "Physical"; + // move.Effect = "Unknown"; + // move.Accuracy = 75; + // } + + // return move; + //} + + //public static string GetMoveName(this PokemonMove move) + //{ + // var val = move.ToString(); + // if (val.ToLower().EndsWith("fast")) val = val.Substring(0, val.Length - 4); + // return val; + //} + + //#endregion + //#region " True Value Extensions " + + //public static double CalculatePokemonValue(this PokemonData pokemon, PokeRoadieSettings settings) + //{ + // var p = System.Convert.ToInt32(PokemonInfo.CalculatePokemonPerfection(pokemon) * 1.5); + // var cp = Convert.ToInt32(pokemon.Cp == 0 ? 0 : pokemon.Cp / twoThousand * oneHundred); + // var m1 = CalculateMoveValue(pokemon.Move1.GetMoveName(), settings) * .5; + // var m2 = CalculateMoveValue(pokemon.Move2.GetMoveName(), settings) * .5; + // var l = (pokemon.GetLevel() == 0 ? 0 : pokemon.GetLevel() * 3.5); + // return Math.Round(p + cp + m1 + m2 + l, 0); + //} + //private static int CalculateMoveValue(string moveName, PokeRoadieSettings settings) + //{ + // var m1a = 100; + // var move1 = settings.PokemonMoves.GetMove(moveName); + // if (move1 == null) return 20; + // m1a = move1.Power + move1.Accuracy + move1.Hit; + // m1a = m1a < 51 ? 50 : m1a > 200 ? 200 : m1a; + // double m1b = (move1.PP > 0 && move1.PP < 15) ? + // 3.0d : 4.0d; + // return Convert.ToInt32(m1a / m1b); + //} + + //#endregion + //#region " Xlo Extesnions " + + //public static void Save(this FortDetailsResponse fortInfo, string filePath, double currentAltitude) + //{ + // try + // { + // var data = new Xml.Pokestop(); + // data.Id = fortInfo.FortId; + // data.Latitude = fortInfo.Latitude; + // data.Longitude = fortInfo.Longitude; + // data.Altitude = currentAltitude; + // data.Name = fortInfo.Name; + // data.Description = fortInfo.Description; + // data.Fp = fortInfo.Fp; + // foreach (var img in fortInfo.ImageUrls) + // { + // data.ImageUrls.Add(img); + // } + // Xml.Serializer.SerializeToFile(data, filePath); + // } + // catch// (Exception e) + // { + // //Logger.Write($"Could not save the pokestop information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); + // } + //} + + //public static void Save(this GetGymDetailsResponse fortDetails, FortDetailsResponse fortInfo, string filePath, double currentAltitude) + //{ + // //write data file + // try + // { + // var data = new Xml.Gym2(); + // data.Id = fortInfo.FortId; + // data.Latitude = fortDetails.GymState.FortData.Latitude; + // data.Longitude = fortDetails.GymState.FortData.Longitude; + // data.Altitude = currentAltitude; + // data.Name = fortDetails.Name; + // data.Description = fortDetails.Description; + // data.Fp = fortInfo.Fp; + // data.CooldownCompleteTimestampMs = fortDetails.GymState.FortData.CooldownCompleteTimestampMs; + // data.GymPoints = fortDetails.GymState.FortData.GymPoints; + // data.LastModifiedTimestampMs = fortDetails.GymState.FortData.LastModifiedTimestampMs; + // data.Sponsor = fortDetails.GymState.FortData.Sponsor.ToString(); + // data.Team = fortDetails.GymState.FortData.OwnedByTeam.ToString(); + // if (fortDetails.GymState.Memberships != null && fortDetails.GymState.Memberships.Count() > 0) + // { + // foreach (var membership in fortDetails.GymState.Memberships) + // { + // var m = new Xml.Membership2(); + // m.Player.Name = membership.TrainerPublicProfile.Name; + // m.Player.Level = membership.TrainerPublicProfile.Level; + // m.Pokemon.BattlesAttacked = membership.PokemonData.BattlesAttacked; + // m.Pokemon.BattlesDefended = membership.PokemonData.BattlesDefended; + // m.Pokemon.Cp = membership.PokemonData.Cp; + // m.Pokemon.Hp = membership.PokemonData.StaminaMax; + // m.Pokemon.HeightM = membership.PokemonData.HeightM; + // m.Pokemon.WeightKg = membership.PokemonData.WeightKg; + // m.Pokemon.Id = membership.PokemonData.Id; + // m.Pokemon.IndividualAttack = membership.PokemonData.IndividualAttack; + // m.Pokemon.IndividualDefense = membership.PokemonData.IndividualDefense; + // m.Pokemon.IndividualStamina = membership.PokemonData.IndividualStamina; + // m.Pokemon.PlayerLevel = membership.TrainerPublicProfile.Level; + // m.Pokemon.PlayerTeam = fortDetails.GymState.FortData.OwnedByTeam.ToString(); + // m.Pokemon.IV = membership.PokemonData.GetPerfection(); + // m.Pokemon.Nickname = membership.PokemonData.Nickname; + // m.Pokemon.V = membership.PokemonData.CalculatePokemonValue(); + // m.Pokemon.Move1 = membership.PokemonData.Move1.ToString(); + // m.Pokemon.Move2 = membership.PokemonData.Move2.ToString(); + // m.Pokemon.Nickname = membership.PokemonData.Nickname; + // m.Pokemon.Level = membership.PokemonData.NumUpgrades; + // m.Pokemon.Origin = membership.PokemonData.Origin; + // m.Pokemon.Type = membership.PokemonData.PokemonId.ToString(); + // data.Memberships.Add(m); + // } + // } + + // foreach (var img in fortInfo.ImageUrls) + // { + // data.ImageUrls.Add(img); + // } + // Xml.Serializer.SerializeToFile(data, filePath); + + // } + // catch// (Exception e) + // { + // //Logger.Write($"Could not save the gym information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); + // } + //} + + //public static void Save(this PokeRoadieInventory inventory, PokemonData pokemon, GeoCoordinate geo, string playerName, int playerLevel, string playerTeam, ulong encounterId, EncounterSourceTypes encounterType, string filePath) + //{ + // try + // { + // var data = new Xml.PokemonEncounter() + // { + // EncounterId = encounterId, + // EncounterType = Convert.ToInt32(encounterType), + // Latitude = geo.Latitude, + // Longitude = geo.Longitude, + // Altitude = geo.Altitude, + // Player = playerName, + // PlayerLevel = playerLevel, + // PlayerTeam = playerTeam, + // Cp = pokemon.Cp, + // IV = pokemon.GetPerfection(), + // V = pokemon.CalculatePokemonValue(), + // NumberOfUpgrades = System.Convert.ToInt32(pokemon.GetLevel()), + // Type = pokemon.PokemonId.ToString() + // }; + // Xml.Serializer.SerializeToFile(data, filePath); + // } + // catch// (Exception e) + // { + // //Logger.Write($"Could not save the encounter information file for {encounterId} - {e.ToString()}", LogLevel.Error); + // } + //} + + //#endregion #region " Location Extensions " //for backwards compatibility diff --git a/PokeRoadie/PokeRoadieInventory.cs b/PokeRoadie/PokeRoadieInventory.cs index 4af01b3..3eff935 100644 --- a/PokeRoadie/PokeRoadieInventory.cs +++ b/PokeRoadie/PokeRoadieInventory.cs @@ -78,7 +78,7 @@ public async Task> GetPokemonToTransfer() ((Context.Settings.AlwaysTransferBelowCp > 0 && x.Cp < Context.Settings.AlwaysTransferBelowCp) || (Context.Settings.AlwaysTransferBelowIV > 0 && x.GetPerfection() < Context.Settings.AlwaysTransferBelowIV) || (Context.Settings.AlwaysTransferBelowLV > 0 && x.GetLevel() < Context.Settings.AlwaysTransferBelowLV) || - (Context.Settings.AlwaysTransferBelowV > 0 && x.CalculatePokemonValue() < Context.Settings.AlwaysTransferBelowV)) + (Context.Settings.AlwaysTransferBelowV > 0 && Context.Utility.CalculatePokemonValue(x) < Context.Settings.AlwaysTransferBelowV)) ); @@ -92,7 +92,7 @@ public async Task> GetPokemonToTransfer() //Keep By V filter if (Context.Settings.KeepAboveV > 0) - query = query.Where(p => p.CalculatePokemonValue() < Context.Settings.KeepAboveV); + query = query.Where(p => Context.Utility.CalculatePokemonValue(p) < Context.Settings.KeepAboveV); //Keep By LV filter if (Context.Settings.KeepAboveLV > 0) @@ -117,7 +117,7 @@ public async Task> GetPokemonToTransfer() orderBy = new Func(x => x.GetLevel()); break; case PriorityTypes.V: - orderBy = new Func(x => x.CalculatePokemonValue()); + orderBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; default: break; @@ -133,7 +133,7 @@ public async Task> GetPokemonToTransfer() thenBy = new Func(x => x.GetPerfection()); break; case PriorityTypes.V: - thenBy = new Func(x => x.CalculatePokemonValue()); + thenBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; case PriorityTypes.LV: thenBy = new Func(x => x.GetLevel()); @@ -208,26 +208,26 @@ public async Task> GetHighestsV(int limit) { var myPokemon = await GetPokemons(); var pokemons = myPokemon.ToList(); - return pokemons.OrderByDescending(x => x.CalculatePokemonValue()).ThenBy(n => n.StaminaMax).Take(limit); + return pokemons.OrderByDescending(x => Context.Utility.CalculatePokemonValue(x)).ThenBy(n => n.StaminaMax).Take(limit); } public async Task> GetPokemonToHeal() { var myPokemon = await GetPokemons(); var pokemons = myPokemon.ToList(); - return pokemons.Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina > 0 && x.Stamina < x.StaminaMax).OrderByDescending(n => n.CalculatePokemonValue()).ThenBy(n => n.Stamina); + return pokemons.Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina > 0 && x.Stamina < x.StaminaMax).OrderByDescending(n => Context.Utility.CalculatePokemonValue(n)).ThenBy(n => n.Stamina); } public async Task> GetPokemonToRevive() { - return (await GetPokemons()).Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina == 0).OrderByDescending(n => n.CalculatePokemonValue()); + return (await GetPokemons()).Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina == 0).OrderByDescending(n => Context.Utility.CalculatePokemonValue(n)); } public async Task> GetHighestsVNotDeployed(int limit) { var myPokemon = await GetPokemons(); var pokemons = myPokemon.ToList(); - return pokemons.Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina == x.StaminaMax).OrderByDescending(x => x.CalculatePokemonValue()).ThenBy(n => n.StaminaMax).Take(limit); + return pokemons.Where(x => string.IsNullOrWhiteSpace(x.DeployedFortId) && x.Stamina == x.StaminaMax).OrderByDescending(x => Context.Utility.CalculatePokemonValue(x)).ThenBy(n => n.StaminaMax).Take(limit); } public async Task> GetHighestsCP(int limit) @@ -276,7 +276,7 @@ public async Task GetHighestPokemonOfTypeByV(PokemonData pokemon) var myPokemon = await GetPokemons(); var pokemons = myPokemon.ToList(); return pokemons.Where(x => x.PokemonId == pokemon.PokemonId) - .OrderByDescending(x => x.CalculatePokemonValue()) + .OrderByDescending(x => Context.Utility.CalculatePokemonValue(x)) .FirstOrDefault(); } @@ -330,7 +330,7 @@ public async Task> GetPokemonToEvolve() //Evolve By V filter if (Context.Settings.EvolveAboveV > 0) - query = query.Where(p => p.CalculatePokemonValue() > Context.Settings.EvolveAboveV); + query = query.Where(p => Context.Utility.CalculatePokemonValue(p) > Context.Settings.EvolveAboveV); if (query.Count() == 0) return new List(); //Evolve By LV filter @@ -349,7 +349,7 @@ public async Task> GetPokemonToEvolve() orderBy = new Func(x => x.GetPerfection()); break; case PriorityTypes.V: - orderBy = new Func(x => x.CalculatePokemonValue()); + orderBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; case PriorityTypes.LV: orderBy = new Func(x => x.GetLevel()); @@ -368,7 +368,7 @@ public async Task> GetPokemonToEvolve() thenBy = new Func(x => x.GetPerfection()); break; case PriorityTypes.V: - thenBy = new Func(x => x.CalculatePokemonValue()); + thenBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; case PriorityTypes.LV: thenBy = new Func(x => x.GetLevel()); @@ -435,7 +435,7 @@ public async Task> GetPokemonToPowerUp() //PowerUp By V filter if (Context.Settings.PowerUpAboveV > 0) - query = query.Where(p => p.CalculatePokemonValue() > Context.Settings.PowerUpAboveV); + query = query.Where(p => Context.Utility.CalculatePokemonValue(p) > Context.Settings.PowerUpAboveV); if (query.Count() == 0) return new List(); //PowerUp By LV filter @@ -455,7 +455,7 @@ public async Task> GetPokemonToPowerUp() orderBy = new Func(x => x.GetPerfection()); break; case PriorityTypes.V: - orderBy = new Func(x => x.CalculatePokemonValue()); + orderBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; case PriorityTypes.LV: orderBy = new Func(x => x.GetLevel()); @@ -474,7 +474,7 @@ public async Task> GetPokemonToPowerUp() thenBy = new Func(x => x.GetPerfection()); break; case PriorityTypes.V: - thenBy = new Func(x => x.CalculatePokemonValue()); + thenBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; case PriorityTypes.LV: thenBy = new Func(x => x.GetLevel()); @@ -506,7 +506,7 @@ public async Task> GetPokemonToFavorite() //Favorite By V filter if (Context.Settings.FavoriteAboveV > 0) - query = query.Where(p => p.CalculatePokemonValue() > Context.Settings.FavoriteAboveV); + query = query.Where(p => Context.Utility.CalculatePokemonValue(p) > Context.Settings.FavoriteAboveV); if (query.Count() == 0) return new List(); //Favorite By LV filter diff --git a/PokeRoadie/PokeRoadieLogic.cs b/PokeRoadie/PokeRoadieLogic.cs index 86ba17a..24caea0 100644 --- a/PokeRoadie/PokeRoadieLogic.cs +++ b/PokeRoadie/PokeRoadieLogic.cs @@ -42,7 +42,7 @@ public class PokeRoadieLogic //system events public event Func OnPromptForCredentials; - public event Func OnPromptForCoords; + //public event Func OnPromptForCoords; //encounter events public event Action OnEncounter; @@ -175,7 +175,7 @@ public PokeRoadieLogic(Context context, ISynchronizeInvoke form) : this(context) } #endregion - #region " Application Methods " + #region " Application Methods " public void Stop() { @@ -378,14 +378,14 @@ private async Task WriteStats() Logger.Write("====== Most Valuable ======", LogLevel.None, ConsoleColor.Yellow); var highestsPokemonV = await Context.Inventory.GetHighestsV(Context.Settings.DisplayPokemonCount); foreach (var pokemon in highestsPokemonV) { - Logger.Write(pokemon.GetStats(), LogLevel.None, ConsoleColor.White); + Logger.Write(Context.Utility.GetStats(pokemon), LogLevel.None, ConsoleColor.White); } Logger.Write("====== Highest CP ======", LogLevel.None, ConsoleColor.Yellow); var highestsPokemonCp = await Context.Inventory.GetHighestsCP(Context.Settings.DisplayPokemonCount); foreach (var pokemon in highestsPokemonCp) { - Logger.Write(pokemon.GetStats(), LogLevel.None, ConsoleColor.White); + Logger.Write(Context.Utility.GetStats(pokemon), LogLevel.None, ConsoleColor.White); } @@ -393,7 +393,7 @@ private async Task WriteStats() var highestsPokemonPerfect = await Context.Inventory.GetHighestsPerfect(Context.Settings.DisplayPokemonCount); foreach (var pokemon in highestsPokemonPerfect) { - Logger.Write(pokemon.GetStats(), LogLevel.None, ConsoleColor.White); + Logger.Write(Context.Utility.GetStats(pokemon), LogLevel.None, ConsoleColor.White); } @@ -402,7 +402,7 @@ private async Task WriteStats() Logger.Write("====== Full List ======", LogLevel.None, ConsoleColor.Yellow); foreach (var pokemon in allPokemon.OrderBy(x => x.PokemonId).ThenByDescending(x => x.Cp)) { - Logger.Write(pokemon.GetStats(), LogLevel.None, ConsoleColor.White); + Logger.Write(Context.Utility.GetStats(pokemon), LogLevel.None, ConsoleColor.White); } } if (Context.Settings.DisplayAggregateLog) @@ -422,11 +422,11 @@ private async Task WriteStats() Logger.Write($"75%-89%: {allPokemon.Where(x => x.GetPerfection() > 74 && x.GetPerfection() < 90).Count()}", LogLevel.None, ConsoleColor.White); Logger.Write($"90%-100%: {allPokemon.Where(x => x.GetPerfection() > 89).Count()}", LogLevel.None, ConsoleColor.White); Logger.Write("====== V ======", LogLevel.None, ConsoleColor.White); - Logger.Write($"< 100 V: {allPokemon.Where(x => x.CalculatePokemonValue() < 100).Count()}", LogLevel.None, ConsoleColor.White); - Logger.Write($"100-199 V: {allPokemon.Where(x => x.CalculatePokemonValue() >= 100 && x.CalculatePokemonValue() < 200).Count()}", LogLevel.None, ConsoleColor.White); - Logger.Write($"200-299 V: {allPokemon.Where(x => x.CalculatePokemonValue() >= 200 && x.CalculatePokemonValue() < 300).Count()}", LogLevel.None, ConsoleColor.White); - Logger.Write($"300-399 V: {allPokemon.Where(x => x.CalculatePokemonValue() >= 300 && x.CalculatePokemonValue() < 400).Count()}", LogLevel.None, ConsoleColor.White); - Logger.Write($"> 400 V: {allPokemon.Where(x => x.CalculatePokemonValue() >= 400).Count()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"< 100 V: {allPokemon.Where(x => Context.Utility.CalculatePokemonValue(x) < 100).Count()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"100-199 V: {allPokemon.Where(x => Context.Utility.CalculatePokemonValue(x) >= 100 && Context.Utility.CalculatePokemonValue(x) < 200).Count()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"200-299 V: {allPokemon.Where(x => Context.Utility.CalculatePokemonValue(x) >= 200 && Context.Utility.CalculatePokemonValue(x) < 300).Count()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"300-399 V: {allPokemon.Where(x => Context.Utility.CalculatePokemonValue(x) >= 300 && Context.Utility.CalculatePokemonValue(x) < 400).Count()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"> 400 V: {allPokemon.Where(x => Context.Utility.CalculatePokemonValue(x) >= 400).Count()}", LogLevel.None, ConsoleColor.White); } _nextWriteStatsTime = DateTime.Now.AddMinutes(Context.Settings.DisplayRefreshMinutes); @@ -625,7 +625,7 @@ private async Task CheckSession() Context.Settings.Session = Context.Settings.NewSession(); } } - + #endregion #region " Navigation Methods " @@ -660,31 +660,31 @@ public void Initialize() if (!isRunning) isRunning = true; - //check lat long - if (Context.Settings.CurrentLongitude == 0 && Context.Settings.CurrentLatitude == 0) - { + ////check lat long + //if (Context.Settings.CurrentLongitude == 0 && Context.Settings.CurrentLatitude == 0) + //{ - //show credentials form - if (OnPromptForCoords != null) - { - //raise event - bool result = false; + // //show credentials form + // if (OnPromptForCoords != null) + // { + // //raise event + // bool result = false; - if (Context.Invoker != null && Context.Invoker.InvokeRequired) - result = (bool)Context.Invoker.Invoke(OnPromptForCoords, new object[] { }); - else - result = OnPromptForCoords.Invoke(); + // if (Context.Invoker != null && Context.Invoker.InvokeRequired) + // result = (bool)Context.Invoker.Invoke(OnPromptForCoords, new object[] { }); + // else + // result = OnPromptForCoords.Invoke(); - if (!result) - { - Logger.Write("User did not provide starting coordinates."); - CloseApplication(4).Wait(); - } - } - //Logger.Write("CurrentLatitude and CurrentLongitude not set in the Configs/Settings.xml. Application will exit in 15 seconds...", LogLevel.Error); - //if (Context.Settings.MoveWhenNoStops && Context.Client != null) Context.Settings.DestinationEndDate = DateTime.Now; - //CloseApplication(1).Wait(); - } + // if (!result) + // { + // Logger.Write("User did not provide starting coordinates."); + // CloseApplication(4).Wait(); + // } + // } + // //Logger.Write("CurrentLatitude and CurrentLongitude not set in the Configs/Settings.xml. Application will exit in 15 seconds...", LogLevel.Error); + // //if (Context.Settings.MoveWhenNoStops && Context.Client != null) Context.Settings.DestinationEndDate = DateTime.Now; + // //CloseApplication(1).Wait(); + //} //do maint @@ -1410,7 +1410,7 @@ private async Task ProcessGym(FortData pokeStop, GetMapObjectsResponse mapObject if (fortDetails.Result == GetGymDetailsResponse.Types.Result.Success) { var location = new LocationData(fortInfo.Latitude, fortInfo.Longitude, Context.Client.CurrentAltitude); - fortDetails.Save(fortInfo, Path.Combine(Context.Directories.GymDirectory, fortInfo.FortId + ".xml"), Context.Client.CurrentAltitude); + Context.Utility.Save(fortDetails, fortInfo, Path.Combine(Context.Directories.GymDirectory, fortInfo.FortId + ".xml"), Context.Client.CurrentAltitude); //raise event if (OnVisitGym != null) @@ -1477,7 +1477,7 @@ private async Task ProcessGym(FortData pokeStop, GetMapObjectsResponse mapObject if (response.Result == FortDeployPokemonResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"(GYM) Deployed {pokemon.GetMinStats()} to {fortDetails.Name}", LogLevel.None, ConsoleColor.Green); + Logger.Write($"(GYM) Deployed {Context.Utility.GetMinStats(pokemon)} to {fortDetails.Name}", LogLevel.None, ConsoleColor.Green); //raise event if (OnDeployToGym != null) @@ -1537,7 +1537,7 @@ private async Task ProcessPokeStop(FortData pokeStop, GetMapObjectsResponse mapO //get fort info var fortInfo = await Context.Client.Fort.GetFort(pokeStop.Id, pokeStop.Latitude, pokeStop.Longitude); - fortInfo.Save(Path.Combine(Context.Directories.PokestopsDirectory, pokeStop.Id + ".xml"), Context.Client.CurrentAltitude); + Context.Utility.Save(fortInfo, Path.Combine(Context.Directories.PokestopsDirectory, pokeStop.Id + ".xml"), Context.Client.CurrentAltitude); //raise event if (OnTravelingToPokestop != null) @@ -1713,7 +1713,7 @@ private async Task ProcessEncounter(LocationData location, ulong encounterId, st orderBy = new Func(x => x.GetLevel()); break; case PriorityTypes.V: - orderBy = new Func(x => x.CalculatePokemonValue()); + orderBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; default: break; @@ -1732,7 +1732,7 @@ private async Task ProcessEncounter(LocationData location, ulong encounterId, st thenBy = new Func(x => x.GetLevel()); break; case PriorityTypes.V: - thenBy = new Func(x => x.CalculatePokemonValue()); + thenBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; default: break; @@ -1838,7 +1838,7 @@ private async Task ProcessLureEncounter(LocationData location, FortData fortData private async Task ProcessCatch(EncounterData encounter) { //save - Context.Inventory.Save(encounter.PokemonData, encounter.Location.GetGeo(), _playerProfile.PlayerData.Username, Context.Statistics.Currentlevel, _playerProfile.PlayerData.Team.ToString().Substring(0, 1).ToUpper(), encounter.EncounterId, encounter.Source, Path.Combine(Context.Directories.EncountersDirectory, encounter.EncounterId + ".xml")); + Context.Utility.Save(Context.Inventory, encounter.PokemonData, encounter.Location.GetGeo(), _playerProfile.PlayerData.Username, Context.Statistics.Currentlevel, _playerProfile.PlayerData.Team.ToString().Substring(0, 1).ToUpper(), encounter.EncounterId, encounter.Source, Path.Combine(Context.Directories.EncountersDirectory, encounter.EncounterId + ".xml")); //raise event if (OnEncounter != null) @@ -1866,7 +1866,7 @@ private async Task ProcessCatch(EncounterData encounter) if (throwData.ItemId == ItemId.ItemUnknown) { //handle same pokemon as before problem - if (encounter.EncounterId != lastMissedEncounterId) Logger.Write($"No Pokeballs :( - We missed {encounter.PokemonData.GetMinStats()}", LogLevel.Warning); + if (encounter.EncounterId != lastMissedEncounterId) Logger.Write($"No Pokeballs :( - We missed {Context.Utility.GetMinStats(encounter.PokemonData)}", LogLevel.Warning); else Logger.Write($"It is that same {encounter.PokemonData}.", LogLevel.Info); lastMissedEncounterId = encounter.EncounterId; @@ -1967,7 +1967,7 @@ private async Task ProcessCatch(EncounterData encounter) ? $"and received XP {caughtPokemonResponse.CaptureAward.Xp.Sum()}" : $""; - Logger.Write($"({encounter.Source} {catchStatus.Replace("Catch","")}) | {encounter.PokemonData.GetMinStats()} | Chance: {(encounter.Probability.HasValue ? ((float)((int)(encounter.Probability * 100)) / 100).ToString() : "Unknown")} | with a {throwData.BallName}Ball {receivedXP}", LogLevel.None, ConsoleColor.Yellow); + Logger.Write($"({encounter.Source} {catchStatus.Replace("Catch","")}) | {Context.Utility.GetMinStats(encounter.PokemonData)} | Chance: {(encounter.Probability.HasValue ? ((float)((int)(encounter.Probability * 100)) / 100).ToString() : "Unknown")} | with a {throwData.BallName}Ball {receivedXP}", LogLevel.None, ConsoleColor.Yellow); //humanize pokedex add if (caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess) @@ -2415,7 +2415,7 @@ private async Task GetThrowData(PokemonData pokemon, float? capturePr if (Context.Settings.EnableHumanizedThrows) { var pokemonIv = pokemon.GetPerfection(); - var pokemonV = pokemon.CalculatePokemonValue(); + var pokemonV = Context.Utility.CalculatePokemonValue(pokemon); //Context.Settings.MissThrowChance @@ -2693,7 +2693,7 @@ private async Task EvolvePokemon(PokemonData pokemon) if (evolvePokemonOutProto.Result == EvolvePokemonResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"{pokemon.GetMinStats()} for {evolvePokemonOutProto.ExperienceAwarded} xp", LogLevel.Evolve); + Logger.Write($"{Context.Utility.GetMinStats(pokemon)} for {evolvePokemonOutProto.ExperienceAwarded} xp", LogLevel.Evolve); Context.Statistics.AddExperience(evolvePokemonOutProto.ExperienceAwarded); //raise event if (OnEvolve != null) @@ -2707,7 +2707,7 @@ private async Task EvolvePokemon(PokemonData pokemon) } else { - Logger.Write($"(EVOLVE ERROR) {pokemon.GetMinStats()} - {evolvePokemonOutProto.Result}", LogLevel.None, ConsoleColor.Red); + Logger.Write($"(EVOLVE ERROR) {Context.Utility.GetMinStats(pokemon)} - {evolvePokemonOutProto.Result}", LogLevel.None, ConsoleColor.Red); await RandomDelay(); } } @@ -2759,8 +2759,8 @@ private async Task TransferPokemon(PokemonData pokemon) string bestPokemonInfo = "NONE"; if (bestPokemonOfType != null) - bestPokemonInfo = bestPokemonOfType.GetMinStats(); - Logger.Write($"{(pokemon.GetMinStats().ToString())} | Candy: {FamilyCandies} | Best {bestPokemonInfo.ToString()} ", LogLevel.Transfer); + bestPokemonInfo = Context.Utility.GetMinStats(bestPokemonOfType); + Logger.Write($"{(Context.Utility.GetMinStats(pokemon).ToString())} | Candy: {FamilyCandies} | Best {bestPokemonInfo.ToString()} ", LogLevel.Transfer); //raise event if (OnTransfer != null) @@ -2810,7 +2810,7 @@ private async Task TransferTrimTheFat() orderBy = new Func(x => x.GetLevel()); break; case PriorityTypes.V: - orderBy = new Func(x => x.CalculatePokemonValue()); + orderBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; default: break; @@ -2829,7 +2829,7 @@ private async Task TransferTrimTheFat() thenBy = new Func(x => x.GetLevel()); break; case PriorityTypes.V: - thenBy = new Func(x => x.CalculatePokemonValue()); + thenBy = new Func(x => Context.Utility.CalculatePokemonValue(x)); break; default: break; @@ -2909,7 +2909,7 @@ public async Task PowerUpPokemon(List pokemons) if (upgradeResult.Result == UpgradePokemonResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"(POWER) Pokemon was powered up! {upgradeResult.UpgradedPokemon.GetMinStats()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"(POWER) Pokemon was powered up! {Context.Utility.GetMinStats(upgradeResult.UpgradedPokemon)}", LogLevel.None, ConsoleColor.White); upgradedNumber++; //raise event if (OnPowerUp != null) @@ -2926,13 +2926,13 @@ public async Task PowerUpPokemon(List pokemons) switch (upgradeResult.Result) { case UpgradePokemonResponse.Types.Result.ErrorInsufficientResources: - Logger.Write($"(POWER) Ran out of candies to powerup {pokemon.GetMinStats()}", LogLevel.None, ConsoleColor.Red); + Logger.Write($"(POWER) Ran out of candies to powerup {Context.Utility.GetMinStats(pokemon)}", LogLevel.None, ConsoleColor.Red); break; case UpgradePokemonResponse.Types.Result.ErrorUpgradeNotAvailable: - Logger.Write($"(POWER) Reached max level {pokemon.GetMinStats()}", LogLevel.None, ConsoleColor.Green); + Logger.Write($"(POWER) Reached max level {Context.Utility.GetMinStats(pokemon)}", LogLevel.None, ConsoleColor.Green); break; default: - Logger.Write($"(POWER ERROR) Unable to powerup {pokemon.GetMinStats()} - {upgradeResult.Result.ToString()}", LogLevel.None, ConsoleColor.Red); + Logger.Write($"(POWER ERROR) Unable to powerup {Context.Utility.GetMinStats(pokemon)} - {upgradeResult.Result.ToString()}", LogLevel.None, ConsoleColor.Red); break; } } @@ -2968,7 +2968,7 @@ public async Task FavoritePokemon(List pokemons) if (response.Result == SetFavoritePokemonResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"(FAVORITE) {pokemon.GetMinStats()}", LogLevel.None, ConsoleColor.White); + Logger.Write($"(FAVORITE) {Context.Utility.GetMinStats(pokemon)}", LogLevel.None, ConsoleColor.White); //raise event if (OnFavorite != null) @@ -3022,7 +3022,7 @@ private async Task UsePotion(PokemonData pokemon) if (response.Result == UseItemPotionResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"Healed {pokemon.GetMinStats()} with {potion} - {response.Stamina}/{pokemon.StaminaMax}", LogLevel.Pokemon); + Logger.Write($"Healed {Context.Utility.GetMinStats(pokemon)} with {potion} - {response.Stamina}/{pokemon.StaminaMax}", LogLevel.Pokemon); hp = response.Stamina; //raise event @@ -3035,7 +3035,7 @@ private async Task UsePotion(PokemonData pokemon) } else { - Logger.Write($"Failed to heal {pokemon.GetMinStats()} with {potion} - {response.Result}", LogLevel.Error); + Logger.Write($"Failed to heal {Context.Utility.GetMinStats(pokemon)} with {potion} - {response.Result}", LogLevel.Error); stopHealing = true; break; } @@ -3200,7 +3200,7 @@ public async Task UseIncubators(bool checkOnly) if (hatched == null) continue; delList.Add(incubator); PokeRoadieInventory.IsDirty = true; - Logger.Write($"Hatched egg! {hatched.GetMinStats()}", LogLevel.Egg); + Logger.Write($"Hatched egg! {Context.Utility.GetMinStats(hatched)}", LogLevel.Egg); //raise event if (OnEggHatched != null) @@ -3333,7 +3333,7 @@ private async Task UseRevives() if (response.Result == UseItemReviveResponse.Types.Result.Success) { PokeRoadieInventory.IsDirty = true; - Logger.Write($"Revived {pokemon.GetMinStats()} with {potion} ", LogLevel.Pokemon); + Logger.Write($"Revived {Context.Utility.GetMinStats(pokemon)} with {potion} ", LogLevel.Pokemon); //raise event if (OnUseRevive != null) { @@ -3344,7 +3344,7 @@ private async Task UseRevives() } else { - Logger.Write($"Failed to revive {pokemon.GetMinStats()} with {potion} - {response.Result}", LogLevel.Error); + Logger.Write($"Failed to revive {Context.Utility.GetMinStats(pokemon)} with {potion} - {response.Result}", LogLevel.Error); } await RandomDelay(); } @@ -3559,7 +3559,7 @@ public async Task TutorialCapture() _playerProfile.PlayerData.TutorialState.Remove(TutorialState.PokemonCapture); Logger.Write($"Completed the POKEMON_CAPTURE tutorial.", LogLevel.Tutorial); - Logger.Write($"Received {result.PokemonData.GetMinStats()}", LogLevel.Pokemon); + Logger.Write($"Received {Context.Utility.GetMinStats(result.PokemonData)}", LogLevel.Pokemon); ProcessCaptureAward(result.CaptureAward); //hummanize diff --git a/PokeRoadie/PokeRoadieSettings.cs b/PokeRoadie/PokeRoadieSettings.cs index f913737..c0710b7 100644 --- a/PokeRoadie/PokeRoadieSettings.cs +++ b/PokeRoadie/PokeRoadieSettings.cs @@ -25,17 +25,6 @@ namespace PokeRoadie public class PokeRoadieSettings : PokemonGo.RocketAPI.ISettings { - #region " Singleton " - - //this is going to be removed, extensions is preventing the removal of this. - private static PokeRoadieSettings _current = null; - public static PokeRoadieSettings Current - { - get { _current = _current ?? (new PokeRoadieSettings()).Load(); return _current; } - set { _current = value; } - } - - #endregion #region " Members " private static object syncRoot = new object(); @@ -978,18 +967,21 @@ public PokeRoadieSettings Load() CurrentLongitude = destination.Longitude; CurrentAltitude = destination.Altitude; } + else + { + var result = PromptForCoords(); + if (!result) + { + Logger.Write($"User quit before providing starting coordinates.", LogLevel.Warning); + Program.ExitApplication(6); + } + } } //resolve unknown waypoint if (WaypointLatitude == 0 && WaypointLongitude == 0) { - if (CurrentLatitude != 0 && CurrentLongitude != 0) - { - WaypointLatitude = CurrentLatitude; - WaypointLongitude = CurrentLongitude; - WaypointAltitude = CurrentAltitude; - } - else if (DestinationsEnabled && Destinations.Any()) + if (DestinationsEnabled && Destinations.Any()) { var index = DestinationIndex < Destinations.Count ? DestinationIndex : 0; var destination = Destinations[index]; @@ -997,6 +989,13 @@ public PokeRoadieSettings Load() WaypointLongitude = destination.Longitude; WaypointAltitude = destination.Altitude; } + else if (CurrentLatitude != 0 && CurrentLongitude != 0) + { + WaypointLatitude = CurrentLatitude; + WaypointLongitude = CurrentLongitude; + WaypointAltitude = CurrentAltitude; + } + } if (createNew) @@ -1006,7 +1005,14 @@ public PokeRoadieSettings Load() if (!result) { Logger.Write($"User quit before providing login credentials.", LogLevel.Warning); - Program.ExitApplication(1); + Program.ExitApplication(5); + } + + var result2 = PromptForCoords(); + if (!result2) + { + Logger.Write($"User quit before providing starting coordinates.", LogLevel.Warning); + Program.ExitApplication(6); } } else @@ -1260,6 +1266,9 @@ public bool PromptForCoords() this.CurrentLatitude = d.Latitude; this.CurrentLongitude = d.Longitude; this.CurrentAltitude = 13; + this.WaypointLatitude = d.Latitude; + this.WaypointLongitude = d.Longitude; + this.WaypointAltitude = 13; this.Save(); } d.Dispose(); diff --git a/PokeRoadie/Program.cs b/PokeRoadie/Program.cs index 13f635a..bf1a480 100644 --- a/PokeRoadie/Program.cs +++ b/PokeRoadie/Program.cs @@ -28,8 +28,8 @@ private static PokeRoadieLogic CreateLogic() //load settings var settings = new PokeRoadieSettings(); - //set singleton - this will be removed once extensions is removed. - PokeRoadieSettings.Current = settings; + //load settings + settings.Load(); //create context var context = new Context(settings); @@ -39,13 +39,7 @@ private static PokeRoadieLogic CreateLogic() //add custom event wiring logic.OnPromptForCredentials += settings.PromptForCredentials; - logic.OnPromptForCoords += settings.PromptForCoords; - - //finally load settings - settings.Load(); - - //set login type - context.Client.Login.SetLoginType(settings); + //logic.OnPromptForCoords += settings.PromptForCoords; try { diff --git a/PokeRoadie/Properties/AssemblyInfo.cs b/PokeRoadie/Properties/AssemblyInfo.cs index 43917f5..961c0c9 100644 --- a/PokeRoadie/Properties/AssemblyInfo.cs +++ b/PokeRoadie/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // 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.*")] -[assembly: AssemblyVersion("2016.9.5.2")] +[assembly: AssemblyVersion("2016.9.5.3")] [assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/PokeRoadie/Utility.cs b/PokeRoadie/Utility.cs new file mode 100644 index 0000000..85215ba --- /dev/null +++ b/PokeRoadie/Utility.cs @@ -0,0 +1,224 @@ +#region " Imports " + +using System; +using System.Collections.Generic; +using System.Linq; + +using PokemonGo.RocketAPI; +using PokemonGo.RocketAPI.Logging; +using PokemonGo.RocketAPI.Helpers; + +using POGOProtos.Data; +using POGOProtos.Enums; + +using PokeRoadie.Extensions; +using POGOProtos.Networking.Responses; + + +#endregion + +namespace PokeRoadie +{ + public class Utility + { + public Context Context { get; set; } + + public Utility(Context context) + { + Context = context; + } + + #region " Stats methods " + + public string GetStats(PokemonData pokemon) + { + return $"{((pokemon.Favorite == 1 ? "*" : "") + pokemon.PokemonId.ToString()).PadRight(19, ' ')} {CalculatePokemonValue(pokemon).ToString().PadRight(3, ' ')} V | {pokemon.Cp.ToString().PadLeft(4, ' ')} Cp | {pokemon.GetPerfection().ToString("0.00").PadLeft(6, ' ')}% IV | Lvl {pokemon.GetLevel().ToString("00")} | {(pokemon.Stamina.ToString() + "/" + pokemon.StaminaMax.ToString() + " Hp").PadLeft(10, ' ')} | {pokemon.IndividualAttack.ToString("00").PadLeft(2)} A | {pokemon.IndividualDefense.ToString("00").PadLeft(2)} D | {pokemon.IndividualStamina.ToString("00").PadLeft(2)} S | {GetMoveName(pokemon.Move1).PadRight(14, ' ')}{CalculateMoveValue(GetMoveName(pokemon.Move1))} | {GetMoveName(pokemon.Move2).PadRight(14, ' ')}{CalculateMoveValue(GetMoveName(pokemon.Move2))}"; + } + + public string GetMinStats(PokemonData pokemon) + { + var name = pokemon.PokemonId.ToString(); + if (name.Length > 10) name = name.Substring(0, 10); + return $"{pokemon.PokemonId.ToString()} " + $"({CalculatePokemonValue(pokemon)}V-{pokemon.Cp.ToString()}Cp-{pokemon.GetPerfection().ToString("0.00")}%-Lv{pokemon.GetLevel().ToString("00")}-{pokemon.StaminaMax.ToString()}Hp)"; + } + + #endregion + #region " Move Extensions " + public MoveData GetMove(ICollection list, string name) + { + var filteredName = name.ToLower(); + var move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); + if (move == null) + { + if (filteredName.EndsWith("fast")) + filteredName = filteredName.Substring(0, filteredName.Length - 4); + move = list.Where(x => x.Name.Replace(" ", "").ToLower() == filteredName).FirstOrDefault(); + } + if (move == null) + { + Logger.Write($"Pokemon move '{name}' could not be found in the PokemonMoveDatas.xml file, using default move.", LogLevel.Error); + move = new MoveData(); + move.Name = name; + move.Power = 50; + move.PP = 20; + move.Type = "Normal"; + move.Category = "Physical"; + move.Effect = "Unknown"; + move.Accuracy = 75; + } + + return move; + } + + public string GetMoveName(PokemonMove move) + { + var val = move.ToString(); + if (val.ToLower().EndsWith("fast")) val = val.Substring(0, val.Length - 4); + return val; + } + + #endregion + #region " True Value Extensions " + + public double CalculatePokemonValue(PokemonData pokemon) + { + var p = System.Convert.ToInt32(PokemonInfo.CalculatePokemonPerfection(pokemon) * 1.5); + var cp = Convert.ToInt32(pokemon.Cp == 0 ? 0 : pokemon.Cp / 2000 * 100); + var m1 = CalculateMoveValue(GetMoveName(pokemon.Move1)) * .5; + var m2 = CalculateMoveValue(GetMoveName(pokemon.Move2)) * .5; + var l = (pokemon.GetLevel() == 0 ? 0 : pokemon.GetLevel() * 3.5); + return Math.Round(p + cp + m1 + m2 + l, 0); + } + public int CalculateMoveValue(string moveName) + { + var m1a = 100; + var move1 = GetMove(Context.Settings.PokemonMoves, moveName); + if (move1 == null) return 20; + m1a = move1.Power + move1.Accuracy + move1.Hit; + m1a = m1a < 51 ? 50 : m1a > 200 ? 200 : m1a; + double m1b = (move1.PP > 0 && move1.PP < 15) ? + 3.0d : 4.0d; + return Convert.ToInt32(m1a / m1b); + } + + #endregion + #region " Xlo Extesnions " + + public void Save(FortDetailsResponse fortInfo, string filePath, double currentAltitude) + { + try + { + var data = new Xml.Pokestop(); + data.Id = fortInfo.FortId; + data.Latitude = fortInfo.Latitude; + data.Longitude = fortInfo.Longitude; + data.Altitude = currentAltitude; + data.Name = fortInfo.Name; + data.Description = fortInfo.Description; + data.Fp = fortInfo.Fp; + foreach (var img in fortInfo.ImageUrls) + { + data.ImageUrls.Add(img); + } + Xml.Serializer.SerializeToFile(data, filePath); + } + catch// (Exception e) + { + //Logger.Write($"Could not save the pokestop information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); + } + } + + public void Save(GetGymDetailsResponse fortDetails, FortDetailsResponse fortInfo, string filePath, double currentAltitude) + { + //write data file + try + { + var data = new Xml.Gym2(); + data.Id = fortInfo.FortId; + data.Latitude = fortDetails.GymState.FortData.Latitude; + data.Longitude = fortDetails.GymState.FortData.Longitude; + data.Altitude = currentAltitude; + data.Name = fortDetails.Name; + data.Description = fortDetails.Description; + data.Fp = fortInfo.Fp; + data.CooldownCompleteTimestampMs = fortDetails.GymState.FortData.CooldownCompleteTimestampMs; + data.GymPoints = fortDetails.GymState.FortData.GymPoints; + data.LastModifiedTimestampMs = fortDetails.GymState.FortData.LastModifiedTimestampMs; + data.Sponsor = fortDetails.GymState.FortData.Sponsor.ToString(); + data.Team = fortDetails.GymState.FortData.OwnedByTeam.ToString(); + if (fortDetails.GymState.Memberships != null && fortDetails.GymState.Memberships.Count() > 0) + { + foreach (var membership in fortDetails.GymState.Memberships) + { + var m = new Xml.Membership2(); + m.Player.Name = membership.TrainerPublicProfile.Name; + m.Player.Level = membership.TrainerPublicProfile.Level; + m.Pokemon.BattlesAttacked = membership.PokemonData.BattlesAttacked; + m.Pokemon.BattlesDefended = membership.PokemonData.BattlesDefended; + m.Pokemon.Cp = membership.PokemonData.Cp; + m.Pokemon.Hp = membership.PokemonData.StaminaMax; + m.Pokemon.HeightM = membership.PokemonData.HeightM; + m.Pokemon.WeightKg = membership.PokemonData.WeightKg; + m.Pokemon.Id = membership.PokemonData.Id; + m.Pokemon.IndividualAttack = membership.PokemonData.IndividualAttack; + m.Pokemon.IndividualDefense = membership.PokemonData.IndividualDefense; + m.Pokemon.IndividualStamina = membership.PokemonData.IndividualStamina; + m.Pokemon.PlayerLevel = membership.TrainerPublicProfile.Level; + m.Pokemon.PlayerTeam = fortDetails.GymState.FortData.OwnedByTeam.ToString(); + m.Pokemon.IV = membership.PokemonData.GetPerfection(); + m.Pokemon.Nickname = membership.PokemonData.Nickname; + m.Pokemon.V = CalculatePokemonValue(membership.PokemonData); + m.Pokemon.Move1 = membership.PokemonData.Move1.ToString(); + m.Pokemon.Move2 = membership.PokemonData.Move2.ToString(); + m.Pokemon.Nickname = membership.PokemonData.Nickname; + m.Pokemon.Level = membership.PokemonData.NumUpgrades; + m.Pokemon.Origin = membership.PokemonData.Origin; + m.Pokemon.Type = membership.PokemonData.PokemonId.ToString(); + data.Memberships.Add(m); + } + } + + foreach (var img in fortInfo.ImageUrls) + { + data.ImageUrls.Add(img); + } + Xml.Serializer.SerializeToFile(data, filePath); + + } + catch// (Exception e) + { + //Logger.Write($"Could not save the gym information file for {fortInfo.FortId} - {e.ToString()}", LogLevel.Error); + } + } + + public void Save(PokeRoadieInventory inventory, PokemonData pokemon, GeoCoordinate geo, string playerName, int playerLevel, string playerTeam, ulong encounterId, EncounterSourceTypes encounterType, string filePath) + { + try + { + var data = new Xml.PokemonEncounter() + { + EncounterId = encounterId, + EncounterType = Convert.ToInt32(encounterType), + Latitude = geo.Latitude, + Longitude = geo.Longitude, + Altitude = geo.Altitude, + Player = playerName, + PlayerLevel = playerLevel, + PlayerTeam = playerTeam, + Cp = pokemon.Cp, + IV = pokemon.GetPerfection(), + V = CalculatePokemonValue(pokemon), + NumberOfUpgrades = System.Convert.ToInt32(pokemon.GetLevel()), + Type = pokemon.PokemonId.ToString() + }; + Xml.Serializer.SerializeToFile(data, filePath); + } + catch// (Exception e) + { + //Logger.Write($"Could not save the encounter information file for {encounterId} - {e.ToString()}", LogLevel.Error); + } + } + + #endregion + } +}