From ff0422cbd7dc51e8e74434d9ceee0b0949046dc6 Mon Sep 17 00:00:00 2001 From: UbitUmarov Date: Mon, 24 Oct 2022 01:37:01 +0100 Subject: [PATCH] search a prim inventory matching both name and asset type, on some LSL and OSSL --- .../Framework/Interfaces/IEntityInventory.cs | 1 + .../Scenes/SceneObjectPartInventory.cs | 16 ++++++++++++++++ .../Framework/Scenes/Scripting/ScriptUtils.cs | 18 +++++++++--------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs index a7772967ed..a5a133688c 100644 --- a/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs +++ b/OpenSim/Region/Framework/Interfaces/IEntityInventory.cs @@ -217,6 +217,7 @@ namespace OpenSim.Region.Framework.Interfaces /// The inventory item. Null if no such item was found. /// TaskInventoryItem GetInventoryItem(string name); + TaskInventoryItem GetInventoryItem(string name, int assetType); /// /// Get inventory items by name. diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs index 74689e1a11..947028beab 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectPartInventory.cs @@ -1095,6 +1095,22 @@ namespace OpenSim.Region.Framework.Scenes return null; } + public TaskInventoryItem GetInventoryItem(string name, int type) + { + m_items.LockItemsForRead(true); + foreach (TaskInventoryItem item in m_items.Values) + { + if (item.Type == type && item.Name == name) + { + m_items.LockItemsForRead(false); + return item; + } + } + m_items.LockItemsForRead(false); + + return null; + } + public List GetInventoryItems(string name) { List items = new List(); diff --git a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs index c653bdbba1..fc6590918b 100644 --- a/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs +++ b/OpenSim/Region/Framework/Scenes/Scripting/ScriptUtils.cs @@ -96,10 +96,10 @@ namespace OpenSim.Region.Framework.Scenes.Scripting if (UUID.TryParse(identifier, out UUID key)) return key; - if (part.Inventory != null) + if (part.Inventory is not null) { - TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier); - if (item != null && item.Type == (int)type) + TaskInventoryItem item = part.Inventory.GetInventoryItem(identifier, (int)type); + if (item is not null) return item.AssetID; } @@ -112,17 +112,17 @@ namespace OpenSim.Region.Framework.Scenes.Scripting return key; TaskInventoryItem item; - if (part.Inventory != null) + if (part.Inventory is not null) { - item = part.Inventory.GetInventoryItem(identifier); - if (item != null && item.Type == (int)type) + item = part.Inventory.GetInventoryItem(identifier, (int)type); + if (item is not null) return item.AssetID; } - if (part.LocalId != host.LocalId && host.Inventory != null) + if (part.LocalId != host.LocalId && host.Inventory is not null) { - item = host.Inventory.GetInventoryItem(identifier); - if (item != null && item.Type == (int)type) + item = host.Inventory.GetInventoryItem(identifier, (int)type); + if (item is not null) return item.AssetID; } return UUID.Zero;