Пример #1
0
        public static async Task SendWarAndSaveAsync(MainRepository repo, CountryWar war)
        {
            MapLog mapLog = null;

            await repo.CountryDiplomacies.SetWarAsync(war);

            if ((war.Status == CountryWarStatus.InReady && war.RequestedStopCountryId == 0) || war.Status == CountryWarStatus.Stoped)
            {
                // 戦争を周りに通知
                var country1 = await repo.Country.GetAliveByIdAsync(war.RequestedCountryId).GetOrErrorAsync(ErrorCode.CountryNotFoundError);

                var country2 = await repo.Country.GetAliveByIdAsync(war.InsistedCountryId).GetOrErrorAsync(ErrorCode.CountryNotFoundError);

                mapLog = new MapLog
                {
                    ApiGameDateTime = (await repo.System.GetAsync()).GameDateTime,
                    Date            = DateTime.Now,
                    IsImportant     = true,
                };
                if (war.Status == CountryWarStatus.InReady)
                {
                    if (war.RequestedStopCountryId == 0)
                    {
                        mapLog.EventType = EventType.WarInReady;
                        if (war.Mode == CountryWarMode.Religion)
                        {
                            mapLog.Message = "<country>" + country1.Name + "</country> は、<date>" + war.StartGameDate.ToString() + "</date> より <country>" + country2.Name + "</country> と宗教戦争を開始します";
                        }
                        else
                        {
                            mapLog.Message = "<country>" + country1.Name + "</country> は、<date>" + war.StartGameDate.ToString() + "</date> より <country>" + country2.Name + "</country> へ侵攻します";
                        }
                        await PushNotificationService.SendCountryAsync(repo, "宣戦布告", $"{war.StartGameDate.ToString()} より {country2.Name} と戦争します", country1.Id);

                        await PushNotificationService.SendCountryAsync(repo, "宣戦布告", $"{war.StartGameDate.ToString()} より {country1.Name} と戦争します", country2.Id);
                    }
                }
                else if (war.Status == CountryWarStatus.Stoped)
                {
                    mapLog.EventType = EventType.WarStopped;
                    mapLog.Message   = "<country>" + country1.Name + "</country> と <country>" + country2.Name + "</country> の戦争は停戦しました";
                    await PushNotificationService.SendCountryAsync(repo, "停戦", $"{country2.Name} との戦争は停戦しました", country1.Id);

                    await PushNotificationService.SendCountryAsync(repo, "停戦", $"{country1.Name} との戦争は停戦しました", country2.Id);
                }
                await repo.MapLog.AddAsync(mapLog);
            }

            await repo.SaveChangesAsync();

            await StatusStreaming.Default.SendAllAsync(ApiData.From(war));

            if (mapLog != null)
            {
                await StatusStreaming.Default.SendAllAsync(ApiData.From(mapLog));

                await AnonymousStreaming.Default.SendAllAsync(ApiData.From(mapLog));
            }
        }
Пример #2
0
        public static async Task UnifyCountryAsync(MainRepository repo, Country country)
        {
            if (country != null)
            {
                await LogService.AddMapLogAsync(repo, true, EventType.Unified, "大陸は、<country>" + country.Name + "</country> によって統一されました");

                await ResetService.RequestResetAsync(repo, country.Id);
            }
            else
            {
                await ResetService.RequestResetAsync(repo, 0);
            }

            await repo.SaveChangesAsync();

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

            if (country != null)
            {
                await PushNotificationService.SendAllAsync(repo, "統一", $"{country.Name} は、大陸を統一しました。ゲームは {system.ResetGameDateTime.ToString()} にリセットされます");
            }
        }
Пример #3
0
        public static async Task OverThrowAsync(MainRepository repo, Country country, Country winnerCountry, bool isLog = true)
        {
            var system = await repo.System.GetAsync();

            country.HasOverthrown      = true;
            country.OverthrownGameDate = system.GameDateTime;

            if (isLog)
            {
                await LogService.AddMapLogAsync(repo, true, EventType.Overthrown, $"<country>{country.Name}</country> は滅亡しました");
            }

            // 戦争勝利ボーナス

            /*
             * var wars = (await repo.CountryDiplomacies.GetAllWarsAsync()).Where(w => w.IsJoin(country.Id));
             * foreach (var war in wars)
             * {
             * var targetId = war.GetEnemy(country.Id);
             * var target = winnerCountry?.Id == targetId ? winnerCountry : (await repo.Country.GetAliveByIdAsync(targetId)).Data;
             * if (target != null)
             * {
             *  var characterCount = war.RequestedCountryId == country.Id ? war.RequestedCountryCharacterMax : war.InsistedCountryCharacterMax;
             *  target.SafeMoney += characterCount * 16_0000;
             *  target.SafeMoney = Math.Min(target.SafeMoney, GetCountrySafeMax((await repo.Country.GetPoliciesAsync(target.Id)).Select(p => p.Type)));
             *  await StatusStreaming.Default.SendCountryAsync(ApiData.From(target), target.Id);
             * }
             * }
             */

            var targetCountryCharacters = await repo.Character.RemoveCountryAsync(country.Id);

            repo.Unit.RemoveUnitsByCountryId(country.Id);
            repo.Reinforcement.RemoveByCountryId(country.Id);
            repo.ChatMessage.RemoveByCountryId(country.Id);
            repo.CountryDiplomacies.RemoveByCountryId(country.Id);
            repo.Country.RemoveDataByCountryId(country.Id);

            // 玉璽
            if (winnerCountry != null)
            {
                if (country.GyokujiStatus != CountryGyokujiStatus.NotHave && country.GyokujiStatus != CountryGyokujiStatus.Refused)
                {
                    if (winnerCountry.GyokujiStatus == CountryGyokujiStatus.NotHave || winnerCountry.GyokujiStatus == CountryGyokujiStatus.Refused)
                    {
                        winnerCountry.IntGyokujiGameDate = system.IntGameDateTime;
                        if (!system.IsBattleRoyaleMode)
                        {
                            await LogService.AddMapLogAsync(repo, true, EventType.Gyokuji, $"<country>{winnerCountry.Name}</country> は玉璽を手に入れました");
                        }
                    }

                    if (winnerCountry.GyokujiStatus != CountryGyokujiStatus.HasGenuine)
                    {
                        winnerCountry.GyokujiStatus = country.GyokujiStatus;
                    }
                    country.GyokujiStatus = CountryGyokujiStatus.NotHave;
                    await StatusStreaming.Default.SendAllExceptForCountryAsync(ApiData.From(new CountryForAnonymous(winnerCountry)), winnerCountry.Id);

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

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

            await AnonymousStreaming.Default.SendAllAsync(ApiData.From(country));

            await AiService.CheckManagedReinforcementsAsync(repo, country.Id);

            // 援軍データをいじって、無所属武将一覧で援軍情報を表示できるようにする
            var reinforcements = await repo.Reinforcement.GetByCountryIdAsync(country.Id);

            foreach (var rein in reinforcements.Where(r => r.RequestedCountryId == country.Id))
            {
                rein.RequestedCountryId = 0;
                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(rein), rein.CharacterId);
            }

            // 滅亡国武将に通知
            var commanders = new CountryMessage
            {
                Type      = CountryMessageType.Commanders,
                Message   = string.Empty,
                CountryId = 0,
            };

            foreach (var targetCountryCharacter in await repo.Country.GetCharactersAsync(country.Id))
            {
                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(targetCountryCharacter), targetCountryCharacter.Id);

                await StatusStreaming.Default.SendCharacterAsync(ApiData.From(commanders), targetCountryCharacter.Id);
            }
            await PushNotificationService.SendCountryAsync(repo, "滅亡", "あなたの国は滅亡しました。どこかの国に仕官するか、登用に応じることでゲームを続行できます", country.Id);

            // 登用分を無効化
            await ChatService.DenyCountryPromotions(repo, country);

            StatusStreaming.Default.UpdateCache(targetCountryCharacters);
            await repo.SaveChangesAsync();

            var allTowns = await repo.Town.GetAllAsync();

            var allCountries = await repo.Country.GetAllAsync();

            var townAiMap    = allTowns.Join(allCountries, t => t.CountryId, c => c.Id, (t, c) => new { CountryId = c.Id, c.AiType, });
            var humanCountry = townAiMap.FirstOrDefault(t => t.AiType != CountryAiType.Terrorists);

            if (allTowns.All(t => t.CountryId > 0) &&
                townAiMap.All(t => t.CountryId == humanCountry.CountryId || t.AiType == CountryAiType.Terrorists))
            {
                if (!system.IsWaitingReset)
                {
                    var unifiedCountry = humanCountry != null?allCountries.FirstOrDefault(c => c.Id == humanCountry.CountryId) : allCountries.FirstOrDefault(c => !c.HasOverthrown);

                    if (unifiedCountry != null)
                    {
                        await UnifyCountryAsync(repo, unifiedCountry);
                    }
                }
            }
        }