Refactor GetAllItems to use folder UUID

Changed GetAllItems to accept a folder UUID instead of InventoryNode, updating all relevant calls. Improved inventory item retrieval logic for outfit management and fixed recursive traversal to use folder UUIDs.
This commit is contained in:
Madpeter 2025-11-03 20:45:01 +00:00
parent 4e7af8d903
commit bbea1b7473

View file

@ -1,16 +1,17 @@
using OpenMetaverse; using Discord;
using SecondBotEvents.Config; using OpenMetaverse;
using System.Collections.Generic;
using System.Text.Json;
using RestSharp;
using OpenMetaverse.StructuredData; using OpenMetaverse.StructuredData;
using System.Linq; using Org.BouncyCastle.Asn1.Ocsp;
using System.Text.RegularExpressions; using RestSharp;
using System.Text;
using System;
using SecondBotEvents.RLV;
using SecondBotEvents.Commands; using SecondBotEvents.Commands;
using Discord; using SecondBotEvents.Config;
using SecondBotEvents.RLV;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
namespace SecondBotEvents.Services namespace SecondBotEvents.Services
@ -308,6 +309,7 @@ namespace SecondBotEvents.Services
foreach (var cmd in e.Message.Substring(1).Split(',')) foreach (var cmd in e.Message.Substring(1).Split(','))
{ {
GetClient().Self.Chat(cmd, 0, ChatType.Normal);
var m = rlv_regex.Match(cmd); var m = rlv_regex.Match(cmd);
if (!m.Success) continue; if (!m.Success) continue;
@ -717,8 +719,8 @@ namespace SecondBotEvents.Services
var folder = client.Inventory.Store.Items[CurrentOutfitFolder.GetAttachmentItem(attachment)].Parent; var folder = client.Inventory.Store.Items[CurrentOutfitFolder.GetAttachmentItem(attachment)].Parent;
if (folder != null) if (folder != null)
{ {
List<InventoryItem> outfit = []; List<InventoryItem> outfit = new List<InventoryItem>();
GetAllItems(folder, true, ref outfit); GetAllItems(folder.Data.UUID, true, ref outfit);
master.CurrentOutfitFolder.RemoveFromOutfit(outfit); master.CurrentOutfitFolder.RemoveFromOutfit(outfit);
} }
} }
@ -752,15 +754,14 @@ namespace SecondBotEvents.Services
InventoryNode folder = FindFolder(rule.Option); InventoryNode folder = FindFolder(rule.Option);
if (folder != null) if (folder != null)
{ {
UUID folderload = GetFolderFromPath(rule.Option);
List<InventoryItem> outfit = []; List<InventoryItem> outfit = [];
if (rule.Behaviour == "attachall" || rule.Behaviour == "attachallover") if (rule.Behaviour == "attachall" || rule.Behaviour == "attachallover")
{ {
GetAllItems(folder, true, ref outfit); GetAllItems(folder.Data.UUID, true, ref outfit);
} }
else else
{ {
GetAllItems(folder, false, ref outfit); GetAllItems(folder.Data.UUID, false, ref outfit);
} }
if (rule.Behaviour == "attachover" || rule.Behaviour == "attachallover") if (rule.Behaviour == "attachover" || rule.Behaviour == "attachallover")
{ {
@ -869,20 +870,19 @@ namespace SecondBotEvents.Services
return true; return true;
} }
private void GetAllItems(InventoryNode root, bool recursive, ref List<InventoryItem> items) private void GetAllItems(UUID folder, bool recursive, ref List<InventoryItem> items)
{ {
foreach (var item in root.Nodes.Values) List<InventoryBase> itemsfound = GetClient().Inventory.FolderContents(folder, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, TimeSpan.FromSeconds(15));
foreach (InventoryBase item in itemsfound)
{ {
if (CurrentOutfitFolder.CanBeWorn(item.Data)) if ((item is InventoryWearable) || (item is InventoryObject))
{ {
items.Add((InventoryItem)item.Data); items.Add((InventoryItem)item);
} }
if (recursive) else if ((item is InventoryFolder) && (recursive == true))
{ {
foreach (var child in item.Nodes.Values) GetAllItems(item.UUID, true, ref items);
{
GetAllItems(child, true, ref items);
}
} }
} }
} }