From 0f48d2ea731a2adf5d54c18d6f3077ad5ed16cba Mon Sep 17 00:00:00 2001 From: milimoe Date: Wed, 1 Jan 2025 03:34:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E4=BB=BB=E5=8A=A1=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E5=92=8C=E6=B7=BB=E5=8A=A0=E7=AD=BE=E5=88=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaCore/Controllers/FunGameController.cs | 74 ++++++++- OshimaCore/OshimaWebAPI.cs | 15 ++ OshimaCore/Utils/FunGameService.cs | 168 +++++++++++++++----- 3 files changed, 217 insertions(+), 40 deletions(-) diff --git a/OshimaCore/Controllers/FunGameController.cs b/OshimaCore/Controllers/FunGameController.cs index 2a03553..e88415b 100644 --- a/OshimaCore/Controllers/FunGameController.cs +++ b/OshimaCore/Controllers/FunGameController.cs @@ -3412,6 +3412,43 @@ namespace Oshima.Core.Controllers } } + [HttpPost("checkworkingquest")] + public string CheckWorkingQuest([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); + + EntityModuleConfig quests = new("quests", userid.ToString()); + quests.LoadConfig(); + string msg = ""; + IEnumerable working = quests.Values.Where(q => q.Status == QuestState.InProgress); + if (working.Any()) + { + msg = "你正在进行中的任务详情如下:\r\n" + string.Join("\r\n", working); + } + else + { + msg = "你当前没有正在进行中的任务!"; + } + + 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) { @@ -3430,7 +3467,7 @@ namespace Oshima.Core.Controllers quests.LoadConfig(); if (quests.Count > 0) { - if (quests.Values.FirstOrDefault(q => q.Status == 1) is Quest quest) + if (quests.Values.FirstOrDefault(q => q.Status == QuestState.InProgress) is Quest quest) { msg = $"你正在进行任务【{quest.Name}】,无法开始新任务!\r\n{quest}"; } @@ -3443,9 +3480,9 @@ namespace Oshima.Core.Controllers else { quest2.StartTime = DateTime.Now; - quest2.Status = 1; + quest2.Status = QuestState.InProgress; quests.SaveConfig(); - msg = $"开始任务【{quest2.Name}】成功!\r\n任务信息如下:{quest2}\r\n预计完成时间:{DateTime.Now.AddMinutes(quest2.EstimatedMinutes).ToString(General.GeneralDateTimeFormatChinese)}"; + msg = $"开始任务【{quest2.Name}】成功!任务信息如下:\r\n{quest2}\r\n预计完成时间:{DateTime.Now.AddMinutes(quest2.EstimatedMinutes).ToString(General.GeneralDateTimeFormatChinese)}"; } } else @@ -3470,6 +3507,37 @@ namespace Oshima.Core.Controllers } } + [HttpPost("signin")] + public string SignIn([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); + bool sign = pc.Get("signed"); + + if (sign) + { + return NetworkUtility.JsonSerialize("你今天已经签过到了哦!"); + } + + string msg = FunGameService.GetSignInResult(user); + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.Add("signed", true); + 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 f3020a0..e21143d 100644 --- a/OshimaCore/OshimaWebAPI.cs +++ b/OshimaCore/OshimaWebAPI.cs @@ -99,6 +99,21 @@ namespace Oshima.Core.WebAPI } Controller.WriteLine("刷新每日任务"); } + // 刷新签到 + directoryPath = $@"{AppDomain.CurrentDomain.BaseDirectory}configs/saved"; + if (Directory.Exists(directoryPath)) + { + string[] filePaths = Directory.GetFiles(directoryPath); + foreach (string filePath in filePaths) + { + string fileName = Path.GetFileNameWithoutExtension(filePath); + PluginConfig pc = new("saved", fileName); + pc.LoadConfig(); + pc.Add("signed", false); + pc.SaveConfig(); + } + Controller.WriteLine("刷新签到"); + } }); TaskScheduler.Shared.AddRecurringTask("刷新boss", TimeSpan.FromHours(1), () => { diff --git a/OshimaCore/Utils/FunGameService.cs b/OshimaCore/Utils/FunGameService.cs index 2e115ed..2eaf4c9 100644 --- a/OshimaCore/Utils/FunGameService.cs +++ b/OshimaCore/Utils/FunGameService.cs @@ -556,41 +556,12 @@ namespace Oshima.Core.Utils // 任务结算 EntityModuleConfig quests = new("quests", user.Id.ToString()); quests.LoadConfig(); - if (quests.Count > 0) + if (quests.Count > 0 && SettleQuest(user, quests)) { - IEnumerable workingQuests = quests.Values.Where(q => q.Status == 1); - foreach (Quest quest in workingQuests) - { - if (quest.StartTime.HasValue && quest.StartTime.Value.AddMinutes(quest.EstimatedMinutes) <= DateTime.Now) - { - quest.Status = 2; - } - } - IEnumerable finishQuests = quests.Values.Where(q => q.Status == 2); - foreach (Quest quest in finishQuests) - { - quest.Status = 3; - quest.SettleTime = DateTime.Now; - 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.Materials += 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); - } - } - } quests.SaveConfig(); + user.LastTime = DateTime.Now; + pc.Add("user", user); + pc.SaveConfig(); } return user; @@ -705,6 +676,89 @@ namespace Oshima.Core.Utils return msg; } + public static string GetSignInResult(User user) + { + string msg = "签到成功!本次签到获得:"; + int currency = Random.Shared.Next(1000, 3000); + msg += $"{currency} 金币和"; + int material = Random.Shared.Next(1000, 3000); + msg += $"{material} 材料!额外获得:"; + user.Inventory.Credits += currency; + user.Inventory.Materials += material; + int r = Random.Shared.Next(6); + double q = Random.Shared.NextDouble() * 100; + QualityType type = q switch + { + <= 69.53 => QualityType.White, + > 69.53 and <= 69.53 + 15.35 => QualityType.Green, + > 69.53 + 15.35 and <= 69.53 + 15.35 + 9.48 => QualityType.Blue, + > 69.53 + 15.35 + 9.48 and <= 69.53 + 15.35 + 9.48 + 4.25 => QualityType.Purple, + > 69.53 + 15.35 + 9.48 + 4.25 and <= 69.53 + 15.35 + 9.48 + 4.25 + 1.33 => QualityType.Orange, + > 69.53 + 15.35 + 9.48 + 4.25 + 1.33 and <= 69.53 + 15.35 + 9.48 + 4.25 + 1.33 + 0.06 => QualityType.Red, + _ => QualityType.White + }; + + switch (r) + { + case 1: + if ((int)type > (int)QualityType.Orange) type = QualityType.Orange; + Item[] 武器 = Equipment.Where(i => i.Id.ToString().StartsWith("11") && i.QualityType == type).ToArray(); + Item a = 武器[Random.Shared.Next(武器.Length)].Copy(); + SetSellAndTradeTime(a); + user.Inventory.Items.Add(a); + msg += ItemSet.GetQualityTypeName(a.QualityType) + ItemSet.GetItemTypeName(a.ItemType) + "【" + a.Name + "】!\r\n" + a.Description; + break; + + case 2: + if ((int)type > (int)QualityType.Green) type = QualityType.Green; + Item[] 防具 = Equipment.Where(i => i.Id.ToString().StartsWith("12") && i.QualityType == type).ToArray(); + Item b = 防具[Random.Shared.Next(防具.Length)].Copy(); + SetSellAndTradeTime(b); + user.Inventory.Items.Add(b); + msg += ItemSet.GetQualityTypeName(b.QualityType) + ItemSet.GetItemTypeName(b.ItemType) + "【" + b.Name + "】!\r\n" + b.Description; + break; + + case 3: + if ((int)type > (int)QualityType.Green) type = QualityType.Green; + Item[] 鞋子 = Equipment.Where(i => i.Id.ToString().StartsWith("13") && i.QualityType == type).ToArray(); + Item c = 鞋子[Random.Shared.Next(鞋子.Length)].Copy(); + SetSellAndTradeTime(c); + user.Inventory.Items.Add(c); + msg += ItemSet.GetQualityTypeName(c.QualityType) + ItemSet.GetItemTypeName(c.ItemType) + "【" + c.Name + "】!\r\n" + c.Description; + break; + + case 4: + if ((int)type > (int)QualityType.Purple) type = QualityType.Purple; + Item[] 饰品 = Equipment.Where(i => i.Id.ToString().StartsWith("14") && i.QualityType == type).ToArray(); + Item d = 饰品[Random.Shared.Next(饰品.Length)].Copy(); + SetSellAndTradeTime(d); + user.Inventory.Items.Add(d); + msg += ItemSet.GetQualityTypeName(d.QualityType) + ItemSet.GetItemTypeName(d.ItemType) + "【" + d.Name + "】!\r\n" + d.Description; + break; + + case 5: + if ((int)type > (int)QualityType.Orange) type = QualityType.Orange; + Item mfk = GenerateMagicCard(type); + SetSellAndTradeTime(mfk); + user.Inventory.Items.Add(mfk); + msg += ItemSet.GetQualityTypeName(mfk.QualityType) + ItemSet.GetItemTypeName(mfk.ItemType) + "【" + mfk.Name + "】!\r\n" + mfk.Description; + break; + + case 0: + default: + if ((int)type > (int)QualityType.Orange) type = QualityType.Orange; + Item? mfkb = GenerateMagicCardPack(3, type); + if (mfkb != null) + { + SetSellAndTradeTime(mfkb); + user.Inventory.Items.Add(mfkb); + msg += ItemSet.GetQualityTypeName(mfkb.QualityType) + ItemSet.GetItemTypeName(mfkb.ItemType) + "【" + mfkb.Name + "】!\r\n" + mfkb.Description; + } + break; + } + return msg; + } + public static void SetSellAndTradeTime(Item item, bool sell = false, bool trade = true, DateTime? nextSell = null, DateTime? nextTrade = null) { if (sell) @@ -1790,8 +1844,8 @@ namespace Oshima.Core.Utils { int minutes = Random.Shared.Next(10, 41); Dictionary items = []; - items[General.GameplayEquilibriumConstant.InGameCurrency] = minutes * 50; - items[General.GameplayEquilibriumConstant.InGameMaterial] = minutes / 10 * 2; + items[General.GameplayEquilibriumConstant.InGameCurrency] = minutes * 20; + items[General.GameplayEquilibriumConstant.InGameMaterial] = minutes / 8 * 1; int index = Random.Shared.Next(AllItems.Count); Item item = AllItems[index]; items.Add(item.Name, 1); @@ -1816,13 +1870,13 @@ namespace Oshima.Core.Utils }; quests.Add(quest.GetIdName(), quest); } - return string.Join("\r\n", quests); + return "☆--- 今日任务列表 ---☆\r\n" + string.Join("\r\n", quests.Values.Select(q => q.ToString())) + "\r\n温馨提示:请务必在次日 4:00 前完成任务结算,未结算的任务都会被取消!"; } else { if (quests.Count > 0) { - return string.Join("\r\n", quests); + return "☆--- 今日任务列表 ---☆\r\n" + string.Join("\r\n", quests.Values.Select(q => q.ToString())) + "\r\n温馨提示:请务必在次日 4:00 前完成任务结算,未结算的任务都会被取消!"; } else { @@ -1830,5 +1884,45 @@ namespace Oshima.Core.Utils } } } + + public static bool SettleQuest(User user, EntityModuleConfig quests) + { + bool result = false; + IEnumerable workingQuests = quests.Values.Where(q => q.Status == QuestState.InProgress); + foreach (Quest quest in workingQuests) + { + if (quest.StartTime.HasValue && quest.StartTime.Value.AddMinutes(quest.EstimatedMinutes) <= DateTime.Now) + { + quest.Status = QuestState.Completed; + result = true; + } + } + IEnumerable finishQuests = quests.Values.Where(q => q.Status == QuestState.Completed); + foreach (Quest quest in finishQuests) + { + quest.Status = QuestState.Settled; + quest.SettleTime = DateTime.Now; + 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.Materials += 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); + } + } + result = true; + } + return result; + } } }