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 (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); } }