コード例 #1
0
        /// <summary>
        /// <para>Grants the user a promotional item</para>
        /// <para>This will trigger the Item Instances Updated event after steam responds with the users inventory items and the items have been updated to reflect the correct instances.</para>
        /// <para> <para>
        /// <para>NOTE: this additivly updates the Instance list for effected items and is not a clean refresh!
        /// Consider a call to Refresh Inventory to resolve a complete and accurate refresh of all player items.</para>
        /// </summary>
        /// <paramref name="itemDefinition">The item type to grant to the user.</paramref>
        public void GrantPromotionalItem(InventoryItemDefinition itemDefinition)
        {
            var result = SteamworksPlayerInventory.AddPromoItem(itemDefinition.DefinitionID, (status, results) =>
            {
                ItemsGranted.Invoke(status, results);
            });

            if (!result)
            {
                Debug.LogWarning("[SteamworksInventorySettings.GrantPromotionalItem] - Call failed");
            }
        }
コード例 #2
0
        /// <summary>
        /// <para>Consumes the indicated number of units of this item from this specific instance stack</para>
        /// <para>NOTE: this is the most efficent way to consume multiple units of an item at a time.</para>
        /// </summary>
        /// <param name="itemDefinition"></param>
        /// <param name="instanceId"></param>
        /// <param name="count"></param>
        public void ConsumeItem(InventoryItemDefinition itemDefinition, SteamItemInstanceID_t instanceId, int count)
        {
            var target = itemDefinition.Instances.FirstOrDefault(p => p.m_itemId == instanceId);
            var result = SteamworksPlayerInventory.ConsumeItem(instanceId, (status, results) =>
            {
                if (status)
                {
                    itemDefinition.Instances.RemoveAll(p => p.m_itemId == target.m_itemId);
                    target.m_unQuantity -= System.Convert.ToUInt16(count);
                    itemDefinition.Instances.Add(target);
                    ItemInstancesUpdated.Invoke();
                    ItemsConsumed.Invoke(status, results);
                }
            });

            if (!result)
            {
                Debug.LogWarning("[SteamworksInventorySettings.ConsumeItem] - Call failed");
            }
        }
コード例 #3
0
 /// <summary>
 /// Consolodate all stacks of this into a single stack
 /// </summary>
 /// <returns></returns>
 public void Consolidate(InventoryItemDefinition item)
 {
     item.Consolidate();
 }
コード例 #4
0
 /// <summary>
 /// Moves the source instance in its entirety to the destination.
 /// </summary>
 /// <param name="source">The source to move</param>
 /// <param name="destination">The target destination</param>
 /// <returns></returns>
 public bool StackInstance(InventoryItemDefinition item, SteamItemDetails_t source, SteamItemInstanceID_t destination)
 {
     return(item.StackInstance(source, destination));
 }
コード例 #5
0
 /// <summary>
 /// Moves the quantity from the source into a new stack
 /// </summary>
 /// <param name="source">Source instance to move units from</param>
 /// <param name="quantity">The number of units to move</param>
 /// <returns></returns>
 public bool SplitInstance(InventoryItemDefinition item, SteamItemDetails_t source, uint quantity)
 {
     return(item.SplitInstance(source, quantity));
 }
コード例 #6
0
 /// <summary>
 /// Splits an instance quantity, if the destination instance is -1 this will create a new stack of the defined quantity.
 /// </summary>
 /// <param name="source">The instance to split</param>
 /// <param name="quantity">The number of items to remove from the source stack</param>
 /// <param name="destination">The target to move the quanity to</param>
 /// <returns></returns>
 public bool TransferQuantity(InventoryItemDefinition item, SteamItemDetails_t source, uint quantity, SteamItemInstanceID_t destination)
 {
     return(item.TransferQuantity(source, quantity, destination));
 }
コード例 #7
0
 public void ExchangeItems(InventoryItemDefinition itemToCraft, int recipeIndex)
 {
     itemToCraft.Craft(recipeIndex);
 }
コード例 #8
0
 /// <summary>
 /// <para>Exchange items for the indicated recipe</para>
 /// <para>NOTE: this method will trigger the Items Exchanged event and can optionally trigger a full inventory refresh on completion of the exchange.</para>
 /// </summary>
 /// <param name="recipe"></param>
 /// <param name="postExchangeRefresh"></param>
 public void ExchangeItems(InventoryItemDefinition itemToCraft, CraftingRecipe recipe)
 {
     itemToCraft.Craft(recipe);
 }
コード例 #9
0
        /// <summary>
        /// <para>Attempts to consume the requested units of the indicated item</para>
        /// <para>NOTE: this may need to iterate over multiple instances and may need to send multiple consume requests any of which may fail and each of which will trigger an Item Instance Update event call.</para>
        /// <para>You are recomended to use the the SteamItemInstance_t overload of this method when consuming more than 1 unit of an item.</para>
        /// </summary>
        /// <param name="itemDefinition">The item to consume for</param>
        /// <param name="count">The number of item units to try and consume</param>
        public void ConsumeItem(InventoryItemDefinition itemDefinition, int count)
        {
            if (count < 1)
            {
                Debug.LogWarning("Attempted to consume a number of items less than 1; this is not possible and was note requested.");
                return;
            }

            List <ExchangeItemCount> counts = new List <ExchangeItemCount>();
            int currentCount = 0;

            foreach (var details in itemDefinition.Instances)
            {
                if (details.m_unQuantity >= count - currentCount)
                {
                    counts.Add(new ExchangeItemCount()
                    {
                        InstanceId = details.m_itemId, Quantity = System.Convert.ToUInt32(count - currentCount)
                    });
                    currentCount = count;
                    break;
                }
                else
                {
                    counts.Add(new ExchangeItemCount()
                    {
                        InstanceId = details.m_itemId, Quantity = details.m_unQuantity
                    });
                    currentCount += details.m_unQuantity;
                }
            }

            bool noErrors = true;

            foreach (var exchange in counts)
            {
                var result = SteamworksPlayerInventory.ConsumeItem(exchange.InstanceId, exchange.Quantity, (status, results) =>
                {
                    if (status)
                    {
                        var target = itemDefinition.Instances.FirstOrDefault(p => p.m_itemId == exchange.InstanceId);
                        itemDefinition.Instances.RemoveAll(p => p.m_itemId == exchange.InstanceId);
                        target.m_unQuantity -= System.Convert.ToUInt16(exchange.Quantity);
                        itemDefinition.Instances.Add(target);
                        ItemInstancesUpdated.Invoke();
                        ItemsConsumed.Invoke(status, results);
                    }
                });

                if (!result)
                {
                    noErrors = false;
                    Debug.LogWarning("Failed to consume all requested items");
                    break;
                }
            }

            if (!noErrors)
            {
                Debug.LogWarning("[SteamworksInventorySettings.ConsumeItem] - Call failed");
            }
        }
コード例 #10
0
 /// <summary>
 /// <para>Consumes the indicate number of units of this item from this specific instance stack</para>
 /// <para>NOTE: this is the most efficent way to consume multiple units of an item at a time.</para>
 /// </summary>
 /// <param name="itemDefinition"></param>
 /// <param name="instanceId"></param>
 /// <param name="count"></param>
 public void ConsumeItem(InventoryItemDefinition itemDefinition, SteamItemInstanceID_t instanceId, int count)
 {
     Settings.ConsumeItem(itemDefinition, instanceId, count);
 }
コード例 #11
0
 /// <summary>
 /// <para>Attempts to consume the requested units of the indicated item</para>
 /// <para>NOTE: this may need to iterate over multiple instances and may need to send multiple consume requests any of which may fail and each of which will trigger an Item Instance Update event call.</para>
 /// <para>You are recomended to use the the SteamItemInstance_t overload of this method when consuming more than 1 unit of an item.</para>
 /// </summary>
 /// <param name="itemDefinition">The item to consume for</param>
 /// <param name="count">The number of item units to try and consume</param>
 public void ConsumeItem(InventoryItemDefinition itemDefinition, int count)
 {
     Settings.ConsumeItem(itemDefinition, count);
 }
コード例 #12
0
 /// <summary>
 /// Consumes a single unit of a single instnace of this item if available.
 /// </summary>
 /// <param name="itemDefinition"></param>
 public void ConsumeItem(InventoryItemDefinition itemDefinition)
 {
     Settings.ConsumeItem(itemDefinition);
 }
コード例 #13
0
 /// <summary>
 /// <para>Grants the user a promotional item</para>
 /// <para>This will trigger the Item Instances Updated event after steam responds with the users inventory items and the items have been updated to reflect the correct instances.</para>
 /// <para> <para>
 /// <para>NOTE: this additivly updates the Instance list for effected items and is not a clean refresh!
 /// Consider a call to Refresh Inventory to resolve a complete and accurate refresh of all player items.</para>
 /// </summary>
 /// <paramref name="itemDefinition">The item type to grant to the user.</paramref>
 public void GrantPromotionalItem(InventoryItemDefinition itemDefinition)
 {
     Settings.GrantPromotionalItem(itemDefinition);
 }