public override async Task <TaskRes> Execute(Account acc) { await base.Execute(acc); // Navigate to dorf2 var townHall = Vill.Build .Buildings .FirstOrDefault(x => x.Type == Classificator.BuildingEnum.TownHall); if (townHall == null) { return(TaskRes.Executed); } await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/build.php?id={townHall.Id}"); var celebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); if (DateTime.Now <= celebrationEnd) { // We already have a celebration running Vill.Expansion.CelebrationEnd = celebrationEnd; this.NextExecute = celebrationEnd; return(TaskRes.Executed); } var bigCeleb = Vill.Expansion.Celebrations == CelebrationEnum.Big && 10 <= townHall.Level; // Check if enough resources to start a celebration if (!MiscCost.EnoughResForCelebration(Vill, bigCeleb)) { ResourcesHelper.NotEnoughRes(acc, Vill, MiscCost.CelebrationCost(bigCeleb), this); return(TaskRes.Executed); } await StartCelebration(acc, bigCeleb); // Post task check for celebration duration Vill.Expansion.CelebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); if (Vill.Expansion.Celebrations != CelebrationEnum.None) { this.NextExecute = Vill.Expansion.CelebrationEnd; } return(TaskRes.Executed); }
public override async Task <TaskRes> Execute(Account acc) { if (!await VillageHelper.EnterBuilding(acc, Vill, Classificator.BuildingEnum.TownHall)) { return(TaskRes.Executed); } var celebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); if (DateTime.Now <= celebrationEnd) { // We already have a celebration running Vill.Expansion.CelebrationEnd = celebrationEnd; this.NextExecute = celebrationEnd; return(TaskRes.Executed); } var buildingNode = acc.Wb.Html.GetElementbyId("build"); (_, var level) = InfrastructureParser.UpgradeBuildingGetInfo(buildingNode); var bigCeleb = Vill.Expansion.Celebrations == CelebrationEnum.Big && 10 <= level; // Check if enough resources to start a celebration if (!MiscCost.EnoughResForCelebration(Vill, bigCeleb)) { ResourcesHelper.NotEnoughRes(acc, Vill, MiscCost.CelebrationCost(bigCeleb), this); return(TaskRes.Executed); } await StartCelebration(acc, bigCeleb); // Post task check for celebration duration Vill.Expansion.CelebrationEnd = TimeParser.GetCelebrationTime(acc.Wb.Html); if (Vill.Expansion.Celebrations != CelebrationEnum.None) { this.NextExecute = Vill.Expansion.CelebrationEnd; } return(TaskRes.Executed); }
public override async Task <TaskRes> Execute(Account acc) { TaskExecutor.RemoveSameTasksForVillage(acc, Vill, typeof(UpdateDorf1), this); TaskExecutor.RemoveSameTasksForVillage(acc, Vill, typeof(UpdateDorf2), this); await acc.Wb.Navigate($"{acc.AccInfo.ServerUrl}/dorf1.php"); // Update dorf1 await Task.Delay(AccountHelper.Delay()); 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()); await UpdateTroopsTraining(acc); var firstTroop = TroopsHelper.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); }