From f66dd7bc853a8e3e6af7ec4801f7c34da42de752 Mon Sep 17 00:00:00 2001 From: milimoe Date: Tue, 31 Dec 2024 02:26:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BB=BB=E5=8A=A1=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaCore/Controllers/FunGameController.cs | 99 ++++++++ OshimaCore/OshimaWebAPI.cs | 17 ++ OshimaCore/Utils/FunGameService.cs | 258 ++++++++++++++++++++ 3 files changed, 374 insertions(+) diff --git a/OshimaCore/Controllers/FunGameController.cs b/OshimaCore/Controllers/FunGameController.cs index 1da0e3d..ebec8f5 100644 --- a/OshimaCore/Controllers/FunGameController.cs +++ b/OshimaCore/Controllers/FunGameController.cs @@ -3383,6 +3383,105 @@ namespace Oshima.Core.Controllers } } + [HttpPost("checkquestlist")] + public string CheckQuestList([FromQuery] long? qq = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + PluginConfig pc2 = new("quests", userid.ToString()); + pc2.LoadConfig(); + string msg = FunGameService.CheckQuestList(pc2); + pc2.SaveConfig(); + + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + + return NetworkUtility.JsonSerialize(msg); + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + + [HttpPost("acceptquest")] + public string AcceptQuest([FromQuery] long? qq = null, [FromQuery] int? id = null) + { + long userid = qq ?? Convert.ToInt64("10" + Verification.CreateVerifyCode(VerifyCodeType.NumberVerifyCode, 11)); + int questid = id ?? 0; + + PluginConfig pc = new("saved", userid.ToString()); + pc.LoadConfig(); + + if (pc.Count > 0) + { + User user = FunGameService.GetUser(pc); + + string msg = ""; + PluginConfig pc2 = new("quests", userid.ToString()); + pc2.LoadConfig(); + if (pc2.Count > 0) + { + List quests = pc2.Get>("list") ?? []; + if (quests.Count > 0) + { + if (quests.FirstOrDefault(q => q.Status == 1) is Quest quest) + { + msg = $"你正在进行任务【{quest.Name}】,无法开始新任务!\r\n{quest}"; + } + else if (quests.FirstOrDefault(q => q.Id == questid) is Quest quest2) + { + if (quest2.Status != 0) + { + msg = $"这个任务正在进行中,或已经完成,不能重复做任务!"; + } + else + { + quest2.Status = 1; + pc2.Add("list", quests); + pc2.SaveConfig(); + msg = $"开始任务【{quest2.Name}】成功!\r\n任务信息如下:{quest2}\r\n预计完成时间:{DateTime.Now.AddMinutes(quest2.EstimatedMinutes).ToString(General.GeneralDateTimeFormatChinese)}"; + Milimoe.FunGame.Core.Api.Utility.TaskScheduler.Shared.AddTask($"{userid}-{quest2.Name}", TimeSpan.FromMinutes(quest2.EstimatedMinutes), () => + { + quest2.Status = 2; + }); + } + } + else + { + msg = $"没有找到序号为 {questid} 的任务!"; + } + } + else + { + msg = "任务列表为空,请等待刷新!"; + } + } + else + { + msg = "任务列表为空,请等待刷新!"; + } + + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); + + return NetworkUtility.JsonSerialize(msg); + } + else + { + return NetworkUtility.JsonSerialize(noSaved); + } + } + [HttpGet("reload")] public string Relaod([FromQuery] long? master = null) { diff --git a/OshimaCore/OshimaWebAPI.cs b/OshimaCore/OshimaWebAPI.cs index f04ef39..ff89189 100644 --- a/OshimaCore/OshimaWebAPI.cs +++ b/OshimaCore/OshimaWebAPI.cs @@ -83,6 +83,23 @@ namespace Oshima.Core.WebAPI Controller.WriteLine("璇诲彇 FunGame 瀛樻。缂撳瓨"); } }, true); + TaskScheduler.Shared.AddTask("鍒锋柊姣忔棩浠诲姟", new TimeSpan(4, 0, 0), () => + { + string directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/quests"; + if (Directory.Exists(directoryPath)) + { + string[] filePaths = Directory.GetFiles(directoryPath); + foreach (string filePath in filePaths) + { + string fileName = Path.GetFileNameWithoutExtension(filePath); + PluginConfig pc = new("quests", fileName); + pc.Clear(); + FunGameService.CheckQuestList(pc); + pc.SaveConfig(); + } + Controller.WriteLine("鍒锋柊姣忔棩浠诲姟"); + } + }); TaskScheduler.Shared.AddRecurringTask("鍒锋柊boss", TimeSpan.FromHours(1), () => { FunGameService.GenerateBoss(); diff --git a/OshimaCore/Utils/FunGameService.cs b/OshimaCore/Utils/FunGameService.cs index c3fdc1c..3cf8242 100644 --- a/OshimaCore/Utils/FunGameService.cs +++ b/OshimaCore/Utils/FunGameService.cs @@ -553,6 +553,42 @@ namespace Oshima.Core.Utils } } + // 浠诲姟缁撶畻 + PluginConfig pc2 = new("quests", user.Id.ToString()); + pc2.LoadConfig(); + if (pc2.Count > 0) + { + List quests = pc2.Get>("list") ?? []; + if (quests.Count > 0) + { + IEnumerable finishQuests = quests.Where(q => q.Status == 2); + foreach (Quest quest in finishQuests) + { + quest.Status = 3; + foreach (string name in quest.Awards.Keys) + { + if (name == General.GameplayEquilibriumConstant.InGameCurrency) + { + user.Inventory.Credits += quest.Awards[name]; + } + else if (name == General.GameplayEquilibriumConstant.InGameMaterial) + { + user.Inventory.Credits += quest.Awards[name]; + } + else if (AllItems.FirstOrDefault(i => i.Name == name) is Item item) + { + Item newItem = item.Copy(); + newItem.User = user; + SetSellAndTradeTime(newItem); + user.Inventory.Items.Add(newItem); + } + } + } + pc2.Add("list", quests); + pc2.SaveConfig(); + } + } + return user; } @@ -1480,6 +1516,176 @@ namespace Oshima.Core.Utils } } + public static Dictionary QuestList + { + get + { + return new() + { + { + "涓㈠け鐨勫叡浜崟杞︿箣璋", + "瀵绘壘琚瓟娉曚紶閫佽蛋鐨勫叡浜崟杞︺" + }, + { + "鍜栧暋搴楃殑绁炵椤惧", + "璋冩煡姣忓ぉ閮界偣濂囨ギ鍝佺殑绁炵椤惧銆" + }, + { + "鍦伴搧閲岀殑骞界伒涔樺", + "鎵惧嚭鍦ㄥ湴閾侀噷鍑烘病鐨勫崐閫忔槑涔樺銆" + }, + { + "鍏洯鐨勭簿鐏垫秱楦", + "娓呴櫎鍏洯閲岀獊鐒跺嚭鐜扮殑绮剧伒娑傞甫銆" + }, + { + "鎵嬫満淇″彿鐨勫共鎵版簮", + "鎵惧嚭骞叉壈鎵嬫満淇″彿鐨勯瓟娉曟簮澶淬" + }, + { + "澶栧崠灏忓摜鐨勫閬", + "甯姪澶栧崠灏忓摜鎵惧洖琚伔璧扮殑榄旀硶澶栧崠銆" + }, + { + "骞垮満鑸炵殑榄旀硶鑺傚", + "璋冩煡骞垮満鑸為煶涔愪腑闅愯棌鐨勯瓟娉曡妭濂忋" + }, + { + "鑷姩璐╁崠鏈虹殑绉樺瘑", + "鎵惧嚭鑷姩璐╁崠鏈洪噷绐佺劧鍑虹幇鐨勫鎬墿鍝併" + }, + { + "渚垮埄搴楃殑寮傛鍏冨叆鍙", + "璋冩煡渚垮埄搴楅噷绐佺劧鍑虹幇鐨勫紓娆″厓鍏ュ彛銆" + }, + { + "琛楀ご鑹轰汉鐨勯瓟娉曡〃婕", + "璋冩煡琛楀ご鑹轰汉琛ㄦ紨涓娇鐢ㄧ殑榄旀硶銆" + }, + { + "鍗堝鐢靛彴鐨勫菇鐏垫潵鐢", + "璋冩煡鍗堝鐢靛彴鏀跺埌鐨勫鎬潵鐢点" + }, + { + "楂樻ゼ澶у帵鐨勭瀵嗛氶亾", + "瀵绘壘闅愯棌鍦ㄩ珮妤煎ぇ鍘﹂噷鐨勭瀵嗛氶亾銆" + }, + { + "鍩庡競涓嬫按閬撶殑绁炵鐢熺墿", + "璋冩煡鍩庡競涓嬫按閬撻噷鍑虹幇鐨勭绉樼敓鐗┿" + }, + { + "搴熷純宸ュ巶鐨勯瓟娉曞疄楠", + "璋冩煡搴熷純宸ュ巶閲岃繘琛岀殑绉樺瘑榄旀硶瀹為獙銆" + }, + { + "鍗氱墿棣嗙殑娲诲寲闆曞儚", + "璋冩煡鍗氱墿棣嗛噷绐佺劧娲诲寲鐨勯洉鍍忋" + }, + { + "鍏洯鐨勯兘甯備紶璇", + "璋冩煡鍏洯閲屾祦浼犵殑閮藉競浼犺銆" + }, + { + "闂归鍏瘬鐨勭湡鐩", + "璋冩煡闂归鍏瘬閲岀殑鐪熺浉銆" + }, + { + "鍦颁笅閰掑惂鐨勭瀵嗕氦鏄", + "璋冩煡鍦颁笅閰掑惂閲岃繘琛岀殑绉樺瘑榄旀硶浜ゆ槗銆" + }, + { + "鏃т功搴楃殑榄旀硶涔︾睄", + "瀵绘壘鏃т功搴楅噷闅愯棌鐨勯瓟娉曚功绫嶃" + }, + { + "娑傞甫澧欑殑棰勮█", + "瑙h娑傞甫澧欎笂鍑虹幇鐨勭绉橀瑷銆" + }, + { + "榛戝鐨勯瓟娉曞叆渚", + "闃绘榛戝鍒╃敤榄旀硶鍏ヤ镜鍩庡競缃戠粶銆" + }, + { + "楂樼鎶榄旀硶瑁呭鐨勬祴璇", + "娴嬭瘯鏂板瀷鐨勯珮绉戞妧榄旀硶瑁呭銆" + }, + { + "鏃犱汉鏈虹殑榄旀硶鏀归", + "鏀归犳棤浜烘満锛屼娇鍏舵嫢鏈夐瓟娉曡兘鍔涖" + }, + { + "浜哄伐鏅鸿兘鐨勮閱", + "璋冩煡浜哄伐鏅鸿兘瑙夐啋鐨勫師鍥犮" + }, + { + "铏氭嫙鐜板疄鐨勯瓟娉曚笘鐣", + "鎺㈢储铏氭嫙鐜板疄涓嚭鐜扮殑榄旀硶涓栫晫銆" + }, + { + "鏅鸿兘瀹跺眳鐨勯瓟娉曟晠闅", + "淇鏅鸿兘瀹跺眳鐨勯瓟娉曟晠闅溿" + }, + { + "鑳介噺楗枡鐨勯瓟娉曞壇浣滅敤", + "璋冩煡鑳介噺楗枡鐨勯瓟娉曞壇浣滅敤銆" + }, + { + "绀句氦濯掍綋鐨勯瓟娉曠梾姣", + "娓呴櫎绀句氦濯掍綋涓婂嚭鐜扮殑榄旀硶鐥呮瘨銆" + }, + { + "鍏变韩姹借溅鐨勯瓟娉曟紓绉", + "璋冩煡鍏变韩姹借溅鐨勯瓟娉曟紓绉荤幇璞°" + }, + { + "鍩庡競鐩戞帶鐨勯瓟娉曞共鎵", + "淇鍩庡競鐩戞帶鐨勯瓟娉曞共鎵般" + }, + { + "瀵绘壘涓㈠け鐨勯瓟娉曞疇鐗", + "瀵绘壘鍦ㄥ煄甯傞噷璧板け鐨勯瓟娉曞疇鐗┿" + }, + { + "鍙傚姞榄旀硶缇庨鑺", + "鍙傚姞鍩庡競涓惧姙鐨勯瓟娉曠編椋熻妭銆" + }, + { + "瑙e紑鍩庡競璋滈", + "瑙e紑闅愯棌鍦ㄥ煄甯傚悇澶勭殑璋滈銆" + }, + { + "鍙傚姞榄旀硶cosplay澶ц禌", + "鍙傚姞鍩庡競涓惧姙鐨勯瓟娉昪osplay澶ц禌銆" + }, + { + "瀵绘壘闅愯棌鐨勯瓟娉曞晢搴", + "瀵绘壘闅愯棌鍦ㄥ煄甯傞噷鐨勯瓟娉曞晢搴椼" + }, + { + "鍒朵綔榄旀硶涓婚鐨勮澶磋壓鏈", + "鍦ㄥ煄甯傞噷鍒涗綔榄旀硶涓婚鐨勮澶磋壓鏈" + }, + { + "涓惧姙涓鍦洪瓟娉曞揩闂椿鍔", + "鍦ㄥ煄甯傞噷涓惧姙涓鍦洪瓟娉曞揩闂椿鍔ㄣ" + }, + { + "瀵绘壘澶辫惤鐨勯瓟娉曚箰鍣", + "瀵绘壘澶辫惤鐨勯瓟娉曚箰鍣紝璁╁煄甯傚厖婊¢煶涔愩" + }, + { + "鍙傚姞榄旀硶杩愬姩浼", + "鍙傚姞鍩庡競涓惧姙鐨勯瓟娉曡繍鍔ㄤ細銆" + }, + { + "鎷晳琚洶鍦ㄩ瓟娉曠粨鐣岄噷鐨勫競姘", + "鎷晳琚洶鍦ㄥ煄甯傞瓟娉曠粨鐣岄噷鐨勫競姘戙" + } + }; + } + } + public static Dictionary> GenerateRoundRewards(int maxRound) { Dictionary> roundRewards = []; @@ -1570,5 +1776,57 @@ namespace Oshima.Core.Utils statistics[character].Rating = CalculateRating(statistics[character], team); } } + + public static string CheckQuestList(PluginConfig pc) + { + if (pc.Count == 0) + { + // 鐢熸垚浠诲姟锛屼换鍔″悕鍜屽鍔辩墿鍝佺殑鏁扮粍 + List quests = []; + for (int i = 0; i < 6; i++) + { + Dictionary items = []; + items[General.GameplayEquilibriumConstant.InGameCurrency] = 1500; + items[General.GameplayEquilibriumConstant.InGameMaterial] = 5; + int index = Random.Shared.Next(AllItems.Count); + Item item = AllItems[index]; + items.Add(item.Name, 1); + while (true) + { + int index2 = Random.Shared.Next(AllItems.Count); + if (index2 != index) + { + Item item2 = AllItems[index2]; + items.Add(item2.Name, 1); + break; + } + } + string name = QuestList.Keys.OrderBy(o => Random.Shared.Next()).First(); + Quest quest = new() + { + Id = quests.Count > 0 ? quests.Max(q => q.Id) + 1 : 1, + Name = name, + Description = QuestList[name], + EstimatedMinutes = Random.Shared.Next(10, 41), + Awards = items + }; + quests.Add(quest); + } + pc.Add("list", quests); + return string.Join("\r\n", quests); + } + else + { + List quests = pc.Get>("list") ?? []; + if (quests.Count > 0) + { + return string.Join("\r\n", quests); + } + else + { + return "浠诲姟鍒楄〃涓虹┖锛岃绛夊緟鍒锋柊锛"; + } + } + } } }