/// <summary> /// When a BotTask doesn't have enough resources in the village, this method will add the /// BotTask to the village's UnfinishedTasks list. Bot will finish the task when village has enough resources /// </summary> /// <param name="acc">Account</param> /// <param name="vill">(target) Village</param> /// <param name="requiredRes">Resources required</param> /// <param name="task">Bot task that doesn't have enough resources</param> /// <param name="buildingTask">Potential building task</param> public static void NotEnoughRes(Account acc, Village vill, Resources requiredRes, BotTask task, BuildingTask buildingTask = null) { var enoughResAt = NewUnfinishedTask(acc, vill, requiredRes, task, buildingTask); if (enoughResAt == null) { return; } var nextRefresh = TimeHelper.RanDelay(acc, enoughResAt ?? DateTime.Now); if (nextRefresh < VillageHelper.GetNextRefresh(acc, vill)) { VillageHelper.SetNextRefresh(acc, vill, nextRefresh); } }
public static void StartAccountTasks(Account acc) { // Get the server info (on first running the account) if (acc.AccInfo.ServerSpeed == 0 || acc.AccInfo.MapSize == 0) { TaskExecutor.AddTaskIfNotExists(acc, new GetServerInfo() { ExecuteAt = DateTime.MinValue.AddHours(2) }); } if (acc.AccInfo.Tribe == null) { TaskExecutor.AddTaskIfNotExists(acc, new GetTribe() { ExecuteAt = DateTime.MinValue.AddHours(3) }); } //FL if (acc.Farming.Enabled) { TaskExecutor.AddTaskIfNotExists(acc, new SendFLs() { ExecuteAt = DateTime.Now }); } // Bot sleep TaskExecutor.AddTaskIfNotExists(acc, new Sleep() { ExecuteAt = DateTime.Now + TimeHelper.GetWorkTime(acc), AutoSleep = true }); // Access change var nextAccessChange = TimeHelper.GetNextProxyChange(acc); if (nextAccessChange != TimeSpan.MaxValue) { TaskExecutor.AddTaskIfNotExists(acc, new ChangeAccess() { ExecuteAt = DateTime.Now + nextAccessChange }); } //research / improve / train troops foreach (var vill in acc.Villages) { //if (vill.Troops.Researched.Count == 0) TaskExecutor.AddTask(acc, 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) { TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new AttackOasis() { Vill = 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; } // Hero update info if (acc.Hero.Settings.AutoRefreshInfo) { Random ran = new Random(); TaskExecutor.AddTask(acc, new HeroUpdateInfo() { ExecuteAt = DateTime.Now.AddMinutes(ran.Next(40, 80)), Priority = Tasks.BotTask.TaskPriority.Low }); } }