public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
        {
            int amount = 0;
            var group  = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);

            if (group == null)
            {
                MyComponentSubstitutionDefinition substitutions;
                if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(contentId, out substitutions))
                {
                    foreach (var providingComponent in substitutions.ProvidingComponents)
                    {
                        amount += (int)inventory.GetItemAmount(providingComponent.Key) / providingComponent.Value;
                    }
                }

                return(amount + inventory.GetItemAmount(contentId));
            }
            else
            {
                Clear();
                inventory.CountItems(m_componentCounts);
                AddItem(group.Id, amount, int.MaxValue);
                Solve(m_componentCounts);
                return(GetSolvedItemCount());
            }
        }
        public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
        {
            int amount = 0;
            var group = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);
            if (group == null)
            {
                MyComponentSubstitutionDefinition substitutions;
                if (MyDefinitionManager.Static.TryGetComponentSubstitutionDefinition(contentId, out substitutions))
                {                    
                    foreach (var providingComponent in substitutions.ProvidingComponents)
                    {
                        amount += (int)inventory.GetItemAmount(providingComponent.Key) / providingComponent.Value;
                    }
                    return amount;
                }

                return inventory.GetItemAmount(contentId);
            }
            else
            {
                Clear();
                inventory.CountItems(m_componentCounts);
                AddItem(group.Id, amount, int.MaxValue);
                Solve(m_componentCounts);
                return GetSolvedItemCount();
            }
        }
Esempio n. 3
0
 private void InstallWorkerFromInventory(MyInventoryBase inv, MyDefinitionId request, ref int amount)
 {
     amount = Math.Min(amount, inv.GetItemAmount(request));
     if (amount == 0)
     {
         return;
     }
     if (!inv.RemoveItems(request, amount))
     {
         amount = 0;
     }
 }
 public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
 {
     int amount = 0;
     var group = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);
     if (group == null)
     {
         return inventory.GetItemAmount(contentId);
     }
     else
     {
         Clear();
         inventory.CountItems(m_componentCounts);
         AddItem(group.Id, amount, int.MaxValue);
         Solve(m_componentCounts);
         return GetSolvedItemCount();
     }
 }
Esempio n. 5
0
        public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
        {
            int amount = 0;
            var group  = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);

            if (group == null)
            {
                return(inventory.GetItemAmount(contentId));
            }
            else
            {
                Clear();
                inventory.CountItems(m_componentCounts);
                AddItem(group.Id, amount, int.MaxValue);
                Solve(m_componentCounts);
                return(GetSolvedItemCount());
            }
        }
Esempio n. 6
0
        /*
         * private void BeforeContentsChanged(MyInventoryBase inventory) {
         *  Log.Trace("BeforeContentsChanged called on inventory " + inventory.Entity.ToString(), "BeforeContentsChanged");
         * }
         */

        private void OnContentsChanged(MyInventoryBase inventory)
        {
            Log.Trace("Updating inventory cache with inventory " + inventory.Entity.ToString(), "OnContentsChanged");

            ItemCountsAggregate cachedCount;

            if (!InventoryTotals.TryGetValue(inventory, out cachedCount))
            {
                Log.Error("Received an update for inventory we're not tracking.", "UpdateInventory");
                return;
            }

            ItemCountsAggregate originalCounts = cachedCount.Copy();

            Totals -= originalCounts;

            if (WatchedItems != null)
            {
                foreach (var id in WatchedItems)
                {
                    cachedCount.Set(id, inventory.GetItemAmount(id));
                }
            }
            else
            {
                foreach (var item in inventory.GetItems())
                {
                    cachedCount.Set(item.Content.GetObjectId(), item.Amount);
                }
            }

            Totals += cachedCount;

            if (SkipNextNotify)
            {
                SkipNextNotify = false;
            }
            else
            {
                NotifyContentsChanged(cachedCount - originalCounts);
            }

            //DebugPrint();
        }
Esempio n. 7
0
        public MyFixedPoint GetItemAmountCombined(MyInventoryBase inventory, MyDefinitionId contentId)
        {
            if (inventory == null)
            {
                return(0);
            }
            int amount = 0;
            MyComponentGroupDefinition groupForComponent = MyDefinitionManager.Static.GetGroupForComponent(contentId, out amount);

            if (groupForComponent == null)
            {
                return(amount + inventory.GetItemAmount(contentId, MyItemFlags.None, true));
            }
            this.Clear();
            inventory.CountItems(m_componentCounts);
            this.AddItem(groupForComponent.Id, amount, 0x7fffffff);
            this.Solve(m_componentCounts);
            return(this.GetSolvedItemCount());
        }
Esempio n. 8
0
        public void MoveItemsToConstructionStockpile(MyInventoryBase fromInventory)
        {
            if (MySession.Static.CreativeMode || MySession.Static.SimpleSurvival)
                return;

            m_tmpComponents.Clear();
            GetMissingComponents(m_tmpComponents);

            if (m_tmpComponents.Count() != 0)
            {
                EnsureConstructionStockpileExists();

                m_stockpile.ClearSyncList();
                foreach (var kv in m_tmpComponents)
                {
                    var id = new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key);
                    int amountAvailable = (int)fromInventory.GetItemAmount(id);
                    int moveAmount = Math.Min(kv.Value, amountAvailable);
                    if (moveAmount > 0)
                    {
                        fromInventory.RemoveItemsOfType(moveAmount, id);
                        m_stockpile.AddItems(moveAmount, new MyDefinitionId(typeof(MyObjectBuilder_Component), kv.Key));
                    }
                }
                CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
                m_stockpile.ClearSyncList();
            }
        }
Esempio n. 9
0
		public static void SetBlockComponents(MyHudBlockInfo hudInfo, MySlimBlock block, MyInventoryBase availableInventory = null)
		{
			hudInfo.Components.Clear();
			for (int i = 0; i < block.ComponentStack.GroupCount; i++)
			{
				var groupInfo = block.ComponentStack.GetGroupInfo(i);
				var componentInfo = new MyHudBlockInfo.ComponentInfo();
                componentInfo.DefinitionId = groupInfo.Component.Id;
				componentInfo.ComponentName = groupInfo.Component.DisplayNameText;
				componentInfo.Icon = groupInfo.Component.Icon;
				componentInfo.TotalCount = groupInfo.TotalCount;
				componentInfo.MountedCount = groupInfo.MountedCount;
				if (availableInventory != null)
					componentInfo.AvailableAmount = (int)availableInventory.GetItemAmount(groupInfo.Component.Id);

				hudInfo.Components.Add(componentInfo);
			}

			if (!block.StockpileEmpty)
			{
				// For each component
				foreach (var comp in block.BlockDefinition.Components)
				{
					// Get amount in stockpile
					int amount = block.GetConstructionStockpileItemAmount(comp.Definition.Id);

					for (int i = 0; amount > 0 && i < hudInfo.Components.Count; i++)
					{
						if (block.ComponentStack.GetGroupInfo(i).Component == comp.Definition)
						{
							if (block.ComponentStack.IsFullyDismounted)
							{
								return;
							}
							// Distribute amount in stockpile from bottom to top
							var info = hudInfo.Components[i];
							int space = info.TotalCount - info.MountedCount;
							int movedItems = Math.Min(space, amount);
							info.StockpileCount = movedItems;
							amount -= movedItems;
							hudInfo.Components[i] = info;
						}
					}
				}
			}
		}
Esempio n. 10
0
        public void MoveFirstItemToConstructionStockpile(MyInventoryBase fromInventory)
        {
            if (MySession.Static.CreativeMode)
            {
                return;
            }

            EnsureConstructionStockpileExists();

            MyComponentStack.GroupInfo info = ComponentStack.GetGroupInfo(0);
            m_stockpile.ClearSyncList();
            if ((int)fromInventory.GetItemAmount(info.Component.Id) >= 1)
            {
                //Other player cant move your inventory and you also when trying to cosntruct so its safe already after check above ^^
                fromInventory.RemoveItemsOfType(1, info.Component.Id, MyItemFlags.None);
                //Debug.Assert(removed, "Item not found, but reported available few lines above");
                m_stockpile.AddItems(1, info.Component.Id);
            }
            CubeGrid.SyncObject.SendStockpileChanged(this, m_stockpile.GetSyncList());
            m_stockpile.ClearSyncList();
        }