コード例 #1
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(SteamItemDetails_t source, uint quantity, SteamItemInstanceID_t destination)
        {
            if (source.m_unQuantity >= quantity)
            {
                var ret = SteamworksPlayerInventory.TransferQuantity(source.m_itemId, quantity, destination, (result) =>
                {
                    Instances.RemoveAll(p => p.m_itemId == source.m_itemId);
                    source.m_unQuantity -= Convert.ToUInt16(quantity);
                    Instances.Add(source);
                });

                return(ret);
            }
            else
            {
                return(false);
            }
        }
コード例 #2
0
        /// <summary>
        /// Consolodate all stacks of this into a single stack
        /// </summary>
        /// <returns></returns>
        public void Consolidate()
        {
            if (Instances != null)
            {
                if (Instances.Count > 1)
                {
                    List <SteamItemInstanceID_t> removedInstances = new List <SteamItemInstanceID_t>();
                    var primary = Instances[0];
                    for (int i = 1; i < Instances.Count; i++)
                    {
                        var toMove = Instances[i];
                        var ret    = SteamworksPlayerInventory.TransferQuantity(toMove.m_itemId, toMove.m_unQuantity, primary.m_itemId, (result) =>
                        {
                            if (!result)
                            {
                                Debug.LogError("Failed to stack an instance, please refresh the item instances for item definition [" + name + "].");
                            }
                            else
                            {
                                removedInstances.Add(toMove.m_itemId);
                            }
                        });

                        if (!ret)
                        {
                            Debug.LogError("Steam activly refused a TransferItemQuantity request during the Consolodate operation. No further requests will be sent.");
                        }
                    }

                    foreach (var instance in removedInstances)
                    {
                        Instances.RemoveAll(p => p.m_itemId == instance);
                    }
                }
                else
                {
                    Debug.LogWarning("Unable to consolodate items, this item only has 1 instance. No action will be taken.");
                }
            }
            else
            {
                Debug.LogWarning("Unable to consolodate items, this item only has no instances. No action will be taken.");
            }
        }
コード例 #3
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(SteamItemDetails_t source, uint quantity)
        {
            if (source.m_unQuantity >= quantity)
            {
                var ret = SteamworksPlayerInventory.TransferQuantity(source.m_itemId, quantity, SteamItemInstanceID_t.Invalid, (result) =>
                {
                    Instances.RemoveAll(p => p.m_itemId == source.m_itemId);
                    source.m_unQuantity -= Convert.ToUInt16(quantity);
                    Instances.Add(source);
                });

                return(ret);
            }
            else
            {
                Debug.LogWarning("Unable to split instance, insufficent units available to move.");
                return(false);
            }
        }