public static bool IsResourceField(BuildingEnum building) { int buildingInt = (int)building; // If id between 1 and 4, it's resource field return(buildingInt < 5 && buildingInt > 0); }
public void ShowLogo(BuildingEnum val) { foreach (BuildingLogo logo in LogoBuildings) { logo.Logo.gameObject.SetActive(logo.Type == val); } }
private static Building GetLowestProduction(List <Building> buildings, Village vill) { //get distinct field types var distinct = buildings.Select(x => x.Type).Distinct().ToList(); long lowestProd = long.MaxValue; BuildingEnum toUpgrade = BuildingEnum.Cropland; foreach (var distinctType in distinct) { if (distinctType == BuildingEnum.Woodcutter && vill.Res.Production.Wood < lowestProd) { lowestProd = vill.Res.Production.Wood; toUpgrade = BuildingEnum.Woodcutter; } if (distinctType == BuildingEnum.ClayPit && vill.Res.Production.Clay < lowestProd) { lowestProd = vill.Res.Production.Clay; toUpgrade = BuildingEnum.ClayPit; } if (distinctType == BuildingEnum.IronMine && vill.Res.Production.Iron < lowestProd) { lowestProd = vill.Res.Production.Iron; toUpgrade = BuildingEnum.IronMine; } if (distinctType == BuildingEnum.Cropland && vill.Res.Production.Crop < lowestProd) { lowestProd = vill.Res.Production.Crop; toUpgrade = BuildingEnum.Cropland; } } return(FindLowestLevelBuilding(buildings.Where(x => x.Type == toUpgrade).ToList())); }
public Purchase Get(BuildingEnum buildingType) { switch (buildingType) { case BuildingEnum.MainBuilding: return(Get(PurchasesEnum.MainBuilding)); case BuildingEnum.Library: return(Get(PurchasesEnum.Library)); case BuildingEnum.Barracks: return(Get(PurchasesEnum.Barracks)); case BuildingEnum.Infirmary: return(Get(PurchasesEnum.Infirmary)); case BuildingEnum.House: return(Get(PurchasesEnum.House)); case BuildingEnum.Mill: return(Get(PurchasesEnum.Mill)); case BuildingEnum.Sawmill: return(Get(PurchasesEnum.Sawmill)); case BuildingEnum.Bank: return(Get(PurchasesEnum.Bank)); default: return(null); } }
public static BuildingCategoryEnum GetBuildingsCategory(BuildingEnum building) { switch (building) { case BuildingEnum.GrainMill: case BuildingEnum.Sawmill: case BuildingEnum.Brickyard: case BuildingEnum.IronFoundry: case BuildingEnum.Bakery: return(BuildingCategoryEnum.Resources); case BuildingEnum.RallyPoint: case BuildingEnum.EarthWall: case BuildingEnum.CityWall: case BuildingEnum.MakeshiftWall: case BuildingEnum.StoneWall: case BuildingEnum.Palisade: case BuildingEnum.Barracks: case BuildingEnum.HerosMansion: case BuildingEnum.Academy: case BuildingEnum.Smithy: case BuildingEnum.Stable: case BuildingEnum.GreatBarracks: case BuildingEnum.GreatStable: case BuildingEnum.Workshop: case BuildingEnum.TournamentSquare: return(BuildingCategoryEnum.Military); default: return(BuildingCategoryEnum.Infrastructure); } }
public static DateTime GetTrainingTimeForBuilding(BuildingEnum building, Village vill) { var def = DateTime.Now; switch (building) { case BuildingEnum.Barracks: return(vill.Troops.CurrentlyTraining.Barracks?.LastOrDefault()?.FinishTraining ?? def); case BuildingEnum.Stable: return(vill.Troops.CurrentlyTraining.Stable?.LastOrDefault()?.FinishTraining ?? def); case BuildingEnum.GreatBarracks: return(vill.Troops.CurrentlyTraining.GB?.LastOrDefault()?.FinishTraining ?? def); case BuildingEnum.GreatStable: return(vill.Troops.CurrentlyTraining.GS?.LastOrDefault()?.FinishTraining ?? def); case BuildingEnum.Workshop: return(vill.Troops.CurrentlyTraining.Workshop?.LastOrDefault()?.FinishTraining ?? def); default: return(def); } }
/// <summary> /// Upgrades specified building for exactly one level. Will upgrade the lowest level building. /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village</param> /// <param name="building">Building to be upgraded by one</param> /// <param name="bottom">Whether to insert the building task on the bottom of the build list</param> /// <returns>Whether the method executed successfully</returns> internal static bool UpgradeBuildingForOneLvl(Account acc, Village vill, BuildingEnum building, bool bottom = true) { // We already have a build task if (!bottom && vill.Build.Tasks.FirstOrDefault()?.Building == building) { return(true); } if (bottom && vill.Build.Tasks.LastOrDefault()?.Building == building) { return(true); } var upgrade = vill.Build .Buildings .OrderBy(x => x.Level) .FirstOrDefault(x => x.Type == building); // We don't have this building in the village yet if (upgrade == null) { return(AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = building, Level = 1, }, bottom)); } var currentLvl = (int)upgrade.Level; RemoveFinishedCB(vill); currentLvl += vill.Build.CurrentlyBuilding.Count(x => x.Building == building); if (BuildingsData.MaxBuildingLevel(acc, building) == currentLvl) { // Building is on max level, construct new building if possible if (!BuildingsData.CanHaveMultipleBuildings(building)) { return(false); } return(AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = building, Level = 1, }, bottom)); } else // Upgrade the defined building { return(AddBuildingTask(acc, vill, new BuildingTask() { TaskType = BuildingType.General, Building = building, Level = currentLvl + 1, BuildingId = upgrade.Id }, bottom)); } }
private bool BonusHelper(Village vill, BuildingEnum field, BuildingEnum bonus, int fieldLvl) // vill does not have bonus building on 5, create or upgrade it { //res field is high enoguh, bonus building is not on 5, there is still space left to build, there isn't already a bonus building buildtask return(!vill.Build.Buildings.Any(x => x.Type == bonus && x.Level >= 5) && vill.Build.Buildings.Any(x => x.Type == field && x.Level >= fieldLvl) && vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Site) && !vill.Build.Tasks.Any(x => x.Building == bonus)); }
public GameObject GetPrefab(BuildingEnum id) { BuildingConfig config = BuildingConfigs.FirstOrDefault(x => x.Id == id); if (config == null) { throw new NullReferenceException($"No Building config for id: {nameof(id)}"); } return(config.Prefab); }
public BaseBuilding Build(BuildingEnum type) { if (Content != null) { return(null); } Content = Instantiate(BuildingFactory.GetPrefab(type), transform); Building = Content.GetComponent <BaseBuilding>(); return(Building); }
public static async Task <bool> EnterBuilding(Account acc, Village vill, BuildingEnum buildingEnum, string query = "", bool dorf = true) { var building = vill.Build.Buildings.FirstOrDefault(x => x.Type == buildingEnum); if (building == null) { acc.Wb.Log($"Tried to enter {buildingEnum} but couldn't find it in village {vill.Name}!"); return(false); } return(await EnterBuilding(acc, vill, building, query, dorf)); }
private void CreateBuilding(Slot slot, BuildingEnum type) { BaseBuilding building = slot.Build(type); if (building == null) { return; } Vector3 original = building.Model.transform.position; building.Model.transform.position -= Vector3.up * 5; building.Model.DOMove(original, 0.4f).SetDelay(0.1f); }
/// <summary> /// Helper method for checking whether the bot should add the bonus building to the build list /// </summary> private bool BonusHelper(Village vill, BuildingEnum field, BuildingEnum bonus, int fieldLvl) { // If the bonus building is currently being upgraded to level 5, don't try to re-add it if (vill.Build.CurrentlyBuilding.Any(x => x.Building == bonus && x.Level == 5)) { return(false); } // Bonus building is not on 5, res field is high enough, there is still space left to build, there isn't already a bonus building buildtask return(!vill.Build.Buildings.Any(x => x.Type == bonus && 5 <= x.Level) && vill.Build.Buildings.Any(x => x.Type == field && fieldLvl <= x.Level) && vill.Build.Buildings.Any(x => x.Type == BuildingEnum.Site) && !vill.Build.Tasks.Any(x => x.Building == bonus)); }
/// <summary> /// Adds all building prerequisites for this building if they do not exist yet. /// After this you should call RemoveDuplicates(). /// </summary> /// <param name="acc"></param> /// <param name="vill"></param> /// <param name="building"></param> /// <returns>Whether we have all prerequisite buildings</returns> public static bool AddBuildingPrerequisites(Account acc, Village vill, BuildingEnum building, bool bottom = true) { RemoveFinishedCB(vill); (var tribe, var prereqs) = BuildingsData.GetBuildingPrerequisites(building); if (acc.AccInfo.Tribe != tribe && tribe != TribeEnum.Any) { return(false); } if (prereqs.Count == 0) { return(true); } var ret = true; foreach (var prereq in prereqs) { var prereqBuilding = vill.Build.Buildings.Where(x => x.Type == prereq.Building); // Prerequired building already exists and is on on/above/being upgraded on desired level if (prereqBuilding.Any(x => prereq.Level <= x.Level + (x.UnderConstruction ? 1 : 0)) ) { continue; } if (bottom && vill.Build.Tasks.Any(x => prereq.Building == x.Building && prereq.Level <= x.Level)) { continue; } // If there is no required building, build it's prerequisites first if (!prereqBuilding.Any()) { AddBuildingPrerequisites(acc, vill, prereq.Building); } AddBuildingTask(acc, vill, new BuildingTask() { Building = prereq.Building, Level = prereq.Level, TaskType = BuildingType.General }, bottom); ret = false; } return(ret); }
/// <summary> /// Enters a specific building. /// </summary> /// <param name="acc">Account</param> /// <param name="vill">Village</param> /// <param name="buildingEnum">Building to enter</param> /// <returns>Whether it was successful</returns> public static async Task <bool> EnterBuilding(Account acc, Village vill, BuildingEnum buildingEnum, string query = "") { var building = vill.Build .Buildings .FirstOrDefault(x => x.Type == buildingEnum); if (building == null) { acc.Wb.Log($"Tried to enter {buildingEnum} but couldn't find it in village {vill.Name}!"); return(false); } await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={building.Id}{query}"); return(true); }
private static void BuildingAddOrUpdate(Account acc, BuildingEnum building, string localizedName) { localizedName = WebUtility.HtmlDecode(localizedName.ToLower()).Trim(); if (acc.Settings.Localization == null) { acc.Settings.Localization = new Dictionary <string, BuildingEnum>(); } if (acc.Settings.Localization.ContainsKey(localizedName)) { acc.Settings.Localization[localizedName] = building; } else { acc.Settings.Localization.Add(localizedName, building); } }
public TemporaryBuilding CreateTemporaryMainBuilding(NetworkInstanceId playerId, BuildingEnum buildingType) { TemporaryBuilding building; switch (buildingType) { case BuildingEnum.MainBuilding: building = Instantiate(mainBuildingPrefab); break; case BuildingEnum.Library: building = Instantiate(libraryPrefab); break; case BuildingEnum.Barracks: building = Instantiate(barracksPrefab); break; case BuildingEnum.Infirmary: building = Instantiate(infirmaryPrefab); break; case BuildingEnum.House: building = Instantiate(housePrefab); break; case BuildingEnum.Mill: building = Instantiate(millPrefab); break; case BuildingEnum.Sawmill: building = Instantiate(sawmillPrefab); break; case BuildingEnum.Bank: building = Instantiate(bankPrefab); break; default: building = null; break; } building.playerNetId = playerId; return(building); }
private static Building GetLowestRes(Account acc, Village vill, List <Building> buildings) { //get distinct field types var distinct = buildings.Select(x => x.Type).Distinct().ToList(); long lowestRes = long.MaxValue; BuildingEnum toUpgrade = BuildingEnum.Cropland; var heroRes = vill.Settings.UseHeroRes ? HeroHelper.GetHeroResources(acc) : new long[] { 0, 0, 0, 0 }; var resSum = ResourcesHelper.SumArr(vill.Res.Stored.Resources.ToArray(), heroRes); foreach (var distinctType in distinct) { if (distinctType == BuildingEnum.Woodcutter && resSum[0] < lowestRes) { lowestRes = resSum[0]; toUpgrade = BuildingEnum.Woodcutter; } else if (distinctType == BuildingEnum.ClayPit && resSum[1] < lowestRes) { lowestRes = resSum[1]; toUpgrade = BuildingEnum.ClayPit; } else if (distinctType == BuildingEnum.IronMine && resSum[2] < lowestRes) { lowestRes = resSum[2]; toUpgrade = BuildingEnum.IronMine; } else if (distinctType == BuildingEnum.Cropland && resSum[3] < lowestRes) { lowestRes = resSum[3]; toUpgrade = BuildingEnum.Cropland; } } return(FindLowestLevelBuilding(buildings.Where(x => x.Type == toUpgrade).ToList())); }
public static bool BuildingRequirementsAreMet(BuildingEnum building, Village vill, TribeEnum tribe) //check if user can construct this building { bool exists = (vill.Build.Buildings.FirstOrDefault(x => x.Type == building) != null); //there is already a building of this type in the vill if (exists) { //check cranny/warehouse/grannary/trapper/GG/GW switch (building) { case BuildingEnum.Warehouse: return(BuildingIsOnLevel(BuildingEnum.Warehouse, 20, vill)); case BuildingEnum.Granary: return(BuildingIsOnLevel(BuildingEnum.Granary, 20, vill)); case BuildingEnum.GreatWarehouse: return(BuildingIsOnLevel(BuildingEnum.GreatWarehouse, 20, vill)); case BuildingEnum.GreatGranary: return(BuildingIsOnLevel(BuildingEnum.GreatGranary, 20, vill)); case BuildingEnum.Trapper: return(BuildingIsOnLevel(BuildingEnum.Trapper, 20, vill)); case BuildingEnum.Cranny: return(BuildingIsOnLevel(BuildingEnum.Cranny, 10, vill)); default: return(false); } } //check for prerequisites for this building (var ReqTribe, var Prerequisites) = BuildingsData.GetBuildingPrerequisites(building); if (ReqTribe != TribeEnum.Any && ReqTribe != tribe) { return(false); } //if we either already have this building OR is on our build task list, requirements are met. foreach (var prerequisite in Prerequisites) { if (!vill.Build.Buildings.Any(x => x.Level >= prerequisite.Level && x.Type == prerequisite.Building) && !vill.Build.Tasks.Any(x => x.Level >= prerequisite.Level && x.Building == prerequisite.Building)) { return(false); } } return(true); }
public static bool IsWall(BuildingEnum building) { switch (building) { // Teutons case BuildingEnum.EarthWall: // Romans case BuildingEnum.CityWall: // Gauls case BuildingEnum.Palisade: // Egyptians case BuildingEnum.StoneWall: // Huns case BuildingEnum.MakeshiftWall: return(true); default: return(false); } }
//factory pattern public void CreateBuilding(BuildingEnum buildingType, Vector3 position) { switch (buildingType) { case BuildingEnum.RedBuilding: allBuildings.Add(new RedBuilding(position)); break; case BuildingEnum.BlueBuildinng: allBuildings.Add(new BlueBuilding(position)); break; case BuildingEnum.GreenBuilding: allBuildings.Add(new GreenBuilding(position)); break; case BuildingEnum.YellowBuilding: allBuildings.Add(new YellowBuilding(position)); break; } }
/// <summary> /// Gets the highest level a building can be on /// </summary> /// <param name="building">Building</param> /// <returns>Max level</returns> public static int MaxBuildingLevel(Account acc, BuildingEnum building) { switch (building) { case BuildingEnum.Brewery: switch (acc.AccInfo.ServerVersion) { case ServerVersionEnum.T4_4: return(10); default: return(20); } case BuildingEnum.Bakery: case BuildingEnum.Brickyard: case BuildingEnum.IronFoundry: case BuildingEnum.GrainMill: case BuildingEnum.Sawmill: return(5); case BuildingEnum.Cranny: return(10); default: return(20); } }
/// <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 bool BuildBuilding(BuildingEnum type) { var purchase = playerState.playerPurchases.Get(type); return(purchase.IsActive(null) && purchase.Do(null)); }
public override async Task <TaskRes> Execute(Account acc) { building = TroopsHelper.GetTroopBuilding(Troop, Great); // Switch hero helmet. If hero will be switched, this TrainTroops task // will be executed right after the hero helmet switch if (HeroHelper.SwitchHelmet(acc, this.Vill, building, this)) { return(TaskRes.Executed); } await base.Execute(acc); if (!await VillageHelper.EnterBuilding(acc, Vill, building)) { return(TaskRes.Executed); } if (this.UpdateOnly || this.Troop == TroopsEnum.None) { return(TaskRes.Executed); } (TimeSpan dur, Resources cost) = TroopsParser.GetTrainCost(acc.Wb.Html, this.Troop); var troopNode = acc.Wb.Html.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)Troop)); if (troopNode == null) { acc.Wb.Log($"Bot tried to train {Troop} in {Vill.Name}, but couldn't find it in {building}! Are you sure you have {Troop} researched?"); return(TaskRes.Executed); } while (!troopNode.HasClass("details")) { troopNode = troopNode.ParentNode; } var inputName = troopNode.Descendants("input").FirstOrDefault().GetAttributeValue("name", ""); long maxNum = 0; switch (acc.AccInfo.ServerVersion) { case ServerVersionEnum.T4_4: maxNum = Parser.RemoveNonNumeric( troopNode.ChildNodes .FirstOrDefault(x => x.Name == "a")?.InnerText ?? "0" ); break; case ServerVersionEnum.T4_5: maxNum = Parser.RemoveNonNumeric( troopNode.ChildNodes .First(x => x.HasClass("cta")) .ChildNodes .First(x => x.Name == "a") .InnerText); break; } if (!HighSpeedServer) { var trainNum = TroopsHelper.TroopsToFill(acc, Vill, this.Troop, this.Great); // Don't train too many troops, just fill up the training building if (maxNum > trainNum) { maxNum = trainNum; } } if (maxNum < 0) { // We have already enough troops in training. return(TaskRes.Executed); } acc.Wb.Driver.ExecuteScript($"document.getElementsByName('{inputName}')[0].value='{maxNum}'"); await Task.Delay(100); await DriverHelper.ExecuteScript(acc, "document.getElementsByName('s1')[0].click()"); UpdateCurrentlyTraining(acc.Wb.Html, acc); if (!HighSpeedServer) { RepeatTrainingCycle(acc.Wb.Html, acc); } return(TaskRes.Executed); }
public override async Task <TaskRes> Execute(HtmlDocument htmlDoc, ChromeDriver wb, Files.Models.AccModels.Account acc) { building = TroopsHelper.GetTroopBuilding(Troop, Great); var buildId = vill.Build.Buildings.FirstOrDefault(x => x.Type == building); if (buildId == null) { //update dorf, no buildingId found? TaskExecutor.AddTask(acc, new UpdateDorf2() { ExecuteAt = DateTime.Now, vill = vill }); Console.WriteLine($"There is no {building} in this village!"); return(TaskRes.Executed); } await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={buildId.Id}"); //after finishing task, update currently training this.PostTaskCheck.Add(UpdateCurrentlyTraining); if (!HighSpeedServer) { this.PostTaskCheck.Add(RepeatTrainingCycle); } if (this.UpdateOnly || this.Troop == TroopsEnum.None) { return(TaskRes.Executed); } (TimeSpan dur, Resources cost) = TroopsParser.GetTrainCost(htmlDoc, this.Troop); var troopNode = htmlDoc.DocumentNode.Descendants("img").FirstOrDefault(x => x.HasClass("u" + (int)Troop)); while (!troopNode.HasClass("details")) { troopNode = troopNode.ParentNode; } var inputName = troopNode.Descendants("input").FirstOrDefault().GetAttributeValue("name", ""); var maxNum = Parser.RemoveNonNumeric(troopNode.ChildNodes.FirstOrDefault(x => x.Name == "a").InnerText); if (!HighSpeedServer) { var trainNum = TroopsHelper.TroopsToFill(acc, vill, this.Troop, this.Great); // Don't train too many troops, just fill up the training building if (maxNum > trainNum) { maxNum = trainNum; } } if (maxNum < 0) { // We have already enough troops in training. return(TaskRes.Executed); } wb.ExecuteScript($"document.getElementsByName('{inputName}')[0].value='{maxNum}'"); await Task.Delay(100); wb.ExecuteScript("document.getElementsByName('s1')[0].click()"); //Train button return(TaskRes.Executed); }
private void CmdCreateTempBuilding(BuildingEnum buildingType) { var tempBuilding = factory.CreateTemporaryMainBuilding(netId, buildingType); NetworkServer.SpawnWithClientAuthority(tempBuilding.gameObject, gameObject); }
/// <summary> /// Creates the temporary building of given type. /// </summary> /// <param name="buildingType">type of the building</param> public void CreateTempBuilding(BuildingEnum buildingType) => CmdCreateTempBuilding(buildingType);
public void CmdCreateBuilding(NetworkInstanceId tempBuildingID, BuildingEnum buildingType) { GameState.Instance.RpcCreateBuilding(tempBuildingID, buildingType); }
private static bool BuildingIsOnLevel(BuildingEnum building, int lvl, Village vill) { //if there already is a building on specific level or there is a task for this building // TODO: change FristOrDefault to Any return(vill.Build.Buildings.FirstOrDefault(x => x.Level == lvl && x.Type == building) != null || vill.Build.Tasks.FirstOrDefault(x => x.Level == lvl && x.Building == building) != null); }