public static void AddBuildTasksFromFile(Account acc, Village vill, string location) { List <BuildingTask> tasks = new List <BuildingTask>(); try { using (StreamReader sr = new StreamReader(location)) { // If .trbc file, decode into List<BuildTask> if (Path.GetExtension(location).Equals(".TRBC", StringComparison.CurrentCultureIgnoreCase)) { var trbc = JsonConvert.DeserializeObject <TbRoot>(sr.ReadToEnd()); tasks = DecodeTrbc(trbc); } else { tasks = JsonConvert.DeserializeObject <List <BuildingTask> >(sr.ReadToEnd()); } } } catch (Exception) { return; } // User canceled foreach (var task in tasks) { BuildingHelper.AddBuildingTask(acc, vill, task); } BuildingHelper.RemoveCompletedTasks(vill, acc); }
private static (string, bool) GetUrlGeneralTask(Village vill, BuildingTask task) { // Check if there is already a different building in this spot (not Site) if (task.BuildingId == null || (vill.Build.Buildings.First(x => x.Id == task.BuildingId).Type != task.Building && vill.Build.Buildings.First(x => x.Id == task.BuildingId).Type != BuildingEnum.Site)) { var targetBuilding = vill.Build.Buildings.FirstOrDefault(x => x.Type == task.Building); // Re-select the buildingId if (targetBuilding != null && !task.ConstructNew) { task.BuildingId = targetBuilding.Id; } else // there's already a building in this spot, construct a building elsewhere { if (!BuildingHelper.FindBuildingId(vill, task)) { return(null, false); } } } var url = task.BuildingId.ToString(); bool constructNew = false; // If there is no building in that space currently, construct a new building if (vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Site && x.Id == task.BuildingId)) { url += "&category=" + (int)BuildingsData.GetBuildingsCategory(task.Building); constructNew = true; } return(url, constructNew); }
public static void SupplyVillagePlan(Account acc, Village vill) { FarmVillagePlan(acc, vill); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Marketplace, Level = 20 }); //market center? }
public static void DeffVillagePlan(Account acc, Village vill) { FarmVillagePlan(acc, vill); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Barracks, Level = 20 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Academy, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Smithy, Level = 20 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Marketplace, Level = 15 }); }
/// <summary> /// Checks whether the resources at more than 95% of the capacity and increases if it's true. /// </summary> /// <param name="acc"></param> /// <param name="vill"></param> private static void AutoExpandStorage(Account acc, Village vill) { if (!vill.Settings.AutoExpandStorage) { return; } double warehouse_delta = vill.Res.Capacity.WarehouseCapacity * 0.95; double granary_delta = vill.Res.Capacity.GranaryCapacity * 0.95; if (warehouse_delta <= vill.Res.Stored.Resources.Wood || warehouse_delta <= vill.Res.Stored.Resources.Clay || warehouse_delta <= vill.Res.Stored.Resources.Iron) { BuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Warehouse, false); return; } if (granary_delta <= vill.Res.Stored.Resources.Crop) { BuildingHelper.UpgradeBuildingForOneLvl(acc, vill, Classificator.BuildingEnum.Granary, false); } }
public static void OffVillagePlan(Account acc, Village vill) { DeffVillagePlan(acc, vill); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Academy, Level = 15 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Stable, Level = 20 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Workshop, Level = 1 }); 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 }); }
/// <summary> /// Upgrades storage of the village /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village</param> /// <param name="building">Storage building</param> private static void UpgradeStorage(Account acc, Village vill, BuildingEnum building) { var task = new BuildingTask() { Building = building, TaskType = Classificator.BuildingType.General }; var current = vill.Build.Buildings.FirstOrDefault(x => x.Type == building && (x.Level != 20 || (x.Level != 19 && x.UnderConstruction)) ); if (current == null) { task.ConstructNew = true; task.Level = 1; } else { task.Level = current.Level + 1; } BuildingHelper.AddBuildingTask(acc, vill, task, false); }
public static void FarmVillagePlan(Account acc, Village vill) { BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.AutoUpgradeResFields, Level = 10, ResourceType = ResTypeEnum.AllResources, BuildingStrategy = BuildingStrategyEnum.BasedOnRes }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.RallyPoint, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.MainBuilding, Level = 3 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 3 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 3 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Marketplace, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 4 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 4 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 5 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 5 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.MainBuilding, Level = 5 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 6 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 6 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 7 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 7 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Residence, Level = 10 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Barracks, Level = 1 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.MainBuilding, Level = 10 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 10 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 10 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 15 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 15 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Warehouse, Level = 20 }); BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = BuildingEnum.Granary, Level = 20 }); }
public static (BuildingTask, DateTime) NextBuildingTask(Account acc, Village vill) { if (vill.Build.Tasks.Count == 0) { return(null, DateTime.Now); } var now = DateTime.Now.AddMinutes(-3); // Since we are already in the village var later = DateTime.Now.AddSeconds(1); var totalBuild = vill.Build.CurrentlyBuilding.Count; if (0 < totalBuild) { later = GetNextBuildTime(acc, vill); } var maxBuild = 1; if (acc.AccInfo.PlusAccount) { maxBuild++; } if (acc.AccInfo.Tribe == TribeEnum.Romans) { maxBuild++; } BuildingTask task = null; // If (roman OR ttwars+plus acc) -> build 1 res + 1 infra at the same time if (1 <= totalBuild && (acc.AccInfo.Tribe == TribeEnum.Romans || (acc.AccInfo.PlusAccount && acc.AccInfo.ServerUrl.ToLower().Contains("ttwars")) )) { // Find the CurrentlyBuilding that executes sooner var cb = vill.Build.CurrentlyBuilding.OrderBy(x => x.Duration).First(); later = cb.Duration; var isResField = BuildingHelper.IsResourceField(cb.Building); task = isResField ? GetFirstInfrastructureTask(vill) : GetFirstResTask(vill); if (task != null) { return(task, now); } if (acc.AccInfo.Tribe == TribeEnum.Romans) { maxBuild--; } } task = vill.Build.Tasks.First(); //If this task is already complete, remove it and repeat the finding process if (BuildingHelper.IsTaskCompleted(vill, acc, task)) { vill.Build.Tasks.Remove(task); //task has been completed return(NextBuildingTask(acc, vill)); } //if buildingId is not yet defined, find one. if (task.BuildingId == null && task.TaskType == BuildingType.General) { var found = BuildingHelper.FindBuildingId(vill, task); //no space found for this building, remove the buildTask if (!found) { vill.Build.Tasks.Remove(task); return(NextBuildingTask(acc, vill)); } } if (totalBuild < maxBuild) { return(task, now); } else { return(task, later); } }
private static BuildingTask GetFirstInfrastructureTask(Village vill) => vill.Build.Tasks.FirstOrDefault(x => !BuildingHelper.IsResourceField(x.Building));
private static BuildingTask GetFirstResTask(Village vill) => vill.Build.Tasks.FirstOrDefault(x => x.TaskType == BuildingType.AutoUpgradeResFields || BuildingHelper.IsResourceField(x.Building) );
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) }); } if (acc.AccInfo.Tribe == null) { 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); } //research / improve / train troops foreach (var vill in acc.Villages) { //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) { acc.Tasks.Add(new AttackOasis() { 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; } // Hero update info if (acc.Hero.Settings.AutoRefreshInfo) { Random ran = new Random(); acc.Tasks.Add(new HeroUpdateInfo() { ExecuteAt = DateTime.Now.AddMinutes(ran.Next(40, 80)), Priority = Tasks.BotTask.TaskPriority.Low }); } }
/// <summary> /// Method will create EquipHero BotTasks that will use resources needed /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village to use resources in</param> /// <param name="neededRes">Needed resources</param> /// <param name="heroRes">Hero resources</param /// <param name="task">Potential BuildingTask that requires the resources</param> private static HeroEquip UseHeroResources(Account acc, Village vill, ref long[] neededRes, long[] heroRes, BuildingTask task = null) { var useRes = new List <(Classificator.HeroItemEnum, int)>(); for (int i = 0; i < 4; i++) { if (neededRes[i] == 0 || heroRes[i] == 0) { continue; } long resToBeUsed = RoundUpTo100(neededRes[i]); if (heroRes[i] < resToBeUsed) { resToBeUsed = heroRes[i]; } neededRes[i] -= resToBeUsed; HeroItemEnum item = HeroItemEnum.Others_Wood_0; switch (i) { case 0: item = HeroItemEnum.Others_Wood_0; break; case 1: item = HeroItemEnum.Others_Clay_0; break; case 2: item = HeroItemEnum.Others_Iron_0; break; case 3: item = HeroItemEnum.Others_Crop_0; break; } useRes.Add((item, (int)resToBeUsed)); } var heroEquip = new HeroEquip() { Items = useRes, ExecuteAt = DateTime.Now.AddHours(-2), // -2 since sendRes is -1 Vill = vill }; acc.Tasks.Add(heroEquip); // A BuildTask needed the resources. If it was auto-build res fields task, make a new // general building task - so resources actually get used for intended building upgrade if (task != null && task.TaskType == Classificator.BuildingType.AutoUpgradeResFields) { var building = vill.Build.Buildings.FirstOrDefault(x => x.Id == task.BuildingId); var lvl = building.Level; if (building.UnderConstruction) { lvl++; } BuildingHelper.AddBuildingTask(acc, vill, new BuildingTask() { TaskType = Classificator.BuildingType.General, Building = task.Building, BuildingId = task.BuildingId, Level = ++lvl }, false); } return(heroEquip); }