Exemplo n.º 1
0
        private static async Task RunCountryPolicyAsync(MainRepository repo, Country country, CountryPolicyType type)
        {
            if (type == CountryPolicyType.TotalMobilization || type == CountryPolicyType.TotalMobilization2)
            {
                foreach (var chara in await repo.Country.GetCharactersAsync(country.Id))
                {
                    chara.SoldierNumber = chara.Leadership;
                    chara.Proficiency   = 100;
                    var formation = await repo.Character.GetFormationAsync(chara.Id, chara.FormationType);

                    formation.Experience += 5000;
                    await CharacterService.StreamCharacterAsync(repo, chara);

                    await StatusStreaming.Default.SendCharacterAsync(ApiData.From(formation), chara.Id);
                }
                await LogService.AddMapLogAsync(repo, true, EventType.Policy, $"<country>{country.Name}</country> は、国民総動員を発動しました");
            }
            else if (type == CountryPolicyType.TotalMobilizationWall || type == CountryPolicyType.TotalMobilizationWall2)
            {
                foreach (var town in await repo.Town.GetByCountryIdAsync(country.Id))
                {
                    town.Technology = town.TechnologyMax;
                    town.Wall       = town.WallMax;
                    await StatusStreaming.Default.SendTownToAllAsync(ApiData.From(town), repo);
                }
                await LogService.AddMapLogAsync(repo, true, EventType.Policy, $"<country>{country.Name}</country> は、城壁作業員総動員を発動しました");
            }
            else if (type == CountryPolicyType.Austerity || type == CountryPolicyType.Austerity2)
            {
                foreach (var chara in await repo.Country.GetCharactersAsync(country.Id))
                {
                    chara.Money += 20_0000;
                    await CharacterService.StreamCharacterAsync(repo, chara);
                }
                await LogService.AddMapLogAsync(repo, true, EventType.Policy, $"<country>{country.Name}</country> は、緊縮財政を発動しました");
            }

            var info = CountryPolicyTypeInfoes.Get(type);

            if (info.HasData && info.Data.Effects.Any(e => e.Type == CountryPolicyEffectType.SubBuildingSizeMax))
            {
                country.TownSubBuildingExtraSpace +=
                    (short)info.Data.Effects
                    .Where(e => e.Type == CountryPolicyEffectType.SubBuildingSizeMax)
                    .Sum(e => e.Value);
            }
        }
Exemplo n.º 2
0
        public static async Task <bool> SetPolicyAndSaveAsync(MainRepository repo, Country country, CountryPolicyType type, CountryPolicyStatus status = CountryPolicyStatus.Available, bool isCheckSubjects = true)
        {
            return(true);

            var info = CountryPolicyTypeInfoes.Get(type);

            if (!info.HasData)
            {
                return(false);
            }

            var policies = await repo.Country.GetPoliciesAsync(country.Id);

            var old = policies.FirstOrDefault(p => p.Type == type);

            if (old != null && old.Status == CountryPolicyStatus.Available)
            {
                return(false);
            }
            var oldStatus = old?.Status ?? CountryPolicyStatus.Unadopted;

            if (status == CountryPolicyStatus.Available && country.PolicyPoint < info.Data.GetRequestedPoint(oldStatus))
            {
                return(false);
            }

            if (isCheckSubjects && info.Data.SubjectAppear != null && !info.Data.SubjectAppear(policies.Where(p => p.Status == CountryPolicyStatus.Available).Select(p => p.Type)))
            {
                return(false);
            }

            var system = await repo.System.GetAsync();

            var param = new CountryPolicy
            {
                CountryId = country.Id,
                Status    = status,
                Type      = type,
                GameDate  = system.GameDateTime.Year >= Config.UpdateStartYear ? system.GameDateTime : new GameDateTime {
                    Year = Config.UpdateStartYear, Month = 1,
                },
            };

            if (status == CountryPolicyStatus.Available)
            {
                country.PolicyPoint -= info.Data.GetRequestedPoint(oldStatus);

                if (info.Data.AvailableDuring > 0)
                {
                    status = param.Status = CountryPolicyStatus.Availabling;
                }

                // 採用した瞬間に効果を発揮する政策
                await RunCountryPolicyAsync(repo, country, type);
            }
            if (old != null)
            {
                repo.Country.RemovePolicy(old);
            }
            await repo.Country.AddPolicyAsync(param);

            await repo.SaveChangesAsync();

            await StatusStreaming.Default.SendCountryAsync(ApiData.From(param), country.Id);

            await StatusStreaming.Default.SendCountryAsync(ApiData.From(country), country.Id);

            await StatusStreaming.Default.SendAllAsync(ApiData.From(new CountryForAnonymous(country)));

            foreach (CountryPolicyType boostType in info.Data.Effects.Where(e => e.Type == CountryPolicyEffectType.BoostWith).Select(e => e.Value))
            {
                var boostInfo = CountryPolicyTypeInfoes.Get(boostType);
                if (boostInfo.HasData)
                {
                    await SetPolicyAndSaveAsync(repo, country, boostType, CountryPolicyStatus.Boosted);
                }
            }

            return(true);
        }