From 3f0d5ffa7d972f50e0817fae4b45b598784ae067 Mon Sep 17 00:00:00 2001 From: milimoe Date: Thu, 20 Nov 2025 01:41:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=BA=93=E5=AD=98=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- OshimaServers/Service/FunGameOrderList.cs | 2 + OshimaWebAPI/Controllers/FunGameController.cs | 110 ++++++++++++++++++ OshimaWebAPI/Services/RainBOTService.cs | 36 ++++++ 3 files changed, 148 insertions(+) diff --git a/OshimaServers/Service/FunGameOrderList.cs b/OshimaServers/Service/FunGameOrderList.cs index 13ce9e4..c632d9e 100644 --- a/OshimaServers/Service/FunGameOrderList.cs +++ b/OshimaServers/Service/FunGameOrderList.cs @@ -47,6 +47,8 @@ {"物品库存 [页码]", "显示库存中所有物品"}, {"角色库存 [页码]", "显示库存中所有角色"}, {"我的物品 <物品序号>", "查看指定物品详细信息"}, + {"库存搜索2/库存查询2 [关键词] [页码]", "查询库存中的物品"}, + {"库存搜索/库存查询 [关键词] [页码]", "查询库存中的物品"}, {"抽卡/十连抽卡", "金币抽卡(1000/次)"}, {"钻石抽卡/钻石十连抽卡", "钻石抽卡(5/次)"}, {"兑换金币 <钻石数>", "1钻石=200金币"}, diff --git a/OshimaWebAPI/Controllers/FunGameController.cs b/OshimaWebAPI/Controllers/FunGameController.cs index 5c400e6..e1627ae 100644 --- a/OshimaWebAPI/Controllers/FunGameController.cs +++ b/OshimaWebAPI/Controllers/FunGameController.cs @@ -1,5 +1,6 @@ using System.Text; using System.Text.RegularExpressions; +using System.Xml.Linq; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Logging; @@ -1296,6 +1297,115 @@ namespace Oshima.FunGame.WebAPI.Controllers return list; } + [HttpGet("inventoryinfo6")] + public List GetInventoryInfo6([FromQuery] long uid = 0, [FromQuery] int page = 1, [FromQuery] string name = "", [FromForm] bool containsDescription = false) + { + if (page <= 0) page = 1; + + PluginConfig pc = FunGameService.GetUserConfig(uid, out _); + FunGameService.ReleaseUserSemaphoreSlim(uid); + + List list = []; + if (pc.Count > 0) + { + if (name == "") + { + return ["搜索关键词为空!"]; + } + + User user = FunGameService.GetUser(pc); + list.Add($"☆★☆ {user.Inventory.Name} ☆★☆"); + list.Add($"{General.GameplayEquilibriumConstant.InGameCurrency}:{user.Inventory.Credits:0.00}"); + list.Add($"{General.GameplayEquilibriumConstant.InGameMaterial}:{user.Inventory.Materials:0.00}"); + List items = [.. user.Inventory.Items]; + + Dictionary> itemCategory = []; + foreach (Item item in items) + { + if (!itemCategory.TryAdd(item.GetIdName(), [item])) + { + itemCategory[item.GetIdName()].Add(item); + } + } + + // 按品质倒序、数量倒序排序 + itemCategory = itemCategory.OrderByDescending(kv => kv.Value.FirstOrDefault()?.QualityType ?? 0).ThenByDescending(kv => kv.Value.Count).ToDictionary(); + + // 移除所有非指定类型的物品 + foreach (List listTemp in itemCategory.Values) + { + if (listTemp.First() is Item item && (!item.Name.Contains(name) && (!containsDescription || (containsDescription && !item.Description.Contains(name))))) + { + itemCategory.Remove(item.GetIdName()); + } + } + + int maxPage = (int)Math.Ceiling((double)itemCategory.Count / FunGameConstant.ItemsPerPage1); + if (maxPage < 1) maxPage = 1; + if (page <= maxPage) + { + List keys = [.. FunGameService.GetPage(itemCategory.Keys, page, FunGameConstant.ItemsPerPage1)]; + int itemCount = 0; + list.Add($"=== 包含【{name}】的物品 ==="); + using SQLHelper? sql = Factory.OpenFactory.GetSQLHelper(); + List itemTrading = []; + if (sql != null) + { + itemTrading = SQLService.GetUserItemGuids(sql, uid); + } + foreach (string key in keys) + { + itemCount++; + List objs = itemCategory[key]; + Item first = objs[0]; + string str = $"{itemCount}. [{ItemSet.GetQualityTypeName(first.QualityType)}|{ItemSet.GetItemTypeName(first.ItemType)}] {first.Name}\r\n"; + str += $"物品描述:{first.Description}\r\n"; + string itemsIndex = string.Join(",", objs.Select(i => items.IndexOf(i) + 1)); + if (objs.Count > 10) + { + itemsIndex = string.Join(",", objs.Take(10).Select(i => items.IndexOf(i) + 1)) + ",..."; + } + IEnumerable itemsEquipable = objs.Where(i => i.IsEquipment && i.Character is null); + string itemsEquipableIndex = string.Join(",", itemsEquipable.Select(i => items.IndexOf(i) + 1)); + if (itemsEquipable.Count() > 10) + { + itemsEquipableIndex = string.Join(",", itemsEquipable.Take(10).Select(i => items.IndexOf(i) + 1)) + ",..."; + } + IEnumerable itemsSellable = objs.Where(i => i.IsSellable && !i.IsLock && !itemTrading.Contains(i.Guid)); + string itemsSellableIndex = string.Join(",", itemsSellable.Select(i => items.IndexOf(i) + 1)); + if (itemsSellable.Count() > 10) + { + itemsSellableIndex = string.Join(",", itemsSellable.Take(10).Select(i => items.IndexOf(i) + 1)) + ",..."; + } + IEnumerable itemsTradable = objs.Where(i => i.IsTradable && !i.IsLock && !itemTrading.Contains(i.Guid)); + string itemsTradableIndex = string.Join(",", itemsTradable.Select(i => items.IndexOf(i) + 1)); + if (itemsTradable.Count() > 10) + { + itemsTradableIndex = string.Join(",", itemsTradable.Take(10).Select(i => items.IndexOf(i) + 1)) + ",..."; + } + str += $"物品序号:{itemsIndex}\r\n"; + if (itemsEquipableIndex != "") str += $"可装备序号:{itemsEquipableIndex}\r\n"; + if (itemsSellableIndex != "") str += $"可出售序号:{itemsSellableIndex}\r\n"; + if (itemsTradableIndex != "") str += $"可交易序号:{itemsTradableIndex}\r\n"; + str += $"拥有数量:{objs.Count}(" + (first.IsEquipment ? $"可装备数量:{itemsEquipable.Count()}," : "") + + (FunGameConstant.ItemCanUsed.Contains(first.ItemType) ? $"可使用数量:{objs.Count(i => i.RemainUseTimes > 0 && !i.IsLock && !itemTrading.Contains(i.Guid))}," : "") + + $"可出售数量:{itemsSellable.Count()},可交易数量:{itemsTradable.Count()})"; + list.Add(str); + } + list.Add($"页数:{page} / {maxPage}"); + } + else + { + list.Add($"没有这么多页!当前总页数为 {maxPage},但你请求的是第 {page} 页。"); + } + } + else + { + list.Add(noSaved); + } + return list; + } + [HttpPost("newcustomcharacter")] public string NewCustomCharacter([FromQuery] long? uid = null) { diff --git a/OshimaWebAPI/Services/RainBOTService.cs b/OshimaWebAPI/Services/RainBOTService.cs index c560350..910a345 100644 --- a/OshimaWebAPI/Services/RainBOTService.cs +++ b/OshimaWebAPI/Services/RainBOTService.cs @@ -1093,6 +1093,42 @@ namespace Oshima.FunGame.WebAPI.Services return result; } + if (e.Detail.StartsWith("库存搜索2", StringComparison.CurrentCultureIgnoreCase) || e.Detail.StartsWith("库存查询2", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.Detail.Replace("库存搜索2", "").Replace("库存查询2", "").Trim(); + string[] strings = detail.Split(" ", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + string search = strings[0]; + int page = 1; + if (strings.Length > 1 && int.TryParse(strings[1], out int p)) + { + page = p; + } + List msgs = Controller.GetInventoryInfo6(uid, page, search, true); + if (msgs.Count > 0) + { + await SendAsync(e, "搜索库存物品(带描述)", "\r\n" + string.Join("\r\n", msgs)); + } + return result; + } + + if (e.Detail.StartsWith("库存搜索", StringComparison.CurrentCultureIgnoreCase) || e.Detail.StartsWith("库存查询", StringComparison.CurrentCultureIgnoreCase)) + { + string detail = e.Detail.Replace("库存搜索", "").Replace("库存查询", "").Trim(); + string[] strings = detail.Split(" ", StringSplitOptions.TrimEntries | StringSplitOptions.RemoveEmptyEntries); + string search = strings[0]; + int page = 1; + if (strings.Length > 1 && int.TryParse(strings[1], out int p)) + { + page = p; + } + List msgs = Controller.GetInventoryInfo6(uid, page, search, false); + if (msgs.Count > 0) + { + await SendAsync(e, "搜索库存物品", "\r\n" + string.Join("\r\n", msgs)); + } + return result; + } + if (e.Detail.StartsWith("我角色", StringComparison.CurrentCultureIgnoreCase)) { string detail = e.Detail.Replace("我角色", "").Trim();