示例#1
0
        /// <summary>
        /// Split stack into two items
        /// </summary>
        public async Task <InventoryResult?> SplitStackAsync(int quantity = 1)
        {
            var sresult = Defines.k_SteamInventoryResultInvalid;

            if (!SteamInventory.Internal.TransferItemQuantity(ref sresult, Id, (uint)quantity, ulong.MaxValue))
            {
                return(null);
            }

            return(await InventoryResult.GetAsync(sresult));
        }
示例#2
0
        /// <summary>
        /// Add x units of the target item to this item
        /// </summary>
        public async Task <InventoryResult?> AddAsync(InventoryItem add, int quantity = 1)
        {
            var sresult = Defines.k_SteamInventoryResultInvalid;

            if (!SteamInventory.Internal.TransferItemQuantity(ref sresult, add.Id, (uint)quantity, Id))
            {
                return(null);
            }

            return(await InventoryResult.GetAsync(sresult));
        }
示例#3
0
        /// <summary>
        /// Consumes items from a user's inventory. If the quantity of the given item goes to zero, it is permanently removed.
        /// Once an item is removed it cannot be recovered.This is not for the faint of heart - if your game implements item removal at all,
        /// a high-friction UI confirmation process is highly recommended.ConsumeItem can be restricted to certain item definitions or fully
        /// blocked via the Steamworks website to minimize support/abuse issues such as the classic "my brother borrowed my laptop and deleted all of my rare items".
        /// </summary>
        public async Task <InventoryResult?> ConsumeAsync(int amount = 1)
        {
            var sresult = Defines.k_SteamInventoryResultInvalid;

            if (!SteamInventory.Internal.ConsumeItem(ref sresult, Id, (uint)amount))
            {
                return(null);
            }

            return(await InventoryResult.GetAsync(sresult));
        }
        /// <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));
        }
        /// <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));
        }