コード例 #1
0
        /// <summary>
        /// Initializes a new village model and creates the task to update the village
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="newVill">new village</param>
        public static void NewVillageFound(Account acc, VillageChecked newVill)
        {
            var vill = new Village()
            {
                Active          = newVill.Active,
                Coordinates     = newVill.Coordinates,
                Id              = newVill.Id,
                Name            = newVill.Name,
                UnderAttack     = newVill.UnderAttack,
                UnfinishedTasks = new List <VillUnfinishedTask>() // Move this inside Init()?
            };

            vill.Init(acc);
            acc.Villages.Add(vill);

            // Update the village
            TaskExecutor.AddTaskIfNotExistInVillage(acc, vill, new UpdateVillage()
            {
                ExecuteAt   = DateTime.Now.AddHours(-2),
                Vill        = vill,
                ImportTasks = true
            });

            DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill);

            // Copy default settings to the new village. TODO: use automapper for this.
            //var defaultSettings = acc.NewVillages.DefaultSettings;
            //vill.Settings = new VillSettings()
            //{
            //    Type = defaultSettings.Type,
            //    BarracksTrain = defaultSettings.BarracksTrain,
            //    StableTrain = defaultSettings.StableTrain,
            //    WorkshopTrain = defaultSettings.WorkshopTrain,
            //    GreatBarracksTrain = defaultSettings.GreatBarracksTrain,
            //    GreatStableTrain = defaultSettings.GreatStableTrain,
            //    SendRes = defaultSettings.SendRes,
            //    GetRes = defaultSettings.GetRes,
            //};

            // Change village name
            var newVillageFromList = acc.NewVillages.Locations
                                     .FirstOrDefault(x =>
                                                     x.SettlersSent &&
                                                     x.Coordinates.x == vill.Coordinates.x &&
                                                     x.Coordinates.y == vill.Coordinates.y
                                                     );

            if (newVillageFromList != null)
            {
                if (string.IsNullOrEmpty(newVillageFromList.Name))
                {
                    newVillageFromList.Name = NewVillageHelper.GenerateName(acc);
                }
                acc.NewVillages.Locations.Remove(newVillageFromList);
                TaskExecutor.AddTaskIfNotExists(acc,
                                                new ChangeVillageName()
                {
                    ExecuteAt  = DateTime.Now,
                    ChangeList = new List <(int, string)> {
                        (vill.Id, newVillageFromList.Name)
                    }
                });
コード例 #2
0
        /// <summary>
        /// Initializes a new village model and creates the task to update the village
        /// </summary>
        /// <param name="acc">Account</param>
        /// <param name="newVill">new village</param>
        public static void NewVillageFound(Account acc, VillageChecked newVill)
        {
            var vill = new Village()
            {
                Active      = newVill.Active,
                Coordinates = newVill.Coordinates,
                Id          = newVill.Id,
                Name        = newVill.Name,
                UnderAttack = newVill.UnderAttack
            };

            vill.Init(acc);
            acc.Villages.Add(vill);

            //on new village set the tasks
            if (string.IsNullOrEmpty(acc.NewVillages.BuildingTasksLocationNewVillage))
            {
                DefaultConfigurations.FarmVillagePlan(acc, vill);
            }
            else
            {
                IoHelperCore.AddBuildTasksFromFile(acc, vill, acc.NewVillages.BuildingTasksLocationNewVillage);
            }

            DefaultConfigurations.SetDefaultTransitConfiguration(acc, vill);
            vill.Build.AutoBuildResourceBonusBuildings = true;
            vill.Troops.TroopToTrain = (Classificator.TroopsEnum)((int)(acc.AccInfo.Tribe ?? Classificator.TribeEnum.Any) * 10); //change to acc wide setting

            // Copy default settings to the new village. TODO: use automapper for this.
            var defaultSettings = acc.NewVillages.DefaultSettings;

            vill.Settings = new Models.Settings.VillSettings()
            {
                Type               = defaultSettings.Type,
                BarracksTrain      = defaultSettings.BarracksTrain,
                StableTrain        = defaultSettings.StableTrain,
                WorkshopTrain      = defaultSettings.WorkshopTrain,
                GreatBarracksTrain = defaultSettings.GreatBarracksTrain,
                GreatStableTrain   = defaultSettings.GreatStableTrain,
                SendRes            = defaultSettings.SendRes,
                GetRes             = defaultSettings.GetRes,
            };

            // Update the village
            UpdateDorfs(acc, vill);

            // Change village name
            var newVillageFromList = acc.NewVillages.Locations
                                     .FirstOrDefault(x =>
                                                     x.SettlersSent &&
                                                     x.coordinates.x == vill.Coordinates.x &&
                                                     x.coordinates.y == vill.Coordinates.y
                                                     );

            if (newVillageFromList != null)
            {
                if (string.IsNullOrEmpty(newVillageFromList.Name))
                {
                    newVillageFromList.Name = NewVillageHelper.GenerateName(acc);
                }
                acc.NewVillages.Locations.Remove(newVillageFromList);
                TaskExecutor.AddTaskIfNotExists(acc,
                                                new ChangeVillageName()
                {
                    ExecuteAt  = DateTime.Now,
                    ChangeList = new List <(int, string)> {
                        (vill.Id, newVillageFromList.Name)
                    }
                });