Beispiel #1
0
        /// <summary>
        /// Restore the state of the players action items.
        /// </summary>
        /// <param name="state"></param>
        public void RestoreState(object state)
        {
            //Recreate the docked item list.  This is to avoid is item multiplication when restoring during game play
            //m_DockedItems = new Dictionary<int, DockedItemSlot>();
            if (m_DockedItems != null)
            {
                m_DockedItems.Clear();
            }
            else
            {
                m_DockedItems = new Dictionary <int, DockedItemSlot>();
            }

            //Load the saved state
            var stateDict = (Dictionary <int, DockedItemRecord>)state;

            foreach (var pair in stateDict)
            {
                //AddAction(InventoryItem.GetFromID(pair.Value.itemID), pair.Key, pair.Value.number);

                //Create a new record and store.
                var slot = new DockedItemSlot();
                slot.actionitem         = InventoryItem.GetFromID(pair.Value.itemID) as ActionItem;
                slot.number             = pair.Value.number;
                m_DockedItems[pair.Key] = slot;
            }

            actionStoreUpdated();
        }
        public void AddItem(InventoryItem item, int index, int number)
        {
            //if we already have an index for the index
            if (_dockedItems.ContainsKey(index))
            {
                //if the object in the action slot is the same as the passed in item
                if (object.ReferenceEquals(item, _dockedItems[index].item))
                {
                    //Then add the number of items to this slot
                    _dockedItems[index].number += number;
                }
            }
            //We have not got this slot filled
            else
            {
                //Create a slot instance and set it up
                var slot = new DockedItemSlot();
                slot.item           = item;
                slot.number         = number;
                _dockedItems[index] = slot;
                //Debug.Log(slot.item.GetDisplayName() + " placed in action bar");
            }

            //Update the action bar
            if (storeUpdated != null)
            {
                storeUpdated();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Add an item to the given index.
        /// </summary>
        /// <param name="item">What item should be added.</param>
        /// <param name="index">Where should the item be added.</param>
        /// <param name="number">How many items to add.</param>
        public void AddAction(InventoryItem item, int index, int number)
        {
            if (item == null)
            {
                Debug.Log("Attempting to add null item.");
                return;
            }
            Debug.Log($"Adding {number} {item}(s) to slot {index}");

            if (dockedItems.ContainsKey(index))
            {
                if (object.ReferenceEquals(item, dockedItems[index].item))
                {
                    dockedItems[index].number += number;
                }
            }
            else
            {
                var slot = new DockedItemSlot();
                slot.item   = item as ActionItem;
                slot.number = number;

                dockedItems[index] = slot;
            }
            if (storeUpdated != null)
            {
                storeUpdated();
            }
        }
 /// <summary>
 /// Add an item to the given index.
 /// </summary>
 /// <param name="item">What item should be added.</param>
 /// <param name="index">Where should the item be added.</param>
 /// <param name="number">How many items to add.</param>
 public void AddAction(InventoryItem item, int index, int number)
 {
     if (dockedItems.ContainsKey(index))
     {
         if (object.ReferenceEquals(item, dockedItems[index].item))
         {
             dockedItems[index].number += number;
         }
     }
     else
     {
         var slot = new DockedItemSlot();
         slot.item          = item as ActionItem;
         slot.number        = number;
         dockedItems[index] = slot;
     }
     if (storeUpdated != null)
     {
         storeUpdated();
     }
 }