From 85b89ac6d611014d9d46609152b37cdbbb4df330 Mon Sep 17 00:00:00 2001 From: milimoe Date: Thu, 25 Dec 2025 19:38:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B4=BB=E5=8A=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E5=8F=AA=E8=83=BD=E5=AE=8C=E6=88=90=E4=B8=8D=E8=83=BD?= =?UTF-8?q?=E7=BB=93=E7=AE=97=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=B9=B6?= =?UTF-8?q?=E5=B0=86=E5=85=B6=E5=92=8C=E4=BB=BB=E5=8A=A1=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaServers/Service/FunGameService.cs | 198 ++++++++++++------ OshimaWebAPI/Controllers/FunGameController.cs | 2 + 2 files changed, 140 insertions(+), 60 deletions(-) diff --git a/OshimaServers/Service/FunGameService.cs b/OshimaServers/Service/FunGameService.cs index 808dd29..5a96c09 100644 --- a/OshimaServers/Service/FunGameService.cs +++ b/OshimaServers/Service/FunGameService.cs @@ -2006,7 +2006,32 @@ namespace Oshima.FunGame.OshimaServers.Service result = true; } } - if (UserExploreItemCache.TryGetValue(user.Id, out List? value) && value != null && value.Count > 0) + if (UserExploreCharacterCache.TryGetValue(user.Id, out List? value) && value != null && value.Count > 0) + { + List willRemove = []; + string[] itemsLoop = [.. value.Distinct()]; + foreach (string item in itemsLoop) + { + IEnumerable items = value.Where(str => str == item); + IEnumerable progressiveQuests = quests.Where(q => q.QuestType == QuestType.Progressive && q.Status == QuestState.InProgress); + foreach (Quest quest in progressiveQuests) + { + if (quest.NeedyExploreCharacterName == item) + { + result = true; + quest.Progress += items.Count(); + if (quest.Progress >= quest.MaxProgress) + { + quest.Progress = quest.MaxProgress; + quest.Status = QuestState.Completed; + } + } + } + willRemove.Add(item); + } + value.RemoveAll(willRemove.Contains); + } + if (UserExploreItemCache.TryGetValue(user.Id, out value) && value != null && value.Count > 0) { // 从缓存中获取收集的物品 List willRemove = []; @@ -2032,6 +2057,31 @@ namespace Oshima.FunGame.OshimaServers.Service } value.RemoveAll(willRemove.Contains); } + if (UserExploreEventCache.TryGetValue(user.Id, out value) && value != null && value.Count > 0) + { + List willRemove = []; + string[] itemsLoop = [.. value.Distinct()]; + foreach (string item in itemsLoop) + { + IEnumerable items = value.Where(str => str == item); + IEnumerable progressiveQuests = quests.Where(q => q.QuestType == QuestType.Progressive && q.Status == QuestState.InProgress); + foreach (Quest quest in progressiveQuests) + { + if (quest.NeedyExploreEventName == item) + { + result = true; + quest.Progress += items.Count(); + if (quest.Progress >= quest.MaxProgress) + { + quest.Progress = quest.MaxProgress; + quest.Status = QuestState.Completed; + } + } + } + willRemove.Add(item); + } + value.RemoveAll(willRemove.Contains); + } IEnumerable finishQuests = quests.Where(q => q.Status == QuestState.Completed && !q.Global); foreach (Quest quest in finishQuests) { @@ -2067,6 +2117,18 @@ namespace Oshima.FunGame.OshimaServers.Service return result; } + public static void AddExploreCharacterCache(long userid, string character) + { + if (UserExploreCharacterCache.TryGetValue(userid, out List? value) && value != null) + { + value.Add(character); + } + else + { + UserExploreCharacterCache[userid] = [character]; + } + } + public static void AddExploreItemCache(long userid, string item) { if (UserExploreItemCache.TryGetValue(userid, out List? value) && value != null) @@ -2079,6 +2141,18 @@ namespace Oshima.FunGame.OshimaServers.Service } } + public static void AddExploreEventCache(long userid, string e) + { + if (UserExploreEventCache.TryGetValue(userid, out List? value) && value != null) + { + value.Add(e); + } + else + { + UserExploreEventCache[userid] = [e]; + } + } + public static string CheckDailyStore(EntityModuleConfig stores, User user) { Store? daily = stores.Get("daily"); @@ -2448,11 +2522,6 @@ namespace Oshima.FunGame.OshimaServers.Service { return "当前没有任何活动,敬请期待。"; } - EntityModuleConfig userActivities = new("activities", user?.Id.ToString() ?? ""); - if (user != null) - { - userActivities.LoadConfig(); - } lock (Activities) { Activities.Clear(); @@ -2461,10 +2530,6 @@ namespace Oshima.FunGame.OshimaServers.Service { activity.UpdateState(); Activities.Add(activity); - if (user != null) - { - update = AddEventActivity(activity, userActivities); - } } if (ActivitiesCharacterCache.Count > 0) { @@ -2475,8 +2540,6 @@ namespace Oshima.FunGame.OshimaServers.Service { IEnumerable items = ActivitiesCharacterCache.Where(str => str == item); IEnumerable quests = activityList.SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - IEnumerable userQuests = userActivities.Values.Where(a => a.Status == ActivityState.InProgress).SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - quests = [.. quests, .. userQuests]; foreach (Quest quest in quests) { if (quest.NeedyExploreCharacterName == item) @@ -2503,8 +2566,6 @@ namespace Oshima.FunGame.OshimaServers.Service { IEnumerable items = ActivitiesItemCache.Where(str => str == item); IEnumerable quests = activityList.SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - IEnumerable userQuests = userActivities.Values.Where(a => a.Status == ActivityState.InProgress).SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - quests = [.. quests, .. userQuests]; foreach (Quest quest in quests) { if (quest.NeedyExploreItemName == item) @@ -2531,8 +2592,6 @@ namespace Oshima.FunGame.OshimaServers.Service { IEnumerable items = ActivitiesEventCache.Where(str => str == item); IEnumerable quests = activityList.SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - IEnumerable userQuests = userActivities.Values.Where(a => a.Status == ActivityState.InProgress).SelectMany(a => a.Quests).Where(q => q.Status == QuestState.InProgress); - quests = [.. quests, .. userQuests]; foreach (Quest quest in quests) { if (quest.NeedyExploreEventName == item) @@ -2561,7 +2620,6 @@ namespace Oshima.FunGame.OshimaServers.Service activities.Add(activity.Id.ToString(), activity); } activities.SaveConfig(); - userActivities.SaveConfig(); } } StringBuilder builder = new(); @@ -2636,6 +2694,49 @@ namespace Oshima.FunGame.OshimaServers.Service return "该活动已删除!"; } + public static bool AddEventActivity(Activity activity, EntityModuleConfig userActivities) + { + if (activity.Id == 7 && activity.Status == ActivityState.InProgress) + { + // 为用户生成或更新活动专属任务 + Activity newActivity; + if (userActivities.Values.FirstOrDefault(a => a.Id == activity.Id) is Activity userActivity) + { + newActivity = userActivity; + } + else + { + newActivity = new(activity.Id, "糖糖一周年纪念活动", new DateTime(2025, 12, 25, 4, 0, 0), new DateTime(2026, 1, 4, 3, 59, 59)) + { + Description = "在活动期间,累计消耗 360 个探索许可即可领取【一周年纪念礼包】,打开后获得金币、钻石奖励以及【一周年纪念套装】(包含武器粉糖雾蝶 * 1,防具糖之誓约 * 1,鞋子蜜步流心 * 1,饰品回忆糖纸 * 1,饰品蜂糖蜜酿 * 1)!自2024年12月进入上线前的测试阶段起,糖糖已经陪我们走过了第一个年头,放眼未来,糖糖将为我们带来更多快乐。" + }; + } + if (!newActivity.Quests.Any(q => q.Id == 1)) + { + Quest newQuest = new() + { + Id = 1, + Name = "糖糖一周年纪念", + Description = "消耗 360 个探索许可(即参与探索玩法、秘境挑战)。", + NeedyExploreEventName = "消耗探索许可", + CreditsAward = 10000, + Awards = [ + new 一周年纪念礼包() + ], + AwardsCount = new() { + { "一周年纪念礼包", 1 } + }, + QuestType = QuestType.Progressive, + MaxProgress = 360 + }; + newActivity.Quests.Add(newQuest); + userActivities.Add(newActivity.Id.ToString(), newActivity); + return true; + } + } + return false; + } + public static string GetSquadInfo(IEnumerable inventory, IEnumerable squadIds, string separator = "\r\n") { Character[] squad = [.. inventory.Where(c => squadIds.Contains(c.Id))]; @@ -4932,49 +5033,6 @@ namespace Oshima.FunGame.OshimaServers.Service return builder.ToString().Trim(); } - public static bool AddEventActivity(Activity activity, EntityModuleConfig userActivities) - { - if (activity.Id == 7 && activity.Status == ActivityState.InProgress) - { - // 为用户生成或更新活动专属任务 - Activity newActivity; - if (userActivities.Values.FirstOrDefault(a => a.Id == activity.Id) is Activity userActivity) - { - newActivity = userActivity; - } - else - { - newActivity = new(activity.Id, "糖糖一周年纪念活动", new DateTime(2025, 12, 25, 4, 0, 0), new DateTime(2026, 1, 4, 3, 59, 59)) - { - Description = "在活动期间,累计消耗 360 个探索许可即可领取【一周年纪念礼包】,打开后获得金币、钻石奖励以及【一周年纪念套装】(包含武器粉糖雾蝶 * 1,防具糖之誓约 * 1,鞋子蜜步流心 * 1,饰品回忆糖纸 * 1,饰品蜂糖蜜酿 * 1)!自2024年12月进入上线前的测试阶段起,糖糖已经陪我们走过了第一个年头,放眼未来,糖糖将为我们带来更多快乐。" - }; - } - if (!newActivity.Quests.Any(q => q.Id == 1)) - { - Quest newQuest = new() - { - Id = 1, - Name = "糖糖一周年纪念", - Description = "消耗 360 个探索许可(即参与探索玩法、秘境挑战)。", - NeedyExploreEventName = "消耗探索许可", - CreditsAward = 10000, - Awards = [ - new 一周年纪念礼包() - ], - AwardsCount = new() { - { "一周年纪念礼包", 1 } - }, - QuestType = QuestType.Progressive, - MaxProgress = 360 - }; - newActivity.Quests.Add(newQuest); - userActivities.Add(newActivity.Id.ToString(), newActivity); - return true; - } - } - return false; - } - public static void RefreshNotice() { Notices.LoadConfig(); @@ -5044,6 +5102,26 @@ namespace Oshima.FunGame.OshimaServers.Service quests.SaveConfig(); updateQuest = true; } + EntityModuleConfig userActivities = new("activities", user.Id.ToString()); + userActivities.LoadConfig(); + foreach (Activity activity in Activities) + { + if (AddEventActivity(activity, userActivities)) + { + updateQuest = true; + } + } + foreach (Activity activity in userActivities.Values) + { + if (SettleQuest(user, activity.Quests, activity)) + { + updateQuest = true; + } + } + if (updateQuest) + { + userActivities.SaveConfig(); + } // 探索结算 PluginConfig pc2 = new("exploring", user.Id.ToString()); pc2.LoadConfig(); diff --git a/OshimaWebAPI/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs index d3d6009..3aaaafa 100644 --- a/OshimaWebAPI/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -6162,6 +6162,7 @@ namespace Oshima.FunGame.WebAPI.Controllers pc.Add("exploreTimes", exploreTimes); for (int useCount = 0; useCount < reduce; useCount++) { + FunGameService.AddExploreEventCache(user.Id, "消耗探索许可"); FunGameService.ActivitiesEventCache.Add("消耗探索许可"); } FunGameService.SetUserConfigAndReleaseSemaphoreSlim(userid, pc, user); @@ -7950,6 +7951,7 @@ namespace Oshima.FunGame.WebAPI.Controllers pc.Add("exploreTimes", exploreTimes); for (int useCount = 0; useCount < reduce; useCount++) { + FunGameService.AddExploreEventCache(user.Id, "消耗探索许可"); FunGameService.ActivitiesEventCache.Add("消耗探索许可"); } }