internal static InventoryRecipe FromString(string part, InventoryDef Result) { var r = new InventoryRecipe { Result = Result }; var parts = part.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); r.Ingredients = parts.Select(x => Ingredient.FromString(x)).Where(x => x.DefinitionId != 0).ToArray(); return(r); }
/// <summary> /// This is used to grant a specific item to the user. This should /// only be used for development prototyping, from a trusted server, /// or if you don't care about hacked clients granting arbitrary items. /// This call can be disabled by a setting on Steamworks. /// </summary> public static async Task <InventoryResult?> GenerateItemAsync(InventoryDef target, int amount) { var sresult = Defines.k_SteamInventoryResultInvalid; var defs = new InventoryDefId[] { target.Id }; var cnts = new uint[] { (uint)amount }; if (!Internal.GenerateItems(ref sresult, defs, cnts, 1)) { return(null); } return(await InventoryResult.GetAsync(sresult)); }
internal static InventoryRecipe FromString(string part, InventoryDef Result) { InventoryRecipe inventoryRecipe = new InventoryRecipe() { Result = Result, Source = part }; InventoryRecipe array = inventoryRecipe; array.Ingredients = ( from x in part.Split(new Char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) select InventoryRecipe.Ingredient.FromString(x) into x where x.DefinitionId != 0 select x).ToArray <InventoryRecipe.Ingredient>(); return(array); }
/// <summary> /// Crafting! Uses the passed items to buy the target item. /// You need to have set up the appropriate exchange rules in your item /// definitions. This assumes all the items passed in aren't stacked. /// </summary> static async Task <InventoryResult?> CraftItem(InventoryItem[] list, InventoryDef target) { var sresult = default(SteamInventoryResult_t); var give = new InventoryDefId[] { target.Id }; var givec = new uint[] { 1 }; var sell = list.Select(x => x.Id).ToArray(); var sellc = list.Select(x => (uint)1).ToArray(); if (!Internal.ExchangeItems(ref sresult, give, givec, 1, sell, sellc, (uint)sell.Length)) { return(null); } return(await InventoryResult.GetAsync(sresult)); }
public static async Task <InventoryResult?> GenerateItemAsync(InventoryDef target, int amount) { InventoryResult? async; SteamInventoryResult_t steamInventoryResultT = new SteamInventoryResult_t(); InventoryDefId[] id = new InventoryDefId[] { target.Id }; uint[] numArray = new UInt32[] { amount }; if (SteamInventory.Internal.GenerateItems(ref steamInventoryResultT, id, numArray, 1)) { async = await InventoryResult.GetAsync(steamInventoryResultT); } else { async = null; } return(async); }
/// <summary> /// Try to find the definition that matches this definition ID. /// Call LoadItemDefinitions before using to skip validation. /// Uses a dictionary so should be about as fast as possible. /// </summary> public static InventoryDef FindDefinition(InventoryDefId defId) { if (_defMap.TryGetValue(defId, out var val)) //can be replaced with Definitions.TryGetValue in .NET Framework 4.7.2+ and _defMap deleted { return(val); } //add missing def for ex. with id above 1000000 var notLoaded = new InventoryDef(defId); var notLoadedExists = !string.IsNullOrEmpty(notLoaded.Type); if (notLoadedExists) { _defMap[defId] = notLoaded; Definitions.Add(notLoaded); return(notLoaded); } return(null); }
/// <summary> /// Crafting! Uses the passed items to buy the target item. /// You need to have set up the appropriate exchange rules in your item /// definitions. This assumes all the items passed in aren't stacked. /// </summary> public static async Task <InventoryResult?> CraftItemAsync(InventoryItem.Amount[] list, InventoryDef target) { var sresult = Defines.k_SteamInventoryResultInvalid; var give = new InventoryDefId[] { target.Id }; var givec = new uint[] { 1 }; var sell = list.Select(x => x.Item.Id).ToArray(); var sellc = list.Select(x => (uint)x.Quantity).ToArray(); if (!Internal.ExchangeItems(ref sresult, give, givec, 1, sell, sellc, (uint)sell.Length)) { return(null); } return(await InventoryResult.GetAsync(sresult)); }
internal bool ContainsIngredient(InventoryDef inventoryDef) { bool flag = this.Ingredients.Any <InventoryRecipe.Ingredient>((InventoryRecipe.Ingredient x) => x.DefinitionId == inventoryDef.Id); return(flag); }
public static async Task <InventoryResult?> CraftItemAsync(InventoryItem.Amount[] list, InventoryDef target) { InventoryResult? async; SteamInventoryResult_t steamInventoryResultT = new SteamInventoryResult_t(); InventoryDefId[] id = new InventoryDefId[] { target.Id }; uint[] numArray = new UInt32[] { 1 }; InventoryItem.Amount[] amountArray = list; InventoryItemId[] array = ( from x in (IEnumerable <InventoryItem.Amount>) amountArray select x.Item.Id).ToArray <InventoryItemId>(); InventoryItem.Amount[] amountArray1 = list; uint[] array1 = ( from x in (IEnumerable <InventoryItem.Amount>) amountArray1 select(uint) x.Quantity).ToArray <uint>(); if (SteamInventory.Internal.ExchangeItems(ref steamInventoryResultT, id, numArray, 1, array, array1, (uint)array.Length)) { async = await InventoryResult.GetAsync(steamInventoryResultT); } else { async = null; } return(async); }
internal bool ContainsIngredient(InventoryDef inventoryDef) { return(Ingredients.Any(x => x.DefinitionId == inventoryDef.Id)); }