diff --git a/TbsCore/Core/TaskExecutor.cs b/TbsCore/Core/TaskExecutor.cs index 73256a3ba..f3832b25f 100644 --- a/TbsCore/Core/TaskExecutor.cs +++ b/TbsCore/Core/TaskExecutor.cs @@ -177,9 +177,6 @@ public static void UpdateDorf2Info(Account acc) var vill = acc.Villages.FirstOrDefault(x => x.Active); if (vill == null) return; - //remove any further UpdateDorf2 BotTasks for this village (if below 5min) - acc.Tasks.Remove(typeof(UpdateDorf2), vill, 5); - UpdateCurrentlyBuilding(acc, vill); var buildings = InfrastructureParser.GetBuildings(acc, acc.Wb.Html); @@ -197,9 +194,6 @@ public static void UpdateDorf1Info(Account acc) var vill = acc.Villages.FirstOrDefault(x => x.Active); if (vill == null) return; - //remove any further UpdateDorf1 BotTasks for this village (if below 5min) - acc.Tasks.Remove(typeof(UpdateDorf1), vill, 5); - UpdateCurrentlyBuilding(acc, vill); var dorf1Movements = TroopsMovementParser.ParseDorf1Movements(acc.Wb.Html); diff --git a/TbsCore/Helpers/AccountHelper.cs b/TbsCore/Helpers/AccountHelper.cs index 55d4bac18..5c95c9bd4 100644 --- a/TbsCore/Helpers/AccountHelper.cs +++ b/TbsCore/Helpers/AccountHelper.cs @@ -1,6 +1,9 @@ -using System; +using Discord.Webhook; +using System; +using System.Collections.Generic; using System.Linq; using TbsCore.Models.AccModels; +using TbsCore.Models.Logging; using TbsCore.Models.VillageModels; using TbsCore.Tasks.LowLevel; using TbsCore.Tasks.SecondLevel; @@ -61,76 +64,122 @@ public static void StartAccountTasks(Account acc) // Get the server info (on first running the account) if (acc.AccInfo.ServerSpeed == 0 || acc.AccInfo.MapSize == 0) { - acc.Tasks.Add(new GetServerInfo() { ExecuteAt = DateTime.MinValue.AddHours(2) }); + acc.Tasks.Add(new GetServerInfo() + { + ExecuteAt = DateTime.MinValue.AddHours(2) + }, true); } if (acc.AccInfo.Tribe == null) { - acc.Tasks.Add(new GetTribe() { ExecuteAt = DateTime.MinValue.AddHours(3) }, true); + acc.Tasks.Add(new GetTribe() + { + ExecuteAt = DateTime.MinValue.AddHours(3) + }, true); } - //FL - if (acc.Farming.Enabled) acc.Tasks.Add(new SendFLs() { ExecuteAt = DateTime.Now }, true); - - // Bot sleep - acc.Tasks.Add(new Sleep() - { - ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc), - AutoSleep = true - }, true); - // Access change var nextAccessChange = TimeHelper.GetNextProxyChange(acc); if (nextAccessChange != TimeSpan.MaxValue) { - acc.Tasks.Add(new ChangeAccess() { ExecuteAt = DateTime.Now + nextAccessChange }, true); + acc.Tasks.Add(new ChangeAccess() + { + ExecuteAt = DateTime.Now + nextAccessChange + }, true); } - //research / improve / train troops - foreach (var vill in acc.Villages) + + var rand = new Random(); + var vills = acc.Villages.OrderBy((item) => rand.Next()); + foreach (var vill in vills) { - //if (vill.Troops.Researched.Count == 0) acc.Tasks.Add( new UpdateTroops() { ExecuteAt = DateTime.Now, vill = vill }); - TroopsHelper.ReStartResearchAndImprovement(acc, vill); - TroopsHelper.ReStartTroopTraining(acc, vill); - BuildingHelper.ReStartBuilding(acc, vill); - BuildingHelper.ReStartDemolishing(acc, vill); - MarketHelper.ReStartSendingToMain(acc, vill); - ReStartCelebration(acc, vill); - VillageHelper.SetNextRefresh(acc, vill); - if (vill.FarmingNonGold.OasisFarmingEnabled) + // update info + var min = vill.Settings.RefreshMin * 60; + var max = vill.Settings.RefreshMax * 60; + int timeUpdate; + + timeUpdate = rand.Next(min, max); + acc.Tasks.Add(new UpdateVillage() + { + ExecuteAt = DateTime.Now.AddSeconds(timeUpdate), + Vill = vill, + NewVillage = false + }, true, vill); + + // this is for task delay, i will add this in next time ~ VINAGHOST + min = 0; + max = 3; + // building + + if (vill.Build.Tasks.Count > 0) { - acc.Tasks.Add(new AttackOasis() { Vill = vill }, true, vill); + timeUpdate = rand.Next(min, max); + + acc.Tasks.Add(new UpgradeBuilding() + { + ExecuteAt = DateTime.Now.AddMilliseconds(timeUpdate), + Vill = vill, + }, true, vill); } - // Remove in later updates! - if (vill.Settings.RefreshMin == 0) vill.Settings.RefreshMin = 30; - if (vill.Settings.RefreshMax == 0) vill.Settings.RefreshMax = 60; - } - // Remove in later updates! - if (acc.Hero.Settings.MinUpdate == 0) acc.Hero.Settings.MinUpdate = 40; - if (acc.Hero.Settings.MaxUpdate == 0) acc.Hero.Settings.MaxUpdate = 80; + // demolish - // Hero update info - if (acc.Hero.Settings.AutoRefreshInfo) - { - Random ran = new Random(); - acc.Tasks.Add(new HeroUpdateInfo() + if (vill.Build.DemolishTasks.Count > 0) { - ExecuteAt = DateTime.Now.AddMinutes(ran.Next(40, 80)), - Priority = Tasks.BotTask.TaskPriority.Low - }); + timeUpdate = rand.Next(min, max); + acc.Tasks.Add(new DemolishBuilding() + { + ExecuteAt = DateTime.Now.AddMilliseconds(timeUpdate), + Vill = vill, + }, true, vill); + } + + TroopsHelper.ReStartResearchAndImprovement(acc, vill); + TroopsHelper.ReStartTroopTraining(acc, vill); } } - public static void ReStartCelebration(Account acc, Village vill) + public static void Loaded(Account acc) { - // If we don't want auto-celebrations, return - if (vill.Expansion.Celebrations == CelebrationEnum.None) return; + if (acc.Settings.DiscordWebhook && !string.IsNullOrEmpty(acc.AccInfo.WebhookUrl)) + { + acc.WebhookClient = new DiscordWebhookClient(acc.AccInfo.WebhookUrl); + } + + SerilogSingleton.LogOutput.AddUsername(acc.AccInfo.Nickname); + acc.Logger = new Logger(acc.AccInfo.Nickname); + acc.Tasks = new TaskList(acc); + acc.Tasks.LoadFromFile(IoHelperCore.GetTaskFileUrl(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl)); + var sleepTask = acc.Tasks?.FindTask(typeof(Sleep)); + if (sleepTask != null) + { + sleepTask.ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc); + } + else + { + acc.Tasks.Add(new Sleep() + { + AutoSleep = true, + ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc), + }, true); + } - acc.Tasks.Add(new Celebration() + var rand = new Random(); + var min = 0; + var max = 3; + foreach (var task in acc.Tasks.ToList()) { - ExecuteAt = vill.Expansion.CelebrationEnd.AddSeconds(7), - Vill = vill - }, true, vill); + if (task.GetType() == typeof(Sleep)) continue; + //reset Vill, obj Vill we save is different with current Vill object account hold + task.Vill = acc.Villages.FirstOrDefault(x => x.Id == task.Vill?.Id); + //reset time execute + if (task.ExecuteAt < DateTime.Now) + { + var timeUpdate = rand.Next(min, max); + task.ExecuteAt = DateTime.Now.AddMilliseconds(timeUpdate); + } + } + + acc.Villages.ForEach(vill => vill.UnfinishedTasks = new List()); } } } \ No newline at end of file diff --git a/TbsCore/Helpers/DefaultConfigurations.cs b/TbsCore/Helpers/DefaultConfigurations.cs index e2d4f38fe..75c2b04f7 100644 --- a/TbsCore/Helpers/DefaultConfigurations.cs +++ b/TbsCore/Helpers/DefaultConfigurations.cs @@ -64,24 +64,5 @@ public static void OffVillagePlan(Account acc, Village vill) BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.RallyPoint, Level = 15 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.TournamentSquare, Level = 1 }); } - - public static void SetDefaultTransitConfiguration(Account acc, Village vill) - { - var res = vill.Market.Settings.Configuration; - var transit = new Resources(); - var limit = new Resources(); - transit.Wood = 90; //% - transit.Clay = 90; - transit.Iron = 90; - transit.Crop = 90; - limit.Wood = 20000; - limit.Clay = 20000; - limit.Iron = 20000; - limit.Crop = 15000; - res.Enabled = true; - res.BalanceType = Tasks.ResourcesConfiguration.BalanceType.RecieveFrom; - res.FillLimit = limit; - res.TargetLimit = transit; - } } } \ No newline at end of file diff --git a/TbsCore/Helpers/DriverHelper.cs b/TbsCore/Helpers/DriverHelper.cs index c424ee9b2..53938f652 100644 --- a/TbsCore/Helpers/DriverHelper.cs +++ b/TbsCore/Helpers/DriverHelper.cs @@ -90,6 +90,7 @@ public static string GetBearerToken(Account acc, bool log = true) internal static async Task WriteCoordinates(Account acc, Coordinates coordinates) { await WriteById(acc, "xCoordInput", coordinates.x); + await Task.Delay(AccountHelper.Delay(acc)); await WriteById(acc, "yCoordInput", coordinates.y); } @@ -132,22 +133,38 @@ public static async Task SelectIndexByName(Account acc, string query, int private static async Task ExecuteAction(Account acc, Query query, Action action, bool log = true, bool update = true) => await ExecuteScript(acc, $"document.{query.val}{action.val}", log, update); - public class QueryById : Query { public QueryById(string str) => base.val = $"getElementById('{str}')"; } + public class QueryById : Query - public class QueryByName : Query { public QueryByName(string str) => base.val = $"getElementsByName('{str}')[0]"; } + { public QueryById(string str) => base.val = $"getElementById('{str}')"; } - public class QueryByClassName : Query { public QueryByClassName(string str) => base.val = $"getElementsByClassName('{str}')[0]"; } + public class QueryByName : Query - public class ActionWrite : Action { public ActionWrite(object str) => base.val = $".value='{str}';"; } + { public QueryByName(string str) => base.val = $"getElementsByName('{str}')[0]"; } - public class ActionClick : Action { public ActionClick() => base.val = ".click();"; } + public class QueryByClassName : Query - public class ActionCheck : Action { public ActionCheck(bool check) => base.val = $".checked={(check ? "true" : "false")};"; } + { public QueryByClassName(string str) => base.val = $"getElementsByClassName('{str}')[0]"; } - public class ActionSelectIndex : Action { public ActionSelectIndex(int index) => base.val = $".selectedIndex = {index};"; } + public class ActionWrite : Action - public abstract class Action { public string val; } + { public ActionWrite(object str) => base.val = $".value='{str}';"; } - public abstract class Query { public string val; } + public class ActionClick : Action + + { public ActionClick() => base.val = ".click();"; } + + public class ActionCheck : Action + + { public ActionCheck(bool check) => base.val = $".checked={(check ? "true" : "false")};"; } + + public class ActionSelectIndex : Action + + { public ActionSelectIndex(int index) => base.val = $".selectedIndex = {index};"; } + + public abstract class Action + { public string val; } + + public abstract class Query + { public string val; } } } \ No newline at end of file diff --git a/TbsCore/Helpers/IoHelperCore.cs b/TbsCore/Helpers/IoHelperCore.cs index 5077d7278..d054fab02 100644 --- a/TbsCore/Helpers/IoHelperCore.cs +++ b/TbsCore/Helpers/IoHelperCore.cs @@ -4,10 +4,8 @@ using System.IO; using System.Linq; using System.Threading.Tasks; -using Discord.Webhook; using TbsCore.Database; using TbsCore.Models.Access; -using TbsCore.Models.Logging; using TbsCore.Models.AccModels; using TbsCore.Models.BuildingModels; using TbsCore.Models.VillageModels; @@ -21,6 +19,7 @@ public static class IoHelperCore { public static string AccountsPath => Path.Combine(TbsPath, "accounts.txt"); public static string CachePath => Path.Combine(TbsPath, "cache"); + public static string TaskPath => Path.Combine(TbsPath, "task"); public static string SqlitePath => Path.Combine(TbsPath, "db.sqlite"); public static string TbsPath => @@ -32,7 +31,13 @@ public static class IoHelperCore public static string GetCacheDir(string username, string server, Access access) { - return Path.Combine(IoHelperCore.CachePath, GetCacheFolder(username, server, access.Proxy)); + return Path.Combine(CachePath, GetCacheFolder(username, server, access.Proxy)); + } + + public static string GetTaskFileUrl(string username, string server) + { + Directory.CreateDirectory(TaskPath); + return Path.Combine(TaskPath, GetTaskFile(username, server)); } /// @@ -140,6 +145,15 @@ public static void RemoveCache(Account acc) } } + public static void RemoveTask(Account acc) + { + var userFile = IoHelperCore.GetTaskFileUrl(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl); + + if (!File.Exists(userFile)) return; + + File.Delete(userFile); + } + /// /// Removes the protocol (http/https) text from the url /// @@ -167,7 +181,7 @@ public static List ReadAccounts() { accounts = JsonConvert.DeserializeObject>(sr.ReadToEnd()); } - if (accounts == null) accounts = new List(); + accounts = accounts ?? new List(); accounts.ForEach(x => ObjectHelper.FixAccObj(x, x)); } @@ -185,21 +199,40 @@ public static List ReadAccounts() /// Server url /// Proxy ip /// - internal static string GetCacheFolder(string username, string server, string proxy) + public static string GetCacheFolder(string username, string server, string proxy) + { + return $"{username}_{UrlRemoveHttp(server)}_{proxy}"; + } + + public static string GetTaskFile(string username, string server) { - return $"{username}_{IoHelperCore.UrlRemoveHttp(server)}_{proxy}"; + return $"{username}_{UrlRemoveHttp(server)}.json"; } /// /// Saves accounts into the SQLite DB /// /// - public static void SaveAccounts(List accounts, bool logout) + public static async Task SaveAccounts(List accounts, bool logout) { + if (logout) + { + var list = new List(); + foreach (var acc in accounts) + { + if (acc.IsLogged) + { + var logoutAwait = Logout(acc); + list.Add(logoutAwait); + } + } + + await Task.WhenAll(list); + } foreach (var acc in accounts) { - if (logout) Logout(acc); DbRepository.SaveAccount(acc); + acc.Tasks.SaveToFile(GetTaskFileUrl(acc.AccInfo.Nickname, acc.AccInfo.ServerUrl)); } } @@ -209,38 +242,43 @@ public static void SaveAccounts(List accounts, bool logout) /// Account public static async Task LoginAccount(Account acc) { + if (acc.IsLogged) return; + if (acc.Wb == null) { - SerilogSingleton.LogOutput.AddUsername(acc.AccInfo.Nickname); - - acc.Logger = new Logger(acc.AccInfo.Nickname); - - acc.Tasks = new TaskList(); - acc.Villages.ForEach(vill => vill.UnfinishedTasks = new List()); - acc.Wb = new WebBrowserInfo(); await acc.Wb.InitSelenium(acc); acc.TaskTimer = new TaskTimer(acc); - - AccountHelper.StartAccountTasks(acc); } if (acc.Settings.DiscordWebhook && !string.IsNullOrEmpty(acc.AccInfo.WebhookUrl)) { - acc.WebhookClient = new DiscordWebhookClient(acc.AccInfo.WebhookUrl); if (acc.Settings.DiscordOnlineAnnouncement) { DiscordHelper.SendMessage(acc, "TravianBotSharp is online now"); } } + + AccountHelper.StartAccountTasks(acc); + + acc.IsLogged = true; } /// /// Logout from the account. Closes web driver. /// /// - public static void Logout(Account acc) + public static async Task Logout(Account acc) { + if (!acc.IsLogged) return; + acc.IsLogged = false; + while (acc.Tasks?.IsTaskExcuting() ?? true) + { + await Task.Delay(1000); + acc.Logger.Information("Waiting current task complete ..."); + } + acc.Logger.Information("Logged out."); + if (acc.TaskTimer != null) { acc.TaskTimer.Dispose(); @@ -251,7 +289,7 @@ public static void Logout(Account acc) acc.Wb.Dispose(); acc.Wb = default; } - acc.Tasks = default; //TODO: somehow save tasks, JSON cant parse/stringify abstract classes :( + acc.Tasks = default; } } } \ No newline at end of file diff --git a/TbsCore/Helpers/MapHelper.cs b/TbsCore/Helpers/MapHelper.cs index cfb4c0c33..6c48d42cb 100644 --- a/TbsCore/Helpers/MapHelper.cs +++ b/TbsCore/Helpers/MapHelper.cs @@ -62,6 +62,21 @@ public static float CalculateDistance(Account acc, Coordinates coord1, Coordinat return (float)distance; } + /// + /// + /// + /// + /// + /// 0 = same distance 1 = this farther than other -1 = other farther than this + public static int Compare(Account acc, Coordinates root, Coordinates a, Coordinates b) + { + var distanceA = CalculateDistance(acc, root, a); + var distanceB = CalculateDistance(acc, root, b); + if (distanceA - distanceB < 0.1) return 0; + if (distanceA < distanceB) return -1; + return 1; + } + /// /// Send raw HTTP request to the server and request the map tiles around the coords. This mimics browser on the map page. /// diff --git a/TbsCore/Helpers/MarketHelper.cs b/TbsCore/Helpers/MarketHelper.cs index 06bfdaa17..5915146cf 100644 --- a/TbsCore/Helpers/MarketHelper.cs +++ b/TbsCore/Helpers/MarketHelper.cs @@ -20,75 +20,80 @@ public static class MarketHelper public static int GetMerchantsSpeed(Classificator.TribeEnum tribe) => MerchantSpeed[(int)tribe]; - /// - /// Will send resources from main village to the target village - /// - /// (target) Village to get the resources - /// Returns DateTime when approximately will resources get transited to target village - public static DateTime TransitResourcesFromMain(Account acc, Village vill) - { - // Transit resources for this village is disabled. - if (!vill.Market.Settings.Configuration.Enabled) return DateTime.MaxValue; + #region Trade route - // There already is a sendResources BotTask for this village - var transitTask = (SendResources)acc.Tasks.FindTasks(typeof(SendResources)).FirstOrDefault(x => ((SendResources)x).Coordinates == vill.Coordinates); - - //vill.Market.Settings.Configuration. - if (transitTask != null) return transitTask.Configuration.TransitArrival; - - //Less than 5min ago we already sent resources. Just to catch bugs. - //if(vill.Market.) + public static void AddTradeRoute(Village vill, TradeRoute trade) + { + if (vill.Market.TradeRoute.TradeRoutes == null) + { + vill.Market.TradeRoute.TradeRoutes = new List(); + } + vill.Market.TradeRoute.TradeRoutes.Add(trade); + } - // Merchants are on their way - if (vill.Market.Settings.Configuration.TransitArrival > DateTime.Now) return vill.Market.Settings.Configuration.TransitArrival; + public static void UpdateTradeRoute(Village vill, TradeRoute trade, int index) + { + if (index < 0) return; + if (index >= vill.Market.TradeRoute.TradeRoutes.Count) return; + vill.Market.TradeRoute.TradeRoutes[index] = trade; + } - //send resources - var sendRes = new Resources(); - var conf = vill.Market.Settings.Configuration; - var currentRes = vill.Res.Stored.Resources; - var cap = vill.Res.Capacity; + public static void RemoveTradeRoute(Village vill, int index) + { + if (index < 0) return; + if (index >= vill.Market.TradeRoute.TradeRoutes.Count) return; + vill.Market.TradeRoute.TradeRoutes.RemoveAt(index); - var woodNeeded = (long)(cap.WarehouseCapacity * conf.TargetLimit.Wood / 100.0); - sendRes.Wood = (woodNeeded > conf.FillLimit.Wood ? conf.FillLimit.Wood : woodNeeded) - currentRes.Wood; - sendRes.Wood = (sendRes.Wood < 0 ? 0 : sendRes.Wood); + if (vill.Market.TradeRoute.Next >= vill.Market.TradeRoute.TradeRoutes.Count) + { + vill.Market.TradeRoute.Next = 0; + } + } - var clayNeeded = (long)(cap.WarehouseCapacity * conf.TargetLimit.Clay / 100.0); - sendRes.Clay = (clayNeeded > conf.FillLimit.Clay ? conf.FillLimit.Clay : clayNeeded) - currentRes.Clay; - sendRes.Clay = (sendRes.Clay < 0 ? 0 : sendRes.Clay); + public static int UpdateNextTradeRoute(Village vill) + { + vill.Market.TradeRoute.Next++; - var ironNeeded = (long)(cap.WarehouseCapacity * conf.TargetLimit.Iron / 100.0); - sendRes.Iron = (ironNeeded > conf.FillLimit.Iron ? conf.FillLimit.Iron : ironNeeded) - currentRes.Iron; - sendRes.Iron = (sendRes.Iron < 0 ? 0 : sendRes.Iron); + if (vill.Market.TradeRoute.Next >= vill.Market.TradeRoute.TradeRoutes.Count) + { + vill.Market.TradeRoute.Next = 0; + } + return vill.Market.TradeRoute.Next; + } - var cropNeeded = (long)(cap.GranaryCapacity * conf.TargetLimit.Crop / 100.0); - sendRes.Crop = (cropNeeded > conf.FillLimit.Crop ? conf.FillLimit.Crop : cropNeeded) - currentRes.Crop; - sendRes.Crop = (sendRes.Crop < 0 ? 0 : sendRes.Crop); + #endregion Trade route - if (ResourcesHelper.IsZeroResources(sendRes)) //we have enough res :) - return DateTime.MinValue; + #region Send resource - // Send resources to a village only once per 5 minutes - TimeSpan transitAfter = vill.Market.LastTransit.AddMinutes(5) - DateTime.Now; - if (transitAfter < TimeSpan.Zero) transitAfter = TimeSpan.Zero; + public static Resources GetResource(Village vill, Resources resources) => + new Resources + { + Wood = resources.Wood > 100 ? resources.Wood : vill.Res.Stored.Resources.Wood * resources.Wood / 100, + Clay = resources.Clay > 100 ? resources.Clay : vill.Res.Stored.Resources.Clay * resources.Clay / 100, + Iron = resources.Iron > 100 ? resources.Iron : vill.Res.Stored.Resources.Iron * resources.Iron / 100, + Crop = resources.Crop > 100 ? resources.Crop : vill.Res.Stored.Resources.Crop * resources.Crop / 100, + }; - var sendResTask = new SendResources + public static Resources Round(Resources resources) + { + var res = resources.ToArray(); + for (int i = 0; i < 4; i++) { - Configuration = conf, - Coordinates = vill.Coordinates, - ExecuteAt = DateTime.Now + transitAfter, - Vill = AccountHelper.GetMainVillage(acc), - Resources = sendRes - }; - - acc.Tasks.Add(sendResTask); - - //AddMinutes(1) since bot has to wait for the SendResources task and then - //go to the marketplace and send resources - //TransitArrival will get updated to more specific time + // To avoid exception devide by zero + if (50 <= res[i]) + { + //round the number to about -1%, for rounder numbers + var digits = Math.Ceiling(Math.Log10(res[i])); + var remainder = res[i] % (long)Math.Pow(10, digits - 2); + res[i] -= remainder; + } + } - return DateTime.Now.Add(transitAfter + CalculateTransitTimeMainVillage(acc, vill)).AddMinutes(1); + return ResourcesHelper.ArrayToResources(res); } + #endregion Send resource + /// /// Used by BotTasks to insert resources/coordinates into the page. /// @@ -188,7 +193,7 @@ public static async Task MarketSendResource(Account acc, long[] resour return TimeSpan.FromTicks(duration.Ticks * (times * 2 - 1)); } - private static (long, int) ParseMerchantsInfo(HtmlDocument html) + public static (long, int) ParseMerchantsInfo(HtmlDocument html) { var merchantsCapacity = Parser.RemoveNonNumeric(html.GetElementbyId("merchantCapacityValue").InnerText); int merchantsNum = (int)Parser.RemoveNonNumeric(html.DocumentNode.Descendants("span").First(x => x.HasClass("merchantsAvailable")).InnerText); @@ -272,31 +277,6 @@ public static long[] SendResCapToStorage(Account acc, Resources resources) return ret; } - /// - /// Calculates how many resources should be sent to the main village based on configurable limit - /// - /// Village - /// Resources to be sent - public static long[] GetResToMainVillage(Village vill) - { - var ret = new long[4]; - var res = vill.Res.Stored.Resources.ToArray(); - var limit = vill.Market.Settings.Configuration.SendResLimit.ToArray(); - for (int i = 0; i < 4; i++) - { - // % into resource mode - if (limit[i] < 100) - { - var capacity = i == 3 ? vill.Res.Capacity.GranaryCapacity : vill.Res.Capacity.WarehouseCapacity; - limit[i] = (long)(limit[i] / 100.0 * capacity); - } - - ret[i] = res[i] - limit[i]; - if (ret[i] < 0) ret[i] = 0; - } - return ret; - } - /// /// Finds out which transits will be over soonest and returns the datetime. /// diff --git a/TbsCore/Helpers/ResourcesHelper.cs b/TbsCore/Helpers/ResourcesHelper.cs index b1a66b950..526052153 100644 --- a/TbsCore/Helpers/ResourcesHelper.cs +++ b/TbsCore/Helpers/ResourcesHelper.cs @@ -98,8 +98,8 @@ public static void NotEnoughRes(Account acc, Village vill, Resources requiredRes var mainVill = AccountHelper.GetMainVillage(acc); if (mainVill == vill) return enoughRes; - DateTime resTransit = MarketHelper.TransitResourcesFromMain(acc, vill); - if (resTransit < enoughRes) enoughRes = resTransit; + //DateTime resTransit = MarketHelper.TransitResourcesFromMain(acc, vill); + //if (resTransit < enoughRes) enoughRes = resTransit; if (enoughRes < DateTime.Now) return DateTime.Now; @@ -304,6 +304,23 @@ private static long[] ResStillNeeded(Village vill, Resources required) return neededRes; } + #region Resource compare + + public static bool IsEnough(Village vill, Resources resources) + { + var resInVill = vill.Res.Stored.Resources.ToArray(); + var res = resources.ToArray(); + for (var i = 0; i < 4; i++) + { + if (resInVill[i] < res[i]) return false; + } + return true; + } + + #endregion Resource compare + + #region Resources class supporter + private static long[] SubtractResources(long[] subtractFrom, long[] subtract, bool capToZero) { var ret = new long[4]; @@ -327,7 +344,7 @@ private static long RoundUpTo100(long res) return res + (100 - remainder); } - internal static long[] SumArr(long[] arr1, long[] arr2) + public static long[] SumArr(long[] arr1, long[] arr2) { var ret = new long[4]; for (int i = 0; i < 4; i++) @@ -336,5 +353,7 @@ internal static long[] SumArr(long[] arr1, long[] arr2) } return ret; } + + #endregion Resources class supporter } } \ No newline at end of file diff --git a/TbsCore/Helpers/UpdateAccountObject.cs b/TbsCore/Helpers/UpdateAccountObject.cs index dae279a0b..5e50a375a 100644 --- a/TbsCore/Helpers/UpdateAccountObject.cs +++ b/TbsCore/Helpers/UpdateAccountObject.cs @@ -21,6 +21,7 @@ public static bool UpdateVillages(HtmlAgilityPack.HtmlDocument htmlDoc, Account { var oldVill = acc.Villages[i]; var foundVill = foundVills.Where(x => x.Id == oldVill.Id).FirstOrDefault(); + //Village was not found -> destroyed/chiefed if (foundVill == null) { @@ -28,12 +29,13 @@ public static bool UpdateVillages(HtmlAgilityPack.HtmlDocument htmlDoc, Account i--; continue; } + oldVill.Name = foundVill.Name; oldVill.Active = foundVill.Active; if (oldVill.UnderAttack != foundVill.UnderAttack && foundVill.UnderAttack && - oldVill.Deffing.AlertType != Models.VillageModels.AlertTypeEnum.Disabled) + oldVill.Deffing.AlertType != AlertTypeEnum.Disabled) { acc.Tasks.Add(new CheckAttacks() { Vill = oldVill, Priority = Tasks.BotTask.TaskPriority.High }, true, oldVill); } @@ -74,46 +76,39 @@ public static void NewVillageFound(Account acc, VillageChecked newVill) { ExecuteAt = DateTime.Now.AddHours(-2), Vill = vill, - ImportTasks = true + NewVillage = true }, true, vill); - DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill); - - // Copy default settings to the new village. TODO: use automapper for this. - //var defaultSettings = acc.NewVillages.DefaultSettings; - //vill.Settings = new VillSettings() - //{ - // Type = defaultSettings.Type, - // BarracksTrain = defaultSettings.BarracksTrain, - // StableTrain = defaultSettings.StableTrain, - // WorkshopTrain = defaultSettings.WorkshopTrain, - // GreatBarracksTrain = defaultSettings.GreatBarracksTrain, - // GreatStableTrain = defaultSettings.GreatStableTrain, - // SendRes = defaultSettings.SendRes, - // GetRes = defaultSettings.GetRes, - //}; - // Change village name var newVillageFromList = acc.NewVillages.Locations .FirstOrDefault(x => - x.SettlersSent && x.Coordinates.x == vill.Coordinates.x && x.Coordinates.y == vill.Coordinates.y ); if (newVillageFromList != null) { - if (string.IsNullOrEmpty(newVillageFromList.Name)) + // set name + if (string.IsNullOrWhiteSpace(newVillageFromList.Name)) { newVillageFromList.Name = NewVillageHelper.GenerateName(acc); } + // remove from list new village acc.NewVillages.Locations.Remove(newVillageFromList); + + // change village name acc.Tasks.Add( new ChangeVillageName() { ExecuteAt = DateTime.Now, ChangeList = new List<(int, string)> { (vill.Id, newVillageFromList.Name) } }, true); + + // load building task + if (!string.IsNullOrWhiteSpace(acc.NewVillages.BuildingTasksLocationNewVillage)) + { + IoHelperCore.AddBuildTasksFromFile(acc, vill, acc.NewVillages.BuildingTasksLocationNewVillage); + } } } } diff --git a/TbsCore/Helpers/VillageHelper.cs b/TbsCore/Helpers/VillageHelper.cs index 9d79351b9..d9f61a28a 100644 --- a/TbsCore/Helpers/VillageHelper.cs +++ b/TbsCore/Helpers/VillageHelper.cs @@ -2,6 +2,9 @@ using System.Linq; using System.Threading.Tasks; using System.Web; + +using HtmlAgilityPack; + using TbsCore.Models.AccModels; using TbsCore.Models.VillageModels; using TbsCore.Parsers; @@ -51,10 +54,10 @@ public static int GetVillageIdFromName(string name, Account acc) public static string VillageType(Village vill) { string type = ""; - type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.Woodcutter).ToString(); - type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.ClayPit).ToString(); - type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.IronMine).ToString(); - type += vill.Build.Buildings.Count(x => x.Type == Classificator.BuildingEnum.Cropland).ToString(); + type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.Woodcutter).ToString(); + type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.ClayPit).ToString(); + type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.IronMine).ToString(); + type += vill.Build.Buildings.Count(x => x.Type == BuildingEnum.Cropland).ToString(); if (type == "11115") type = "15c"; return type; } @@ -106,13 +109,12 @@ public static async Task SwitchVillage(Account acc, int id) /// Building to enter /// Additional query (to specify tab) /// Whether we want to first navigate to dorf (less suspicious) - /// Whether we want to force update the current page /// Whether it was successful - public static async Task EnterBuilding(Account acc, Building building, string query = "", bool dorf = true, bool update = false) + private static async Task EnterBuilding(Account acc, Building building, string query = "", bool dorf = true) { // If we are already at the desired building (if gid is correct) Uri currentUri = new Uri(acc.Wb.CurrentUrl); - if (HttpUtility.ParseQueryString(currentUri.Query).Get("gid") == ((int)building.Type).ToString() && !update) + if (HttpUtility.ParseQueryString(currentUri.Query).Get("gid") == ((int)building.Type).ToString()) { acc.Wb.UpdateHtml(); return true; @@ -129,10 +131,11 @@ public static async Task EnterBuilding(Account acc, Building building, str } await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={building.Id}{query}"); + return true; } - public static async Task EnterBuilding(Account acc, Village vill, BuildingEnum buildingEnum, string query = "", bool dorf = true, bool update = false) + public static async Task EnterBuilding(Account acc, Village vill, BuildingEnum buildingEnum, string query = "", bool dorf = true) { var building = vill.Build.Buildings.FirstOrDefault(x => x.Type == buildingEnum); @@ -141,7 +144,11 @@ public static async Task EnterBuilding(Account acc, Village vill, Building acc.Logger.Warning($"Tried to enter {buildingEnum} but couldn't find it in village {vill.Name}!"); return false; } - return await EnterBuilding(acc, building, query, dorf, update); + + await EnterBuilding(acc, building, query, dorf); + UpdateInfoPage(vill, building, acc.Wb.Html); + + return true; } /// @@ -157,27 +164,83 @@ public static void SetNextRefresh(Account acc, Village vill, DateTime? time = nu var ran = new Random(); if (time == null) time = DateTime.Now.AddMinutes(ran.Next(vill.Settings.RefreshMin, vill.Settings.RefreshMax)); - var task = acc.Tasks.FindTask(typeof(UpdateDorf1), vill); - - if (task == null) + acc.Tasks.Add(new UpdateVillage { - acc.Tasks.Add(new UpdateDorf1 - { - Vill = vill, - ExecuteAt = time ?? default, - Priority = Tasks.BotTask.TaskPriority.Low - }); - return; - } - - task.ExecuteAt = time ?? default; - acc.Tasks.ReOrder(); + Vill = vill, + ExecuteAt = time ?? default, + NewVillage = false + }, true); } public static DateTime GetNextRefresh(Account acc, Village vill) { - var task = acc.Tasks.FindTask(typeof(UpdateDorf1), vill); + var task = acc.Tasks.FindTask(typeof(UpdateVillage), vill); return task.NextExecute ?? DateTime.MaxValue; } + + public static void UpdateInfoPage(Village vill, Building building, HtmlDocument html) + { + switch (building.Type) + { + case BuildingEnum.Marketplace: + { + vill.Market.MerchantInfo.Number = building.Level; + (vill.Market.MerchantInfo.Capacity, vill.Market.MerchantInfo.Free) = MarketHelper.ParseMerchantsInfo(html); + break; + } + case BuildingEnum.TownHall: + { + vill.Expansion.CelebrationEnd = TimeParser.GetCelebrationTime(html); + break; + } + case BuildingEnum.Smithy: + { + var levels = TroopsParser.GetTroopLevels(html); + + foreach (var troop in vill.Troops.Levels) + { + if (troop != null) + { + var level = levels.FirstOrDefault(x => x.Troop == troop.Troop); + + vill.Troops.Levels.Remove(troop); + vill.Troops.Levels.Add(level); + } + } + + break; + } + case BuildingEnum.Barracks: + { + TroopsHelper.UpdateTroopsResearched(vill, html); + vill.Troops.CurrentlyTraining.Barracks = TroopsParser.GetTroopsCurrentlyTraining(html); + break; + } + case BuildingEnum.GreatBarracks: + { + TroopsHelper.UpdateTroopsResearched(vill, html); + vill.Troops.CurrentlyTraining.GB = TroopsParser.GetTroopsCurrentlyTraining(html); + break; + } + case BuildingEnum.Stable: + { + TroopsHelper.UpdateTroopsResearched(vill, html); + vill.Troops.CurrentlyTraining.Stable = TroopsParser.GetTroopsCurrentlyTraining(html); + break; + } + case BuildingEnum.GreatStable: + { + TroopsHelper.UpdateTroopsResearched(vill, html); + vill.Troops.CurrentlyTraining.GS = TroopsParser.GetTroopsCurrentlyTraining(html); + break; + } + case BuildingEnum.Workshop: + { + TroopsHelper.UpdateTroopsResearched(vill, html); + vill.Troops.CurrentlyTraining.Workshop = TroopsParser.GetTroopsCurrentlyTraining(html); + break; + } + } + } } } \ No newline at end of file diff --git a/TbsCore/Models/AccModels/Account.cs b/TbsCore/Models/AccModels/Account.cs index 245e73fe0..fd46f21d1 100644 --- a/TbsCore/Models/AccModels/Account.cs +++ b/TbsCore/Models/AccModels/Account.cs @@ -23,7 +23,7 @@ public void Init() Hero = new Hero(); Hero.init(); - Tasks = new TaskList(); + Tasks = new TaskList(this); Villages = new List(); Access = new AccessInfo(); @@ -53,13 +53,13 @@ public void Init() public NewVillageSettings NewVillages { get; set; } public GeneralSettings Settings { get; set; } - [JsonIgnore] + [JsonIgnore] public WebBrowserInfo Wb { get; set; } - [JsonIgnore] + [JsonIgnore] public TaskList Tasks; - [JsonIgnore] + [JsonIgnore] public TaskTimer TaskTimer { get; set; } [JsonIgnore] @@ -67,5 +67,8 @@ public void Init() [JsonIgnore] public Logger Logger; + + [JsonIgnore] + public bool IsLogged; } } \ No newline at end of file diff --git a/TbsCore/Models/AccModels/TaskList.cs b/TbsCore/Models/AccModels/TaskList.cs index 79a97fb80..b9a8b840a 100644 --- a/TbsCore/Models/AccModels/TaskList.cs +++ b/TbsCore/Models/AccModels/TaskList.cs @@ -4,6 +4,8 @@ using TbsCore.Models.VillageModels; using TbsCore.Tasks; using static TbsCore.Tasks.BotTask; +using Newtonsoft.Json; +using System.IO; namespace TbsCore.Models.AccModels { @@ -14,7 +16,7 @@ public class TaskList private readonly List _tasks; public TaskUpdated OnUpdateTask; - public TaskList() + public TaskList(Account acc) { _tasks = new List(); } @@ -151,5 +153,30 @@ public List ToList() { return _tasks.ToList(); } + + public void SaveToFile(string urlFile) + { + var listTask = new string[_tasks.Count]; + for (var i = 0; i < _tasks.Count; i++) + { + listTask[i] = $"{_tasks[i].GetType()}_{JsonConvert.SerializeObject(_tasks[i], Formatting.None)}"; + } + + File.WriteAllLines(urlFile, listTask); + } + + public void LoadFromFile(string urlFile) + { + if (!File.Exists(urlFile)) return; + var listTask = File.ReadAllLines(urlFile); + for (var i = 0; i < listTask.Length; i++) + { + var str = listTask[i].Split(new[] { '_' }, 2); + var type = Type.GetType(str[0]); + var obj = JsonConvert.DeserializeObject(str[1], type); + + Add((BotTask)obj); + } + } } } \ No newline at end of file diff --git a/TbsCore/Models/ResourceModels/Resources.cs b/TbsCore/Models/ResourceModels/Resources.cs index cf137bf1f..91004262c 100644 --- a/TbsCore/Models/ResourceModels/Resources.cs +++ b/TbsCore/Models/ResourceModels/Resources.cs @@ -8,7 +8,11 @@ public class Resources public long Crop { get; set; } public long[] ToArray() => new long[] { Wood, Clay, Iron, Crop }; + public long Sum() => (Wood + Clay + Iron + Crop); + + public bool Empty() => (Wood == 0 && Clay == 0 && Iron == 0 && Crop == 0); + public override string ToString() => $"Wood: {Wood}, Clay: {Clay}, Iron: {Iron}, Crop: {Crop}"; }; -} +} \ No newline at end of file diff --git a/TbsCore/Models/ResourceModels/SendResourcesConfiguration.cs b/TbsCore/Models/ResourceModels/SendResourcesConfiguration.cs index 7df494e3a..c4ccdae35 100644 --- a/TbsCore/Models/ResourceModels/SendResourcesConfiguration.cs +++ b/TbsCore/Models/ResourceModels/SendResourcesConfiguration.cs @@ -1,44 +1,16 @@ -using System; -using TbsCore.Tasks.ResourcesConfiguration; - -namespace TbsCore.Models.ResourceModels +namespace TbsCore.Models.ResourceModels { public class SendResourcesConfiguration { public void Init() { - TargetLimit = new Resources(); - FillLimit = new Resources(); - SendResLimit = new Resources() - { - Wood = 10, - Clay = 10, - Iron = 10, - Crop = 10 - }; + Enabled = false; + Condition = new Resources(); + Amount = new Resources(); } - - //public int TargetVillageId { get; set; } //use global setting for this, public bool Enabled { get; set; } - public BalanceType BalanceType { get; set; } - public Resources TargetLimit { get; set; } //in % - public Resources FillLimit { get; set; } //if 50k, max fill will be 50k res - - /// - /// When sending resources to main village, only send above these %: - /// - public Resources SendResLimit { get; set; } - - public DateTime TransitArrival { get; set; } - } -} - -namespace TbsCore.Tasks.ResourcesConfiguration -{ - public enum BalanceType - { - SendTo, - RecieveFrom + public Resources Condition { get; set; } + public Resources Amount { get; set; } } } \ No newline at end of file diff --git a/TbsCore/Models/Settings/AutoMarketSettings.cs b/TbsCore/Models/Settings/AutoMarketSettings.cs new file mode 100644 index 000000000..d9b722205 --- /dev/null +++ b/TbsCore/Models/Settings/AutoMarketSettings.cs @@ -0,0 +1,21 @@ +using TbsCore.Models.ResourceModels; + +namespace TbsCore.Models.Settings +{ + public class AutoMarketSettings + { + public void Init() + { + SendToMain = new SendResourcesConfiguration(); + SendToMain.Init(); + SendToNeed = new SendResourcesConfiguration(); + SendToNeed.Init(); + } + + public SendResourcesConfiguration SendToMain { get; set; } + public SendResourcesConfiguration SendToNeed { get; set; } + public bool NeedWhenBuild { get; set; } + public bool NeedWhenTrain { get; set; } + public bool NeedWhenOther { get; set; } + } +} \ No newline at end of file diff --git a/TbsCore/Models/Settings/MarketSettings.cs b/TbsCore/Models/Settings/MarketSettings.cs deleted file mode 100644 index e95b55672..000000000 --- a/TbsCore/Models/Settings/MarketSettings.cs +++ /dev/null @@ -1,14 +0,0 @@ -using TbsCore.Models.ResourceModels; - -namespace TbsCore.Models.Settings -{ - public class MarketSettings - { - public void Init() - { - Configuration = new SendResourcesConfiguration(); - Configuration.Init(); - } - public SendResourcesConfiguration Configuration { get; set; } - } -} diff --git a/TbsCore/Models/Settings/TradeRouteSettings.cs b/TbsCore/Models/Settings/TradeRouteSettings.cs new file mode 100644 index 000000000..4cbe3a11b --- /dev/null +++ b/TbsCore/Models/Settings/TradeRouteSettings.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; + +using TbsCore.Models.MapModels; +using TbsCore.Models.ResourceModels; + +namespace TbsCore.Models.Settings +{ + public class TradeRouteSettings + { + public void Init() + { + TradeRoutes = new List(); + Next = 0; + } + + public List TradeRoutes { get; set; } + public int Next { get; set; } + } + + public class TradeRoute + { + public Coordinates Location { get; set; } + public Resources Resource { get; set; } + public int Time { get; set; } + public int TimeDelay { get; set; } + public DateTime Last { get; set; } + public bool Active { get; set; } + } +} \ No newline at end of file diff --git a/TbsCore/Models/VillageModels/VillMarket.cs b/TbsCore/Models/VillageModels/VillMarket.cs index 684f2ebe0..df53999d4 100644 --- a/TbsCore/Models/VillageModels/VillMarket.cs +++ b/TbsCore/Models/VillageModels/VillMarket.cs @@ -9,29 +9,66 @@ public class VillMarket { public void Init() { - Settings = new MarketSettings(); - Settings.Init(); + AutoMarket = new AutoMarketSettings(); + AutoMarket.Init(); Npc = new NpcSettings(); Npc.Init(); - OngoingMerchants = new List(); + TradeRoute = new TradeRouteSettings(); + MerchantInfo = new Merchant(); + OngoingMerchants = new List(); } /// - /// Market settings + /// For auto market settings /// - public MarketSettings Settings { get; set; } + public AutoMarketSettings AutoMarket { get; set; } + /// /// For NPC settings /// - public NpcSettings Npc { get; set; } + public NpcSettings Npc { get; set; } + + /// + /// For trade route + /// + public TradeRouteSettings TradeRoute { get; set; } + /// /// List of all ongoing resource transits /// - public List OngoingMerchants { get; set; } + public List OngoingMerchants { get; set; } + /// - /// Last transit of resources to this village + /// Merchant village's info /// - public DateTime LastTransit { get; set; } + public Merchant MerchantInfo { get; set; } - } -} + /// + /// Last transit of resources to this village + /// + public DateTime LastTransit { get; set; } + } + + public class Merchant + { + /// + /// Maximum merchant village has + /// + public int Number { get; set; } + + /// + /// Current merchant in village + /// + public int Free { get; set; } + + /// + /// Capacity of merchant + /// + public long Capacity { get; set; } + + /// + /// Last update info time + /// + public DateTime LastUpdate { get; set; } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ChangeAccess.cs b/TbsCore/Tasks/LowLevel/Basic/ChangeAccess.cs similarity index 99% rename from TbsCore/Tasks/LowLevel/ChangeAccess.cs rename to TbsCore/Tasks/LowLevel/Basic/ChangeAccess.cs index ad57c954f..82c813ba8 100644 --- a/TbsCore/Tasks/LowLevel/ChangeAccess.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ChangeAccess.cs @@ -1,6 +1,6 @@ using System; using System.Threading.Tasks; -using TbsCore.Models.AccModels; +using TbsCore.Models.AccModels; using TbsCore.Helpers; namespace TbsCore.Tasks.LowLevel @@ -11,24 +11,24 @@ namespace TbsCore.Tasks.LowLevel public class ChangeAccess : BotTask { public int? WaitSecMin { get; set; } - public int? WaitSecMax { get; set; } - + public int? WaitSecMax { get; set; } + public override async Task Execute(Account acc) { acc.Wb.Dispose(); //TODO: make this configurable (wait time between switches) - var rand = new Random(); - int sleepSec = rand.Next(WaitSecMin ?? 30, WaitSecMax ?? 600); + var rand = new Random(); + int sleepSec = rand.Next(WaitSecMin ?? 30, WaitSecMax ?? 600); var sleepEnd = DateTime.Now.AddSeconds(sleepSec); await TimeHelper.SleepUntilPrioTask(acc, TaskPriority.High, sleepEnd); - await acc.Wb.InitSelenium(acc); - - // Remove all other ChangeAccess tasks - acc.Tasks.Remove(typeof(ChangeAccess), thisTask: this); - + await acc.Wb.InitSelenium(acc); + + // Remove all other ChangeAccess tasks + acc.Tasks.Remove(typeof(ChangeAccess), thisTask: this); + var nextProxyChange = TimeHelper.GetNextProxyChange(acc); if (nextProxyChange != TimeSpan.MaxValue) { diff --git a/TbsCore/Tasks/LowLevel/ChangeVillageName.cs b/TbsCore/Tasks/LowLevel/Basic/ChangeVillageName.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/ChangeVillageName.cs rename to TbsCore/Tasks/LowLevel/Basic/ChangeVillageName.cs index b6ac95c5a..6260668b2 100644 --- a/TbsCore/Tasks/LowLevel/ChangeVillageName.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ChangeVillageName.cs @@ -1,74 +1,74 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; -using static TbsCore.Helpers.Classificator; - -namespace TbsCore.Tasks.LowLevel -{ - public class ChangeVillageName : BotTask - { - public List<(int, string)> ChangeList { get; set; } - - public override async Task Execute(Account acc) - { - switch (acc.AccInfo.ServerVersion) - { - case ServerVersionEnum.T4_4: - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/spieler.php?s=2"); - - if (acc.Wb.Html.GetElementbyId("PlayerProfileEditor") == null) - { - // Sitter. Can't change the name of the village. TODO: check if sitter before - // creating the task. - acc.Logger.Warning("Sitter cannot change the name of the village"); - return TaskRes.Executed; - } - - foreach (var change in ChangeList) - { - var script = $"document.getElementsByName('dname[{change.Item1}]=')[0].value='{change.Item2}'"; - acc.Wb.ExecuteScript(script); //insert new name into the textbox - } - - await Task.Delay(AccountHelper.Delay(acc)); - - acc.Wb.ExecuteScript("document.getElementById('PlayerProfileEditor').submit()"); //click save button - - return TaskRes.Executed; - - //support T4.5 and above, if they change we will and more to here - default: - //i dont know they change this when - //but u need click on "Edit profile" to change your profile - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile"); - - if (acc.Wb.Html.DocumentNode.SelectSingleNode("//a[@class='tabItem normal']").GetAttributeValue("disabled", "string") == "disabled") - { - // Sitter. Can't change the name of the village. TODO: check if sitter before - // creating the task. - acc.Logger.Warning("Sitter cannot change the name of the village"); - return TaskRes.Executed; - } - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile/edit"); - foreach (var change in ChangeList) - { - //seem like they want we typing instead of setting value (= =) - //if u only setting value by javascript the button still disable - - var script = $"document.getElementsByName('dname[{change.Item1}]=')[0].value=''"; - //empty value of textbox - acc.Wb.ExecuteScript(script); - //insert new name into the textbox - acc.Wb.FindElementByXPath($"//input[@name='dname[{change.Item1}]=']").SendKeys(change.Item2); - } - - await Task.Delay(AccountHelper.Delay(acc)); - acc.Wb.FindElementById("btn_ok").Click(); //click save button - - return TaskRes.Executed; - } - } - } +using System.Collections.Generic; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using static TbsCore.Helpers.Classificator; + +namespace TbsCore.Tasks.LowLevel +{ + public class ChangeVillageName : BotTask + { + public List<(int, string)> ChangeList { get; set; } + + public override async Task Execute(Account acc) + { + switch (acc.AccInfo.ServerVersion) + { + case ServerVersionEnum.T4_4: + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/spieler.php?s=2"); + + if (acc.Wb.Html.GetElementbyId("PlayerProfileEditor") == null) + { + // Sitter. Can't change the name of the village. TODO: check if sitter before + // creating the task. + acc.Logger.Warning("Sitter cannot change the name of the village"); + return TaskRes.Executed; + } + + foreach (var change in ChangeList) + { + var script = $"document.getElementsByName('dname[{change.Item1}]=')[0].value='{change.Item2}'"; + acc.Wb.ExecuteScript(script); //insert new name into the textbox + } + + await Task.Delay(AccountHelper.Delay(acc)); + + acc.Wb.ExecuteScript("document.getElementById('PlayerProfileEditor').submit()"); //click save button + + return TaskRes.Executed; + + //support T4.5 and above, if they change we will and more to here + default: + //i dont know they change this when + //but u need click on "Edit profile" to change your profile + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile"); + + if (acc.Wb.Html.DocumentNode.SelectSingleNode("//a[@class='tabItem normal']").GetAttributeValue("disabled", "string") == "disabled") + { + // Sitter. Can't change the name of the village. TODO: check if sitter before + // creating the task. + acc.Logger.Warning("Sitter cannot change the name of the village"); + return TaskRes.Executed; + } + + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile/edit"); + foreach (var change in ChangeList) + { + //seem like they want we typing instead of setting value (= =) + //if u only setting value by javascript the button still disable + + var script = $"document.getElementsByName('dname[{change.Item1}]=')[0].value=''"; + //empty value of textbox + acc.Wb.ExecuteScript(script); + //insert new name into the textbox + acc.Wb.FindElementByXPath($"//input[@name='dname[{change.Item1}]=']").SendKeys(change.Item2); + } + + await Task.Delay(AccountHelper.Delay(acc)); + acc.Wb.FindElementById("btn_ok").Click(); //click save button + + return TaskRes.Executed; + } + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ClaimBeginnerTask.cs b/TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/ClaimBeginnerTask.cs rename to TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask.cs index 6bec71368..8caccd2da 100644 --- a/TbsCore/Tasks/LowLevel/ClaimBeginnerTask.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask.cs @@ -1,37 +1,37 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; -using TbsCore.Models.SideBarModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class ClaimBeginnerTask : BotTask - { - public Quest QuestToClaim { get; set; } - - public override async Task Execute(Account acc) - { - var script = $"document.getElementById('mentorTaskList').querySelector('[data-questid=\"{this.QuestToClaim.Id}\"]').click();"; - await DriverHelper.ExecuteScript(acc, script); - await Task.Delay(AccountHelper.Delay(acc) * 2); - - string buttonId = ""; - switch (acc.AccInfo.ServerVersion) - { - case Classificator.ServerVersionEnum.T4_5: - buttonId = acc.Wb.Html.DocumentNode.Descendants("button").FirstOrDefault(x => x.GetAttributeValue("questid", "") == this.QuestToClaim.Id).Id; - break; - - case Classificator.ServerVersionEnum.T4_4: - buttonId = acc.Wb.Html.DocumentNode.Descendants("button").FirstOrDefault(x => x.HasClass("questButtonNext"))?.Id; - break; - } - - await DriverHelper.ClickById(acc, buttonId); - await TaskExecutor.PageLoaded(acc); // Optional - - return TaskRes.Executed; - } - } +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.SideBarModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class ClaimBeginnerTask : BotTask + { + public Quest QuestToClaim { get; set; } + + public override async Task Execute(Account acc) + { + var script = $"document.getElementById('mentorTaskList').querySelector('[data-questid=\"{this.QuestToClaim.Id}\"]').click();"; + await DriverHelper.ExecuteScript(acc, script); + await Task.Delay(AccountHelper.Delay(acc) * 2); + + string buttonId = ""; + switch (acc.AccInfo.ServerVersion) + { + case Classificator.ServerVersionEnum.T4_5: + buttonId = acc.Wb.Html.DocumentNode.Descendants("button").FirstOrDefault(x => x.GetAttributeValue("questid", "") == this.QuestToClaim.Id).Id; + break; + + case Classificator.ServerVersionEnum.T4_4: + buttonId = acc.Wb.Html.DocumentNode.Descendants("button").FirstOrDefault(x => x.HasClass("questButtonNext"))?.Id; + break; + } + + await DriverHelper.ClickById(acc, buttonId); + await TaskExecutor.PageLoaded(acc); // Optional + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ClaimBeginnerTask2021.cs b/TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask2021.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/ClaimBeginnerTask2021.cs rename to TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask2021.cs index d10646bd1..a8d3a74e0 100644 --- a/TbsCore/Tasks/LowLevel/ClaimBeginnerTask2021.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ClaimBeginnerTask2021.cs @@ -1,42 +1,42 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class ClaimBeginnerTask2021 : BotTask - { - public override async Task Execute(Account acc) - { - // Claim village-wide rewards - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks"); - await ClaimRewards(acc); - - if (acc.Wb.Html - .GetElementbyId("sidebarBoxQuestmaster")? - .Descendants()? - .Any(x => x.HasClass("newQuestSpeechBubble")) ?? false) - { - // Claim account-wide rewards - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks?t=2"); - await ClaimRewards(acc); - } - - acc.Tasks.Add(new HeroUpdateInfo() { ExecuteAt = DateTime.Now }); - - return TaskRes.Executed; - } - - private async Task ClaimRewards(Account acc) - { - await Task.Delay(AccountHelper.Delay(acc)); - do - { - await DriverHelper.ClickByClassName(acc, "collect", false); - } - while (acc.Wb.Html.DocumentNode.Descendants("button").Any(x => x.HasClass("collect"))); - } - } +using System; +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class ClaimBeginnerTask2021 : BotTask + { + public override async Task Execute(Account acc) + { + // Claim village-wide rewards + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks"); + await ClaimRewards(acc); + + if (acc.Wb.Html + .GetElementbyId("sidebarBoxQuestmaster")? + .Descendants()? + .Any(x => x.HasClass("newQuestSpeechBubble")) ?? false) + { + // Claim account-wide rewards + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/tasks?t=2"); + await ClaimRewards(acc); + } + + acc.Tasks.Add(new HeroUpdateInfo() { ExecuteAt = DateTime.Now }); + + return TaskRes.Executed; + } + + private async Task ClaimRewards(Account acc) + { + await Task.Delay(AccountHelper.Delay(acc)); + do + { + await DriverHelper.ClickByClassName(acc, "collect", false); + } + while (acc.Wb.Html.DocumentNode.Descendants("button").Any(x => x.HasClass("collect"))); + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ClaimDailyTask.cs b/TbsCore/Tasks/LowLevel/Basic/ClaimDailyTask.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/ClaimDailyTask.cs rename to TbsCore/Tasks/LowLevel/Basic/ClaimDailyTask.cs index 2f8a622c7..28628f0ac 100644 --- a/TbsCore/Tasks/LowLevel/ClaimDailyTask.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ClaimDailyTask.cs @@ -1,33 +1,33 @@ -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class ClaimDailyTask : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - - await DriverHelper.ExecuteScript(acc, "Travian.Game.Quest.openTodoListDialog('', true);"); - - switch (acc.AccInfo.ServerVersion) - { - case Classificator.ServerVersionEnum.T4_4: - var script = "var dialog = document.getElementById('dialogContent');"; - script += "dialog.getElementsByClassName('active')[0].click();"; - await DriverHelper.ExecuteScript(acc, script); - break; - - case Classificator.ServerVersionEnum.T4_5: - await DriverHelper.ExecuteScript(acc, "document.getElementsByClassName('rewardReady')[0].click();"); - break; - } - - await DriverHelper.ExecuteScript(acc, "document.getElementsByClassName('questButtonGainReward')[0].click();"); - - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class ClaimDailyTask : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); + + await DriverHelper.ExecuteScript(acc, "Travian.Game.Quest.openTodoListDialog('', true);"); + + switch (acc.AccInfo.ServerVersion) + { + case Classificator.ServerVersionEnum.T4_4: + var script = "var dialog = document.getElementById('dialogContent');"; + script += "dialog.getElementsByClassName('active')[0].click();"; + await DriverHelper.ExecuteScript(acc, script); + break; + + case Classificator.ServerVersionEnum.T4_5: + await DriverHelper.ExecuteScript(acc, "document.getElementsByClassName('rewardReady')[0].click();"); + break; + } + + await DriverHelper.ExecuteScript(acc, "document.getElementsByClassName('questButtonGainReward')[0].click();"); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/DonateAllyBonus.cs b/TbsCore/Tasks/LowLevel/Basic/DonateAllyBonus.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/DonateAllyBonus.cs rename to TbsCore/Tasks/LowLevel/Basic/DonateAllyBonus.cs index f9a1c7d9a..7e2dc88c7 100644 --- a/TbsCore/Tasks/LowLevel/DonateAllyBonus.cs +++ b/TbsCore/Tasks/LowLevel/Basic/DonateAllyBonus.cs @@ -1,45 +1,45 @@ -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; -using TbsCore.Models.ResourceModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class DonateAllyBonus : BotTask - { - public Resources ResToDonate { get; set; } - - private string[] Ids = new string[] - { - "bonusTroopProductionSpeed", - "bonusCPProduction", - "bonusSmithyPower", - "bonusMerchantCapacity" - }; - - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/alliance/bonuses"); - - for (int i = 0; i < 4; i++) - { - var radioId = Ids[i]; - var radio = acc.Wb.Html.GetElementbyId(radioId); - - // If the bonus is max / already being upgraded - if (radio.GetAttributeValue("disabled", "") == "disabled") continue; - - await DriverHelper.ClickById(acc, radioId); - } - - var donateArr = ResToDonate.ToArray(); - for (int i = 0; i < 4; i++) - { - await DriverHelper.WriteById(acc, $"donate{(i + 1)}", donateArr[i]); - } - - await DriverHelper.ClickById(acc, "donate_green"); - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.ResourceModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class DonateAllyBonus : BotTask + { + public Resources ResToDonate { get; set; } + + private string[] Ids = new string[] + { + "bonusTroopProductionSpeed", + "bonusCPProduction", + "bonusSmithyPower", + "bonusMerchantCapacity" + }; + + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/alliance/bonuses"); + + for (int i = 0; i < 4; i++) + { + var radioId = Ids[i]; + var radio = acc.Wb.Html.GetElementbyId(radioId); + + // If the bonus is max / already being upgraded + if (radio.GetAttributeValue("disabled", "") == "disabled") continue; + + await DriverHelper.ClickById(acc, radioId); + } + + var donateArr = ResToDonate.ToArray(); + for (int i = 0; i < 4; i++) + { + await DriverHelper.WriteById(acc, $"donate{(i + 1)}", donateArr[i]); + } + + await DriverHelper.ClickById(acc, "donate_green"); + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/EditPreferences.cs b/TbsCore/Tasks/LowLevel/Basic/EditPreferences.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/EditPreferences.cs rename to TbsCore/Tasks/LowLevel/Basic/EditPreferences.cs index eac2900b7..5f0b190c8 100644 --- a/TbsCore/Tasks/LowLevel/EditPreferences.cs +++ b/TbsCore/Tasks/LowLevel/Basic/EditPreferences.cs @@ -1,41 +1,41 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class EditPreferences : BotTask - { - /// - /// Disable contextual help - /// - public bool? ContextualHelp { get; set; } - - /// - /// Troop movements per page in rally point - /// - public int? TroopsPerPage { get; set; } - - public override async Task Execute(Account acc) - { - await VersionHelper.Navigate(acc, "/options.php", "/options"); - - if (ContextualHelp != null) - await DriverHelper.CheckById(acc, "v13", ContextualHelp ?? true); - - if (TroopsPerPage != null) - await DriverHelper.WriteById(acc, "troopMovementsPerPage", TroopsPerPage ?? 10); - - var acceptButton = acc.Wb.Html.DocumentNode - .Descendants("div") - .First(x => x.HasClass("submitButtonContainer")) - .Descendants("button") - .First(); - - await DriverHelper.ClickById(acc, acceptButton.Id); - - return TaskRes.Executed; - } - } +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class EditPreferences : BotTask + { + /// + /// Disable contextual help + /// + public bool? ContextualHelp { get; set; } + + /// + /// Troop movements per page in rally point + /// + public int? TroopsPerPage { get; set; } + + public override async Task Execute(Account acc) + { + await VersionHelper.Navigate(acc, "/options.php", "/options"); + + if (ContextualHelp != null) + await DriverHelper.CheckById(acc, "v13", ContextualHelp ?? true); + + if (TroopsPerPage != null) + await DriverHelper.WriteById(acc, "troopMovementsPerPage", TroopsPerPage ?? 10); + + var acceptButton = acc.Wb.Html.DocumentNode + .Descendants("div") + .First(x => x.HasClass("submitButtonContainer")) + .Descendants("button") + .First(); + + await DriverHelper.ClickById(acc, acceptButton.Id); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ExtendProtection.cs b/TbsCore/Tasks/LowLevel/Basic/ExtendProtection.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/ExtendProtection.cs rename to TbsCore/Tasks/LowLevel/Basic/ExtendProtection.cs index 0450181ac..13e870a67 100644 --- a/TbsCore/Tasks/LowLevel/ExtendProtection.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ExtendProtection.cs @@ -1,17 +1,17 @@ -using System.Threading.Tasks; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - /// - /// Extend beginners protection - /// - public class ExtendProtection : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/options/game?extendBeginnersProtection"); - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + /// + /// Extend beginners protection + /// + public class ExtendProtection : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/options/game?extendBeginnersProtection"); + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/FindVillageToSettle.cs b/TbsCore/Tasks/LowLevel/Basic/FindVillageToSettle.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/FindVillageToSettle.cs rename to TbsCore/Tasks/LowLevel/Basic/FindVillageToSettle.cs index fb42df85f..a44f9f9fd 100644 --- a/TbsCore/Tasks/LowLevel/FindVillageToSettle.cs +++ b/TbsCore/Tasks/LowLevel/Basic/FindVillageToSettle.cs @@ -1,61 +1,61 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; -using TbsCore.Models.MapModels; -using TbsCore.Models.VillageModels; -using TbsCore.Parsers; - -namespace TbsCore.Tasks.LowLevel -{ - public class FindVillageToSettle : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/karte.php"); - - var mainVill = AccountHelper.GetMainVillage(acc); - - var mapTiles = MapHelper.GetMapTiles(acc, mainVill.Coordinates); - - Coordinates closesCoords = GetClosestCoordinates(acc, mapTiles); - if (closesCoords == null) return TaskRes.Retry; - - acc.NewVillages.Locations.Add(new NewVillage() - { - Coordinates = closesCoords, - Name = NewVillageHelper.GenerateName(acc), - }); - - return TaskRes.Executed; - } - - private Coordinates GetClosestCoordinates(Account acc, List tiles) - { - var mainVill = AccountHelper.GetMainVillage(acc); - var closesCoords = new Coordinates(); - var closest = 1000.0; - foreach (var tile in tiles) - { - if (tile.Title == null || !tile.Title.StartsWith("{k.vt}")) continue; - - // Check if village type meets criteria - if (acc.NewVillages.Types.Count != 0) - { - var num = (int)Parser.RemoveNonNumeric(tile.Title.Split('f')[1]); - var type = (Classificator.VillTypeEnum)(num); - if (!acc.NewVillages.Types.Any(x => x == type)) continue; - } - - var distance = MapHelper.CalculateDistance(acc, mainVill.Coordinates, tile.Coordinates); - if (distance < closest) - { - closest = distance; - closesCoords = tile.Coordinates; - } - } - return closesCoords; - } - } +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.MapModels; +using TbsCore.Models.VillageModels; +using TbsCore.Parsers; + +namespace TbsCore.Tasks.LowLevel +{ + public class FindVillageToSettle : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/karte.php"); + + var mainVill = AccountHelper.GetMainVillage(acc); + + var mapTiles = MapHelper.GetMapTiles(acc, mainVill.Coordinates); + + Coordinates closesCoords = GetClosestCoordinates(acc, mapTiles); + if (closesCoords == null) return TaskRes.Retry; + + acc.NewVillages.Locations.Add(new NewVillage() + { + Coordinates = closesCoords, + Name = NewVillageHelper.GenerateName(acc), + }); + + return TaskRes.Executed; + } + + private Coordinates GetClosestCoordinates(Account acc, List tiles) + { + var mainVill = AccountHelper.GetMainVillage(acc); + var closesCoords = new Coordinates(); + var closest = 1000.0; + foreach (var tile in tiles) + { + if (tile.Title == null || !tile.Title.StartsWith("{k.vt}")) continue; + + // Check if village type meets criteria + if (acc.NewVillages.Types.Count != 0) + { + var num = (int)Parser.RemoveNonNumeric(tile.Title.Split('f')[1]); + var type = (Classificator.VillTypeEnum)(num); + if (!acc.NewVillages.Types.Any(x => x == type)) continue; + } + + var distance = MapHelper.CalculateDistance(acc, mainVill.Coordinates, tile.Coordinates); + if (distance < closest) + { + closest = distance; + closesCoords = tile.Coordinates; + } + } + return closesCoords; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/InstaUpgrade.cs b/TbsCore/Tasks/LowLevel/Basic/InstaUpgrade.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/InstaUpgrade.cs rename to TbsCore/Tasks/LowLevel/Basic/InstaUpgrade.cs index 09eb071c5..23c4709f8 100644 --- a/TbsCore/Tasks/LowLevel/InstaUpgrade.cs +++ b/TbsCore/Tasks/LowLevel/Basic/InstaUpgrade.cs @@ -1,41 +1,41 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - /// - /// Instantly upgrade currently building - /// - public class InstaUpgrade : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); - - var finishClass = acc.Wb.Html.DocumentNode - .Descendants("div") - .FirstOrDefault(x => x.HasClass("finishNow")); - var button = finishClass.Descendants("button").FirstOrDefault(); - await DriverHelper.ExecuteScript(acc, $"document.getElementById('{button.GetAttributeValue("id", "")}').click()"); - - var dialog = acc.Wb.Html.GetElementbyId("finishNowDialog"); - var useButton = dialog.Descendants("button").FirstOrDefault(); - await DriverHelper.ExecuteScript(acc, $"document.getElementById('{useButton.GetAttributeValue("id", "")}').click()"); - - // Execute next build task right away - var task = acc.Tasks.FindTask(typeof(UpgradeBuilding), Vill); - - if (task != null) - { - task.ExecuteAt = DateTime.Now; - } - - await TaskExecutor.PageLoaded(acc); - - return TaskRes.Executed; - } - } +using System; +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + /// + /// Instantly upgrade currently building + /// + public class InstaUpgrade : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); + + var finishClass = acc.Wb.Html.DocumentNode + .Descendants("div") + .FirstOrDefault(x => x.HasClass("finishNow")); + var button = finishClass.Descendants("button").FirstOrDefault(); + await DriverHelper.ExecuteScript(acc, $"document.getElementById('{button.GetAttributeValue("id", "")}').click()"); + + var dialog = acc.Wb.Html.GetElementbyId("finishNowDialog"); + var useButton = dialog.Descendants("button").FirstOrDefault(); + await DriverHelper.ExecuteScript(acc, $"document.getElementById('{useButton.GetAttributeValue("id", "")}').click()"); + + // Execute next build task right away + var task = acc.Tasks.FindTask(typeof(UpgradeBuilding), Vill); + + if (task != null) + { + task.ExecuteAt = DateTime.Now; + } + + await TaskExecutor.PageLoaded(acc); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/NYSUpdateTribesOfVillas.cs b/TbsCore/Tasks/LowLevel/Basic/NYSUpdateTribesOfVillas.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/NYSUpdateTribesOfVillas.cs rename to TbsCore/Tasks/LowLevel/Basic/NYSUpdateTribesOfVillas.cs index 70a8d2a41..4c7815642 100644 --- a/TbsCore/Tasks/LowLevel/NYSUpdateTribesOfVillas.cs +++ b/TbsCore/Tasks/LowLevel/Basic/NYSUpdateTribesOfVillas.cs @@ -1,18 +1,18 @@ -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Parsers; - -namespace TbsCore.Tasks.LowLevel -{ - public class NYSUpdateTribesOfVillas : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile"); - - ProfileParser.ParseVillageTribes(acc, acc.Wb.Html); - - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Parsers; + +namespace TbsCore.Tasks.LowLevel +{ + public class NYSUpdateTribesOfVillas : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/profile"); + + ProfileParser.ParseVillageTribes(acc, acc.Wb.Html); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/RandomTask.cs b/TbsCore/Tasks/LowLevel/Basic/RandomTask.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/RandomTask.cs rename to TbsCore/Tasks/LowLevel/Basic/RandomTask.cs index 86418c7e3..662248440 100644 --- a/TbsCore/Tasks/LowLevel/RandomTask.cs +++ b/TbsCore/Tasks/LowLevel/Basic/RandomTask.cs @@ -1,74 +1,74 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - /// - /// Just a random navigation event - to make bot less suspicious to Travian. - /// - public class RandomTask : BotTask - { - public int MinWait { get; set; } = 5000; - public int MaxWait { get; set; } = 20000; - - private readonly string[] UrlT4_4 = new string[] { - "/statistiken.php", // player - "/statistiken.php?id=1", // ally - "/statistiken.php?id=1&idSub=3", // ally TOP10 - "/statistiken.php?id=3", // hero - "/statistiken.php?id=0&idSub=3", // player top10 - "/spieler.php", // profile - "/statistiken.php?id=0&idSub=1", // players top attackers - "/statistiken.php?id=0&idSub=2", // players top deffenders - "/messages.php", // messages - "/hero.php?t=4", // Hero auctions - "/reports.php", - "/reports.php?t=1", - "/reports.php?t=2", - "/reports.php?t=3", - "/reports.php?t=4", - }; - - private readonly string[] UrlT4_5 = new string[] { - "/statistics", // player - "/statistics/alliance", // ally - "/statistics/alliance?idSub=3", // ally TOP10 - "/statistics/hero", // hero - "/statistics/player?idSub=3", // player top10 - "/profile", // profile - "/statistics/player?idSub=1", // players top attackers - "/statistics/player?idSub=2", // players top deffenders - "/messages.php", // messages - "/hero/auction", // Hero auctions - "/report", - "/report/offensive", - "/report/defensive", - "/report/scouting", - "/report/other", - }; - - public override async Task Execute(Account acc) - { - string[] Urls = new string[0]; - switch (acc.AccInfo.ServerVersion) - { - case Helpers.Classificator.ServerVersionEnum.T4_4: - Urls = UrlT4_4; - break; - - case Helpers.Classificator.ServerVersionEnum.T4_5: - Urls = UrlT4_5; - break; - } - - var ran = new Random(); - var id = ran.Next(0, Urls.Length - 1); - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}{Urls[id]}"); - await Task.Delay(ran.Next(MinWait, MaxWait)); - - return TaskRes.Executed; - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + /// + /// Just a random navigation event - to make bot less suspicious to Travian. + /// + public class RandomTask : BotTask + { + public int MinWait { get; set; } = 5000; + public int MaxWait { get; set; } = 20000; + + private readonly string[] UrlT4_4 = new string[] { + "/statistiken.php", // player + "/statistiken.php?id=1", // ally + "/statistiken.php?id=1&idSub=3", // ally TOP10 + "/statistiken.php?id=3", // hero + "/statistiken.php?id=0&idSub=3", // player top10 + "/spieler.php", // profile + "/statistiken.php?id=0&idSub=1", // players top attackers + "/statistiken.php?id=0&idSub=2", // players top deffenders + "/messages.php", // messages + "/hero.php?t=4", // Hero auctions + "/reports.php", + "/reports.php?t=1", + "/reports.php?t=2", + "/reports.php?t=3", + "/reports.php?t=4", + }; + + private readonly string[] UrlT4_5 = new string[] { + "/statistics", // player + "/statistics/alliance", // ally + "/statistics/alliance?idSub=3", // ally TOP10 + "/statistics/hero", // hero + "/statistics/player?idSub=3", // player top10 + "/profile", // profile + "/statistics/player?idSub=1", // players top attackers + "/statistics/player?idSub=2", // players top deffenders + "/messages.php", // messages + "/hero/auction", // Hero auctions + "/report", + "/report/offensive", + "/report/defensive", + "/report/scouting", + "/report/other", + }; + + public override async Task Execute(Account acc) + { + string[] Urls = new string[0]; + switch (acc.AccInfo.ServerVersion) + { + case Helpers.Classificator.ServerVersionEnum.T4_4: + Urls = UrlT4_4; + break; + + case Helpers.Classificator.ServerVersionEnum.T4_5: + Urls = UrlT4_5; + break; + } + + var ran = new Random(); + var id = ran.Next(0, Urls.Length - 1); + + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}{Urls[id]}"); + await Task.Delay(ran.Next(MinWait, MaxWait)); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ReadMessage.cs b/TbsCore/Tasks/LowLevel/Basic/ReadMessage.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/ReadMessage.cs rename to TbsCore/Tasks/LowLevel/Basic/ReadMessage.cs index bd1d11149..d2d8315d6 100644 --- a/TbsCore/Tasks/LowLevel/ReadMessage.cs +++ b/TbsCore/Tasks/LowLevel/Basic/ReadMessage.cs @@ -1,26 +1,26 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class ReadMessage : BotTask - { - public override async Task Execute(Account acc) - { - while (true) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/messages.php"); - var msg = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("messageStatusUnread")); - if (msg != null) - { - var url = msg.ParentNode.GetAttributeValue("href", "").Replace("amp;", ""); - await acc.Wb.Navigate(acc.AccInfo.ServerUrl + "/" + url); - await Task.Delay(AccountHelper.Delay(acc) * 5); - } - else return TaskRes.Executed; - } - } - } +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + public class ReadMessage : BotTask + { + public override async Task Execute(Account acc) + { + while (true) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/messages.php"); + var msg = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("messageStatusUnread")); + if (msg != null) + { + var url = msg.ParentNode.GetAttributeValue("href", "").Replace("amp;", ""); + await acc.Wb.Navigate(acc.AccInfo.ServerUrl + "/" + url); + await Task.Delay(AccountHelper.Delay(acc) * 5); + } + else return TaskRes.Executed; + } + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/Basic/Update.cs b/TbsCore/Tasks/LowLevel/Basic/Update.cs new file mode 100644 index 000000000..3b4a6d6c3 --- /dev/null +++ b/TbsCore/Tasks/LowLevel/Basic/Update.cs @@ -0,0 +1,39 @@ +using System; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.VillageModels; +using static TbsCore.Helpers.Classificator; + +namespace TbsCore.Tasks.LowLevel +{ + public class Update : BotTask + { + /// + /// What building does bot will enter + /// + protected BuildingEnum BuildingType; + + /// + /// Was bot in building + /// + protected bool IsInBuilding = false; + + public Update(Village vill, DateTime executeAt, BuildingEnum buildingType, TaskPriority priority = TaskPriority.Medium) + { + Vill = vill; + ExecuteAt = executeAt; + Priority = priority; + BuildingType = buildingType; + } + + public override async Task Execute(Account acc) + { + if (await VillageHelper.EnterBuilding(acc, Vill, BuildingType)) + { + IsInBuilding = true; + } + return TaskRes.Executed; + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/Basic/UpdateVillage.cs b/TbsCore/Tasks/LowLevel/Basic/UpdateVillage.cs new file mode 100644 index 000000000..44f1a8d8f --- /dev/null +++ b/TbsCore/Tasks/LowLevel/Basic/UpdateVillage.cs @@ -0,0 +1,88 @@ +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.TravianData; +using TbsCore.Parsers; +using System; +using TbsCore.Models.VillageModels; +using static TbsCore.Helpers.Classificator; + +namespace TbsCore.Tasks.LowLevel +{ + /// + /// If village is new, we just update dorf1, dorf2, add building task and that it + /// Other update will be later not now + /// If normal update, update dorf1 and 60% chance update dorf2 (custom later) + /// + public class UpdateVillage : BotTask + { + public bool NewVillage { get; set; } + public bool Dorf2 { get; set; } + + public override async Task Execute(Account acc) + { + if (NewVillage) + { + await UpdateNewVillage(acc); + } + else + { + await UpdateOldVillage(acc); + VillageHelper.SetNextRefresh(acc, Vill); + } + return TaskRes.Executed; + } + + public async Task UpdateNewVillage(Account acc) + { + if (acc.Wb.CurrentUrl.Contains("dorf1")) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 + } + else if (acc.Wb.CurrentUrl.Contains("dorf2")) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 + } + else + { + if ((new Random()).Next(1, 100) > 50) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 + await Task.Delay(AccountHelper.Delay(acc)); + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 + } + else + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 + await Task.Delay(AccountHelper.Delay(acc)); + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 + } + } + + var firstTroop = TroopsData.TribeFirstTroop(acc.AccInfo.Tribe); + Vill.Troops.Researched.Add(firstTroop); + } + + public async Task UpdateOldVillage(Account acc) + { + var dorf2 = false; + if (acc.Wb.CurrentUrl.Contains("dorf2")) + { + // already update dorf2, noneed update more + dorf2 = true; + } + if (!acc.Wb.CurrentUrl.Contains("/dorf1.php")) // Don't re-navigate + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); + } + + // if Dorf2 = true just update it, otherwise 60% to check update dorf2 + if (Dorf2 || (!dorf2 && (new Random()).Next(1, 100) > 40)) // 41 -> 100 : 60 values + { + await Task.Delay(AccountHelper.Delay(acc)); + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 + } + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/DemolishBuilding.cs b/TbsCore/Tasks/LowLevel/DemolishBuilding.cs index 7a6ad5481..837d2d969 100644 --- a/TbsCore/Tasks/LowLevel/DemolishBuilding.cs +++ b/TbsCore/Tasks/LowLevel/DemolishBuilding.cs @@ -14,7 +14,7 @@ public class DemolishBuilding : BotTask public override async Task Execute(Account acc) { // First navigate to dorf2 and then to the main building, to make sure the currently demolish list is refreshed - if (!await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.MainBuilding, update: true)) + if (!await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.MainBuilding)) return TaskRes.Executed; if (Vill.Build.DemolishTasks.Count == 0) return TaskRes.Executed; //No more demolish tasks diff --git a/TbsCore/Tasks/LowLevel/HeroEquip.cs b/TbsCore/Tasks/LowLevel/Hero/HeroEquip.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/HeroEquip.cs rename to TbsCore/Tasks/LowLevel/Hero/HeroEquip.cs index 31988c2ad..813ef4c3e 100644 --- a/TbsCore/Tasks/LowLevel/HeroEquip.cs +++ b/TbsCore/Tasks/LowLevel/Hero/HeroEquip.cs @@ -1,81 +1,81 @@ -using System; -using System.Collections.Generic; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -using static TbsCore.Helpers.Classificator; - -namespace TbsCore.Tasks.LowLevel -{ - public class HeroEquip : BotTask - { - public List<(HeroItemEnum, int)> Items { get; set; } - - public override async Task Execute(Account acc) - { - await HeroHelper.NavigateToHeroAttributes(acc); - - HeroHelper.ParseHeroPage(acc); - - foreach (var use in Items) - { - var (item, amount) = use; - - var (category, name, tier) = HeroHelper.ParseHeroItem(item); - if (category != HeroItemCategory.Others) - { - // Check if hero is at home - if (acc.Hero.Status != Hero.StatusEnum.Home) - { - // Wait for hero to come home - var nextExecute = acc.Hero.NextHeroSend > acc.Hero.HeroArrival ? - acc.Hero.NextHeroSend : - acc.Hero.HeroArrival; - - var in5Min = DateTime.Now.AddMinutes(5); - if (nextExecute < in5Min) nextExecute = in5Min; - this.NextExecute = nextExecute; - return TaskRes.Retry; - } - } - - string script = "var items = document.getElementById('itemsToSale');"; - - switch (acc.AccInfo.ServerVersion) - { - case ServerVersionEnum.T4_5: - script += $"items.querySelector('div[class$=\"_{(int)item}\"]').click();"; - break; - - case ServerVersionEnum.T4_4: - script += $"items.querySelector('div[class$=\"_{(int)item} \"]').click();"; - break; - } - - await DriverHelper.ExecuteScript(acc, script); - - // No amount specified, meaning we have already equipt the item - if (amount == 0) return Done(acc); - - await DriverHelper.WriteById(acc, "amount", amount); - - await DriverHelper.ClickByClassName(acc, "ok"); - } - - return Done(acc); - } - - /// - /// Refresh the hero page after equipping an item - /// - /// Account - /// TaskRes - - private TaskRes Done(Account acc) - { - HeroHelper.ParseHeroPage(acc); - return TaskRes.Executed; - } - } +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +using static TbsCore.Helpers.Classificator; + +namespace TbsCore.Tasks.LowLevel +{ + public class HeroEquip : BotTask + { + public List<(HeroItemEnum, int)> Items { get; set; } + + public override async Task Execute(Account acc) + { + await HeroHelper.NavigateToHeroAttributes(acc); + + HeroHelper.ParseHeroPage(acc); + + foreach (var use in Items) + { + var (item, amount) = use; + + var (category, name, tier) = HeroHelper.ParseHeroItem(item); + if (category != HeroItemCategory.Others) + { + // Check if hero is at home + if (acc.Hero.Status != Hero.StatusEnum.Home) + { + // Wait for hero to come home + var nextExecute = acc.Hero.NextHeroSend > acc.Hero.HeroArrival ? + acc.Hero.NextHeroSend : + acc.Hero.HeroArrival; + + var in5Min = DateTime.Now.AddMinutes(5); + if (nextExecute < in5Min) nextExecute = in5Min; + this.NextExecute = nextExecute; + return TaskRes.Retry; + } + } + + string script = "var items = document.getElementById('itemsToSale');"; + + switch (acc.AccInfo.ServerVersion) + { + case ServerVersionEnum.T4_5: + script += $"items.querySelector('div[class$=\"_{(int)item}\"]').click();"; + break; + + case ServerVersionEnum.T4_4: + script += $"items.querySelector('div[class$=\"_{(int)item} \"]').click();"; + break; + } + + await DriverHelper.ExecuteScript(acc, script); + + // No amount specified, meaning we have already equipt the item + if (amount == 0) return Done(acc); + + await DriverHelper.WriteById(acc, "amount", amount); + + await DriverHelper.ClickByClassName(acc, "ok"); + } + + return Done(acc); + } + + /// + /// Refresh the hero page after equipping an item + /// + /// Account + /// TaskRes + + private TaskRes Done(Account acc) + { + HeroHelper.ParseHeroPage(acc); + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/HeroSetPoints.cs b/TbsCore/Tasks/LowLevel/Hero/HeroSetPoints.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/HeroSetPoints.cs rename to TbsCore/Tasks/LowLevel/Hero/HeroSetPoints.cs index f27fa5a29..235b07c6d 100644 --- a/TbsCore/Tasks/LowLevel/HeroSetPoints.cs +++ b/TbsCore/Tasks/LowLevel/Hero/HeroSetPoints.cs @@ -1,55 +1,55 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class HeroSetPoints : BotTask - { - private readonly string[] domId = new string[] { - "attributepower", - "attributeoffBonus", - "attributedefBonus", - "attributeproductionPoints" - }; - - public override async Task Execute(Account acc) - { - await HeroHelper.NavigateToHeroAttributes(acc); - - HeroHelper.ParseHeroPage(acc); - - float sum = 0; - for (int i = 0; i < 4; i++) sum += acc.Hero.Settings.Upgrades[i]; - if (sum == 0) - { - // Upgrade points were not set. Set points to default - acc.Hero.Settings.Upgrades = new byte[4] { 2, 0, 0, 2 }; - sum = 4; - } - - var points = acc.Hero.HeroInfo.AvaliblePoints; - - for (int i = 0; i < 4; i++) - { - var amount = Math.Ceiling(acc.Hero.Settings.Upgrades[i] * points / sum); - if (amount == 0) continue; - - var script = $"var attribute = document.getElementById('{domId[i]}');"; - script += "var upPoint = attribute.getElementsByClassName('pointsValueSetter')[1];"; - script += "upPoint.getElementsByTagName('a')[0].click();"; - - for (int j = 0; j < (int)amount; j++) - { - // Execute the script (set point) to add 1 point - acc.Wb.ExecuteScript(script); - } - await Task.Delay(AccountHelper.Delay(acc)); - } - - acc.Wb.ExecuteScript("document.getElementById('saveHeroAttributes').click();"); - return TaskRes.Executed; - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + public class HeroSetPoints : BotTask + { + private readonly string[] domId = new string[] { + "attributepower", + "attributeoffBonus", + "attributedefBonus", + "attributeproductionPoints" + }; + + public override async Task Execute(Account acc) + { + await HeroHelper.NavigateToHeroAttributes(acc); + + HeroHelper.ParseHeroPage(acc); + + float sum = 0; + for (int i = 0; i < 4; i++) sum += acc.Hero.Settings.Upgrades[i]; + if (sum == 0) + { + // Upgrade points were not set. Set points to default + acc.Hero.Settings.Upgrades = new byte[4] { 2, 0, 0, 2 }; + sum = 4; + } + + var points = acc.Hero.HeroInfo.AvaliblePoints; + + for (int i = 0; i < 4; i++) + { + var amount = Math.Ceiling(acc.Hero.Settings.Upgrades[i] * points / sum); + if (amount == 0) continue; + + var script = $"var attribute = document.getElementById('{domId[i]}');"; + script += "var upPoint = attribute.getElementsByClassName('pointsValueSetter')[1];"; + script += "upPoint.getElementsByTagName('a')[0].click();"; + + for (int j = 0; j < (int)amount; j++) + { + // Execute the script (set point) to add 1 point + acc.Wb.ExecuteScript(script); + } + await Task.Delay(AccountHelper.Delay(acc)); + } + + acc.Wb.ExecuteScript("document.getElementById('saveHeroAttributes').click();"); + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/HeroUpdateInfo.cs b/TbsCore/Tasks/LowLevel/Hero/HeroUpdateInfo.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/HeroUpdateInfo.cs rename to TbsCore/Tasks/LowLevel/Hero/HeroUpdateInfo.cs index 846317f96..f0df116a5 100644 --- a/TbsCore/Tasks/LowLevel/HeroUpdateInfo.cs +++ b/TbsCore/Tasks/LowLevel/Hero/HeroUpdateInfo.cs @@ -1,29 +1,29 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class HeroUpdateInfo : BotTask - { - public override async Task Execute(Account acc) - { - await HeroHelper.NavigateToHeroAttributes(acc); - - HeroHelper.ParseHeroPage(acc); - - if (acc.Hero.Settings.AutoRefreshInfo) - { - var ran = new Random(); - - this.NextExecute = DateTime.Now.AddMinutes( - ran.Next(acc.Hero.Settings.MinUpdate, acc.Hero.Settings.MaxUpdate) - ); - } - acc.Tasks.Remove(typeof(HeroUpdateInfo), thisTask: this); - - return TaskRes.Executed; - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + public class HeroUpdateInfo : BotTask + { + public override async Task Execute(Account acc) + { + await HeroHelper.NavigateToHeroAttributes(acc); + + HeroHelper.ParseHeroPage(acc); + + if (acc.Hero.Settings.AutoRefreshInfo) + { + var ran = new Random(); + + this.NextExecute = DateTime.Now.AddMinutes( + ran.Next(acc.Hero.Settings.MinUpdate, acc.Hero.Settings.MaxUpdate) + ); + } + acc.Tasks.Remove(typeof(HeroUpdateInfo), thisTask: this); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ReviveHero.cs b/TbsCore/Tasks/LowLevel/Hero/ReviveHero.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/ReviveHero.cs rename to TbsCore/Tasks/LowLevel/Hero/ReviveHero.cs index ee67bb9cc..a707cff12 100644 --- a/TbsCore/Tasks/LowLevel/ReviveHero.cs +++ b/TbsCore/Tasks/LowLevel/Hero/ReviveHero.cs @@ -1,34 +1,34 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class ReviveHero : BotTask - { - public override async Task Execute(Account acc) - { - await HeroHelper.NavigateToHeroAttributes(acc); - - //heroRegeneration - var reviveButton = acc.Wb.Html.GetElementbyId("heroRegeneration"); - if (reviveButton == null) - { - acc.Logger.Warning("No revive button found!"); - return TaskRes.Executed; - } - if (reviveButton.HasClass("green")) - { - acc.Wb.ExecuteScript("document.getElementById('heroRegeneration').click()"); //revive hero - return TaskRes.Executed; - } - else - { - //no resources? - this.NextExecute = DateTime.Now.AddMinutes(10); - return TaskRes.Executed; - } - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + public class ReviveHero : BotTask + { + public override async Task Execute(Account acc) + { + await HeroHelper.NavigateToHeroAttributes(acc); + + //heroRegeneration + var reviveButton = acc.Wb.Html.GetElementbyId("heroRegeneration"); + if (reviveButton == null) + { + acc.Logger.Warning("No revive button found!"); + return TaskRes.Executed; + } + if (reviveButton.HasClass("green")) + { + acc.Wb.ExecuteScript("document.getElementById('heroRegeneration').click()"); //revive hero + return TaskRes.Executed; + } + else + { + //no resources? + this.NextExecute = DateTime.Now.AddMinutes(10); + return TaskRes.Executed; + } + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/SellOnAuctions.cs b/TbsCore/Tasks/LowLevel/Hero/SellOnAuctions.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/SellOnAuctions.cs rename to TbsCore/Tasks/LowLevel/Hero/SellOnAuctions.cs index c4fe71d85..81757804a 100644 --- a/TbsCore/Tasks/LowLevel/SellOnAuctions.cs +++ b/TbsCore/Tasks/LowLevel/Hero/SellOnAuctions.cs @@ -1,21 +1,21 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class SellOnAuctions : BotTask - { - public int ItemId { get; set; } - - public override async Task Execute(Account acc) - { - await VersionHelper.Navigate(acc, "/hero.php?t=4&action=sell", "/hero/auction?action=sell"); - - acc.Wb.ExecuteScript($"document.getElementsByClassName(\"green ok dialogButtonOk\")[0].click()"); - - return TaskRes.Executed; - } - } +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class SellOnAuctions : BotTask + { + public int ItemId { get; set; } + + public override async Task Execute(Account acc) + { + await VersionHelper.Navigate(acc, "/hero.php?t=4&action=sell", "/hero/auction?action=sell"); + + acc.Wb.ExecuteScript($"document.getElementsByClassName(\"green ok dialogButtonOk\")[0].click()"); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/SetCapital.cs b/TbsCore/Tasks/LowLevel/Hero/SetCapital.cs similarity index 100% rename from TbsCore/Tasks/LowLevel/SetCapital.cs rename to TbsCore/Tasks/LowLevel/Hero/SetCapital.cs diff --git a/TbsCore/Tasks/LowLevel/SendResToMain.cs b/TbsCore/Tasks/LowLevel/SendResToMain.cs index 057c12e9b..a3b5f69cc 100644 --- a/TbsCore/Tasks/LowLevel/SendResToMain.cs +++ b/TbsCore/Tasks/LowLevel/SendResToMain.cs @@ -26,9 +26,9 @@ public override async Task Execute(Account acc) var mainVill = AccountHelper.GetMainVillage(acc); - var res = MarketHelper.GetResToMainVillage(Vill); + //var res = MarketHelper.GetResToMainVillage(Vill); - var ret = await MarketHelper.MarketSendResource(acc, res, mainVill, this); + //var ret = await MarketHelper.MarketSendResource(acc, null, mainVill, this); return TaskRes.Executed; } } diff --git a/TbsCore/Tasks/LowLevel/SendResource.cs b/TbsCore/Tasks/LowLevel/SendResource.cs new file mode 100644 index 000000000..10fbf1e19 --- /dev/null +++ b/TbsCore/Tasks/LowLevel/SendResource.cs @@ -0,0 +1,105 @@ +using System; +using System.Threading.Tasks; +using System.Linq; +using HtmlAgilityPack; +using TbsCore.Helpers; +using TbsCore.Parsers; +using TbsCore.Models.AccModels; +using TbsCore.Models.ResourceModels; +using TbsCore.Models.MapModels; +using TbsCore.Models.VillageModels; +using static TbsCore.Helpers.Classificator; + +namespace TbsCore.Tasks.LowLevel +{ + public class SendResource : Update + { + /// + /// How much resources will bot send + /// + protected Resources Resources { get; set; } + + /// + /// Target village's coordinate + /// + protected Coordinates Coordinates { get; set; } + + /// + /// Duration after bot click "Prepare" button. + /// There is delay between this and real duration after clicking "Send" button + /// + protected TimeSpan? Duration { get; set; } + + //public int RunTimes { get; set; } //once / twice / 3 times + + public SendResource(Village vill, Resources resources, Coordinates coordinates, DateTime executeAt, TaskPriority priority = TaskPriority.Medium) : base(vill, executeAt, BuildingEnum.Marketplace, priority) + { + Resources = resources; + Coordinates = coordinates; + } + + public override async Task Execute(Account acc) + { + // Checking before entering building to avoid bot detector + if (Coordinates == Vill.Coordinates) + { + acc.Logger.Warning($"{this.Vill.Name} cannot send resource to itself"); + return TaskRes.Executed; + } + + if (!ResourcesHelper.IsEnough(Vill, Resources)) + { + acc.Logger.Warning($"{Vill.Name} doesn't have enough resource to send."); + acc.Logger.Warning($"Wood: {Resources.Wood}/{Vill.Res.Stored.Resources.Wood}, Clay: {Resources.Clay}/{Vill.Res.Stored.Resources.Clay}, Iron: {Resources.Iron}/{Vill.Res.Stored.Resources.Iron}, Crop: {Resources.Crop}/{Vill.Res.Stored.Resources.Crop}"); + return TaskRes.Executed; + } + + await base.Execute(acc); + + if (!IsInBuilding) + { + return TaskRes.Executed; + } + + var merchantsCapacity = Vill.Market.MerchantInfo.Capacity; + var merchantsNum = Vill.Market.MerchantInfo.Free; + if (Resources.Sum() > merchantsCapacity * merchantsNum) + { + return TaskRes.Executed; + } + + var sendRes = Resources.ToArray(); + + for (int i = 0; i < 4; i++) + { + await DriverHelper.WriteById(acc, "r" + (i + 1), sendRes[i]); + await Task.Delay(AccountHelper.Delay(acc)); + } + + await DriverHelper.WriteCoordinates(acc, Coordinates); + await Task.Delay(AccountHelper.Delay(acc)); + await DriverHelper.ClickById(acc, "enabledButton"); + + // Prepare state + HtmlNode durNode = null; + while (durNode == null) + { + acc.Wb.UpdateHtml(); + durNode = acc.Wb.Html.GetElementbyId("target_validate"); + await Task.Delay(100); + } + var dur = durNode.Descendants("td").ToList()[3].InnerText.Replace("\t", "").Replace("\n", ""); + Duration = TimeParser.ParseDuration(dur); + + await DriverHelper.ClickById(acc, "enabledButton"); + + await Task.Delay(2000); + acc.Wb.UpdateHtml(); + (Vill.Market.MerchantInfo.Capacity, Vill.Market.MerchantInfo.Free) = MarketHelper.ParseMerchantsInfo(acc.Wb.Html); + + await TaskExecutor.PageLoaded(acc); + + return TaskRes.Executed; + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/SendResources.cs b/TbsCore/Tasks/LowLevel/SendResources.cs deleted file mode 100644 index bcde7e52d..000000000 --- a/TbsCore/Tasks/LowLevel/SendResources.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Models.MapModels; -using TbsCore.Models.ResourceModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class SendResources : BotTask - { - public SendResourcesConfiguration Configuration { get; set; } - public Resources Resources { get; set; } - public Coordinates Coordinates { get; set; } - public int RunTimes { get; set; } //once / twice / 3 times - - public override async Task Execute(Account acc) - { - if (!await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.Marketplace, "&t=5")) - return TaskRes.Executed; - - if (this.Resources == null) - { - this.Resources = Vill.Res.Stored.Resources; - } - // Check if we have enough resources in main village - var resToSend = MarketHelper.SendResCapToStorage(acc, this.Resources); - - var targetVillage = acc.Villages.FirstOrDefault(x => x.Coordinates == this.Coordinates); - - var duration = await MarketHelper.MarketSendResource(acc, resToSend, targetVillage, this); - - var targetVill = acc.Villages.FirstOrDefault(x => x.Coordinates == Coordinates); - targetVill.Market.Settings.Configuration.TransitArrival = DateTime.Now.Add(duration); - - if (this.Configuration != null && duration != null) - { - this.Configuration.TransitArrival = DateTime.Now.Add(duration); - } - // When you send resources there actually isn't a page load - return TaskRes.Executed; - } - } -} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/CheckProxy.cs b/TbsCore/Tasks/LowLevel/System/CheckProxy.cs similarity index 99% rename from TbsCore/Tasks/LowLevel/CheckProxy.cs rename to TbsCore/Tasks/LowLevel/System/CheckProxy.cs index 6f94de31d..8c608c30c 100644 --- a/TbsCore/Tasks/LowLevel/CheckProxy.cs +++ b/TbsCore/Tasks/LowLevel/System/CheckProxy.cs @@ -1,24 +1,24 @@ using System; using System.Threading.Tasks; -using TbsCore.Models.AccModels; +using TbsCore.Models.AccModels; using TbsCore.Helpers; namespace TbsCore.Tasks.LowLevel { - /// - /// TODO: replace selenium navigation with RestSharp client! - /// ProxyHelper.TestProxy(acc); + /// + /// TODO: replace selenium navigation with RestSharp client! + /// ProxyHelper.TestProxy(acc); /// public class CheckProxy : BotTask { public override async Task Execute(Account acc) - { - var currentProxy = acc.Access.GetCurrentAccess().Proxy; - acc.Logger.Information("Checking proxy " + currentProxy); - + { + var currentProxy = acc.Access.GetCurrentAccess().Proxy; + acc.Logger.Information("Checking proxy " + currentProxy); + await acc.Wb.Navigate("https://api.ipify.org/"); - var ip = acc.Wb.Html.DocumentNode.InnerText; - + var ip = acc.Wb.Html.DocumentNode.InnerText; + if (!string.IsNullOrEmpty(currentProxy) && ip.Trim() != currentProxy.Trim()) { @@ -27,7 +27,7 @@ public override async Task Execute(Account acc) if (acc.Access.AllAccess.Count > 1) { // Try another access. - var changeAccess = new ChangeAccess(); + var changeAccess = new ChangeAccess(); await changeAccess.Execute(acc); return TaskRes.Executed; } @@ -43,8 +43,8 @@ public override async Task Execute(Account acc) // Proxy OK acc.Logger.Information($"Proxy OK!"); await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); - } - return TaskRes.Executed; + } + return TaskRes.Executed; } } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/GetServerInfo.cs b/TbsCore/Tasks/LowLevel/System/GetServerInfo.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/GetServerInfo.cs rename to TbsCore/Tasks/LowLevel/System/GetServerInfo.cs index cf54e3f92..f641a15d6 100644 --- a/TbsCore/Tasks/LowLevel/GetServerInfo.cs +++ b/TbsCore/Tasks/LowLevel/System/GetServerInfo.cs @@ -1,27 +1,27 @@ -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class GetServerInfo : BotTask - { - public override async Task Execute(Account acc) - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - - // Get Map size - var size = DriverHelper.GetJsObj(acc, "window.TravianDefaults.Map.Size.top"); - acc.AccInfo.MapSize = (int)size; - - // Get server speed - var speed = DriverHelper.GetJsObj(acc, "Travian.Game.speed"); - acc.AccInfo.ServerSpeed = (int)speed; - - // Get server version - acc.AccInfo.ServerVersion = (acc.Wb.Html.GetElementbyId("sidebarBoxDailyquests") == null ? Classificator.ServerVersionEnum.T4_5 : Classificator.ServerVersionEnum.T4_4); - - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class GetServerInfo : BotTask + { + public override async Task Execute(Account acc) + { + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); + + // Get Map size + var size = DriverHelper.GetJsObj(acc, "window.TravianDefaults.Map.Size.top"); + acc.AccInfo.MapSize = (int)size; + + // Get server speed + var speed = DriverHelper.GetJsObj(acc, "Travian.Game.speed"); + acc.AccInfo.ServerSpeed = (int)speed; + + // Get server version + acc.AccInfo.ServerVersion = (acc.Wb.Html.GetElementbyId("sidebarBoxDailyquests") == null ? Classificator.ServerVersionEnum.T4_5 : Classificator.ServerVersionEnum.T4_4); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/GetTribe.cs b/TbsCore/Tasks/LowLevel/System/GetTribe.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/GetTribe.cs rename to TbsCore/Tasks/LowLevel/System/GetTribe.cs index 756ccb938..f7a92b504 100644 --- a/TbsCore/Tasks/LowLevel/GetTribe.cs +++ b/TbsCore/Tasks/LowLevel/System/GetTribe.cs @@ -1,64 +1,64 @@ -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; -using TbsCore.Parsers; - -namespace TbsCore.Tasks.LowLevel -{ - public class GetTribe : RandomTask - { - public override async Task Execute(Account acc) - { - // Tribe => id="questmasterButton", class name vid_{tribeId} - // If no questmasterButton, check tribe after updating villages => rally point/barracks - - base.MinWait = 500; - base.MaxWait = 3000; - await base.Execute(acc); - - var questMaster = acc.Wb.Html.GetElementbyId("questmasterButton"); - if (questMaster != null) - { - var vid = questMaster.GetClasses().FirstOrDefault(x => x.StartsWith("vid")); - var tribeId = Parser.RemoveNonNumeric(vid); - - SetTribe(acc, (Classificator.TribeEnum)tribeId); - - return TaskRes.Executed; - } - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id=39&tt=0"); - - List idsChecked = new List(acc.Villages.Count); - - // If no rally point, navigate somewhere else - while (acc.Wb.Html.GetElementbyId("contract") == null) - { - idsChecked.Add(acc.Villages.FirstOrDefault(x => x.Active).Id); - - var nextId = NextVillCheck(acc, idsChecked); - if (nextId == 0) throw new System.Exception("Can't get account tribe! Please build rally point!"); - await VillageHelper.SwitchVillage(acc, nextId); - } - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id=39&tt=2"); - - var unitImg = acc.Wb.Html.DocumentNode.Descendants("img").First(x => x.HasClass("unit")); - var unitInt = Parser.RemoveNonNumeric(unitImg.GetClasses().First(x => x != "unit")); - int tribeInt = (int)(unitInt / 10); - // ++ since the first element in Classificator.TribeEnum is Any, second is Romans. - tribeInt++; - SetTribe(acc, (Classificator.TribeEnum)tribeInt); - - return TaskRes.Executed; - } - - private void SetTribe(Account acc, Classificator.TribeEnum tribe) => acc.AccInfo.Tribe = tribe; - - private int NextVillCheck(Account acc, List villsChecked) => - acc.Villages.FirstOrDefault(x => !villsChecked.Contains(x.Id))?.Id ?? 0; - } +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; +using TbsCore.Parsers; + +namespace TbsCore.Tasks.LowLevel +{ + public class GetTribe : RandomTask + { + public override async Task Execute(Account acc) + { + // Tribe => id="questmasterButton", class name vid_{tribeId} + // If no questmasterButton, check tribe after updating villages => rally point/barracks + + base.MinWait = 500; + base.MaxWait = 3000; + await base.Execute(acc); + + var questMaster = acc.Wb.Html.GetElementbyId("questmasterButton"); + if (questMaster != null) + { + var vid = questMaster.GetClasses().FirstOrDefault(x => x.StartsWith("vid")); + var tribeId = Parser.RemoveNonNumeric(vid); + + SetTribe(acc, (Classificator.TribeEnum)tribeId); + + return TaskRes.Executed; + } + + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id=39&tt=0"); + + List idsChecked = new List(acc.Villages.Count); + + // If no rally point, navigate somewhere else + while (acc.Wb.Html.GetElementbyId("contract") == null) + { + idsChecked.Add(acc.Villages.FirstOrDefault(x => x.Active).Id); + + var nextId = NextVillCheck(acc, idsChecked); + if (nextId == 0) throw new System.Exception("Can't get account tribe! Please build rally point!"); + await VillageHelper.SwitchVillage(acc, nextId); + } + + await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id=39&tt=2"); + + var unitImg = acc.Wb.Html.DocumentNode.Descendants("img").First(x => x.HasClass("unit")); + var unitInt = Parser.RemoveNonNumeric(unitImg.GetClasses().First(x => x != "unit")); + int tribeInt = (int)(unitInt / 10); + // ++ since the first element in Classificator.TribeEnum is Any, second is Romans. + tribeInt++; + SetTribe(acc, (Classificator.TribeEnum)tribeInt); + + return TaskRes.Executed; + } + + private void SetTribe(Account acc, Classificator.TribeEnum tribe) => acc.AccInfo.Tribe = tribe; + + private int NextVillCheck(Account acc, List villsChecked) => + acc.Villages.FirstOrDefault(x => !villsChecked.Contains(x.Id))?.Id ?? 0; + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/LoginTask.cs b/TbsCore/Tasks/LowLevel/System/LoginTask.cs similarity index 97% rename from TbsCore/Tasks/LowLevel/LoginTask.cs rename to TbsCore/Tasks/LowLevel/System/LoginTask.cs index dad500799..8b37594e7 100644 --- a/TbsCore/Tasks/LowLevel/LoginTask.cs +++ b/TbsCore/Tasks/LowLevel/System/LoginTask.cs @@ -1,50 +1,50 @@ -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; - -namespace TbsCore.Tasks.LowLevel -{ - public class LoginTask : BotTask - { - public override async Task Execute(Account acc) - { - if (!TaskExecutor.IsLoginScreen(acc)) - { - await Task.Delay(AccountHelper.Delay(acc) * 2); - return TaskRes.Executed; - } - - var access = acc.Access.GetCurrentAccess(); - - if (acc.AccInfo.ServerUrl.Contains("ttwars")) - { - await DriverHelper.WriteByName(acc, "user", acc.AccInfo.Nickname); - await DriverHelper.WriteByName(acc, "pw", access.Password); - } - else - { - await DriverHelper.WriteByName(acc, "name", acc.AccInfo.Nickname); - await DriverHelper.WriteByName(acc, "password", access.Password); - } - - await DriverHelper.ClickByName(acc, "s1"); - - if (TaskExecutor.IsLoginScreen(acc)) - { - // Wrong password/nickname - acc.Logger.Warning("Password is incorrect!"); - acc.TaskTimer.Stop(); - } - else - { - await TaskExecutor.PageLoaded(acc); - // check sitter account - var auction = acc.Wb.Html.DocumentNode.SelectSingleNode("//a[contains(@class,'auction')]"); - - acc.Access.GetCurrentAccess().IsSittering = (auction != null && auction.HasClass("disable")); - } - - return TaskRes.Executed; - } - } +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; + +namespace TbsCore.Tasks.LowLevel +{ + public class LoginTask : BotTask + { + public override async Task Execute(Account acc) + { + if (!TaskExecutor.IsLoginScreen(acc)) + { + await Task.Delay(AccountHelper.Delay(acc) * 2); + return TaskRes.Executed; + } + + var access = acc.Access.GetCurrentAccess(); + + if (acc.AccInfo.ServerUrl.Contains("ttwars")) + { + await DriverHelper.WriteByName(acc, "user", acc.AccInfo.Nickname); + await DriverHelper.WriteByName(acc, "pw", access.Password); + } + else + { + await DriverHelper.WriteByName(acc, "name", acc.AccInfo.Nickname); + await DriverHelper.WriteByName(acc, "password", access.Password); + } + + await DriverHelper.ClickByName(acc, "s1"); + + if (TaskExecutor.IsLoginScreen(acc)) + { + // Wrong password/nickname + acc.Logger.Warning("Password is incorrect!"); + acc.TaskTimer.Stop(); + } + else + { + await TaskExecutor.PageLoaded(acc); + // check sitter account + var auction = acc.Wb.Html.DocumentNode.SelectSingleNode("//a[contains(@class,'auction')]"); + + acc.Access.GetCurrentAccess().IsSittering = (auction != null && auction.HasClass("disable")); + } + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/ReopenDriver.cs b/TbsCore/Tasks/LowLevel/System/ReopenDriver.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/ReopenDriver.cs rename to TbsCore/Tasks/LowLevel/System/ReopenDriver.cs index 85275c765..02bb33117 100644 --- a/TbsCore/Tasks/LowLevel/ReopenDriver.cs +++ b/TbsCore/Tasks/LowLevel/System/ReopenDriver.cs @@ -1,35 +1,35 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - /// - /// Task will close and reopen driver then the next Normal/High priority task has to be executed - /// - public class ReopenDriver : BotTask - { - /// - /// Lowest task priority that will cause the bot to wake up - /// - public TaskPriority LowestPrio { get; set; } - - /// - /// Reopen the chrome at specific time - /// - public DateTime? ReopenAt { get; set; } - - public override async Task Execute(Account acc) - { - acc.Wb.Dispose(); - - await TimeHelper.SleepUntilPrioTask(acc, LowestPrio, ReopenAt); - - // Use the same access - await acc.Wb.InitSelenium(acc, false); - - return TaskRes.Executed; - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + /// + /// Task will close and reopen driver then the next Normal/High priority task has to be executed + /// + public class ReopenDriver : BotTask + { + /// + /// Lowest task priority that will cause the bot to wake up + /// + public TaskPriority LowestPrio { get; set; } + + /// + /// Reopen the chrome at specific time + /// + public DateTime? ReopenAt { get; set; } + + public override async Task Execute(Account acc) + { + acc.Wb.Dispose(); + + await TimeHelper.SleepUntilPrioTask(acc, LowestPrio, ReopenAt); + + // Use the same access + await acc.Wb.InitSelenium(acc, false); + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/Sleep.cs b/TbsCore/Tasks/LowLevel/System/Sleep.cs similarity index 96% rename from TbsCore/Tasks/LowLevel/Sleep.cs rename to TbsCore/Tasks/LowLevel/System/Sleep.cs index c0db668e8..b032e3b8d 100644 --- a/TbsCore/Tasks/LowLevel/Sleep.cs +++ b/TbsCore/Tasks/LowLevel/System/Sleep.cs @@ -1,40 +1,40 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class Sleep : ReopenDriver - { - public bool AutoSleep { get; set; } - public int MinSleepSec { get; set; } - public int MaxSleepSec { get; set; } - - public override async Task Execute(Account acc) - { - if (AutoSleep) - { - MinSleepSec = acc.Settings.Time.MinSleep * 60; - MaxSleepSec = acc.Settings.Time.MaxSleep * 60; - } - var rand = new Random(); - int sleepSec = rand.Next(MinSleepSec, MaxSleepSec); - var sleepEnd = DateTime.Now.AddSeconds(sleepSec); - - acc.Logger.Information($"Sleep will end at {sleepEnd}"); - - base.LowestPrio = TaskPriority.High; - base.ReopenAt = sleepEnd; - - await base.Execute(acc); - - if (AutoSleep) - { - this.NextExecute = DateTime.Now + TimeHelper.GetWorkTime(acc); - } - - return TaskRes.Executed; - } - } +using System; +using System.Threading.Tasks; +using TbsCore.Models.AccModels; +using TbsCore.Helpers; + +namespace TbsCore.Tasks.LowLevel +{ + public class Sleep : ReopenDriver + { + public bool AutoSleep { get; set; } + public int MinSleepSec { get; set; } + public int MaxSleepSec { get; set; } + + public override async Task Execute(Account acc) + { + if (AutoSleep) + { + MinSleepSec = acc.Settings.Time.MinSleep * 60; + MaxSleepSec = acc.Settings.Time.MaxSleep * 60; + } + var rand = new Random(); + int sleepSec = rand.Next(MinSleepSec, MaxSleepSec); + var sleepEnd = DateTime.Now.AddSeconds(sleepSec); + + acc.Logger.Information($"Sleep will end at {sleepEnd}"); + + base.LowestPrio = TaskPriority.High; + base.ReopenAt = sleepEnd; + + await base.Execute(acc); + + if (AutoSleep) + { + this.NextExecute = DateTime.Now + TimeHelper.GetWorkTime(acc); + } + + return TaskRes.Executed; + } + } } \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/TrainSettlers.cs b/TbsCore/Tasks/LowLevel/TrainSettlers.cs index 049321139..cabb37389 100644 --- a/TbsCore/Tasks/LowLevel/TrainSettlers.cs +++ b/TbsCore/Tasks/LowLevel/TrainSettlers.cs @@ -19,7 +19,7 @@ public override async Task Execute(Account acc) x.Type == Classificator.BuildingEnum.CommandCenter ); - if (!await VillageHelper.EnterBuilding(acc, building, "&s=1")) + if (!await VillageHelper.EnterBuilding(acc, Vill, building.Type, "&s=1")) return TaskRes.Executed; var settler = TroopsData.TribeSettler(acc.AccInfo.Tribe); diff --git a/TbsCore/Tasks/LowLevel/TrainTroops.cs b/TbsCore/Tasks/LowLevel/TrainTroops.cs index a6a7e605f..e2ad9ceee 100644 --- a/TbsCore/Tasks/LowLevel/TrainTroops.cs +++ b/TbsCore/Tasks/LowLevel/TrainTroops.cs @@ -149,14 +149,14 @@ public void RepeatTrainingCycle(HtmlDocument htmlDoc, Account acc) var trainingEnds = TroopsHelper.GetTrainingTimeForBuilding(building, Vill); // If sendRes is activated and there are some resources left to send - if (Vill.Settings.SendRes && 0 < MarketHelper.GetResToMainVillage(this.Vill).Sum()) - { - // Check If all troops are filled in this vill before sending resources back to main village - if (TroopsHelper.EverythingFilled(acc, Vill)) - { - acc.Tasks.Add(new SendResToMain() { Vill = this.Vill, ExecuteAt = DateTime.MinValue.AddHours(1) }); - } - } + //if (Vill.Settings.SendRes && 0 < MarketHelper.GetResToMainVillage(this.Vill).Sum()) + //{ + // // Check If all troops are filled in this vill before sending resources back to main village + // if (TroopsHelper.EverythingFilled(acc, Vill)) + // { + // acc.Tasks.Add(new SendResToMain() { Vill = this.Vill, ExecuteAt = DateTime.MinValue.AddHours(1) }); + // } + //} var mainVill = AccountHelper.GetMainVillage(acc); if (Vill.Settings.GetRes && mainVill != this.Vill) @@ -173,10 +173,11 @@ public void RepeatTrainingCycle(HtmlDocument htmlDoc, Account acc) } else { - acc.Tasks.Add(new UpdateDorf1() + acc.Tasks.Add(new UpdateVillage() { ExecuteAt = nextCycle, - Vill = this.Vill + Vill = this.Vill, + NewVillage = false, }); } diff --git a/TbsCore/Tasks/LowLevel/UpdateDorf1.cs b/TbsCore/Tasks/LowLevel/UpdateDorf1.cs deleted file mode 100644 index 1b8da6fa3..000000000 --- a/TbsCore/Tasks/LowLevel/UpdateDorf1.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class UpdateDorf1 : BotTask - { - public override async Task Execute(Account acc) - { - acc.Tasks.Remove(this.GetType(), Vill, thisTask: this); - - if (!acc.Wb.CurrentUrl.Contains("/dorf1.php")) // Don't re-navigate - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); - } - - // 60% to check update dorf2 - Random ran = new Random(); - if (ran.Next(1, 100) > 40) - { - acc.Tasks.Add(new UpdateDorf2() - { - ExecuteAt = DateTime.Now.AddMinutes(1), - Vill = Vill - }, true, Vill); - } - - return TaskRes.Executed; - } - } -} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/UpdateDorf2.cs b/TbsCore/Tasks/LowLevel/UpdateDorf2.cs deleted file mode 100644 index b556e7d0d..000000000 --- a/TbsCore/Tasks/LowLevel/UpdateDorf2.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - public class UpdateDorf2 : BotTask - { - public override async Task Execute(Account acc) - { - acc.Tasks.Remove(this.GetType(), Vill, thisTask: this); - - if (!acc.Wb.CurrentUrl.Contains("/dorf2.php")) // Don't re-navigate - { - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - } - - return TaskRes.Executed; - } - } -} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/UpdateTaskUseRes.cs b/TbsCore/Tasks/LowLevel/UpdateTaskUseRes.cs deleted file mode 100644 index f7f30426d..000000000 --- a/TbsCore/Tasks/LowLevel/UpdateTaskUseRes.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Models.AccModels; -using TbsCore.Helpers; - -namespace TbsCore.Tasks.LowLevel -{ - internal class UpdateTaskUseRes : BotTask - { - public override async Task Execute(Account acc) - { - // Troops task - TroopsHelper.ReStartTroopTraining(acc, Vill); - await Task.Delay(AccountHelper.Delay(acc)); - TroopsHelper.ReStartResearchAndImprovement(acc, Vill); - await Task.Delay(AccountHelper.Delay(acc)); - - // Building task - BuildingHelper.ReStartBuilding(acc, Vill); - await Task.Delay(AccountHelper.Delay(acc)); - BuildingHelper.ReStartDemolishing(acc, Vill); - await Task.Delay(AccountHelper.Delay(acc)); - - // Celebration task - AccountHelper.ReStartCelebration(acc, Vill); - return TaskRes.Executed; - } - } -} \ No newline at end of file diff --git a/TbsCore/Tasks/LowLevel/UpdateVillage.cs b/TbsCore/Tasks/LowLevel/UpdateVillage.cs deleted file mode 100644 index 222ea09b8..000000000 --- a/TbsCore/Tasks/LowLevel/UpdateVillage.cs +++ /dev/null @@ -1,121 +0,0 @@ -using System.Linq; -using System.Threading.Tasks; -using TbsCore.Helpers; -using TbsCore.Models.AccModels; -using TbsCore.TravianData; -using TbsCore.Parsers; - -namespace TbsCore.Tasks.LowLevel -{ - public class UpdateVillage : BotTask - { - /// - /// If village is new, we want to import the building tasks to the village - /// - public bool ImportTasks { get; set; } - - public override async Task Execute(Account acc) - { - acc.Tasks.Remove(typeof(UpdateDorf1), Vill, thisTask: this); - acc.Tasks.Remove(typeof(UpdateDorf2), Vill, thisTask: this); - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 - await Task.Delay(AccountHelper.Delay(acc)); - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); // Update dorf2 - - // On new village import the building tasks - if (ImportTasks && !string.IsNullOrEmpty(acc.NewVillages.BuildingTasksLocationNewVillage)) - { - IoHelperCore.AddBuildTasksFromFile(acc, Vill, acc.NewVillages.BuildingTasksLocationNewVillage); - } - - await UpdateTroopsResearchedAndLevels(acc); - - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - await Task.Delay(AccountHelper.Delay(acc)); - await UpdateTroopsTraining(acc); - - var firstTroop = TroopsData.TribeFirstTroop(acc.AccInfo.Tribe); - Vill.Troops.TroopToTrain = firstTroop; - Vill.Troops.Researched.Add(firstTroop); - - if (await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.TownHall)) - { - // Village has town hall, parse celebration duration - Vill.Expansion.CelebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); - } - - return TaskRes.Executed; - } - - // Copied from UpdateTroops BotTask - public async Task UpdateTroopsResearchedAndLevels(Account acc) - { - if (acc.AccInfo.PlusAccount) - { - // From overview we get all researched troops and their levels - await VersionHelper.Navigate(acc, "/dorf3.php?s=5&su=2", "/village/statistics/troops?su=2"); - - OverviewParser.UpdateTroopsLevels(acc.Wb.Html, ref acc); - // We have updated all villages at the same time. No need to continue. - acc.Tasks.Remove(typeof(UpdateTroops)); - return; - } - - var smithy = Vill.Build.Buildings.FirstOrDefault(x => x.Type == Classificator.BuildingEnum.Smithy); - if (smithy != null) - { - // If smithy exists, we get all researched troops and their levels - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={smithy.Id}"); - Vill.Troops.Levels = TroopsParser.GetTroopLevels(acc.Wb.Html); - TroopsHelper.UpdateResearchedTroops(Vill); - return; - } - } - - private readonly Classificator.BuildingEnum[] trainingBuildings = new Classificator.BuildingEnum[] { - Classificator.BuildingEnum.Barracks, - Classificator.BuildingEnum.Stable, - Classificator.BuildingEnum.Workshop, - Classificator.BuildingEnum.GreatBarracks, - Classificator.BuildingEnum.GreatStable - }; - - public async Task UpdateTroopsTraining(Account acc) - { - foreach (var trainingBuilding in trainingBuildings) - { - if (!await VillageHelper.EnterBuilding(acc, Vill, trainingBuilding)) continue; - - // Mark troops that user can train in building as researched - TroopsHelper.UpdateTroopsResearched(Vill, acc.Wb.Html); - - var ct = TroopsParser.GetTroopsCurrentlyTraining(acc.Wb.Html); - switch (trainingBuilding) - { - case Classificator.BuildingEnum.Barracks: - Vill.Troops.CurrentlyTraining.Barracks = ct; - break; - - case Classificator.BuildingEnum.Stable: - Vill.Troops.CurrentlyTraining.Stable = ct; - break; - - case Classificator.BuildingEnum.GreatBarracks: - Vill.Troops.CurrentlyTraining.GB = ct; - break; - - case Classificator.BuildingEnum.GreatStable: - Vill.Troops.CurrentlyTraining.GS = ct; - break; - - case Classificator.BuildingEnum.Workshop: - Vill.Troops.CurrentlyTraining.Workshop = ct; - break; - } - await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf2.php"); - await Task.Delay(AccountHelper.Delay(acc)); - } - } - } -} \ No newline at end of file diff --git a/TbsCore/Tasks/SecondLevel/SendRoute.cs b/TbsCore/Tasks/SecondLevel/SendRoute.cs new file mode 100644 index 000000000..ef55c8d7f --- /dev/null +++ b/TbsCore/Tasks/SecondLevel/SendRoute.cs @@ -0,0 +1,47 @@ +using System; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.ResourceModels; +using TbsCore.Models.VillageModels; +using TbsCore.Tasks.LowLevel; + +namespace TbsCore.Tasks.SecondLevel +{ + public class SendRoute : SendResource + { + public SendRoute(Village vill, DateTime executeAt, TaskPriority priority = TaskPriority.Medium) : base(vill, null, null, executeAt, priority) + { + } + + public override async Task Execute(Account acc) + { + var index = Vill.Market.TradeRoute.Next; + var route = Vill.Market.TradeRoute.TradeRoutes[index]; + while (!route.Active) + { + index = MarketHelper.UpdateNextTradeRoute(Vill); + route = Vill.Market.TradeRoute.TradeRoutes[index]; + } + + Coordinates = route.Location; + Resources = route.Resource; + await base.Execute(acc); + if (Duration != null) + { + route.Last = DateTime.Now; + index = MarketHelper.UpdateNextTradeRoute(Vill); + route = Vill.Market.TradeRoute.TradeRoutes[index]; + while (!route.Active) + { + index = MarketHelper.UpdateNextTradeRoute(Vill); + route = Vill.Market.TradeRoute.TradeRoutes[index]; + } + var ran = new Random(); + NextExecute = DateTime.Now.AddMinutes(route.Time + ran.Next(-route.TimeDelay, route.TimeDelay)); + } + + return TaskRes.Executed; + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/SecondLevel/SendToMain.cs b/TbsCore/Tasks/SecondLevel/SendToMain.cs new file mode 100644 index 000000000..41724af6d --- /dev/null +++ b/TbsCore/Tasks/SecondLevel/SendToMain.cs @@ -0,0 +1,23 @@ +using System; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.VillageModels; +using TbsCore.Tasks.LowLevel; + +namespace TbsCore.Tasks.SecondLevel +{ + public class SendToMain : SendResource + { + public SendToMain(Village vill, Village villMain, DateTime executeAt, TaskPriority priority = TaskPriority.Medium) : base(vill, MarketHelper.Round(MarketHelper.GetResource(vill, vill.Market.AutoMarket.SendToMain.Amount)), villMain.Coordinates, executeAt, priority) + { + } + + public override async Task Execute(Account acc) + { + if (!Vill.Market.AutoMarket.SendToMain.Enabled) return TaskRes.Executed; + await base.Execute(acc); + return TaskRes.Executed; + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/SecondLevel/SendToNeed.cs b/TbsCore/Tasks/SecondLevel/SendToNeed.cs new file mode 100644 index 000000000..91e2f4d61 --- /dev/null +++ b/TbsCore/Tasks/SecondLevel/SendToNeed.cs @@ -0,0 +1,59 @@ +using System; +using System.Linq; +using System.Threading.Tasks; +using TbsCore.Helpers; +using TbsCore.Models.AccModels; +using TbsCore.Models.ResourceModels; +using TbsCore.Models.VillageModels; +using TbsCore.Tasks.LowLevel; + +namespace TbsCore.Tasks.SecondLevel +{ + public class SendToNeed : SendResource + { + private Resources ResourcesNeed; + + public SendToNeed(Village vill, Resources resources, DateTime executeAt, TaskPriority priority = TaskPriority.Medium) : base(vill, null, vill.Coordinates, executeAt, priority) + { + ResourcesNeed = resources; + } + + public override async Task Execute(Account acc) + { + var villCanSend = acc.Villages + .Where(vill => vill.Market.AutoMarket.SendToNeed.Enabled && vill.Id != Vill.Id) + .ToList(); + + villCanSend.Sort((x, y) => MapHelper.Compare(acc, Vill.Coordinates, x.Coordinates, y.Coordinates)); + foreach (var vill in villCanSend) + { + Resources = MarketHelper.GetResource(vill, vill.Market.AutoMarket.SendToNeed.Amount); + await VillageHelper.SwitchVillage(acc, vill.Id); + await Task.Delay(AccountHelper.Delay(acc)); + if (!ResourcesHelper.IsEnough(vill, Resources)) + { + if (!ResourcesHelper.IsEnough(vill, ResourcesNeed)) + { + continue; + } + + // send all resource in stored + // this is temporary behaviour and will change later in release + // dont worry + Resources = new Resources + { + Wood = vill.Res.Stored.Resources.Wood, + Clay = vill.Res.Stored.Resources.Clay, + Iron = vill.Res.Stored.Resources.Iron, + Crop = vill.Res.Stored.Resources.Crop, + }; + } + + await base.Execute(acc); + + if (Duration != null) { break; } + } + return TaskRes.Executed; + } + } +} \ No newline at end of file diff --git a/TbsCore/Tasks/SecondLevel/TransitToMainAcc.cs b/TbsCore/Tasks/SecondLevel/TransitToMainAcc.cs index ae5c855d1..6bbcdd818 100644 --- a/TbsCore/Tasks/SecondLevel/TransitToMainAcc.cs +++ b/TbsCore/Tasks/SecondLevel/TransitToMainAcc.cs @@ -27,7 +27,7 @@ public override async Task Execute(Account acc) await Task.Delay(AccountHelper.Delay(acc)); //Resources res = new Resources() { Wood = 50000000, Clay = 50000000, Iron = 50000000, Crop = 50000000 }; - acc.Tasks.Add(new SendResources() { ExecuteAt = DateTime.Now, Coordinates = coords, Vill = this.Vill }); + //acc.Tasks.Add(new SendResource() { ExecuteAt = DateTime.Now, Coordinates = coords, Vill = this.Vill }); return TaskRes.Executed; } diff --git a/TravBotSharp/ControlPanel.Designer.cs b/TravBotSharp/ControlPanel.Designer.cs index b70052310..962bd777c 100644 --- a/TravBotSharp/ControlPanel.Designer.cs +++ b/TravBotSharp/ControlPanel.Designer.cs @@ -40,6 +40,7 @@ private void InitializeComponent() this.overviewUc1 = new TravBotSharp.Views.OverviewUc(); this.troopsTab = new System.Windows.Forms.TabPage(); this.overviewTroopsUc1 = new TravBotSharp.Views.OverviewTroopsUc(); + this.marketsTab = new System.Windows.Forms.TabPage(); this.FarmingTab = new System.Windows.Forms.TabPage(); this.farmingUc1 = new TravBotSharp.Views.FarmingUc(); this.newVillagesTab = new System.Windows.Forms.TabPage(); @@ -49,6 +50,7 @@ private void InitializeComponent() this.questsTab = new System.Windows.Forms.TabPage(); this.questsUc1 = new TravBotSharp.Views.QuestsUc(); this.discordTab = new System.Windows.Forms.TabPage(); + this.discordUc1 = new TravBotSharp.Views.DiscordUc(); this.debugTab = new System.Windows.Forms.TabPage(); this.debugUc1 = new TravBotSharp.Views.DebugUc(); this.button2 = new System.Windows.Forms.Button(); @@ -65,13 +67,14 @@ private void InitializeComponent() this.button4 = new System.Windows.Forms.Button(); this.panel2 = new System.Windows.Forms.Panel(); this.panel5 = new System.Windows.Forms.Panel(); - this.discordUc1 = new TravBotSharp.Views.DiscordUc(); + this.overviewMarketUc1 = new TravBotSharp.Views.OverviewMarketUc(); this.accTabController.SuspendLayout(); this.tabGeneral.SuspendLayout(); this.tabHero.SuspendLayout(); this.tabVillages.SuspendLayout(); this.tabOverview.SuspendLayout(); this.troopsTab.SuspendLayout(); + this.marketsTab.SuspendLayout(); this.FarmingTab.SuspendLayout(); this.newVillagesTab.SuspendLayout(); this.deffendingTab.SuspendLayout(); @@ -102,6 +105,7 @@ private void InitializeComponent() this.accTabController.Controls.Add(this.tabVillages); this.accTabController.Controls.Add(this.tabOverview); this.accTabController.Controls.Add(this.troopsTab); + this.accTabController.Controls.Add(this.marketsTab); this.accTabController.Controls.Add(this.FarmingTab); this.accTabController.Controls.Add(this.newVillagesTab); this.accTabController.Controls.Add(this.deffendingTab); @@ -114,7 +118,6 @@ private void InitializeComponent() this.accTabController.SelectedIndex = 0; this.accTabController.Size = new System.Drawing.Size(971, 661); this.accTabController.TabIndex = 3; - this.accTabController.SelectedIndexChanged += new System.EventHandler(this.debugUc1.tabControl1_SelectedIndexChanged); this.accTabController.SelectedIndexChanged += new System.EventHandler(this.tabControl1_SelectedIndexChanged); // // tabGeneral @@ -215,6 +218,16 @@ private void InitializeComponent() this.overviewTroopsUc1.Size = new System.Drawing.Size(957, 629); this.overviewTroopsUc1.TabIndex = 0; // + // marketsTab + // + this.marketsTab.Controls.Add(this.overviewMarketUc1); + this.marketsTab.Location = new System.Drawing.Point(4, 22); + this.marketsTab.Name = "marketsTab"; + this.marketsTab.Size = new System.Drawing.Size(963, 635); + this.marketsTab.TabIndex = 12; + this.marketsTab.Text = "Markets"; + this.marketsTab.UseVisualStyleBackColor = true; + // // FarmingTab // this.FarmingTab.Controls.Add(this.farmingUc1); @@ -306,6 +319,14 @@ private void InitializeComponent() this.discordTab.Text = "Discord"; this.discordTab.UseVisualStyleBackColor = true; // + // discordUc1 + // + this.discordUc1.Cursor = System.Windows.Forms.Cursors.Default; + this.discordUc1.Location = new System.Drawing.Point(2, 2); + this.discordUc1.Name = "discordUc1"; + this.discordUc1.Size = new System.Drawing.Size(950, 536); + this.discordUc1.TabIndex = 0; + // // debugTab // this.debugTab.Controls.Add(this.debugUc1); @@ -467,12 +488,12 @@ private void InitializeComponent() this.panel5.Size = new System.Drawing.Size(971, 661); this.panel5.TabIndex = 12; // - // discordUc1 + // overviewMarketUc1 // - this.discordUc1.Location = new System.Drawing.Point(2, 2); - this.discordUc1.Name = "discordUc1"; - this.discordUc1.Size = new System.Drawing.Size(950, 536); - this.discordUc1.TabIndex = 0; + this.overviewMarketUc1.Location = new System.Drawing.Point(3, 3); + this.overviewMarketUc1.Name = "overviewMarketUc1"; + this.overviewMarketUc1.Size = new System.Drawing.Size(957, 629); + this.overviewMarketUc1.TabIndex = 0; // // ControlPanel // @@ -490,6 +511,7 @@ private void InitializeComponent() this.tabVillages.ResumeLayout(false); this.tabOverview.ResumeLayout(false); this.troopsTab.ResumeLayout(false); + this.marketsTab.ResumeLayout(false); this.FarmingTab.ResumeLayout(false); this.newVillagesTab.ResumeLayout(false); this.deffendingTab.ResumeLayout(false); @@ -544,5 +566,7 @@ private void InitializeComponent() private System.Windows.Forms.Button button4; private System.Windows.Forms.TabPage discordTab; private Views.DiscordUc discordUc1; + private System.Windows.Forms.TabPage marketsTab; + private Views.OverviewMarketUc overviewMarketUc1; } } \ No newline at end of file diff --git a/TravBotSharp/ControlPanel.cs b/TravBotSharp/ControlPanel.cs index 16a59cc68..7c09751a1 100644 --- a/TravBotSharp/ControlPanel.cs +++ b/TravBotSharp/ControlPanel.cs @@ -24,6 +24,7 @@ public partial class ControlPanel : Form private int accSelected = 0; private System.Timers.Timer saveAccountsTimer; private ITbsUc[] Ucs; + private bool IsClose = false; public ControlPanel() { @@ -40,6 +41,7 @@ public ControlPanel() villagesUc1, overviewUc1, overviewTroopsUc1, + overviewMarketUc1, farmingUc1, newVillagesUc1, deffendingUc1, @@ -78,7 +80,11 @@ private void LoadAccounts() accounts = DbRepository.GetAccounts(); - accounts.ForEach(x => ObjectHelper.FixAccObj(x, x)); + accounts.ForEach(x => + { + ObjectHelper.FixAccObj(x, x); + AccountHelper.Loaded(x); + }); RefreshAccView(); } @@ -97,14 +103,27 @@ private void button1_Click(object sender, EventArgs e) // Add account string.IsNullOrEmpty(acc.AccInfo.ServerUrl)) return; accounts.Add(acc); + AccountHelper.Loaded(acc); + RefreshAccView(); } } } - private void ControlPanel_FormClosing(object sender, FormClosingEventArgs e) + private async void ControlPanel_FormClosing(object sender, FormClosingEventArgs e) { - IoHelperCore.SaveAccounts(accounts, true); + if (!IsClose) + { + var f = (Form)sender; + e.Cancel = true; + f.Enabled = false; + var closeForm = new Close(); + closeForm.Show(this); + await IoHelperCore.SaveAccounts(accounts, true); + IsClose = true; + closeForm.Close(); + f.Close(); + } } /// diff --git a/TravBotSharp/Forms/Close.Designer.cs b/TravBotSharp/Forms/Close.Designer.cs new file mode 100644 index 000000000..f13027308 --- /dev/null +++ b/TravBotSharp/Forms/Close.Designer.cs @@ -0,0 +1,64 @@ + +namespace TravBotSharp.Forms +{ + partial class Close + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.progressBar1 = new System.Windows.Forms.ProgressBar(); + this.SuspendLayout(); + // + // progressBar1 + // + this.progressBar1.Location = new System.Drawing.Point(12, 12); + this.progressBar1.Name = "progressBar1"; + this.progressBar1.Size = new System.Drawing.Size(213, 41); + this.progressBar1.TabIndex = 0; + this.progressBar1.Value = 80; + // + // Close + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(237, 65); + this.ControlBox = false; + this.Controls.Add(this.progressBar1); + this.Name = "Close"; + this.ShowIcon = false; + this.ShowInTaskbar = false; + this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; + this.Text = "Please wait"; + this.Load += new System.EventHandler(this.Close_Load); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.ProgressBar progressBar1; + } +} \ No newline at end of file diff --git a/TravBotSharp/Forms/Close.cs b/TravBotSharp/Forms/Close.cs new file mode 100644 index 000000000..3a64373c2 --- /dev/null +++ b/TravBotSharp/Forms/Close.cs @@ -0,0 +1,18 @@ +using System; +using System.Windows.Forms; + +namespace TravBotSharp.Forms +{ + public partial class Close : Form + { + public Close() + { + InitializeComponent(); + } + + private void Close_Load(object sender, EventArgs e) + { + this.CenterToParent(); + } + } +} \ No newline at end of file diff --git a/TravBotSharp/Forms/Close.resx b/TravBotSharp/Forms/Close.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TravBotSharp/Forms/Close.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravBotSharp/Forms/ResourceSelector.Designer.cs b/TravBotSharp/Forms/ResourceSelector.Designer.cs new file mode 100644 index 000000000..042c5357e --- /dev/null +++ b/TravBotSharp/Forms/ResourceSelector.Designer.cs @@ -0,0 +1,103 @@ + +namespace TravBotSharp.Forms +{ + partial class ResourceSelector + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + TbsCore.Models.ResourceModels.Resources resources1 = new TbsCore.Models.ResourceModels.Resources(); + this.resourceSelectorUc1 = new TravBotSharp.UserControls.ResourceSelectorUc(); + this.button1 = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.label2 = new System.Windows.Forms.Label(); + this.SuspendLayout(); + // + // resourceSelectorUc1 + // + this.resourceSelectorUc1.Location = new System.Drawing.Point(16, 44); + this.resourceSelectorUc1.Name = "resourceSelectorUc1"; + resources1.Clay = ((long)(0)); + resources1.Crop = ((long)(0)); + resources1.Iron = ((long)(0)); + resources1.Wood = ((long)(0)); + this.resourceSelectorUc1.resources = resources1; + this.resourceSelectorUc1.Size = new System.Drawing.Size(146, 99); + this.resourceSelectorUc1.TabIndex = 0; + // + // button1 + // + this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button1.Location = new System.Drawing.Point(203, 44); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 99); + this.button1.TabIndex = 2; + this.button1.Text = "OK"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(14, 13); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(264, 13); + this.label1.TabIndex = 4; + this.label1.Text = "If value is less or equal 100, it will be based on percent"; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(13, 28); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(203, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Otherwise, it will be based on that number"; + // + // ResourceSelector + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(290, 155); + this.Controls.Add(this.label2); + this.Controls.Add(this.label1); + this.Controls.Add(this.button1); + this.Controls.Add(this.resourceSelectorUc1); + this.Name = "ResourceSelector"; + this.Text = "ResourceSelector"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private UserControls.ResourceSelectorUc resourceSelectorUc1; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Label label2; + } +} \ No newline at end of file diff --git a/TravBotSharp/Forms/ResourceSelector.cs b/TravBotSharp/Forms/ResourceSelector.cs new file mode 100644 index 000000000..b20d065e4 --- /dev/null +++ b/TravBotSharp/Forms/ResourceSelector.cs @@ -0,0 +1,39 @@ +using System.Windows.Forms; + +using TbsCore.Models.ResourceModels; + +namespace TravBotSharp.Forms +{ + public partial class ResourceSelector : Form + { + private Resources resources; + + public ResourceSelector(Resources res) + { + InitializeComponent(); + Resources = res; + } + + public Resources Resources + { + get + { + return resources; + } + set + { + if (value != null) + { + resources = value; + resourceSelectorUc1.resources = resources; + } + } + } + + private void button1_Click(object sender, System.EventArgs e) + { + this.DialogResult = DialogResult.OK; + this.Close(); + } + } +} \ No newline at end of file diff --git a/TravBotSharp/Forms/ResourceSelector.resx b/TravBotSharp/Forms/ResourceSelector.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TravBotSharp/Forms/ResourceSelector.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravBotSharp/Forms/TroopsSelector.Designer.cs b/TravBotSharp/Forms/TroopsSelector.Designer.cs index 6c686f5ff..2c9d6d631 100644 --- a/TravBotSharp/Forms/TroopsSelector.Designer.cs +++ b/TravBotSharp/Forms/TroopsSelector.Designer.cs @@ -40,7 +40,17 @@ private void InitializeComponent() this.troopsSelectorUc1.Name = "troopsSelectorUc1"; this.troopsSelectorUc1.Size = new System.Drawing.Size(139, 264); this.troopsSelectorUc1.TabIndex = 0; - this.troopsSelectorUc1.Troops = null; + this.troopsSelectorUc1.Troops = new int[] { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0}; // // button1 // diff --git a/TravBotSharp/FormsResources.Designer.cs b/TravBotSharp/FormsResources.Designer.cs index 6c340a318..7e086fb40 100644 --- a/TravBotSharp/FormsResources.Designer.cs +++ b/TravBotSharp/FormsResources.Designer.cs @@ -119,6 +119,16 @@ internal static System.Drawing.Bitmap Nature { } } + /// + /// Looks up a localized resource of type System.Drawing.Bitmap. + /// + internal static System.Drawing.Bitmap resource { + get { + object obj = ResourceManager.GetObject("resource", resourceCulture); + return ((System.Drawing.Bitmap)(obj)); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/TravBotSharp/FormsResources.resx b/TravBotSharp/FormsResources.resx index 178d6021d..d16331c2d 100644 --- a/TravBotSharp/FormsResources.resx +++ b/TravBotSharp/FormsResources.resx @@ -136,6 +136,9 @@ Resources\Nature.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + + Resources\resource.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + Resources\Romans.gif;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a diff --git a/TravBotSharp/Resources/resource.gif b/TravBotSharp/Resources/resource.gif new file mode 100644 index 000000000..065c21796 Binary files /dev/null and b/TravBotSharp/Resources/resource.gif differ diff --git a/TravBotSharp/TbsWinForms.csproj b/TravBotSharp/TbsWinForms.csproj index 6c25ed364..3b05d7361 100644 --- a/TravBotSharp/TbsWinForms.csproj +++ b/TravBotSharp/TbsWinForms.csproj @@ -397,6 +397,12 @@ ControlPanel.cs + + Form + + + Close.cs + Form @@ -420,6 +426,24 @@ NewRelease.cs + + Form + + + ResourceSelector.cs + + + UserControl + + + ResourceDisplayUc.cs + + + UserControl + + + ResourceSelectorUc.cs + UserControl @@ -474,6 +498,12 @@ AddFarmlistNonGold.cs + + UserControl + + + OverviewMarketUc.cs + UserControl @@ -576,6 +606,9 @@ AlertForm.cs + + Close.cs + InactiveFinder.cs @@ -589,6 +622,15 @@ NewRelease.cs + + ResourceSelector.cs + + + ResourceDisplayUc.cs + + + ResourceSelectorUc.cs + TroopsDisplayUc.cs @@ -614,6 +656,9 @@ DiscordUc.cs + + OverviewMarketUc.cs + OverviewTroopsUc.cs @@ -667,6 +712,7 @@ + SettingsSingleFileGenerator Settings.Designer.cs @@ -719,6 +765,7 @@ + diff --git a/TravBotSharp/UserControls/ResourceDisplayUc.Designer.cs b/TravBotSharp/UserControls/ResourceDisplayUc.Designer.cs new file mode 100644 index 000000000..764861873 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceDisplayUc.Designer.cs @@ -0,0 +1,99 @@ + +namespace TravBotSharp.UserControls +{ + partial class ResourceDisplayUc + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.pictureBox1 = new System.Windows.Forms.PictureBox(); + this.pictureBox2 = new System.Windows.Forms.PictureBox(); + this.pictureBox3 = new System.Windows.Forms.PictureBox(); + this.pictureBox4 = new System.Windows.Forms.PictureBox(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).BeginInit(); + this.SuspendLayout(); + // + // pictureBox1 + // + this.pictureBox1.Location = new System.Drawing.Point(3, 2); + this.pictureBox1.Name = "pictureBox1"; + this.pictureBox1.Size = new System.Drawing.Size(18, 18); + this.pictureBox1.TabIndex = 0; + this.pictureBox1.TabStop = false; + // + // pictureBox2 + // + this.pictureBox2.Location = new System.Drawing.Point(3, 26); + this.pictureBox2.Name = "pictureBox2"; + this.pictureBox2.Size = new System.Drawing.Size(18, 18); + this.pictureBox2.TabIndex = 1; + this.pictureBox2.TabStop = false; + // + // pictureBox3 + // + this.pictureBox3.Location = new System.Drawing.Point(3, 50); + this.pictureBox3.Name = "pictureBox3"; + this.pictureBox3.Size = new System.Drawing.Size(18, 18); + this.pictureBox3.TabIndex = 2; + this.pictureBox3.TabStop = false; + // + // pictureBox4 + // + this.pictureBox4.Location = new System.Drawing.Point(3, 74); + this.pictureBox4.Name = "pictureBox4"; + this.pictureBox4.Size = new System.Drawing.Size(18, 18); + this.pictureBox4.TabIndex = 3; + this.pictureBox4.TabStop = false; + // + // ResourceDisplayUc + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.pictureBox4); + this.Controls.Add(this.pictureBox3); + this.Controls.Add(this.pictureBox2); + this.Controls.Add(this.pictureBox1); + this.Name = "ResourceDisplayUc"; + this.Size = new System.Drawing.Size(24, 96); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBox4)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.PictureBox pictureBox1; + private System.Windows.Forms.PictureBox pictureBox2; + private System.Windows.Forms.PictureBox pictureBox3; + private System.Windows.Forms.PictureBox pictureBox4; + } +} diff --git a/TravBotSharp/UserControls/ResourceDisplayUc.cs b/TravBotSharp/UserControls/ResourceDisplayUc.cs new file mode 100644 index 000000000..f5c783c49 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceDisplayUc.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace TravBotSharp.UserControls +{ + public partial class ResourceDisplayUc : UserControl + { + public ResourceDisplayUc() + { + InitializeComponent(); + + var img = FormsResources.resource; + pictureBox1.Image = img.Clone( + new Rectangle(0, 0, 18, 18), + System.Drawing.Imaging.PixelFormat.Format24bppRgb + ); + + pictureBox2.Image = img.Clone( + new Rectangle(0, 25, 18, 18), + System.Drawing.Imaging.PixelFormat.Format24bppRgb + ); + + pictureBox3.Image = img.Clone( + new Rectangle(0, 52, 18, 18), + System.Drawing.Imaging.PixelFormat.Format24bppRgb + ); + + pictureBox4.Image = img.Clone( + new Rectangle(0, 77, 18, 18), + System.Drawing.Imaging.PixelFormat.Format24bppRgb + ); + } + } +} \ No newline at end of file diff --git a/TravBotSharp/UserControls/ResourceDisplayUc.resx b/TravBotSharp/UserControls/ResourceDisplayUc.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceDisplayUc.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravBotSharp/UserControls/ResourceSelectorUc.Designer.cs b/TravBotSharp/UserControls/ResourceSelectorUc.Designer.cs new file mode 100644 index 000000000..711f4dd21 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceSelectorUc.Designer.cs @@ -0,0 +1,125 @@ + +namespace TravBotSharp.UserControls +{ + partial class ResourceSelectorUc + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.resourceDisplayUc1 = new TravBotSharp.UserControls.ResourceDisplayUc(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); + this.SuspendLayout(); + // + // resourceDisplayUc1 + // + this.resourceDisplayUc1.Location = new System.Drawing.Point(3, 3); + this.resourceDisplayUc1.Name = "resourceDisplayUc1"; + this.resourceDisplayUc1.Size = new System.Drawing.Size(24, 96); + this.resourceDisplayUc1.TabIndex = 0; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(33, 3); + this.numericUpDown1.Maximum = new decimal(new int[] { + 1000000000, + 0, + 0, + 0}); + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(110, 20); + this.numericUpDown1.TabIndex = 2; + // + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(33, 28); + this.numericUpDown2.Maximum = new decimal(new int[] { + 1000000000, + 0, + 0, + 0}); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(110, 20); + this.numericUpDown2.TabIndex = 3; + // + // numericUpDown3 + // + this.numericUpDown3.Location = new System.Drawing.Point(33, 53); + this.numericUpDown3.Maximum = new decimal(new int[] { + 1000000000, + 0, + 0, + 0}); + this.numericUpDown3.Name = "numericUpDown3"; + this.numericUpDown3.Size = new System.Drawing.Size(110, 20); + this.numericUpDown3.TabIndex = 4; + // + // numericUpDown4 + // + this.numericUpDown4.Location = new System.Drawing.Point(33, 76); + this.numericUpDown4.Maximum = new decimal(new int[] { + 1000000000, + 0, + 0, + 0}); + this.numericUpDown4.Name = "numericUpDown4"; + this.numericUpDown4.Size = new System.Drawing.Size(110, 20); + this.numericUpDown4.TabIndex = 5; + // + // ResourceSelectorUc + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.numericUpDown4); + this.Controls.Add(this.numericUpDown3); + this.Controls.Add(this.numericUpDown2); + this.Controls.Add(this.numericUpDown1); + this.Controls.Add(this.resourceDisplayUc1); + this.Name = "ResourceSelectorUc"; + this.Size = new System.Drawing.Size(146, 99); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); + this.ResumeLayout(false); + + } + + #endregion + + private ResourceDisplayUc resourceDisplayUc1; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.NumericUpDown numericUpDown2; + private System.Windows.Forms.NumericUpDown numericUpDown3; + private System.Windows.Forms.NumericUpDown numericUpDown4; + } +} diff --git a/TravBotSharp/UserControls/ResourceSelectorUc.cs b/TravBotSharp/UserControls/ResourceSelectorUc.cs new file mode 100644 index 000000000..a9665f764 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceSelectorUc.cs @@ -0,0 +1,39 @@ +using System.Windows.Forms; + +using TbsCore.Models.ResourceModels; + +namespace TravBotSharp.UserControls +{ + public partial class ResourceSelectorUc : UserControl + { + public ResourceSelectorUc() + { + InitializeComponent(); + } + + public Resources resources + { + get + { + Resources res = new Resources + { + Wood = (long)numericUpDown1.Value, + Clay = (long)numericUpDown2.Value, + Iron = (long)numericUpDown3.Value, + Crop = (long)numericUpDown4.Value, + }; + return res; + } + set + { + if (value != null) + { + numericUpDown1.Value = value.Wood; + numericUpDown2.Value = value.Clay; + numericUpDown3.Value = value.Iron; + numericUpDown4.Value = value.Crop; + } + } + } + } +} \ No newline at end of file diff --git a/TravBotSharp/UserControls/ResourceSelectorUc.resx b/TravBotSharp/UserControls/ResourceSelectorUc.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TravBotSharp/UserControls/ResourceSelectorUc.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravBotSharp/Views/OverviewMarketUc.Designer.cs b/TravBotSharp/Views/OverviewMarketUc.Designer.cs new file mode 100644 index 000000000..8df0fb618 --- /dev/null +++ b/TravBotSharp/Views/OverviewMarketUc.Designer.cs @@ -0,0 +1,99 @@ + +namespace TravBotSharp.Views +{ + partial class OverviewMarketUc + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + XPTable.Models.DataSourceColumnBinder dataSourceColumnBinder1 = new XPTable.Models.DataSourceColumnBinder(); + XPTable.Renderers.DragDropRenderer dragDropRenderer1 = new XPTable.Renderers.DragDropRenderer(); + this.table1 = new XPTable.Models.Table(); + this.comboBox1 = new System.Windows.Forms.ComboBox(); + this.label1 = new System.Windows.Forms.Label(); + ((System.ComponentModel.ISupportInitialize)(this.table1)).BeginInit(); + this.SuspendLayout(); + // + // table1 + // + this.table1.BorderColor = System.Drawing.Color.Black; + this.table1.DataMember = null; + this.table1.DataSourceColumnBinder = dataSourceColumnBinder1; + dragDropRenderer1.ForeColor = System.Drawing.Color.Red; + this.table1.DragDropRenderer = dragDropRenderer1; + this.table1.GridLinesContrainedToData = false; + this.table1.HeaderFont = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.table1.Location = new System.Drawing.Point(3, 32); + this.table1.MultiSelect = true; + this.table1.Name = "table1"; + this.table1.Size = new System.Drawing.Size(951, 594); + this.table1.TabIndex = 1; + this.table1.Text = "table1"; + this.table1.UnfocusedBorderColor = System.Drawing.Color.Black; + // + // comboBox1 + // + this.comboBox1.FormattingEnabled = true; + this.comboBox1.Items.AddRange(new object[] { + "NPC", + "Auto market"}); + this.comboBox1.Location = new System.Drawing.Point(87, 6); + this.comboBox1.Name = "comboBox1"; + this.comboBox1.Size = new System.Drawing.Size(168, 21); + this.comboBox1.TabIndex = 3; + this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(35, 9); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(46, 13); + this.label1.TabIndex = 4; + this.label1.Text = "??????:"; + // + // OverviewMarketUc + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.label1); + this.Controls.Add(this.comboBox1); + this.Controls.Add(this.table1); + this.Name = "OverviewMarketUc"; + this.Size = new System.Drawing.Size(957, 629); + ((System.ComponentModel.ISupportInitialize)(this.table1)).EndInit(); + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private XPTable.Models.Table table1; + private System.Windows.Forms.ComboBox comboBox1; + private System.Windows.Forms.Label label1; + } +} diff --git a/TravBotSharp/Views/OverviewMarketUc.cs b/TravBotSharp/Views/OverviewMarketUc.cs new file mode 100644 index 000000000..820fa9553 --- /dev/null +++ b/TravBotSharp/Views/OverviewMarketUc.cs @@ -0,0 +1,429 @@ +using System; +using System.Linq; +using System.Windows.Forms; + +using TbsCore.Models.AccModels; +using TravBotSharp.Interfaces; +using TravBotSharp.Forms; +using XPTable.Models; +using XPTable.Events; + +namespace TravBotSharp.Views +{ + public partial class OverviewMarketUc : TbsBaseUc, ITbsUc + { + private enum TypeModel + { + NPC = 0, + AUTOMARKET, + } + + private TableModel[] tableModels = new TableModel[2]; + private ColumnModel[] columnModels = new ColumnModel[2]; + private TypeModel currentType; + + public OverviewMarketUc() + { + InitializeComponent(); + currentType = TypeModel.NPC; + foreach (int i in Enum.GetValues(typeof(TypeModel))) + { + tableModels[i] = new TableModel(); + columnModels[i] = new ColumnModel(); + } + + table1.CellButtonClicked += cellButton_Click; + table1.CellPropertyChanged += cell_PropertyChanged; + } + + public void UpdateUc() + { + var acc = GetSelectedAcc(); + if (acc.Villages.Count == 0) return; + + table1.ColumnModel = columnModels[(int)currentType]; + table1.ColumnModel.Columns.Clear(); + + table1.TableModel = tableModels[(int)currentType]; + table1.TableModel.Rows.Clear(); + + switch (currentType) + { + case TypeModel.NPC: + InitNPC(); + foreach (var vill in acc.Villages) + { + var r = new Row(); + r.Cells.Add(new Cell(vill.Id) + { + Tag = currentType + }); //vill id + r.Cells.Add(new Cell(vill.Name)); //vill name + + r.Cells.Add(new Cell("", vill.Market.Npc.Enabled)); //Auto NPC + r.Cells.Add(new Cell(vill.Market.Npc.ResourcesRatio.Wood)); //Wood ratio + r.Cells.Add(new Cell(vill.Market.Npc.ResourcesRatio.Clay)); //Clay ratio + r.Cells.Add(new Cell(vill.Market.Npc.ResourcesRatio.Iron)); //Iron ratio + r.Cells.Add(new Cell(vill.Market.Npc.ResourcesRatio.Crop)); //Crop ratio + r.Cells.Add(new Cell("", vill.Market.Npc.NpcIfOverflow)); // Ignore Overflow + table1.TableModel.Rows.Add(r); + } + break; + + case TypeModel.AUTOMARKET: + InitAutoMarket(); + foreach (var vill in acc.Villages) + { + var r = new Row(); + r.Cells.Add(new Cell(vill.Id) + { + Tag = currentType + }); //vill id + r.Cells.Add(new Cell(vill.Name)); //vill name + + r.Cells.Add(new Cell("", vill.Market.AutoMarket.SendToMain.Enabled)); //send to main + r.Cells.Add(new Cell("Resource")); // amount + r.Cells.Add(new Cell("Condition")); // condition + r.Cells.Add(new Cell("", vill.Market.AutoMarket.SendToNeed.Enabled)); // send to need + r.Cells.Add(new Cell("Resource")); // amount + r.Cells.Add(new Cell("Condition")); // condition + r.Cells.Add(new Cell("", vill.Market.AutoMarket.NeedWhenBuild)); + r.Cells.Add(new Cell("", vill.Market.AutoMarket.NeedWhenTrain)); + r.Cells.Add(new Cell("", vill.Market.AutoMarket.NeedWhenOther)); + table1.TableModel.Rows.Add(r); + } + break; + } + } + + #region Initialize column model + + private void InitNPC() + { + var columnmodel = table1.ColumnModel; + + //VillageId + NumberColumn villId = new NumberColumn + { + Editable = false, + Text = "Id", + ToolTipText = "Village Id", + Width = 40 + }; + columnmodel.Columns.Add(villId); + + //Village name + TextColumn vill = new TextColumn + { + Editable = false, + Text = "Village", + ToolTipText = "Village name", + Width = 120 + }; + columnmodel.Columns.Add(vill); + + //Auto NPC + CheckBoxColumn autoNPC = new CheckBoxColumn + { + Text = "NPC", + Width = 40, + ToolTipText = "Auto NPC Crop to other resource", + }; + columnmodel.Columns.Add(autoNPC); + + NumberColumn woodRatio = new NumberColumn + { + Text = "Wood", + Width = 50, + ToolTipText = "Wood ratio", + Maximum = long.MaxValue + }; + + columnmodel.Columns.Add(woodRatio); + + NumberColumn clayRatio = new NumberColumn + { + Text = "Clay", + Width = 50, + ToolTipText = "Clay ratio", + Maximum = long.MaxValue + }; + + columnmodel.Columns.Add(clayRatio); + + NumberColumn ironRatio = new NumberColumn + { + Text = "Iron", + Width = 50, + ToolTipText = "Iron ratio", + Maximum = long.MaxValue + }; + + columnmodel.Columns.Add(ironRatio); + + NumberColumn cropRatio = new NumberColumn + { + Text = "Crop", + Width = 50, + ToolTipText = "Crop ratio", + Maximum = long.MaxValue + }; + + columnmodel.Columns.Add(cropRatio); + + CheckBoxColumn overflow = new CheckBoxColumn + { + Text = "Overflow ignore", + Width = 110, + ToolTipText = "NPC even if overflow" + }; + + columnmodel.Columns.Add(overflow); + } + + private void InitAutoMarket() + { + var columnmodel = table1.ColumnModel; + //VillageId + NumberColumn villId = new NumberColumn + { + Editable = false, + Text = "Id", + ToolTipText = "Village Id", + Width = 40 + }; + columnmodel.Columns.Add(villId); + + //Village name + TextColumn vill = new TextColumn + { + Editable = false, + Text = "Village", + ToolTipText = "Village name", + Width = 120 + }; + columnmodel.Columns.Add(vill); + + //Send to main + CheckBoxColumn sendToMain = new CheckBoxColumn + { + Text = "Send to main", + Width = 90, + ToolTipText = "Auto send to main" + }; + columnmodel.Columns.Add(sendToMain); + + //Send to main amount + ButtonColumn sendToMainAmount = new ButtonColumn + { + Text = "resources", + Width = 70, + }; + columnmodel.Columns.Add(sendToMainAmount); + + //Send to main condition + ButtonColumn sendToMainCondition = new ButtonColumn + { + Text = "when above", + Width = 90, + }; + columnmodel.Columns.Add(sendToMainCondition); + + //Send to need + CheckBoxColumn sendToNeed = new CheckBoxColumn + { + Text = "Send to need", + Width = 90, + ToolTipText = "Auto send to need" + }; + columnmodel.Columns.Add(sendToNeed); + + //Send to need amount + ButtonColumn sendToNeedAmount = new ButtonColumn + { + Text = "resources", + Width = 70, + }; + columnmodel.Columns.Add(sendToNeedAmount); + + //Send to need condition + ButtonColumn sendToNeedCondition = new ButtonColumn + { + Text = "when above", + Width = 90, + }; + columnmodel.Columns.Add(sendToNeedCondition); + + //Need when build building + CheckBoxColumn needWhenBuild = new CheckBoxColumn + { + Text = "Building", + Width = 70, + }; + columnmodel.Columns.Add(needWhenBuild); + + //Need when train troop + CheckBoxColumn needWhenTrain = new CheckBoxColumn + { + Text = "Training", + Width = 70, + }; + columnmodel.Columns.Add(needWhenTrain); + + //Need when other + CheckBoxColumn needWhenOther = new CheckBoxColumn + { + Text = "Other", + Width = 70, + }; + columnmodel.Columns.Add(needWhenOther); + } + + #endregion Initialize column model + + private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) + { + currentType = (TypeModel)comboBox1.SelectedIndex; + UpdateUc(); + } + + private void cellButton_Click(object sender, CellButtonEventArgs e) + { + var row = table1.TableModel.Rows[e.Row]; + var firstCell = row.Cells[0]; + var idVillage = firstCell.Data as int?; + var acc = GetSelectedAcc(); + var vill = acc.Villages.FirstOrDefault(x => x.Id == idVillage); + var type = firstCell.Tag as TypeModel?; + + switch (type) + { + case TypeModel.NPC: + break; + + case TypeModel.AUTOMARKET: + switch (e.Column) + { + case 3: + using (var form = new ResourceSelector(vill.Market.AutoMarket.SendToMain.Amount)) + { + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + vill.Market.AutoMarket.SendToMain.Amount = form.Resources; + } + } + break; + + case 4: + using (var form = new ResourceSelector(vill.Market.AutoMarket.SendToMain.Condition)) + { + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + vill.Market.AutoMarket.SendToMain.Condition = form.Resources; + } + } + break; + + case 6: + using (var form = new ResourceSelector(vill.Market.AutoMarket.SendToNeed.Amount)) + { + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + vill.Market.AutoMarket.SendToNeed.Amount = form.Resources; + } + } + break; + + case 7: + using (var form = new ResourceSelector(vill.Market.AutoMarket.SendToNeed.Condition)) + { + var result = form.ShowDialog(); + if (result == DialogResult.OK) + { + vill.Market.AutoMarket.SendToNeed.Condition = form.Resources; + } + } + break; + } + + break; + + default: + break; + } + } + + private void cell_PropertyChanged(object sender, CellEventArgs e) + { + var row = table1.TableModel.Rows[e.Row]; + var firstCell = row.Cells[0]; + var idVillage = firstCell.Data as int?; + var acc = GetSelectedAcc(); + var vill = acc.Villages.FirstOrDefault(x => x.Id == idVillage); + var type = firstCell.Tag as TypeModel?; + + switch (type) + { + case TypeModel.NPC: + switch (e.Column) + { + case 2: + vill.Market.Npc.Enabled = e.Cell.Checked; + break; + + case 3: + vill.Market.Npc.ResourcesRatio.Wood = Convert.ToInt64(e.Cell.Data); + break; + + case 4: + vill.Market.Npc.ResourcesRatio.Clay = Convert.ToInt64(e.Cell.Data); + break; + + case 5: + vill.Market.Npc.ResourcesRatio.Iron = Convert.ToInt64(e.Cell.Data); + break; + + case 6: + vill.Market.Npc.ResourcesRatio.Crop = Convert.ToInt64(e.Cell.Data); + break; + + case 7: + vill.Market.Npc.NpcIfOverflow = e.Cell.Checked; + break; + } + break; + + case TypeModel.AUTOMARKET: + switch (e.Column) + { + case 2: + vill.Market.AutoMarket.SendToMain.Enabled = e.Cell.Checked; + break; + + case 5: + vill.Market.AutoMarket.SendToNeed.Enabled = e.Cell.Checked; + break; + + case 8: + vill.Market.AutoMarket.NeedWhenBuild = e.Cell.Checked; + break; + + case 9: + vill.Market.AutoMarket.NeedWhenTrain = e.Cell.Checked; + break; + + case 10: + vill.Market.AutoMarket.NeedWhenOther = e.Cell.Checked; + break; + } + break; + + default: + break; + } + } + } +} \ No newline at end of file diff --git a/TravBotSharp/Views/OverviewMarketUc.resx b/TravBotSharp/Views/OverviewMarketUc.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/TravBotSharp/Views/OverviewMarketUc.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/TravBotSharp/Views/OverviewUc.cs b/TravBotSharp/Views/OverviewUc.cs index 0a9e4fae7..6ded530e9 100644 --- a/TravBotSharp/Views/OverviewUc.cs +++ b/TravBotSharp/Views/OverviewUc.cs @@ -226,17 +226,42 @@ private void button1_Click(object sender, EventArgs e) column++; vill.Settings.Donate = (DonateEnum)Enum.Parse(typeof(DonateEnum), cells[column].Text); - if (vill.Expansion.Celebrations != CelebrationEnum.None && acc.Tasks != null) AccountHelper.ReStartCelebration(acc, vill); - } - //Change name of village/s - if (0 < changeVillNames.Count && acc.Tasks != null) - { - acc.Tasks.Add( - new ChangeVillageName() - { - ExecuteAt = DateTime.Now, - ChangeList = changeVillNames - }, true); + var celeb = (CelebrationEnum)Enum.Parse(typeof(CelebrationEnum), cells[column].Text); + if (vill.Expansion.Celebrations != celeb) + { + vill.Expansion.Celebrations = celeb; + switch (celeb) + { + case CelebrationEnum.None: + { + acc.Tasks?.Remove(typeof(Celebration), vill); + break; + } + default: + { + var task = acc.Tasks?.FindTask(typeof(Celebration), vill); + if (task == null) + { + acc.Tasks?.Add(new Celebration() + { + ExecuteAt = DateTime.Now, + Vill = vill, + }, true, vill); + } + break; + } + } + } + //Change name of village/s + if (0 < changeVillNames.Count && acc.Tasks != null) + { + acc.Tasks.Add( + new ChangeVillageName() + { + ExecuteAt = DateTime.Now, + ChangeList = changeVillNames + }, true); + } } } diff --git a/TravBotSharp/Views/VillageViews/BuildUc.cs b/TravBotSharp/Views/VillageViews/BuildUc.cs index b1faa92b0..202bb5d26 100644 --- a/TravBotSharp/Views/VillageViews/BuildUc.cs +++ b/TravBotSharp/Views/VillageViews/BuildUc.cs @@ -501,15 +501,12 @@ private void button2_Click_1(object sender, EventArgs e) var acc = GetSelectedAcc(); var vill = GetSelectedVillage(acc); - acc.Tasks.Add(new UpdateDorf1() + acc.Tasks.Add(new UpdateVillage() { Vill = vill, - NextExecute = DateTime.Now - }); - acc.Tasks.Add(new UpdateDorf2() - { - Vill = vill, - NextExecute = DateTime.Now + NextExecute = DateTime.Now, + NewVillage = false, + Dorf2 = true, }); } } diff --git a/TravBotSharp/Views/VillageViews/MarketUc.Designer.cs b/TravBotSharp/Views/VillageViews/MarketUc.Designer.cs index 2ebdb9ecb..431f8ddd8 100644 --- a/TravBotSharp/Views/VillageViews/MarketUc.Designer.cs +++ b/TravBotSharp/Views/VillageViews/MarketUc.Designer.cs @@ -28,742 +28,656 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.transitResEnabled = new System.Windows.Forms.CheckBox(); - this.TransitArrival = new System.Windows.Forms.Label(); - this.LastTransit = new System.Windows.Forms.Label(); - this.label30 = new System.Windows.Forms.Label(); - this.label29 = new System.Windows.Forms.Label(); - this.label25 = new System.Windows.Forms.Label(); - this.label26 = new System.Windows.Forms.Label(); - this.label27 = new System.Windows.Forms.Label(); - this.label28 = new System.Windows.Forms.Label(); - this.label24 = new System.Windows.Forms.Label(); - this.label23 = new System.Windows.Forms.Label(); - this.label22 = new System.Windows.Forms.Label(); - this.FillLimitCrop = new System.Windows.Forms.NumericUpDown(); - this.FillLimitIron = new System.Windows.Forms.NumericUpDown(); - this.FillLimitClay = new System.Windows.Forms.NumericUpDown(); - this.FillLimitWood = new System.Windows.Forms.NumericUpDown(); - this.TargetLimitCrop = new System.Windows.Forms.NumericUpDown(); - this.TargetLimitIron = new System.Windows.Forms.NumericUpDown(); - this.TargetLimitClay = new System.Windows.Forms.NumericUpDown(); - this.TargetLimitWood = new System.Windows.Forms.NumericUpDown(); - this.label21 = new System.Windows.Forms.Label(); - this.label20 = new System.Windows.Forms.Label(); - this.label19 = new System.Windows.Forms.Label(); - this.label18 = new System.Windows.Forms.Label(); + TbsCore.Models.MapModels.Coordinates coordinates1 = new TbsCore.Models.MapModels.Coordinates(); + this.panel1 = new System.Windows.Forms.Panel(); + this.groupBox1 = new System.Windows.Forms.GroupBox(); + this.VillageComboBox = new System.Windows.Forms.ComboBox(); + this.coordinatesUc1 = new TravBotSharp.UserControls.CoordinatesUc(); + this.radioButton2 = new System.Windows.Forms.RadioButton(); + this.radioButton1 = new System.Windows.Forms.RadioButton(); this.label1 = new System.Windows.Forms.Label(); - this.npcEnabled = new System.Windows.Forms.CheckBox(); - this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.panel3 = new System.Windows.Forms.Panel(); + this.label6 = new System.Windows.Forms.Label(); + this.label5 = new System.Windows.Forms.Label(); this.numericUpDown2 = new System.Windows.Forms.NumericUpDown(); - this.numericUpDown3 = new System.Windows.Forms.NumericUpDown(); - this.numericUpDown4 = new System.Windows.Forms.NumericUpDown(); - this.label2 = new System.Windows.Forms.Label(); - this.label3 = new System.Windows.Forms.Label(); + this.checkBox1 = new System.Windows.Forms.CheckBox(); this.label4 = new System.Windows.Forms.Label(); - this.label5 = new System.Windows.Forms.Label(); - this.label6 = new System.Windows.Forms.Label(); - this.overflowProtection = new System.Windows.Forms.CheckBox(); - this.label7 = new System.Windows.Forms.Label(); - this.label8 = new System.Windows.Forms.Label(); - this.label9 = new System.Windows.Forms.Label(); - this.label10 = new System.Windows.Forms.Label(); + this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); + this.label3 = new System.Windows.Forms.Label(); + this.button5 = new System.Windows.Forms.Button(); + this.button4 = new System.Windows.Forms.Button(); + this.button3 = new System.Windows.Forms.Button(); this.label11 = new System.Windows.Forms.Label(); - this.cropSend = new System.Windows.Forms.NumericUpDown(); - this.ironSend = new System.Windows.Forms.NumericUpDown(); - this.claySend = new System.Windows.Forms.NumericUpDown(); - this.woodSend = new System.Windows.Forms.NumericUpDown(); - this.label12 = new System.Windows.Forms.Label(); - this.label13 = new System.Windows.Forms.Label(); - this.label14 = new System.Windows.Forms.Label(); + this.panel4 = new System.Windows.Forms.Panel(); + this.label19 = new System.Windows.Forms.Label(); this.label15 = new System.Windows.Forms.Label(); + this.label14 = new System.Windows.Forms.Label(); + this.numericUpDown6 = new System.Windows.Forms.NumericUpDown(); this.label16 = new System.Windows.Forms.Label(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitCrop)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitIron)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitClay)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitWood)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitCrop)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitIron)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitClay)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitWood)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.label18 = new System.Windows.Forms.Label(); + this.numericUpDown7 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown9 = new System.Windows.Forms.NumericUpDown(); + this.numericUpDown8 = new System.Windows.Forms.NumericUpDown(); + this.label17 = new System.Windows.Forms.Label(); + this.button1 = new System.Windows.Forms.Button(); + this.panel5 = new System.Windows.Forms.Panel(); + this.button7 = new System.Windows.Forms.Button(); + this.richTextBox1 = new System.Windows.Forms.RichTextBox(); + this.MerchantInfo = new System.Windows.Forms.Label(); + this.button2 = new System.Windows.Forms.Button(); + this.label20 = new System.Windows.Forms.Label(); + this.routeTradeList = new System.Windows.Forms.ListView(); + this.transitIdHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitLocationHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitWoodHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitClayHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitIronHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitCropHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitTimeHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitLastHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.transitActiveHeader = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.panel2 = new System.Windows.Forms.Panel(); + this.label2 = new System.Windows.Forms.Label(); + this.panel1.SuspendLayout(); + this.groupBox1.SuspendLayout(); + this.panel3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.cropSend)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.ironSend)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.claySend)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.woodSend)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); + this.panel4.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown7)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown9)).BeginInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown8)).BeginInit(); + this.panel5.SuspendLayout(); + this.panel2.SuspendLayout(); this.SuspendLayout(); // - // transitResEnabled - // - this.transitResEnabled.AutoSize = true; - this.transitResEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.transitResEnabled.Location = new System.Drawing.Point(312, 15); - this.transitResEnabled.Margin = new System.Windows.Forms.Padding(4); - this.transitResEnabled.Name = "transitResEnabled"; - this.transitResEnabled.Size = new System.Drawing.Size(78, 20); - this.transitResEnabled.TabIndex = 51; - this.transitResEnabled.Text = "Enabled"; - this.transitResEnabled.UseVisualStyleBackColor = true; - this.transitResEnabled.CheckedChanged += new System.EventHandler(this.transitResEnabled_CheckedChanged); - // - // TransitArrival - // - this.TransitArrival.AutoSize = true; - this.TransitArrival.Location = new System.Drawing.Point(159, 302); - this.TransitArrival.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.TransitArrival.Name = "TransitArrival"; - this.TransitArrival.Size = new System.Drawing.Size(11, 16); - this.TransitArrival.TabIndex = 50; - this.TransitArrival.Text = " "; - // - // LastTransit - // - this.LastTransit.AutoSize = true; - this.LastTransit.Location = new System.Drawing.Point(136, 262); - this.LastTransit.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.LastTransit.Name = "LastTransit"; - this.LastTransit.Size = new System.Drawing.Size(11, 16); - this.LastTransit.TabIndex = 49; - this.LastTransit.Text = " "; - // - // label30 - // - this.label30.AutoSize = true; - this.label30.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label30.Location = new System.Drawing.Point(11, 295); - this.label30.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label30.Name = "label30"; - this.label30.Size = new System.Drawing.Size(102, 20); - this.label30.TabIndex = 48; - this.label30.Text = "Transit arrival"; - // - // label29 - // - this.label29.AutoSize = true; - this.label29.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label29.Location = new System.Drawing.Point(11, 256); - this.label29.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label29.Name = "label29"; - this.label29.Size = new System.Drawing.Size(88, 20); - this.label29.TabIndex = 47; - this.label29.Text = "Last transit"; - // - // label25 - // - this.label25.AutoSize = true; - this.label25.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label25.Location = new System.Drawing.Point(356, 181); - this.label25.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label25.Name = "label25"; - this.label25.Size = new System.Drawing.Size(37, 16); - this.label25.TabIndex = 46; - this.label25.Text = "Crop"; - // - // label26 - // - this.label26.AutoSize = true; - this.label26.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label26.Location = new System.Drawing.Point(356, 117); - this.label26.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label26.Name = "label26"; - this.label26.Size = new System.Drawing.Size(35, 16); - this.label26.TabIndex = 45; - this.label26.Text = "Clay"; - // - // label27 - // - this.label27.AutoSize = true; - this.label27.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label27.Location = new System.Drawing.Point(359, 149); - this.label27.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label27.Name = "label27"; - this.label27.Size = new System.Drawing.Size(30, 16); - this.label27.TabIndex = 44; - this.label27.Text = "Iron"; - // - // label28 - // - this.label28.AutoSize = true; - this.label28.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label28.Location = new System.Drawing.Point(356, 85); - this.label28.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label28.Name = "label28"; - this.label28.Size = new System.Drawing.Size(45, 16); - this.label28.TabIndex = 43; - this.label28.Text = "Wood"; - // - // label24 - // - this.label24.AutoSize = true; - this.label24.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label24.Location = new System.Drawing.Point(133, 181); - this.label24.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label24.Name = "label24"; - this.label24.Size = new System.Drawing.Size(52, 16); - this.label24.TabIndex = 42; - this.label24.Text = "% Crop"; - // - // label23 - // - this.label23.AutoSize = true; - this.label23.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label23.Location = new System.Drawing.Point(212, 54); - this.label23.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label23.Name = "label23"; - this.label23.Size = new System.Drawing.Size(59, 20); - this.label23.TabIndex = 41; - this.label23.Text = "Fill limit"; - // - // label22 - // - this.label22.AutoSize = true; - this.label22.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label22.Location = new System.Drawing.Point(15, 57); - this.label22.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label22.Name = "label22"; - this.label22.Size = new System.Drawing.Size(86, 20); - this.label22.TabIndex = 40; - this.label22.Text = "Target limit"; - // - // FillLimitCrop - // - this.FillLimitCrop.Location = new System.Drawing.Point(217, 178); - this.FillLimitCrop.Margin = new System.Windows.Forms.Padding(4); - this.FillLimitCrop.Maximum = new decimal(new int[] { - 1000000, - 0, - 0, - 0}); - this.FillLimitCrop.Name = "FillLimitCrop"; - this.FillLimitCrop.Size = new System.Drawing.Size(131, 22); - this.FillLimitCrop.TabIndex = 39; - this.FillLimitCrop.ValueChanged += new System.EventHandler(this.FillLimitCrop_ValueChanged); + // panel1 + // + this.panel1.BackColor = System.Drawing.SystemColors.ControlLight; + this.panel1.Controls.Add(this.groupBox1); + this.panel1.Controls.Add(this.label1); + this.panel1.Location = new System.Drawing.Point(3, 3); + this.panel1.Name = "panel1"; + this.panel1.Size = new System.Drawing.Size(224, 159); + this.panel1.TabIndex = 187; + // + // groupBox1 + // + this.groupBox1.BackColor = System.Drawing.SystemColors.Control; + this.groupBox1.Controls.Add(this.VillageComboBox); + this.groupBox1.Controls.Add(this.coordinatesUc1); + this.groupBox1.Controls.Add(this.radioButton2); + this.groupBox1.Controls.Add(this.radioButton1); + this.groupBox1.Location = new System.Drawing.Point(12, 27); + this.groupBox1.Name = "groupBox1"; + this.groupBox1.Size = new System.Drawing.Size(206, 126); + this.groupBox1.TabIndex = 189; + this.groupBox1.TabStop = false; + // + // VillageComboBox + // + this.VillageComboBox.FormattingEnabled = true; + this.VillageComboBox.Location = new System.Drawing.Point(68, 10); + this.VillageComboBox.Name = "VillageComboBox"; + this.VillageComboBox.Size = new System.Drawing.Size(130, 21); + this.VillageComboBox.TabIndex = 190; + // + // coordinatesUc1 + // + this.coordinatesUc1.BackColor = System.Drawing.SystemColors.ControlDark; + coordinates1.x = 0; + coordinates1.y = 0; + this.coordinatesUc1.Coords = coordinates1; + this.coordinatesUc1.Location = new System.Drawing.Point(65, 62); + this.coordinatesUc1.Name = "coordinatesUc1"; + this.coordinatesUc1.Size = new System.Drawing.Size(133, 56); + this.coordinatesUc1.TabIndex = 190; + // + // radioButton2 + // + this.radioButton2.AutoSize = true; + this.radioButton2.Location = new System.Drawing.Point(6, 65); + this.radioButton2.Name = "radioButton2"; + this.radioButton2.Size = new System.Drawing.Size(53, 17); + this.radioButton2.TabIndex = 188; + this.radioButton2.Text = "Coord"; + this.radioButton2.UseVisualStyleBackColor = true; + this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged); + // + // radioButton1 + // + this.radioButton1.AutoSize = true; + this.radioButton1.Checked = true; + this.radioButton1.Location = new System.Drawing.Point(6, 12); + this.radioButton1.Name = "radioButton1"; + this.radioButton1.Size = new System.Drawing.Size(56, 17); + this.radioButton1.TabIndex = 187; + this.radioButton1.TabStop = true; + this.radioButton1.Text = "Village"; + this.radioButton1.UseVisualStyleBackColor = true; + this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged); // - // FillLimitIron + // label1 // - this.FillLimitIron.Location = new System.Drawing.Point(217, 146); - this.FillLimitIron.Margin = new System.Windows.Forms.Padding(4); - this.FillLimitIron.Maximum = new decimal(new int[] { - 1000000, - 0, - 0, - 0}); - this.FillLimitIron.Name = "FillLimitIron"; - this.FillLimitIron.Size = new System.Drawing.Size(131, 22); - this.FillLimitIron.TabIndex = 38; - this.FillLimitIron.ValueChanged += new System.EventHandler(this.FillLimitIron_ValueChanged); + this.label1.AutoSize = true; + this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label1.Location = new System.Drawing.Point(9, 8); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(105, 16); + this.label1.TabIndex = 186; + this.label1.Text = "Target village"; + // + // panel3 + // + this.panel3.BackColor = System.Drawing.SystemColors.ControlLight; + this.panel3.Controls.Add(this.label6); + this.panel3.Controls.Add(this.label5); + this.panel3.Controls.Add(this.numericUpDown2); + this.panel3.Controls.Add(this.checkBox1); + this.panel3.Controls.Add(this.label4); + this.panel3.Controls.Add(this.numericUpDown1); + this.panel3.Controls.Add(this.label3); + this.panel3.Controls.Add(this.button5); + this.panel3.Controls.Add(this.button4); + this.panel3.Controls.Add(this.button3); + this.panel3.Controls.Add(this.label11); + this.panel3.Location = new System.Drawing.Point(451, 3); + this.panel3.Name = "panel3"; + this.panel3.Size = new System.Drawing.Size(212, 322); + this.panel3.TabIndex = 191; + // + // label6 + // + this.label6.AutoSize = true; + this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label6.Location = new System.Drawing.Point(83, 65); + this.label6.Name = "label6"; + this.label6.Size = new System.Drawing.Size(15, 16); + this.label6.TabIndex = 204; + this.label6.Text = "±"; // - // FillLimitClay + // label5 + // + this.label5.AutoSize = true; + this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label5.Location = new System.Drawing.Point(144, 65); + this.label5.Name = "label5"; + this.label5.Size = new System.Drawing.Size(36, 16); + this.label5.TabIndex = 203; + this.label5.Text = "mins"; // - this.FillLimitClay.Location = new System.Drawing.Point(217, 114); - this.FillLimitClay.Margin = new System.Windows.Forms.Padding(4); - this.FillLimitClay.Maximum = new decimal(new int[] { - 1000000, + // numericUpDown2 + // + this.numericUpDown2.Location = new System.Drawing.Point(97, 64); + this.numericUpDown2.Name = "numericUpDown2"; + this.numericUpDown2.Size = new System.Drawing.Size(45, 20); + this.numericUpDown2.TabIndex = 202; + // + // checkBox1 + // + this.checkBox1.AutoSize = true; + this.checkBox1.Checked = true; + this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked; + this.checkBox1.Location = new System.Drawing.Point(18, 92); + this.checkBox1.Name = "checkBox1"; + this.checkBox1.Size = new System.Drawing.Size(56, 17); + this.checkBox1.TabIndex = 201; + this.checkBox1.Text = "Active"; + this.checkBox1.UseVisualStyleBackColor = true; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label4.Location = new System.Drawing.Point(144, 39); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(36, 16); + this.label4.TabIndex = 200; + this.label4.Text = "mins"; + // + // numericUpDown1 + // + this.numericUpDown1.Location = new System.Drawing.Point(97, 38); + this.numericUpDown1.Minimum = new decimal(new int[] { + 1, 0, 0, 0}); - this.FillLimitClay.Name = "FillLimitClay"; - this.FillLimitClay.Size = new System.Drawing.Size(131, 22); - this.FillLimitClay.TabIndex = 37; - this.FillLimitClay.ValueChanged += new System.EventHandler(this.FillLimitClay_ValueChanged); - // - // FillLimitWood - // - this.FillLimitWood.Location = new System.Drawing.Point(217, 82); - this.FillLimitWood.Margin = new System.Windows.Forms.Padding(4); - this.FillLimitWood.Maximum = new decimal(new int[] { - 1000000, + this.numericUpDown1.Name = "numericUpDown1"; + this.numericUpDown1.Size = new System.Drawing.Size(45, 20); + this.numericUpDown1.TabIndex = 195; + this.numericUpDown1.Value = new decimal(new int[] { + 1, 0, 0, 0}); - this.FillLimitWood.Name = "FillLimitWood"; - this.FillLimitWood.Size = new System.Drawing.Size(131, 22); - this.FillLimitWood.TabIndex = 36; - this.FillLimitWood.ValueChanged += new System.EventHandler(this.FillLimitWood_ValueChanged); - // - // TargetLimitCrop - // - this.TargetLimitCrop.Location = new System.Drawing.Point(20, 181); - this.TargetLimitCrop.Margin = new System.Windows.Forms.Padding(4); - this.TargetLimitCrop.Name = "TargetLimitCrop"; - this.TargetLimitCrop.Size = new System.Drawing.Size(109, 22); - this.TargetLimitCrop.TabIndex = 35; - this.TargetLimitCrop.ValueChanged += new System.EventHandler(this.TargetLimitCrop_ValueChanged); - // - // TargetLimitIron - // - this.TargetLimitIron.Location = new System.Drawing.Point(20, 149); - this.TargetLimitIron.Margin = new System.Windows.Forms.Padding(4); - this.TargetLimitIron.Name = "TargetLimitIron"; - this.TargetLimitIron.Size = new System.Drawing.Size(109, 22); - this.TargetLimitIron.TabIndex = 34; - this.TargetLimitIron.ValueChanged += new System.EventHandler(this.TargetLimitIron_ValueChanged); - // - // TargetLimitClay - // - this.TargetLimitClay.Location = new System.Drawing.Point(20, 117); - this.TargetLimitClay.Margin = new System.Windows.Forms.Padding(4); - this.TargetLimitClay.Name = "TargetLimitClay"; - this.TargetLimitClay.Size = new System.Drawing.Size(109, 22); - this.TargetLimitClay.TabIndex = 33; - this.TargetLimitClay.ValueChanged += new System.EventHandler(this.TargetLimitClay_ValueChanged); - // - // TargetLimitWood - // - this.TargetLimitWood.Location = new System.Drawing.Point(20, 85); - this.TargetLimitWood.Margin = new System.Windows.Forms.Padding(4); - this.TargetLimitWood.Name = "TargetLimitWood"; - this.TargetLimitWood.Size = new System.Drawing.Size(109, 22); - this.TargetLimitWood.TabIndex = 32; - this.TargetLimitWood.ValueChanged += new System.EventHandler(this.TargetLimitWood_ValueChanged); - // - // label21 - // - this.label21.AutoSize = true; - this.label21.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label21.Location = new System.Drawing.Point(133, 117); - this.label21.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label21.Name = "label21"; - this.label21.Size = new System.Drawing.Size(50, 16); - this.label21.TabIndex = 31; - this.label21.Text = "% Clay"; // - // label20 + // label3 // - this.label20.AutoSize = true; - this.label20.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label20.Location = new System.Drawing.Point(133, 149); - this.label20.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label20.Name = "label20"; - this.label20.Size = new System.Drawing.Size(45, 16); - this.label20.TabIndex = 30; - this.label20.Text = "% Iron"; + this.label3.AutoSize = true; + this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label3.Location = new System.Drawing.Point(13, 39); + this.label3.Name = "label3"; + this.label3.Size = new System.Drawing.Size(85, 16); + this.label3.TabIndex = 196; + this.label3.Text = "Repeat after "; + // + // button5 + // + this.button5.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button5.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button5.Location = new System.Drawing.Point(143, 276); + this.button5.Name = "button5"; + this.button5.Size = new System.Drawing.Size(64, 43); + this.button5.TabIndex = 198; + this.button5.Text = "Delete"; + this.button5.UseVisualStyleBackColor = false; + this.button5.Click += new System.EventHandler(this.button5_Click); + // + // button4 + // + this.button4.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button4.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button4.Location = new System.Drawing.Point(73, 276); + this.button4.Name = "button4"; + this.button4.Size = new System.Drawing.Size(64, 43); + this.button4.TabIndex = 197; + this.button4.Text = "Edit"; + this.button4.UseVisualStyleBackColor = false; + this.button4.Click += new System.EventHandler(this.button4_Click); + // + // button3 + // + this.button3.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button3.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button3.Location = new System.Drawing.Point(3, 276); + this.button3.Name = "button3"; + this.button3.Size = new System.Drawing.Size(64, 43); + this.button3.TabIndex = 196; + this.button3.Text = "Add"; + this.button3.UseVisualStyleBackColor = false; + this.button3.Click += new System.EventHandler(this.button3_Click); + // + // label11 + // + this.label11.AutoSize = true; + this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label11.Location = new System.Drawing.Point(15, 9); + this.label11.Name = "label11"; + this.label11.Size = new System.Drawing.Size(92, 16); + this.label11.TabIndex = 190; + this.label11.Text = "Transit list ?"; + // + // panel4 + // + this.panel4.BackColor = System.Drawing.SystemColors.ControlLight; + this.panel4.Controls.Add(this.label19); + this.panel4.Controls.Add(this.label15); + this.panel4.Controls.Add(this.label14); + this.panel4.Controls.Add(this.numericUpDown6); + this.panel4.Controls.Add(this.label16); + this.panel4.Controls.Add(this.label18); + this.panel4.Controls.Add(this.numericUpDown7); + this.panel4.Controls.Add(this.numericUpDown9); + this.panel4.Controls.Add(this.numericUpDown8); + this.panel4.Controls.Add(this.label17); + this.panel4.Location = new System.Drawing.Point(233, 3); + this.panel4.Name = "panel4"; + this.panel4.Size = new System.Drawing.Size(147, 159); + this.panel4.TabIndex = 191; // // label19 // this.label19.AutoSize = true; this.label19.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label19.Location = new System.Drawing.Point(133, 85); - this.label19.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label19.Location = new System.Drawing.Point(15, 137); this.label19.Name = "label19"; - this.label19.Size = new System.Drawing.Size(60, 16); - this.label19.TabIndex = 29; - this.label19.Text = "% Wood"; + this.label19.Size = new System.Drawing.Size(122, 16); + this.label19.TabIndex = 187; + this.label19.Text = "need 0 merchant(s)"; + // + // label15 + // + this.label15.AutoSize = true; + this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label15.Location = new System.Drawing.Point(13, 88); + this.label15.Name = "label15"; + this.label15.Size = new System.Drawing.Size(30, 16); + this.label15.TabIndex = 192; + this.label15.Text = "Iron"; + // + // label14 + // + this.label14.AutoSize = true; + this.label14.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label14.Location = new System.Drawing.Point(13, 8); + this.label14.Name = "label14"; + this.label14.Size = new System.Drawing.Size(75, 16); + this.label14.TabIndex = 190; + this.label14.Text = "Resource"; + // + // numericUpDown6 + // + this.numericUpDown6.Location = new System.Drawing.Point(59, 112); + this.numericUpDown6.Maximum = new decimal(new int[] { + 1, + 0, + 0, + 0}); + this.numericUpDown6.Name = "numericUpDown6"; + this.numericUpDown6.Size = new System.Drawing.Size(78, 20); + this.numericUpDown6.TabIndex = 190; + this.numericUpDown6.ValueChanged += new System.EventHandler(this.numericUpDown6_ValueChanged); + // + // label16 + // + this.label16.AutoSize = true; + this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label16.Location = new System.Drawing.Point(13, 114); + this.label16.Name = "label16"; + this.label16.Size = new System.Drawing.Size(37, 16); + this.label16.TabIndex = 194; + this.label16.Text = "Crop"; // // label18 // this.label18.AutoSize = true; - this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label18.Location = new System.Drawing.Point(15, 15); - this.label18.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label18.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label18.Location = new System.Drawing.Point(13, 63); this.label18.Name = "label18"; - this.label18.Size = new System.Drawing.Size(215, 20); - this.label18.TabIndex = 28; - this.label18.Text = "Send resources to this village"; + this.label18.Size = new System.Drawing.Size(35, 16); + this.label18.TabIndex = 193; + this.label18.Text = "Clay"; + // + // numericUpDown7 + // + this.numericUpDown7.Location = new System.Drawing.Point(59, 86); + this.numericUpDown7.Name = "numericUpDown7"; + this.numericUpDown7.Size = new System.Drawing.Size(78, 20); + this.numericUpDown7.TabIndex = 189; + this.numericUpDown7.ValueChanged += new System.EventHandler(this.numericUpDown7_ValueChanged); + // + // numericUpDown9 + // + this.numericUpDown9.Location = new System.Drawing.Point(59, 37); + this.numericUpDown9.Name = "numericUpDown9"; + this.numericUpDown9.Size = new System.Drawing.Size(78, 20); + this.numericUpDown9.TabIndex = 187; + this.numericUpDown9.ValueChanged += new System.EventHandler(this.numericUpDown9_ValueChanged); + // + // numericUpDown8 + // + this.numericUpDown8.Location = new System.Drawing.Point(59, 61); + this.numericUpDown8.Name = "numericUpDown8"; + this.numericUpDown8.Size = new System.Drawing.Size(78, 20); + this.numericUpDown8.TabIndex = 188; + this.numericUpDown8.ValueChanged += new System.EventHandler(this.numericUpDown8_ValueChanged); + // + // label17 + // + this.label17.AutoSize = true; + this.label17.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label17.Location = new System.Drawing.Point(13, 37); + this.label17.Name = "label17"; + this.label17.Size = new System.Drawing.Size(45, 16); + this.label17.TabIndex = 191; + this.label17.Text = "Wood"; + // + // button1 + // + this.button1.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button1.Location = new System.Drawing.Point(380, 3); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(70, 159); + this.button1.TabIndex = 195; + this.button1.Text = "SEND NOW"; + this.button1.UseVisualStyleBackColor = false; + this.button1.Click += new System.EventHandler(this.button1_Click); + // + // panel5 + // + this.panel5.BackColor = System.Drawing.SystemColors.ControlLight; + this.panel5.Controls.Add(this.button7); + this.panel5.Controls.Add(this.richTextBox1); + this.panel5.Controls.Add(this.MerchantInfo); + this.panel5.Controls.Add(this.button2); + this.panel5.Controls.Add(this.label20); + this.panel5.Location = new System.Drawing.Point(3, 406); + this.panel5.Name = "panel5"; + this.panel5.Size = new System.Drawing.Size(663, 68); + this.panel5.TabIndex = 191; + // + // button7 + // + this.button7.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button7.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button7.Location = new System.Drawing.Point(107, 31); + this.button7.Name = "button7"; + this.button7.Size = new System.Drawing.Size(76, 27); + this.button7.TabIndex = 200; + this.button7.Text = "NPC"; + this.button7.UseVisualStyleBackColor = false; + this.button7.Click += new System.EventHandler(this.button7_Click); + // + // richTextBox1 + // + this.richTextBox1.Location = new System.Drawing.Point(212, 10); + this.richTextBox1.Name = "richTextBox1"; + this.richTextBox1.Size = new System.Drawing.Size(448, 26); + this.richTextBox1.TabIndex = 199; + this.richTextBox1.Text = ""; + // + // MerchantInfo + // + this.MerchantInfo.AutoSize = true; + this.MerchantInfo.Location = new System.Drawing.Point(211, 39); + this.MerchantInfo.Name = "MerchantInfo"; + this.MerchantInfo.Size = new System.Drawing.Size(120, 13); + this.MerchantInfo.TabIndex = 198; + this.MerchantInfo.Text = "Merchant: 20/20 (1337)"; + // + // button2 + // + this.button2.BackColor = System.Drawing.SystemColors.ScrollBar; + this.button2.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.button2.Location = new System.Drawing.Point(18, 31); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(76, 27); + this.button2.TabIndex = 196; + this.button2.Text = "Refresh "; + this.button2.UseVisualStyleBackColor = false; // - // label1 + // label20 // - this.label1.AutoSize = true; - this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label1.Location = new System.Drawing.Point(329, 314); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(72, 31); - this.label1.TabIndex = 53; - this.label1.Text = "NPC"; - // - // npcEnabled - // - this.npcEnabled.AutoSize = true; - this.npcEnabled.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.npcEnabled.Location = new System.Drawing.Point(433, 327); - this.npcEnabled.Margin = new System.Windows.Forms.Padding(4); - this.npcEnabled.Name = "npcEnabled"; - this.npcEnabled.Size = new System.Drawing.Size(78, 20); - this.npcEnabled.TabIndex = 54; - this.npcEnabled.Text = "Enabled"; - this.npcEnabled.UseVisualStyleBackColor = true; - this.npcEnabled.CheckedChanged += new System.EventHandler(this.npcEnabled_CheckedChanged); + this.label20.AutoSize = true; + this.label20.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label20.Location = new System.Drawing.Point(15, 12); + this.label20.Name = "label20"; + this.label20.Size = new System.Drawing.Size(173, 16); + this.label20.TabIndex = 190; + this.label20.Text = "Current village resource"; // - // numericUpDown1 + // routeTradeList // - this.numericUpDown1.Location = new System.Drawing.Point(312, 480); - this.numericUpDown1.Margin = new System.Windows.Forms.Padding(4); - this.numericUpDown1.Name = "numericUpDown1"; - this.numericUpDown1.Size = new System.Drawing.Size(109, 22); - this.numericUpDown1.TabIndex = 58; - this.numericUpDown1.ValueChanged += new System.EventHandler(this.numericUpDown1_ValueChanged); + this.routeTradeList.BackColor = System.Drawing.SystemColors.MenuText; + this.routeTradeList.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { + this.transitIdHeader, + this.transitLocationHeader, + this.transitWoodHeader, + this.transitClayHeader, + this.transitIronHeader, + this.transitCropHeader, + this.transitTimeHeader, + this.transitLastHeader, + this.transitActiveHeader}); + this.routeTradeList.FullRowSelect = true; + this.routeTradeList.GridLines = true; + this.routeTradeList.HideSelection = false; + this.routeTradeList.Location = new System.Drawing.Point(3, 168); + this.routeTradeList.MultiSelect = false; + this.routeTradeList.Name = "routeTradeList"; + this.routeTradeList.Size = new System.Drawing.Size(442, 232); + this.routeTradeList.TabIndex = 192; + this.routeTradeList.UseCompatibleStateImageBehavior = false; + this.routeTradeList.View = System.Windows.Forms.View.Details; + this.routeTradeList.SelectedIndexChanged += new System.EventHandler(this.routeTradeList_SelectedIndexChanged); // - // numericUpDown2 + // transitIdHeader // - this.numericUpDown2.Location = new System.Drawing.Point(312, 448); - this.numericUpDown2.Margin = new System.Windows.Forms.Padding(4); - this.numericUpDown2.Name = "numericUpDown2"; - this.numericUpDown2.Size = new System.Drawing.Size(109, 22); - this.numericUpDown2.TabIndex = 57; - this.numericUpDown2.ValueChanged += new System.EventHandler(this.numericUpDown2_ValueChanged); + this.transitIdHeader.Text = "Id"; + this.transitIdHeader.Width = 25; // - // numericUpDown3 + // transitLocationHeader // - this.numericUpDown3.Location = new System.Drawing.Point(312, 414); - this.numericUpDown3.Margin = new System.Windows.Forms.Padding(4); - this.numericUpDown3.Name = "numericUpDown3"; - this.numericUpDown3.Size = new System.Drawing.Size(109, 22); - this.numericUpDown3.TabIndex = 56; - this.numericUpDown3.ValueChanged += new System.EventHandler(this.numericUpDown3_ValueChanged); + this.transitLocationHeader.Text = "Location"; + this.transitLocationHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // - // numericUpDown4 + // transitWoodHeader // - this.numericUpDown4.Location = new System.Drawing.Point(312, 384); - this.numericUpDown4.Margin = new System.Windows.Forms.Padding(4); - this.numericUpDown4.Name = "numericUpDown4"; - this.numericUpDown4.Size = new System.Drawing.Size(109, 22); - this.numericUpDown4.TabIndex = 55; - this.numericUpDown4.ValueChanged += new System.EventHandler(this.numericUpDown4_ValueChanged); + this.transitWoodHeader.Text = "Wood"; + this.transitWoodHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitWoodHeader.Width = 45; // - // label2 + // transitClayHeader // - this.label2.AutoSize = true; - this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label2.Location = new System.Drawing.Point(429, 485); - this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(37, 16); - this.label2.TabIndex = 62; - this.label2.Text = "Crop"; + this.transitClayHeader.Text = "Clay"; + this.transitClayHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitClayHeader.Width = 45; // - // label3 + // transitIronHeader // - this.label3.AutoSize = true; - this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label3.Location = new System.Drawing.Point(429, 421); - this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label3.Name = "label3"; - this.label3.Size = new System.Drawing.Size(35, 16); - this.label3.TabIndex = 61; - this.label3.Text = "Clay"; + this.transitIronHeader.Text = "Iron"; + this.transitIronHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitIronHeader.Width = 45; // - // label4 + // transitCropHeader // - this.label4.AutoSize = true; - this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label4.Location = new System.Drawing.Point(429, 453); - this.label4.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label4.Name = "label4"; - this.label4.Size = new System.Drawing.Size(30, 16); - this.label4.TabIndex = 60; - this.label4.Text = "Iron"; + this.transitCropHeader.Text = "Crop"; + this.transitCropHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitCropHeader.Width = 45; // - // label5 + // transitTimeHeader // - this.label5.AutoSize = true; - this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label5.Location = new System.Drawing.Point(429, 389); - this.label5.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label5.Name = "label5"; - this.label5.Size = new System.Drawing.Size(45, 16); - this.label5.TabIndex = 59; - this.label5.Text = "Wood"; - // - // label6 - // - this.label6.AutoSize = true; - this.label6.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label6.Location = new System.Drawing.Point(308, 361); - this.label6.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label6.Name = "label6"; - this.label6.Size = new System.Drawing.Size(136, 16); - this.label6.TabIndex = 63; - this.label6.Text = "Target resource ratio:"; - // - // overflowProtection - // - this.overflowProtection.AutoSize = true; - this.overflowProtection.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.overflowProtection.Location = new System.Drawing.Point(337, 516); - this.overflowProtection.Margin = new System.Windows.Forms.Padding(4); - this.overflowProtection.Name = "overflowProtection"; - this.overflowProtection.Size = new System.Drawing.Size(150, 20); - this.overflowProtection.TabIndex = 64; - this.overflowProtection.Text = "NPC even if overflow"; - this.overflowProtection.UseVisualStyleBackColor = true; - this.overflowProtection.CheckedChanged += new System.EventHandler(this.overflowProtection_CheckedChanged); - // - // label7 - // - this.label7.AutoSize = true; - this.label7.Location = new System.Drawing.Point(308, 544); - this.label7.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label7.Name = "label7"; - this.label7.Size = new System.Drawing.Size(191, 16); - this.label7.TabIndex = 65; - this.label7.Text = "If checked, bot will NPC even if "; - // - // label8 - // - this.label8.AutoSize = true; - this.label8.Location = new System.Drawing.Point(308, 560); - this.label8.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label8.Name = "label8"; - this.label8.Size = new System.Drawing.Size(222, 16); - this.label8.TabIndex = 66; - this.label8.Text = "some resource will get filled to 100%"; - // - // label9 - // - this.label9.AutoSize = true; - this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label9.Location = new System.Drawing.Point(543, 16); - this.label9.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label9.Name = "label9"; - this.label9.Size = new System.Drawing.Size(224, 20); - this.label9.TabIndex = 67; - this.label9.Text = "Send resources to main village"; - // - // label10 - // - this.label10.AutoSize = true; - this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label10.Location = new System.Drawing.Point(685, 178); - this.label10.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label10.Name = "label10"; - this.label10.Size = new System.Drawing.Size(52, 16); - this.label10.TabIndex = 76; - this.label10.Text = "% Crop"; + this.transitTimeHeader.Text = "Time"; + this.transitTimeHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; // - // label11 + // transitLastHeader // - this.label11.AutoSize = true; - this.label11.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label11.Location = new System.Drawing.Point(567, 54); - this.label11.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label11.Name = "label11"; - this.label11.Size = new System.Drawing.Size(105, 15); - this.label11.TabIndex = 75; - this.label11.Text = "Resources above:"; - // - // cropSend - // - this.cropSend.Location = new System.Drawing.Point(572, 178); - this.cropSend.Margin = new System.Windows.Forms.Padding(4); - this.cropSend.Name = "cropSend"; - this.cropSend.Size = new System.Drawing.Size(109, 22); - this.cropSend.TabIndex = 74; - this.cropSend.ValueChanged += new System.EventHandler(this.cropSend_ValueChanged); - // - // ironSend - // - this.ironSend.Location = new System.Drawing.Point(572, 146); - this.ironSend.Margin = new System.Windows.Forms.Padding(4); - this.ironSend.Name = "ironSend"; - this.ironSend.Size = new System.Drawing.Size(109, 22); - this.ironSend.TabIndex = 73; - this.ironSend.ValueChanged += new System.EventHandler(this.ironSend_ValueChanged); - // - // claySend - // - this.claySend.Location = new System.Drawing.Point(572, 114); - this.claySend.Margin = new System.Windows.Forms.Padding(4); - this.claySend.Name = "claySend"; - this.claySend.Size = new System.Drawing.Size(109, 22); - this.claySend.TabIndex = 72; - this.claySend.ValueChanged += new System.EventHandler(this.claySend_ValueChanged); - // - // woodSend - // - this.woodSend.Location = new System.Drawing.Point(572, 82); - this.woodSend.Margin = new System.Windows.Forms.Padding(4); - this.woodSend.Name = "woodSend"; - this.woodSend.Size = new System.Drawing.Size(109, 22); - this.woodSend.TabIndex = 71; - this.woodSend.ValueChanged += new System.EventHandler(this.woodSend_ValueChanged); - // - // label12 - // - this.label12.AutoSize = true; - this.label12.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label12.Location = new System.Drawing.Point(685, 114); - this.label12.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label12.Name = "label12"; - this.label12.Size = new System.Drawing.Size(50, 16); - this.label12.TabIndex = 70; - this.label12.Text = "% Clay"; - // - // label13 - // - this.label13.AutoSize = true; - this.label13.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label13.Location = new System.Drawing.Point(685, 146); - this.label13.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label13.Name = "label13"; - this.label13.Size = new System.Drawing.Size(45, 16); - this.label13.TabIndex = 69; - this.label13.Text = "% Iron"; + this.transitLastHeader.Text = "LastTransit"; + this.transitLastHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitLastHeader.Width = 70; // - // label14 + // transitActiveHeader // - this.label14.AutoSize = true; - this.label14.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label14.Location = new System.Drawing.Point(685, 82); - this.label14.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label14.Name = "label14"; - this.label14.Size = new System.Drawing.Size(60, 16); - this.label14.TabIndex = 68; - this.label14.Text = "% Wood"; + this.transitActiveHeader.Text = "Active"; + this.transitActiveHeader.TextAlign = System.Windows.Forms.HorizontalAlignment.Center; + this.transitActiveHeader.Width = 42; // - // label15 + // panel2 // - this.label15.AutoSize = true; - this.label15.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label15.Location = new System.Drawing.Point(568, 213); - this.label15.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label15.Name = "label15"; - this.label15.Size = new System.Drawing.Size(175, 15); - this.label15.TabIndex = 78; - this.label15.Text = "Will get sent to the main village"; + this.panel2.BackColor = System.Drawing.SystemColors.ControlLight; + this.panel2.Controls.Add(this.label2); + this.panel2.Location = new System.Drawing.Point(451, 331); + this.panel2.Name = "panel2"; + this.panel2.Size = new System.Drawing.Size(215, 69); + this.panel2.TabIndex = 198; // - // label16 + // label2 // - this.label16.AutoSize = true; - this.label16.Font = new System.Drawing.Font("Microsoft Sans Serif", 6.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.label16.Location = new System.Drawing.Point(568, 236); - this.label16.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); - this.label16.Name = "label16"; - this.label16.Size = new System.Drawing.Size(203, 12); - this.label16.TabIndex = 79; - this.label16.Text = "If values are above 100, limit by resources not %"; + this.label2.AutoSize = true; + this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label2.Location = new System.Drawing.Point(15, 9); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(85, 16); + this.label2.TabIndex = 190; + this.label2.Text = "Next transit"; // // MarketUc // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.label16); - this.Controls.Add(this.label15); - this.Controls.Add(this.label10); - this.Controls.Add(this.label11); - this.Controls.Add(this.cropSend); - this.Controls.Add(this.ironSend); - this.Controls.Add(this.claySend); - this.Controls.Add(this.woodSend); - this.Controls.Add(this.label12); - this.Controls.Add(this.label13); - this.Controls.Add(this.label14); - this.Controls.Add(this.label9); - this.Controls.Add(this.label8); - this.Controls.Add(this.label7); - this.Controls.Add(this.overflowProtection); - this.Controls.Add(this.label6); - this.Controls.Add(this.label2); - this.Controls.Add(this.label3); - this.Controls.Add(this.label4); - this.Controls.Add(this.label5); - this.Controls.Add(this.numericUpDown1); - this.Controls.Add(this.numericUpDown2); - this.Controls.Add(this.numericUpDown3); - this.Controls.Add(this.numericUpDown4); - this.Controls.Add(this.npcEnabled); - this.Controls.Add(this.label1); - this.Controls.Add(this.transitResEnabled); - this.Controls.Add(this.TransitArrival); - this.Controls.Add(this.LastTransit); - this.Controls.Add(this.label30); - this.Controls.Add(this.label29); - this.Controls.Add(this.label25); - this.Controls.Add(this.label26); - this.Controls.Add(this.label27); - this.Controls.Add(this.label28); - this.Controls.Add(this.label24); - this.Controls.Add(this.label23); - this.Controls.Add(this.label22); - this.Controls.Add(this.FillLimitCrop); - this.Controls.Add(this.FillLimitIron); - this.Controls.Add(this.FillLimitClay); - this.Controls.Add(this.FillLimitWood); - this.Controls.Add(this.TargetLimitCrop); - this.Controls.Add(this.TargetLimitIron); - this.Controls.Add(this.TargetLimitClay); - this.Controls.Add(this.TargetLimitWood); - this.Controls.Add(this.label21); - this.Controls.Add(this.label20); - this.Controls.Add(this.label19); - this.Controls.Add(this.label18); - this.Margin = new System.Windows.Forms.Padding(4); + this.Controls.Add(this.panel2); + this.Controls.Add(this.button1); + this.Controls.Add(this.panel5); + this.Controls.Add(this.panel4); + this.Controls.Add(this.panel3); + this.Controls.Add(this.panel1); + this.Controls.Add(this.routeTradeList); this.Name = "MarketUc"; - this.Size = new System.Drawing.Size(901, 587); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitCrop)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitIron)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitClay)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.FillLimitWood)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitCrop)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitIron)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitClay)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.TargetLimitWood)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.Size = new System.Drawing.Size(669, 477); + this.panel1.ResumeLayout(false); + this.panel1.PerformLayout(); + this.groupBox1.ResumeLayout(false); + this.groupBox1.PerformLayout(); + this.panel3.ResumeLayout(false); + this.panel3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.cropSend)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.ironSend)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.claySend)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.woodSend)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); + this.panel4.ResumeLayout(false); + this.panel4.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown6)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown7)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown9)).EndInit(); + ((System.ComponentModel.ISupportInitialize)(this.numericUpDown8)).EndInit(); + this.panel5.ResumeLayout(false); + this.panel5.PerformLayout(); + this.panel2.ResumeLayout(false); + this.panel2.PerformLayout(); this.ResumeLayout(false); - this.PerformLayout(); } #endregion - private System.Windows.Forms.CheckBox transitResEnabled; - private System.Windows.Forms.Label TransitArrival; - private System.Windows.Forms.Label LastTransit; - private System.Windows.Forms.Label label30; - private System.Windows.Forms.Label label29; - private System.Windows.Forms.Label label25; - private System.Windows.Forms.Label label26; - private System.Windows.Forms.Label label27; - private System.Windows.Forms.Label label28; - private System.Windows.Forms.Label label24; - private System.Windows.Forms.Label label23; - private System.Windows.Forms.Label label22; - private System.Windows.Forms.NumericUpDown FillLimitCrop; - private System.Windows.Forms.NumericUpDown FillLimitIron; - private System.Windows.Forms.NumericUpDown FillLimitClay; - private System.Windows.Forms.NumericUpDown FillLimitWood; - private System.Windows.Forms.NumericUpDown TargetLimitCrop; - private System.Windows.Forms.NumericUpDown TargetLimitIron; - private System.Windows.Forms.NumericUpDown TargetLimitClay; - private System.Windows.Forms.NumericUpDown TargetLimitWood; - private System.Windows.Forms.Label label21; - private System.Windows.Forms.Label label20; - private System.Windows.Forms.Label label19; - private System.Windows.Forms.Label label18; + private System.Windows.Forms.Panel panel1; + private System.Windows.Forms.GroupBox groupBox1; + private System.Windows.Forms.RadioButton radioButton2; + private System.Windows.Forms.RadioButton radioButton1; private System.Windows.Forms.Label label1; - private System.Windows.Forms.CheckBox npcEnabled; - private System.Windows.Forms.NumericUpDown numericUpDown1; - private System.Windows.Forms.NumericUpDown numericUpDown2; - private System.Windows.Forms.NumericUpDown numericUpDown3; - private System.Windows.Forms.NumericUpDown numericUpDown4; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.Label label3; - private System.Windows.Forms.Label label4; - private System.Windows.Forms.Label label5; - private System.Windows.Forms.Label label6; - private System.Windows.Forms.CheckBox overflowProtection; - private System.Windows.Forms.Label label7; - private System.Windows.Forms.Label label8; - private System.Windows.Forms.Label label9; - private System.Windows.Forms.Label label10; + private UserControls.CoordinatesUc coordinatesUc1; + private System.Windows.Forms.ComboBox VillageComboBox; + private System.Windows.Forms.Panel panel3; private System.Windows.Forms.Label label11; - private System.Windows.Forms.NumericUpDown cropSend; - private System.Windows.Forms.NumericUpDown ironSend; - private System.Windows.Forms.NumericUpDown claySend; - private System.Windows.Forms.NumericUpDown woodSend; - private System.Windows.Forms.Label label12; - private System.Windows.Forms.Label label13; + private System.Windows.Forms.Panel panel4; private System.Windows.Forms.Label label14; private System.Windows.Forms.Label label15; + private System.Windows.Forms.NumericUpDown numericUpDown6; private System.Windows.Forms.Label label16; + private System.Windows.Forms.Label label18; + private System.Windows.Forms.NumericUpDown numericUpDown7; + private System.Windows.Forms.NumericUpDown numericUpDown9; + private System.Windows.Forms.NumericUpDown numericUpDown8; + private System.Windows.Forms.Label label17; + private System.Windows.Forms.Button button1; + private System.Windows.Forms.Label label19; + private System.Windows.Forms.Panel panel5; + private System.Windows.Forms.Label label20; + private System.Windows.Forms.Label MerchantInfo; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.RichTextBox richTextBox1; + private System.Windows.Forms.Button button7; + private System.Windows.Forms.ListView routeTradeList; + private System.Windows.Forms.ColumnHeader transitIdHeader; + private System.Windows.Forms.ColumnHeader transitLocationHeader; + private System.Windows.Forms.ColumnHeader transitWoodHeader; + private System.Windows.Forms.ColumnHeader transitClayHeader; + private System.Windows.Forms.ColumnHeader transitIronHeader; + private System.Windows.Forms.ColumnHeader transitCropHeader; + private System.Windows.Forms.ColumnHeader transitTimeHeader; + private System.Windows.Forms.ColumnHeader transitLastHeader; + private System.Windows.Forms.Button button5; + private System.Windows.Forms.Button button4; + private System.Windows.Forms.Button button3; + private System.Windows.Forms.Panel panel2; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ColumnHeader transitActiveHeader; + private System.Windows.Forms.CheckBox checkBox1; + private System.Windows.Forms.Label label4; + private System.Windows.Forms.NumericUpDown numericUpDown1; + private System.Windows.Forms.Label label3; + private System.Windows.Forms.Label label6; + private System.Windows.Forms.Label label5; + private System.Windows.Forms.NumericUpDown numericUpDown2; } } diff --git a/TravBotSharp/Views/VillageViews/MarketUc.cs b/TravBotSharp/Views/VillageViews/MarketUc.cs index 7db88f4fa..3b373ec3b 100644 --- a/TravBotSharp/Views/VillageViews/MarketUc.cs +++ b/TravBotSharp/Views/VillageViews/MarketUc.cs @@ -1,106 +1,279 @@ using System; +using System.Linq; +using System.Drawing; +using System.Windows.Forms; using TravBotSharp.Interfaces; +using TbsCore.Models.VillageModels; +using TbsCore.Models.ResourceModels; +using TbsCore.Models.MapModels; +using TbsCore.Models.Settings; +using static TbsCore.Helpers.MarketHelper; +using TbsCore.Tasks.LowLevel; +using TbsCore.Tasks.SecondLevel; namespace TravBotSharp.Views { public partial class MarketUc : BaseVillageUc, ITbsUc { + public Resources _res; + public MarketUc() { InitializeComponent(); + _res = new Resources(); + numericUpDown6.Maximum = long.MaxValue; + numericUpDown7.Maximum = long.MaxValue; + numericUpDown8.Maximum = long.MaxValue; + numericUpDown9.Maximum = long.MaxValue; } public void UpdateUc() { var vill = GetSelectedVillage(); - TargetLimitWood.Value = vill.Market.Settings.Configuration.TargetLimit.Wood; - TargetLimitClay.Value = vill.Market.Settings.Configuration.TargetLimit.Clay; - TargetLimitIron.Value = vill.Market.Settings.Configuration.TargetLimit.Iron; - TargetLimitCrop.Value = vill.Market.Settings.Configuration.TargetLimit.Crop; - FillLimitWood.Value = vill.Market.Settings.Configuration.FillLimit.Wood; - FillLimitClay.Value = vill.Market.Settings.Configuration.FillLimit.Clay; - FillLimitIron.Value = vill.Market.Settings.Configuration.FillLimit.Iron; - FillLimitCrop.Value = vill.Market.Settings.Configuration.FillLimit.Crop; - transitResEnabled.Checked = vill.Market.Settings.Configuration.Enabled; - TransitArrival.Text = vill.Market.Settings.Configuration.TransitArrival.ToString(); - LastTransit.Text = vill.Market.LastTransit.ToString(); - //Send res to main vill config - woodSend.Value = vill.Market.Settings.Configuration.SendResLimit.Wood; - claySend.Value = vill.Market.Settings.Configuration.SendResLimit.Clay; - ironSend.Value = vill.Market.Settings.Configuration.SendResLimit.Iron; - cropSend.Value = vill.Market.Settings.Configuration.SendResLimit.Crop; - //For npc - npcEnabled.Checked = vill.Market.Npc.Enabled; - overflowProtection.Checked = vill.Market.Npc.NpcIfOverflow; - numericUpDown4.Value = vill.Market.Npc.ResourcesRatio.Wood; - numericUpDown3.Value = vill.Market.Npc.ResourcesRatio.Clay; - numericUpDown2.Value = vill.Market.Npc.ResourcesRatio.Iron; - numericUpDown1.Value = vill.Market.Npc.ResourcesRatio.Crop; + var acc = GetSelectedAcc(); + if (acc == null) return; + + VillageComboBox.Items.Clear(); + foreach (var _vill in acc.Villages) + { + if (_vill.Id == vill.Id) continue; + VillageComboBox.Items.Add(_vill.Name); + } + if (VillageComboBox.Items.Count > 0) + { + VillageComboBox.SelectedIndex = 0; + } + UpdateTradeRouteView(vill); + + richTextBox1.Text = vill.Res.Stored.Resources.ToString(); + //vill.Market.Merchant = vill.Market.Merchant ?? new MerchantInfo(); + //MerchantInfo.Text = $"Merchant: {vill.Market.Merchant.Free}/ {vill.Market.Merchant.Number} ({vill.Market.Merchant.Capacity})"; } - private void transitResEnabled_CheckedChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.Enabled = transitResEnabled.Checked; + private void UpdateMerchantNeed(Village vill) + { + //var merchant = vill.Market.Merchant; + //if (merchant.Capacity > 0) + //{ + // var reminder = _res.Sum() % merchant.Capacity; + // if (reminder > 0) + // { + // label19.Text = $"Need {_res.Sum() / merchant.Capacity + 1} merchant"; + // } + // else + // { + // label19.Text = $"Need {_res.Sum() / merchant.Capacity} merchant"; + // } + //} + } - private void overflowProtection_CheckedChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.NpcIfOverflow = overflowProtection.Checked; + private void UpdateTradeRouteView(Village vill) + { + var traderoute = vill.Market.TradeRoute; + if (traderoute == null) return; + var vills = GetSelectedAcc().Villages; - private void numericUpDown4_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.ResourcesRatio.Wood = (long)numericUpDown4.Value; + routeTradeList.Items.Clear(); + foreach (var route in traderoute.TradeRoutes) + { + ListViewItem item = new ListViewItem(); - private void numericUpDown3_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.ResourcesRatio.Clay = (long)numericUpDown3.Value; + item.SubItems[0].Text = (routeTradeList.Items.Count + 1).ToString(); + item.SubItems.Add(vills.FirstOrDefault(x => x.Coordinates.Equals(route.Location))?.Name ?? route.Location.ToString()); + item.SubItems.Add(route.Resource.Wood.ToString()); + item.SubItems.Add(route.Resource.Clay.ToString()); + item.SubItems.Add(route.Resource.Iron.ToString()); + item.SubItems.Add(route.Resource.Crop.ToString()); + item.SubItems.Add(route.Time.ToString()); + item.SubItems.Add(route.Last.ToString()); + item.SubItems.Add(route.Active ? "✔" : "✘"); - private void numericUpDown2_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.ResourcesRatio.Iron = (long)numericUpDown2.Value; + item.ForeColor = Color.White; + routeTradeList.Items.Add(item); + } + } - private void numericUpDown1_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.ResourcesRatio.Crop = (long)numericUpDown1.Value; + #region Target Village radiobutton - private void npcEnabled_CheckedChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Npc.Enabled = npcEnabled.Checked; + private void radioButton1_CheckedChanged(object sender, EventArgs e) + { + this.VillageComboBox.Enabled = radioButton1.Checked; + } - #region SendMainVill Callbacks - private void woodSend_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.SendResLimit.Wood = (long)woodSend.Value; + private void radioButton2_CheckedChanged(object sender, EventArgs e) + { + this.coordinatesUc1.Enabled = radioButton2.Checked; + } - private void claySend_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.SendResLimit.Clay = (long)claySend.Value; + #endregion Target Village radiobutton - private void ironSend_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.SendResLimit.Iron = (long)ironSend.Value; + //private void button2_Click(object sender, EventArgs e) => + // GetSelectedAcc().Tasks.Add( + // new UpdateMarket + // { + // ExecuteAt = DateTime.Now.AddHours(-10), + // Vill = GetSelectedVillage(), + // }, + // true, + // GetSelectedVillage()); - private void cropSend_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.SendResLimit.Crop = (long)cropSend.Value; - #endregion + private void button1_Click(object sender, EventArgs e) + { + Coordinates coord; + if (radioButton1.Checked) + { + if (VillageComboBox.SelectedIndex == -1) return; + coord = GetSelectedAcc().Villages.FirstOrDefault(x => x.Name == VillageComboBox.Items[VillageComboBox.SelectedIndex].ToString()).Coordinates; + } + else + { + coord = coordinatesUc1.Coords; + } + GetSelectedAcc().Tasks.Add( + new SendResource( + GetSelectedVillage(), + _res, + coord, + DateTime.Now.AddHours(-10))); + } - #region TargetLimit Callbacks - private void TargetLimitWood_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.TargetLimit.Wood = (long)TargetLimitWood.Value; + private void button7_Click(object sender, EventArgs e) + { + var acc = GetSelectedAcc(); + var vill = GetSelectedVillage(); + acc.Tasks.Remove(typeof(NPC), vill); + acc.Tasks.Add( + new NPC() + { + ExecuteAt = DateTime.Now, + Vill = vill, + }); + } - private void TargetLimitClay_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.TargetLimit.Clay = (long)TargetLimitClay.Value; + #region Resource numeric group - private void TargetLimitIron_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.TargetLimit.Iron = (long)TargetLimitIron.Value; + private void numericUpDown9_ValueChanged(object sender, EventArgs e) + { + _res.Wood = (long)numericUpDown9.Value; + UpdateMerchantNeed(GetSelectedVillage()); + } - private void TargetLimitCrop_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.TargetLimit.Crop = (long)TargetLimitCrop.Value; - #endregion + private void numericUpDown8_ValueChanged(object sender, EventArgs e) + { + _res.Clay = (long)numericUpDown8.Value; + UpdateMerchantNeed(GetSelectedVillage()); + } - #region FillLimit Callbacks - private void FillLimitWood_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.FillLimit.Wood = (long)FillLimitWood.Value; + private void numericUpDown7_ValueChanged(object sender, EventArgs e) + { + _res.Iron = (long)numericUpDown7.Value; + UpdateMerchantNeed(GetSelectedVillage()); + } - private void FillLimitClay_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.FillLimit.Clay = (long)FillLimitClay.Value; + private void numericUpDown6_ValueChanged(object sender, EventArgs e) + { + _res.Crop = (long)numericUpDown6.Value; + UpdateMerchantNeed(GetSelectedVillage()); + } + + #endregion Resource numeric group + + #region Route trade button group + + private void button3_Click(object sender, EventArgs e) + { + Coordinates coord; + if (radioButton1.Checked) + { + if (VillageComboBox.SelectedIndex == -1) + { + MessageBox.Show("Missing coordinate"); + return; + } + coord = GetSelectedAcc().Villages.FirstOrDefault(x => x.Name == VillageComboBox.Items[VillageComboBox.SelectedIndex].ToString()).Coordinates; + } + else + { + coord = coordinatesUc1.Coords; + } + + var route = new TradeRoute + { + Location = coord, + Resource = _res, + Time = (int)numericUpDown1.Value, + TimeDelay = (int)numericUpDown2.Value, + Active = checkBox1.Checked, + }; + + var vill = GetSelectedVillage(GetSelectedAcc()); + AddTradeRoute(vill, route); + UpdateTradeRouteView(vill); + + GetSelectedAcc().Tasks.Add(new SendRoute(vill, DateTime.Now)); + } + + private void button4_Click(object sender, EventArgs e) + { + if (routeTradeList.FocusedItem == null) return; - private void FillLimitIron_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.FillLimit.Iron = (long)FillLimitIron.Value; + Coordinates coord; + if (radioButton1.Checked) + { + if (VillageComboBox.SelectedIndex == -1) + { + MessageBox.Show("Missing coordinate"); + return; + } + coord = GetSelectedAcc().Villages.FirstOrDefault(x => x.Name == VillageComboBox.Items[VillageComboBox.SelectedIndex].ToString()).Coordinates; + } + else + { + coord = coordinatesUc1.Coords; + } - private void FillLimitCrop_ValueChanged(object sender, EventArgs e) => - GetSelectedVillage().Market.Settings.Configuration.FillLimit.Crop = (long)FillLimitCrop.Value; - #endregion + var route = new TradeRoute + { + Location = coord, + Resource = _res, + Time = (int)numericUpDown1.Value, + TimeDelay = (int)numericUpDown2.Value, + Active = checkBox1.Checked, + }; + var vill = GetSelectedVillage(GetSelectedAcc()); + UpdateTradeRoute(vill, route, routeTradeList.FocusedItem.Index); + UpdateTradeRouteView(vill); + } + + private void button5_Click(object sender, EventArgs e) + { + if (routeTradeList.FocusedItem == null) return; + + var vill = GetSelectedVillage(GetSelectedAcc()); + RemoveTradeRoute(vill, routeTradeList.FocusedItem.Index); + UpdateTradeRouteView(vill); + } + + #endregion Route trade button group + private void routeTradeList_SelectedIndexChanged(object sender, EventArgs e) + { + if (routeTradeList.FocusedItem == null) return; + var vill = GetSelectedVillage(GetSelectedAcc()); + var route = vill.Market.TradeRoute.TradeRoutes[routeTradeList.FocusedItem.Index]; + + radioButton2.Checked = true; + coordinatesUc1.Coords = route.Location; + + numericUpDown9.Value = route.Resource.Wood; + numericUpDown8.Value = route.Resource.Clay; + numericUpDown7.Value = route.Resource.Iron; + numericUpDown6.Value = route.Resource.Crop; + + numericUpDown2.Value = route.TimeDelay; + numericUpDown1.Value = route.Time; + checkBox1.Checked = route.Active; + } } -} +} \ No newline at end of file diff --git a/TravBotSharp/Views/VillagesUc.cs b/TravBotSharp/Views/VillagesUc.cs index 7c484d400..b6e2105e0 100644 --- a/TravBotSharp/Views/VillagesUc.cs +++ b/TravBotSharp/Views/VillagesUc.cs @@ -111,7 +111,7 @@ private void RefreshVillage(Account acc, Village vill) // Refresh village { ExecuteAt = DateTime.Now.AddHours(-1), Vill = vill, - ImportTasks = false + NewVillage = false }); } }