示例#1
0
        /// <summary>
        /// Gets an item from the inventory by its id.
        /// </summary>
        /// <param name="ItemID">The item id.</param>
        /// <returns>Returns the item. [null if failed]</returns>
        public ItemInfo GetItemByID(uint ItemID)
        {
            byte pos = GetPositionFromItemID(ItemID);

            ItemInfo rItem;

            if (InventoryItems.TryGetValue(pos, out rItem))
            {
                return(rItem);
            }
            return(null);
        }
示例#2
0
 /// <summary>
 /// Gets an item position from an item uid.
 /// </summary>
 /// <param name="ItemID">The item id.</param>
 /// <returns>Returns the item uid.</returns>
 public byte GetPositionFromItemUID(uint ItemUID)
 {
     foreach (byte key in InventoryItems.Keys)
     {
         ItemInfo finditem;
         if (InventoryItems.TryGetValue(key, out finditem))
         {
             if (finditem.UID == ItemUID)
             {
                 return(key);
             }
         }
     }
     return(40);
 }
示例#3
0
        /// <summary>
        /// Gets an uid from an item id.
        /// </summary>
        /// <param name="ItemID">The item id.</param>
        /// <param name="TotalAmounts">[out] The total amount of items contained with the id.</param>
        /// <returns>Returns the item uid.</returns>
        public uint GetUIDFromItemID(uint ItemID, out byte TotalAmounts)
        {
            uint find = 0;

            TotalAmounts = 0;
            foreach (byte key in InventoryItems.Keys)
            {
                ItemInfo finditem;
                if (InventoryItems.TryGetValue(key, out finditem))
                {
                    if (finditem.ItemID == ItemID)
                    {
                        if (TotalAmounts == 0)
                        {
                            find = finditem.UID;
                        }
                        TotalAmounts++;
                    }
                }
            }
            return(find);
        }
示例#4
0
        internal void StartAmmoTask()
        {
            InventoryUpdate = true;
            if (ITask.valid && ITask.Exceptions != null)
            {
                TaskHasErrors(ref ITask, "ITask");
            }

            StallReporter.Start("StartAmmoTask", 3);
            foreach (var ai in GridsToUpdateInventories)
            {
                var logged = 0;
                foreach (var inventory in ai.InventoryMonitor.Values)
                {
                    var items = inventory?.GetItems();
                    if (items != null)
                    {
                        MyConcurrentList <MyPhysicalInventoryItem> phyItemList;
                        if (InventoryItems.TryGetValue(inventory, out phyItemList))
                        {
                            phyItemList.AddRange(items);
                        }
                        else if (logged++ == 0)
                        {
                            Log.Line($"phyItemList and inventory.entity is null in StartAmmoTask - grid:{ai.MyGrid.DebugName} - aiMarked:{ai.MarkedForClose} - cTick:{Tick - ai.AiCloseTick} - mTick:{Tick - ai.AiMarkedTick} - sTick:{Tick - ai.CreatedTick}");
                        }
                    }
                }
            }
            StallReporter.End();

            DefIdsComparer.Clear();
            GridsToUpdateInventories.Clear();

            ITask = MyAPIGateway.Parallel.StartBackground(ProccessAmmoMoves, ProccessAmmoCallback);
        }
示例#5
0
 /// <summary>
 /// Removes an item from the inventory based on is iteminfo.
 /// </summary>
 /// <param name="info">The item info.</param>
 /// <returns>Returns true if the item was removed.</returns>
 public bool RemoveItem(ItemInfo info)
 {
     foreach (byte key in InventoryItems.Keys)
     {
         ItemInfo ritem;
         if (InventoryItems.TryGetValue(key, out ritem))
         {
             if (ritem.UID == info.UID)
             {
                 if (InventoryItems.TryRemove(key, out ritem))
                 {
                     Database.CharacterDatabase.SaveInventory(Owner, null, key);
                     RemoveItemFromClient(ritem);
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             }
         }
     }
     return(false);
 }