From 5bef89759922bbfc2588351dcbf0837417aa1b45 Mon Sep 17 00:00:00 2001 From: Gabriele Coquillard Date: Thu, 1 Apr 2021 18:37:27 +0200 Subject: [PATCH] fix autocargo and autorepatriate improve logging minor code cleaning bump version implement more helper methods for future use --- TBot/Includes/Helpers.cs | 134 +++++++++++++++++++++++++++++++++++++-- TBot/Model/Enums.cs | 24 +++---- TBot/Model/Types.cs | 6 +- TBot/Program.cs | 90 +++++++++++++++++++------- TBot/TBot.csproj | 6 +- 5 files changed, 210 insertions(+), 50 deletions(-) diff --git a/TBot/Includes/Helpers.cs b/TBot/Includes/Helpers.cs index ae6cab6d..26f1c236 100644 --- a/TBot/Includes/Helpers.cs +++ b/TBot/Includes/Helpers.cs @@ -35,13 +35,13 @@ public static void LogToConsole(LogType type, LogSender sender, string message) public static void LogToFile(LogType type, LogSender sender, string message) { string path = Directory.GetCurrentDirectory() + "/log"; - DirectoryInfo dir = new DirectoryInfo(path); + DirectoryInfo dir = new(path); if (!dir.Exists) dir.Create(); string fileName = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() + "_TBot.log"; try { - StreamWriter file = new StreamWriter(path + "/" + fileName, true); + StreamWriter file = new(path + "/" + fileName, true); file.WriteLine("[" + type.ToString() + "] " + "[" + sender.ToString() + "] " + "[" + DateTime.Now.ToString() + "] - " + message); file.Close(); } @@ -253,7 +253,6 @@ public static int CalcShipSpeed(Buildables buildable, int combustionDrive, int i case Buildables.Deathstar: baseSpeed = 100; bonus = hyperspaceDrive * 3; - if (playerClass == Classes.General) bonus += 10; break; case Buildables.Battlecruiser: baseSpeed = 10000; @@ -276,6 +275,31 @@ public static int CalcShipSpeed(Buildables buildable, int combustionDrive, int i return (int)Math.Round(((float)baseSpeed * ((float)bonus + 10) / 10), MidpointRounding.ToZero); } + public static int CalcSlowestSpeed(Ships fleet, Researches researches, Classes playerClass) + { + return CalcSlowestSpeed(fleet, researches.CombustionDrive, researches.ImpulseDrive, researches.HyperspaceDrive, playerClass); + } + + public static int CalcSlowestSpeed(Ships fleet, int combustionDrive, int impulseDrive, int hyperspaceDrive, Classes playerClass) + { + int lowest = int.MaxValue; + foreach (PropertyInfo prop in fleet.GetType().GetProperties()) + { + long qty = (long)prop.GetValue(fleet, null); + + if (qty == 0) continue; + if (Enum.TryParse(prop.Name, out Buildables buildable)) + { + if (buildable == Buildables.SolarSatellite || buildable == Buildables.Crawler) + continue; + int speed = CalcShipSpeed(buildable, combustionDrive, impulseDrive, hyperspaceDrive, playerClass); + if (speed < lowest) + lowest = speed; + } + } + return lowest; + } + public static int CalcFleetSpeed(Ships fleet, Researches researches, Classes playerClass) { return CalcFleetSpeed(fleet, researches.CombustionDrive, researches.ImpulseDrive, researches.HyperspaceDrive, playerClass); @@ -297,6 +321,104 @@ public static int CalcFleetSpeed(Ships fleet, int combustionDrive, int impulseDr return minSpeed; } + public static int CalcShipConsumption(Buildables buildable, Researches researches, ServerData serverData, Classes playerClass) + { + return CalcShipConsumption(buildable, researches.ImpulseDrive, researches.HyperspaceDrive, serverData.GlobalDeuteriumSaveFactor, playerClass); + } + + public static int CalcShipConsumption(Buildables buildable, int impulseDrive, int hyperspaceDrive, double deuteriumSaveFactor, Classes playerClass) + { + int baseConsumption; + switch (buildable) + { + case Buildables.SmallCargo: + baseConsumption = 20; + if (impulseDrive >= 5) + baseConsumption *= 2; + break; + case Buildables.LargeCargo: + baseConsumption = 50; + break; + case Buildables.LightFighter: + baseConsumption = 20; + break; + case Buildables.HeavyFighter: + baseConsumption = 75; + break; + case Buildables.Cruiser: + baseConsumption = 300; + break; + case Buildables.Battleship: + baseConsumption = 500; + break; + case Buildables.ColonyShip: + baseConsumption = 1000; + break; + case Buildables.Recycler: + baseConsumption = 2000; + if (hyperspaceDrive >= 15) + baseConsumption *= 3; + else if (impulseDrive >= 17) + baseConsumption *= 2; + break; + case Buildables.EspionageProbe: + baseConsumption = 1; + break; + case Buildables.Bomber: + baseConsumption = 700; + if (hyperspaceDrive >= 8) + baseConsumption *= 3 / 2; + break; + case Buildables.Destroyer: + baseConsumption = 1000; + break; + case Buildables.Deathstar: + baseConsumption = 1; + break; + case Buildables.Battlecruiser: + baseConsumption = 250; + break; + case Buildables.Reaper: + baseConsumption = 1100; + break; + case Buildables.Pathfinder: + baseConsumption = 300; + break; + default: + return 0; + } + float fuelConsumption = (float)(deuteriumSaveFactor * baseConsumption); + if (playerClass == Classes.General) + fuelConsumption /= 2; + return (int)Math.Round(fuelConsumption, MidpointRounding.ToZero); + } + + public static int CalcFlightTime(Coordinate origin, Coordinate destination, Ships ships, Speeds speed, Researches researches, ServerData serverData, Classes playerClass) + { + return CalcFlightTime(origin, destination, ships, speed, researches.CombustionDrive, researches.ImpulseDrive, researches.HyperspaceDrive, serverData.Galaxies, serverData.Systems, serverData.DonutGalaxy, serverData.DonutSystem, serverData.SpeedFleet, playerClass); + } + + public static int CalcFlightTime(Coordinate origin, Coordinate destination, Ships ships, Speeds speed, int combustionDrive, int impulseDrive, int hyperspaceDrive, int numberOfGalaxies, int numberOfSystems, bool donutGalaxies, bool donutSystems, int fleetSpeed, Classes playerClass) + { + var fleetSpeedPercent = speed switch + { + Speeds.HundredPercent => 1, + Speeds.NinetyPercent => 0.9, + Speeds.EightyPercent => 0.8, + Speeds.SeventyPercent => 0.7, + Speeds.SixtyPercent => 0.6, + Speeds.FiftyPercent => 0.5, + Speeds.FourtyPercent => 0.4, + Speeds.ThirtyPercent => 0.3, + Speeds.TwentyPercent => 0.2, + Speeds.TenPercent => 0.1, + _ => 1, + }; + int slowestShipSpeed = CalcSlowestSpeed(ships, combustionDrive, impulseDrive, hyperspaceDrive, playerClass); + int distance = CalcDistance(origin, destination, numberOfGalaxies, numberOfSystems, donutGalaxies, donutSystems); + return (int)Math.Round(((3500 / fleetSpeedPercent) * (Math.Sqrt(distance * 10 / slowestShipSpeed) + 10) / fleetSpeed), MidpointRounding.AwayFromZero); + } + public static Resources CalcMaxTransportableResources(Ships ships, Resources resources, int hyperspaceTech, Classes playerClass) { var capacity = CalcFleetCapacity(ships, hyperspaceTech, playerClass); @@ -614,7 +736,7 @@ public static long CalcDeuteriumProduction(Planet planet, int speedFactor, float public static Resources CalcPlanetHourlyProduction(Planet planet, int speedFactor, float ratio = 1, Researches researches = null, Classes playerClass = Classes.NoClass, bool hasGeologist = false, bool hasStaff = false) { - Resources hourlyProduction = new Resources + Resources hourlyProduction = new() { Metal = CalcMetalProduction(planet, speedFactor, ratio, researches, playerClass, hasGeologist, hasStaff), Crystal = CalcCrystalProduction(planet, speedFactor, ratio, researches, playerClass, hasGeologist, hasStaff), @@ -625,7 +747,7 @@ public static Resources CalcPlanetHourlyProduction(Planet planet, int speedFacto public static Resources CalcPrice(Buildables buildable, int level) { - Resources output = new Resources(); + Resources output = new(); switch (buildable) { @@ -1049,7 +1171,7 @@ public static Buildables GetNextMineToBuild(Planet planet, int maxMetalMine = 10 dic.Add(mine, CalcPrice(mine, GetNextLevel(planet, mine)).ConvertedDeuterium); } - if (dic.Count() == 0) + if (dic.Count == 0) return Buildables.Null; dic = dic.OrderBy(m => m.Value) diff --git a/TBot/Model/Enums.cs b/TBot/Model/Enums.cs index 4be17d71..ca758241 100644 --- a/TBot/Model/Enums.cs +++ b/TBot/Model/Enums.cs @@ -108,29 +108,25 @@ public enum Missions public enum Speeds { - TenPercent = 1, - TwentyPercent = 2, - ThirtyPercent = 3, - FourtyPercent = 4, - FiftyPercent = 5, - SixtyPercent = 6, - SeventyPercent = 7, - EightyPercent = 8, - NinetyPercent = 9, - HundredPercent = 10 - } - - public enum Percents - { + FivePercent = 5, TenPercent = 10, + FifteenPercent = 15, TwentyPercent = 20, + TwentyfivePercent = 25, ThirtyPercent = 30, + ThirtyfivePercent = 35, FourtyPercent = 40, + FourtyfivePercent = 45, FiftyPercent = 50, + FiftyfivePercent = 55, SixtyPercent = 60, + SixtyfivePercent = 65, SeventyPercent = 70, + SeventyfivePercent = 75, EightyPercent = 80, + EightyfivePercent = 85, NinetyPercent = 90, + NinetyfivePercent = 95, HundredPercent = 100 } diff --git a/TBot/Model/Types.cs b/TBot/Model/Types.cs index b2f3cb40..d406e797 100644 --- a/TBot/Model/Types.cs +++ b/TBot/Model/Types.cs @@ -195,9 +195,9 @@ public class ServerData public bool ACS { get; set; } public bool RapidFire { get; set; } public bool DefToTF { get; set; } - public double DebrisFactor { get; set; } + public float DebrisFactor { get; set; } public int DebrisFactorDef { get; set; } - public double RepairFactor { get; set; } + public float RepairFactor { get; set; } public int NewbieProtectionLimit { get; set; } public int NewbieProtectionHigh { get; set; } public int TopScore { get; set; } @@ -208,7 +208,7 @@ public class ServerData public int WfMinimumRessLost { get; set; } public int WfMinimumLossPercentage { get; set; } public int WfBasicPercentageRepairable { get; set; } - public double GlobalDeuteriumSaveFactor { get; set; } + public float GlobalDeuteriumSaveFactor { get; set; } public int Bashlimit { get; set; } public int ProbeCargo { get; set; } public int ResearchDurationDivisor { get; set; } diff --git a/TBot/Program.cs b/TBot/Program.cs index 841e15b0..940126dd 100644 --- a/TBot/Program.cs +++ b/TBot/Program.cs @@ -43,7 +43,7 @@ static void Main(string[] args) Helpers.SetTitle(); settings = Config.Global; - Credentials credentials = new Credentials + Credentials credentials = new() { Universe = settings.Credentials.Universe.ToString(), Username = settings.Credentials.Email.ToString(), @@ -67,7 +67,9 @@ static void Main(string[] args) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Tbot, "Unable to start ogamed: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } + try { ogamedService.SetUserAgent(settings.General.UserAgent.ToString()); @@ -75,6 +77,7 @@ static void Main(string[] args) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Tbot, "Unable to set user agent: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } Thread.Sleep(Helpers.CalcRandomInterval(IntervalType.LessThanASecond)); @@ -87,6 +90,7 @@ static void Main(string[] args) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Tbot, "Unable to login: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } Thread.Sleep(Helpers.CalcRandomInterval(IntervalType.AFewSeconds)); @@ -225,7 +229,7 @@ private static List UpdatePlanets(UpdateType updateType = UpdateType. { localPlanets = celestials; } - List newPlanets = new List(); + List newPlanets = new(); foreach (Celestial planet in localPlanets) { newPlanets.Add(UpdatePlanet(planet, updateType)); @@ -303,6 +307,7 @@ private static Celestial UpdatePlanet(Celestial planet, UpdateType updateType = catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Tbot, "Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); Helpers.WriteLog(LogType.Warning, LogSender.Tbot, "An error has occurred. Skipping update"); } return planet; @@ -329,22 +334,22 @@ private static void InitializeBrain() { Helpers.WriteLog(LogType.Info, LogSender.Tbot, "Initializing brain..."); - if (settings.Brain.AutoCargo.Active) + if ((bool)settings.Brain.AutoCargo.Active) { timers.Add("CapacityTimer", new Timer(AutoBuildCargo, null, Helpers.CalcRandomInterval(IntervalType.AMinuteOrTwo), Helpers.CalcRandomInterval((int)settings.Brain.AutoCargo.CheckIntervalMin, (int)settings.Brain.AutoCargo.CheckIntervalMax))); } - if (settings.Brain.AutoRepatriate.Active) + if ((bool)settings.Brain.AutoRepatriate.Active) { timers.Add("RepatriateTimer", new Timer(AutoRepatriate, null, Helpers.CalcRandomInterval(IntervalType.AboutFiveMinutes), Helpers.CalcRandomInterval((int)settings.Brain.AutoRepatriate.CheckIntervalMin, (int)settings.Brain.AutoRepatriate.CheckIntervalMax))); } /*Lorenzo 05/02/2021 * Adding timer for auto buil mine */ - if (settings.Brain.AutoMine.Active) + if ((bool)settings.Brain.AutoMine.Active) { timers.Add("AutoMineTimer", new Timer(AutoMine, null, Helpers.CalcRandomInterval(IntervalType.SomeSeconds), Helpers.CalcRandomInterval((int)settings.Brain.Automine.CheckIntervalMin, (int)settings.Brain.Automine.CheckIntervalMax))); } - if (settings.Brain.BuyOfferOfTheDay.Active) + if ((bool)settings.Brain.BuyOfferOfTheDay.Active) { timers.Add("OfferOfTheDayTimer", new Timer(BuyOfferOfTheDay, null, Helpers.CalcRandomInterval(IntervalType.SomeSeconds), Helpers.CalcRandomInterval((int)settings.Brain.BuyOfferOfTheDay.CheckIntervalMin, (int)settings.Brain.BuyOfferOfTheDay.CheckIntervalMax))); } @@ -398,6 +403,7 @@ private static void Defender(object state) catch (Exception e) { Helpers.WriteLog(LogType.Warning, LogSender.Defender, "An error has occurred while checking for attacks: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); DateTime time = GetDateTime(); int interval = Helpers.CalcRandomInterval(IntervalType.AFewSeconds); DateTime newTime = time.AddMilliseconds(interval); @@ -430,6 +436,7 @@ private static void BuyOfferOfTheDay(object state) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Brain, "BuyOfferOfTheDay Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } finally { @@ -529,6 +536,7 @@ private static void AutoMine(object state) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Brain, "AutoMine Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } finally { @@ -604,6 +612,7 @@ private static void mHandleDeposit(Celestial xCelestial, ref Buildables xBuildab catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Brain, "mHandleDeposit Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } } /*Lorenzo 06/02/2021 @@ -633,6 +642,7 @@ private static void mHandleMines(Celestial xCelestial, ref Buildables xBuildable catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Brain, "mHandleMines Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } } @@ -675,6 +685,7 @@ private static void mHandleBuildCelestialBuild(Celestial xCelestial, Buildables catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Brain, "mHandleBuildCelestialMines Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } } @@ -760,7 +771,8 @@ private static void AutoBuildCargo(object state) } catch (Exception e) { - Helpers.WriteLog(LogType.Error, LogSender.Brain, "Unable to complete autocargo: " + e.Message); + Helpers.WriteLog(LogType.Error, LogSender.Brain, "Unable to complete autocargo: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } finally { @@ -802,7 +814,7 @@ private static void AutoRepatriate(object state) } Buildables preferredShip = Enum.Parse(settings.Brain.AutoRepatriate.CargoType.ToString() ?? "SmallCargo") ?? Buildables.SmallCargo; long idealShips = Helpers.CalcShipNumberForPayload(celestial.Resources, preferredShip, researches.HyperspaceTechnology, userInfo.Class); - Ships ships = new Ships(); + Ships ships = new(); if (idealShips <= celestial.Ships.GetAmount(preferredShip)) { ships.Add(preferredShip, idealShips); @@ -836,6 +848,7 @@ private static void AutoRepatriate(object state) catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Brain, "Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Unable to parse custom destination"); } } @@ -844,7 +857,8 @@ private static void AutoRepatriate(object state) } catch (Exception e) { - Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Unable to complete repatriate: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Unable to complete repatriate: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } finally { @@ -859,9 +873,29 @@ private static void AutoRepatriate(object state) } } - private static int SendFleet(Celestial origin, Ships ships, Coordinate destination, Missions mission, Speeds speed, Model.Resources payload = null, bool force = false) + private static int SendFleet(Celestial origin, Ships ships, Coordinate destination, Missions mission, Speeds speed, Model.Resources payload = null, Classes playerClass = Classes.NoClass, bool force = false) { - Helpers.WriteLog(LogType.Info, LogSender.Tbot, "Sending fleet from " + origin.Coordinate.ToString() + " to " + destination.ToString() + ". Mission: " + mission.ToString() + ". Ships: " + ships.ToString()); + Helpers.WriteLog(LogType.Info, LogSender.Tbot, "Sending fleet from " + origin.Coordinate.ToString() + " to " + destination.ToString() + ". Mission: " + mission.ToString() + ". Speed: " + speed.ToString() + ". Ships: " + ships.ToString()); + + if ( + playerClass != Classes.General && ( + speed == Speeds.FivePercent || + speed == Speeds.FifteenPercent || + speed == Speeds.TwentyfivePercent || + speed == Speeds.ThirtyfivePercent || + speed == Speeds.FourtyfivePercent || + speed == Speeds.FiftyfivePercent || + speed == Speeds.SixtyfivePercent || + speed == Speeds.SeventyfivePercent || + speed == Speeds.EightyfivePercent || + speed == Speeds.NinetyfivePercent + ) + ) + { + Helpers.WriteLog(LogType.Warning, LogSender.Tbot, "Unable to send fleet, speed not available for your class"); + return 0; + } + slots = UpdateSlots(); if (slots.Free > 1 || force) { @@ -879,6 +913,7 @@ private static int SendFleet(Celestial origin, Ships ships, Coordinate destinati catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Tbot, "Unable to send fleet: an exception has occurred: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); return 0; } } @@ -913,6 +948,7 @@ private static bool CancelFleet(Fleet fleet) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Tbot, "Unable to recall fleet: an exception has occurred: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); return false; } } @@ -952,7 +988,7 @@ private static void HandleAttack(object state) Celestial attackedCelestial = celestials.SingleOrDefault(planet => planet.Coordinate.Galaxy == attack.Destination.Galaxy && planet.Coordinate.System == attack.Destination.System && planet.Coordinate.Position == attack.Destination.Position && planet.Coordinate.Type == attack.Destination.Type); attackedCelestial = UpdatePlanet(attackedCelestial, UpdateType.Ships); Helpers.WriteLog(LogType.Warning, LogSender.Defender, "Player " + attack.AttackerName + " (" + attack.AttackerID + ") is attacking your planet " + attackedCelestial.ToString() + " arriving at " + attack.ArrivalTime.ToString()); - if (settings.Defender.SpyAttacker.Active) + if ((bool)settings.Defender.SpyAttacker.Active) { slots = UpdateSlots(); if (slots.Free > 0) @@ -966,7 +1002,7 @@ private static void HandleAttack(object state) try { Coordinate destination = attack.Origin; - Ships ships = new Ships { EspionageProbe = (int)settings.Defender.SpyAttacker.Probes }; + Ships ships = new() { EspionageProbe = (int)settings.Defender.SpyAttacker.Probes }; int fleetId = SendFleet(attackedCelestial, ships, destination, Missions.Spy, Speeds.HundredPercent); Fleet fleet = fleets.Single(fleet => fleet.ID == fleetId); Helpers.WriteLog(LogType.Info, LogSender.Defender, "Spying attacker from " + attackedCelestial.ToString() + " to " + destination.ToString() + " with " + settings.Defender.SpyAttacker.Probes + " probes. Arrival at " + fleet.ArrivalTime.ToString()); @@ -974,6 +1010,7 @@ private static void HandleAttack(object state) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Defender, "Could not spy attacker: an exception has occurred: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } } @@ -983,11 +1020,11 @@ private static void HandleAttack(object state) Helpers.WriteLog(LogType.Warning, LogSender.Defender, "Could not send probes: no slots available."); } } - if (settings.Defender.MessageAttacker.Active) + if ((bool)settings.Defender.MessageAttacker.Active) { try { - Random random = new Random(); + Random random = new(); string[] messages = settings.Defender.MessageAttacker.Messages; int messageIndex = random.Next(0, messages.Length); string message = messages[messageIndex]; @@ -1002,9 +1039,10 @@ private static void HandleAttack(object state) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Defender, "Could not message attacker: an exception has occurred: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); } } - if (settings.Defender.Autofleet.Active) + if ((bool)settings.Defender.Autofleet.Active) { slots = UpdateSlots(); if (slots.Free > 0) @@ -1062,7 +1100,7 @@ private static void HandleAttack(object state) else { Resources resources = Helpers.CalcMaxTransportableResources(ships, attackedCelestial.Resources, researches.HyperspaceTechnology, userInfo.Class); - int fleetId = SendFleet(attackedCelestial, ships, destination.Coordinate, mission, Speeds.TenPercent, resources, true); + int fleetId = SendFleet(attackedCelestial, ships, destination.Coordinate, mission, Speeds.TenPercent, resources, userInfo.Class, true); if (fleetId != 0) { Fleet fleet = fleets.Single(fleet => fleet.ID == fleetId); @@ -1094,6 +1132,7 @@ private static void HandleAttack(object state) catch (Exception e) { Helpers.WriteLog(LogType.Error, LogSender.Defender, "Could not fleetsave: an exception has occurred: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); DateTime time = GetDateTime(); int interval = Helpers.CalcRandomInterval(IntervalType.AFewSeconds); DateTime newTime = time.AddMilliseconds(interval); @@ -1145,27 +1184,29 @@ private static void HandleExpeditions(object state) { if (slots.Free > 0) { - List origins = new List(); + List origins = new(); if (settings.Expeditions.AutoSendExpeditions.Origin.Length > 0) { try { foreach (var origin in settings.Expeditions.AutoSendExpeditions.Origin) { - Coordinate customOriginCoords = new Coordinate( + Coordinate customOriginCoords = new( (int)origin.Galaxy, (int)origin.System, (int)origin.Position, - Enum.Parse(origin.Type.ToString())); - Celestial customOrigin = celestials - .Single(planet => planet.HasCoords(customOriginCoords)); - customOrigin = UpdatePlanet(customOrigin, UpdateType.Ships); - origins.Add(customOrigin); + Enum.Parse(origin.Type.ToString()) + ); + Celestial customOrigin = celestials + .Single(planet => planet.HasCoords(customOriginCoords)); + customOrigin = UpdatePlanet(customOrigin, UpdateType.Ships); + origins.Add(customOrigin); } } catch (Exception e) { Helpers.WriteLog(LogType.Debug, LogSender.Expeditions, "Exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "Unable to parse custom origin"); celestials = UpdatePlanets(UpdateType.Ships); @@ -1377,6 +1418,7 @@ private static void HandleExpeditions(object state) catch (Exception e) { Helpers.WriteLog(LogType.Warning, LogSender.Expeditions, "HandleExpeditions exception: " + e.Message); + Helpers.WriteLog(LogType.Warning, LogSender.Brain, "Stacktrace: " + e.StackTrace); int interval = (int)(Helpers.CalcRandomInterval(IntervalType.AMinuteOrTwo)); var time = GetDateTime(); DateTime newTime = time.AddMilliseconds(interval); diff --git a/TBot/TBot.csproj b/TBot/TBot.csproj index 8bc0dcf7..f56dee94 100644 --- a/TBot/TBot.csproj +++ b/TBot/TBot.csproj @@ -5,15 +5,15 @@ net5.0 disable ELK-Lab - 0.2.0 + 0.2.1 Tbot.Program AnyCPU;x64;x86 2021 © ELK-Lab https://licenses.nuget.org/MIT https://www.ogame-tbot.net https://github.com/ogame-tbot/TBot - 0.2.0.0 - 0.2.0.0 + 0.2.1.0 + 0.2.1.0 OGame Bot false ELK-Lab.pfx