Added InventoryDef.GetRecipesContainingThis()

This commit is contained in:
Garry Newman 2019-05-14 16:05:28 +01:00
parent fed6ccdefa
commit 17d7263973
2 changed files with 24 additions and 0 deletions

View File

@ -201,5 +201,24 @@ public int LocalBasePrice
}
public string LocalBasePriceFormatted => Utility.FormatPrice( SteamInventory.Currency, LocalPrice / 100.0 );
InventoryRecipe[] _recContaining;
/// <summary>
/// Return a list of recepies that contain this item
/// </summary>
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;
}
}
}

View File

@ -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 );
}
}
}