diff --git a/Facepunch.Steamworks/Structs/InventoryDef.cs b/Facepunch.Steamworks/Structs/InventoryDef.cs index f93368e..45e6028 100644 --- a/Facepunch.Steamworks/Structs/InventoryDef.cs +++ b/Facepunch.Steamworks/Structs/InventoryDef.cs @@ -201,5 +201,24 @@ public int LocalBasePrice } public string LocalBasePriceFormatted => Utility.FormatPrice( SteamInventory.Currency, LocalPrice / 100.0 ); + + InventoryRecipe[] _recContaining; + + /// + /// Return a list of recepies that contain this item + /// + public InventoryRecipe[] GetRecipesContainingThis() + { + if ( _recContaining != null ) return _recContaining; + + var allRec = SteamInventory.Definitions + .Select( x => x.GetRecipes() ) + .Where( x => x != null ) + .SelectMany( x => x ); + + _recContaining = allRec.Where( x => x.ContainsIngredient( this ) ).ToArray(); + return _recContaining; + } + } } \ No newline at end of file diff --git a/Facepunch.Steamworks/Structs/InventoryRecipe.cs b/Facepunch.Steamworks/Structs/InventoryRecipe.cs index 9131a7d..03384e8 100644 --- a/Facepunch.Steamworks/Structs/InventoryRecipe.cs +++ b/Facepunch.Steamworks/Structs/InventoryRecipe.cs @@ -82,5 +82,10 @@ internal static InventoryRecipe FromString( string part, InventoryDef Result ) r.Ingredients = parts.Select( x => Ingredient.FromString( x ) ).Where( x => x.DefinitionId != 0 ).ToArray(); return r; } + + internal bool ContainsIngredient( InventoryDef inventoryDef ) + { + return Ingredients.Any( x => x.DefinitionId == inventoryDef.Id ); + } } } \ No newline at end of file