Пример #1
0
        internal static InventoryRecipe FromString(string part, InventoryDef Result)
        {
            var r = new InventoryRecipe
            {
                Result = Result,
                Source = part
            };

            var parts = part.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            r.Ingredients = parts.Select(x => Ingredient.FromString(x)).Where(x => x.DefinitionId != 0).ToArray();
            return(r);
        }
Пример #2
0
        /// <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));
        }
Пример #3
0
        /// <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));
        }
Пример #4
0
 internal bool ContainsIngredient(InventoryDef inventoryDef)
 {
     return(Ingredients.Any(x => x.DefinitionId == inventoryDef.Id));
 }