public InventoryEntity( MyObjectBuilder_Inventory definition, Object backingObject )
			: base( definition, backingObject )
		{
			//m_itemManager = new InventoryItemManager(this, backingObject, InventoryGetItemListMethod);
			//m_itemManager.Refresh();
			m_itemDeltaQueue = new Queue<InventoryDelta>( );
		}
Exemplo n.º 2
0
        public InventoryEditorModel(MyObjectBuilder_Inventory inventory, float maxVolume, MyObjectBuilder_Character character = null)
        {
            _inventory = inventory;
            _maxVolume = maxVolume;
            _character = character;
            UpdateGeneralFromEntityBase();

            // Cube.InventorySize.X * CUbe.InventorySize.Y * CUbe.InventorySize.Z * 1000 * Sandbox.InventorySizeMultiplier;
            // or Cube.InventoryMaxVolume * 1000 * Sandbox.InventorySizeMultiplier;
            //Character.Inventory = 0.4 * 1000 * Sandbox.InventorySizeMultiplier;
        }
Exemplo n.º 3
0
        public InventoryEntity(MyObjectBuilder_Inventory definition)
            : base(definition)
        {
            m_itemManager = new InventoryItemManager(this);

            List<InventoryItemEntity> itemList = new List<InventoryItemEntity>();
            foreach (MyObjectBuilder_InventoryItem item in definition.Items)
            {
                InventoryItemEntity newItem = new InventoryItemEntity(item);
                newItem.Container = this;
                itemList.Add(newItem);
            }
            m_itemManager.Load(itemList);
        }
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            m_items.Clear();

            if (objectBuilder == null)
                return;

            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount > 0)
                {
                    MyStockpileItem newItem = new MyStockpileItem();
                    newItem.Amount = (int)(item.Amount);
                    newItem.Content = item.PhysicalContent;
                    m_items.Add(newItem);
                }
            }
        }
		private void CheckOxygenInventory(MyObjectBuilder_Inventory inventory)
		{
			if (inventory == null)
				return;

			foreach (var inventoryItem in inventory.Items)
			{
				var oxygenContainer = inventoryItem.PhysicalContent as MyObjectBuilder_OxygenContainerObject;
				if (oxygenContainer == null)
					continue;

				FixOxygenContainer(oxygenContainer);
			}
		}
Exemplo n.º 6
0
        public static void FillInventoryWithDefaults(MyObjectBuilder_Inventory inventory, MyScenarioDefinition scenario)
        {
            if (inventory.Items == null)
                inventory.Items = new List<MyObjectBuilder_InventoryItem>(15);
            else
                inventory.Items.Clear();

            if (scenario != null && MySession.Static.Settings.SpawnWithTools)
            {
                MyStringId[] guns;
                if (MySession.Static.CreativeMode)
                    guns = scenario.CreativeModeWeapons;// new string[] { "AngleGrinderItem", "AutomaticRifleItem", "HandDrillItem", "WelderItem" };
                else
                    guns = scenario.SurvivalModeWeapons;// new string[] { "AngleGrinderItem", "HandDrillItem", "WelderItem" };

                if (guns != null)
                {
                    foreach (var gun in guns)
                    {
                        var inventoryItem = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_InventoryItem>();
                        inventoryItem.Amount = 1;
                        inventoryItem.Content = MyObjectBuilderSerializer.CreateNewObject<MyObjectBuilder_PhysicalGunObject>(gun.ToString());
                        inventory.Items.Add(inventoryItem);
                    }
                }
            }
        }
Exemplo n.º 7
0
 public void RefreshInventory()
 {
     try
     {
         if (BackingObject != null)
         {
             //Update the base entity
             MethodInfo getObjectBuilder = BackingObject.GetType().GetMethod(InventoryGetObjectBuilderMethod);
             MyObjectBuilder_Inventory inventory = (MyObjectBuilder_Inventory)getObjectBuilder.Invoke(BackingObject, new object[] { });
             ObjectBuilder = inventory;
         }
         else
         {
             //Update the item manager
             MyObjectBuilder_Inventory inventory = (MyObjectBuilder_Inventory)ObjectBuilder;
             List<InventoryItemEntity> itemList = new List<InventoryItemEntity>();
             foreach (MyObjectBuilder_InventoryItem item in inventory.Items)
             {
                 InventoryItemEntity newItem = new InventoryItemEntity(item);
                 newItem.Container = this;
                 itemList.Add(newItem);
             }
             m_itemManager.Load(itemList);
         }
     }
     catch (Exception ex)
     {
         LogManager.ErrorLog.WriteLine(ex);
     }
 }
Exemplo n.º 8
0
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            Clear();

            if (objectBuilder == null)
                return;
            if (!Sync.IsServer)
                m_nextItemID = objectBuilder.nextItemId;
            else
                m_nextItemID = 0;
            int i = 0;
            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount <= 0)
                {
                    // Remove all items with 0 amount when loading inventory.
                    // Should only solve backward problems with saves. 0 amount items should not be created.
                    Debug.Fail(string.Format("Removing item with invalid amount: {0}x '{1}'. This is safe to ignore.", item.Amount, item.PhysicalContent.GetObjectId()));
                    continue;
                }

                var contentId = item.PhysicalContent.GetObjectId();

                if (!CanItemsBeAdded(item.Amount, contentId))
                    continue;

                var canStackWithItself = item.PhysicalContent.CanStack(item.PhysicalContent);
                if (!canStackWithItself)
                {
                    MyFixedPoint added = 0;
                    while (added < item.Amount)
                    {
                        AddItemsInternal(1, item.PhysicalContent, i, itemId: (Sync.IsServer) ? null : (uint?)item.ItemId);
                        added += 1;
                        ++i;
                    }
                }
                else
                {
                    if (Sync.IsServer)
                        AddItemsInternal(item.Amount, item.PhysicalContent, i);
                    else
                        //Building from information recieved from server - dont send msg about adding this
                        AddItemsInternal(item.Amount, item.PhysicalContent, i, itemId: item.ItemId);
                }
                i++;
            }
            VerifyIntegrity();
        }
Exemplo n.º 9
0
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            Clear();

            if (objectBuilder == null)
            {
                if (myObjectBuilder_InventoryDefinition != null)
                {
                    m_maxMass = (MyFixedPoint)myObjectBuilder_InventoryDefinition.InventoryMass;
                    m_maxVolume = (MyFixedPoint)myObjectBuilder_InventoryDefinition.InventoryVolume;
                    m_size = new Vector3(myObjectBuilder_InventoryDefinition.InventorySizeX, myObjectBuilder_InventoryDefinition.InventorySizeY, myObjectBuilder_InventoryDefinition.InventorySizeZ);
                }
                return;
            }

            if (objectBuilder.Mass.HasValue)
                m_maxMass = objectBuilder.Mass.Value;
            if (objectBuilder.Volume.HasValue)
            {
                MyFixedPoint savedValue = objectBuilder.Volume.Value;
                if (savedValue != MyFixedPoint.MaxValue || MyPerGameSettings.ConstrainInventory() == false)
                {
                    m_maxVolume = savedValue;
                }
            }
            if (objectBuilder.Size.HasValue)
                m_size = objectBuilder.Size.Value;
            if (objectBuilder.InventoryFlags.HasValue)
                m_flags = objectBuilder.InventoryFlags.Value;

            // HACK: when the session is being loaded, ids get reset. Later on they stay the same. This fixes the issue with desync of ids which may cause inventories to work incorrectly
            bool keepIds = !Sync.IsServer || MySession.Ready;
            if (keepIds)
                m_nextItemID = objectBuilder.nextItemId;
            else
                m_nextItemID = 0;

            int i = 0;
            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount <= 0)
                {
                    // Remove all items with 0 amount when loading inventory.
                    // Should only solve backward problems with saves. 0 amount items should not be created.
                    Debug.Fail(string.Format("Removing item with invalid amount: {0}x '{1}'. This is safe to ignore.", item.Amount, item.PhysicalContent.GetObjectId()));
                    continue;
                }

                if (!MyInventoryItemAdapter.Static.TryAdapt(item.PhysicalContent.GetObjectId()))
                {
                    Debug.Assert(false, "Invalid inventory item: " + item.PhysicalContent.GetObjectId().ToString() + " Not adding it!");
                    continue;
                }

                var contentId = item.PhysicalContent.GetObjectId();

                if (!CanItemsBeAdded(item.Amount, contentId))
                    continue;

                var canStackWithItself = item.PhysicalContent.CanStack(item.PhysicalContent);
                if (!canStackWithItself)
                {
                    MyFixedPoint added = 0;
                    while (added < item.Amount)
                    {
                        AddItemsInternal(1, item.PhysicalContent, i, itemId: !keepIds ? null : (uint?)item.ItemId);
                        added += 1;
                        ++i;
                    }
                }
                else
                {
                    if (!keepIds)
                        AddItemsInternal(item.Amount, item.PhysicalContent, i);
                    else
                        //Building from information recieved from server - dont send msg about adding this
                        AddItemsInternal(item.Amount, item.PhysicalContent, i, itemId: item.ItemId);
                }
                i++;
            }
            VerifyIntegrity();
        }
Exemplo n.º 10
0
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            Clear();

            if (objectBuilder == null)
                return;

            if (objectBuilder.Mass.HasValue)
                m_maxMass = objectBuilder.Mass.Value;
            if (objectBuilder.Volume.HasValue)
            {
                MyFixedPoint savedValue = objectBuilder.Volume.Value;
                if(savedValue != MyFixedPoint.MaxValue || MyPerGameSettings.ConstrainInventory() == false)
                {
                    m_maxVolume = savedValue;
                }
            }
            if (objectBuilder.Size.HasValue)
                m_size = objectBuilder.Size.Value;
            if (objectBuilder.InventoryFlags.HasValue)
                m_flags = objectBuilder.InventoryFlags.Value;

            if (!Sync.IsServer)
                m_nextItemID = objectBuilder.nextItemId;
            else
                m_nextItemID = 0;

            int i = 0;
            foreach (var item in objectBuilder.Items)
            {
                if (item.Amount <= 0)
                {
                    // Remove all items with 0 amount when loading inventory.
                    // Should only solve backward problems with saves. 0 amount items should not be created.
                    Debug.Fail(string.Format("Removing item with invalid amount: {0}x '{1}'. This is safe to ignore.", item.Amount, item.PhysicalContent.GetObjectId()));
                    continue;
                }

                if (!MyInventoryItemAdapter.Static.TryAdapt(item.PhysicalContent.GetObjectId()))
                {
                    Debug.Assert(false, "Invalid inventory item: " + item.PhysicalContent.GetObjectId().ToString() + " Not adding it!");
                    continue;
                }

                var contentId = item.PhysicalContent.GetObjectId();

                if (!CanItemsBeAdded(item.Amount, contentId))
                    continue;

                var canStackWithItself = item.PhysicalContent.CanStack(item.PhysicalContent);
                if (!canStackWithItself)
                {
                    MyFixedPoint added = 0;
                    while (added < item.Amount)
                    {
                        AddItemsInternal(1, item.PhysicalContent, i, itemId: (Sync.IsServer) ? null : (uint?)item.ItemId);
                        added += 1;
                        ++i;
                    }
                }
                else
                {
                    if (Sync.IsServer)
                        AddItemsInternal(item.Amount, item.PhysicalContent, i);
                    else
                        //Building from information recieved from server - dont send msg about adding this
                        AddItemsInternal(item.Amount, item.PhysicalContent, i, itemId: item.ItemId);
                }
                i++;
            }
            VerifyIntegrity();
        }
Exemplo n.º 11
0
        private static InventoryEditorModel ParseInventory(MyObjectBuilder_Inventory inventory, MyObjectBuilder_CubeBlockDefinition definition = null)
        {
            if (inventory == null)
                return null;
            float volumeMultiplier = 1f; // Unsure if there should be a default of 1 if there isn't a InventorySize defined.

            if (definition == null)
                volumeMultiplier = 0.4f;
            else
            {
                var definitionType = definition.GetType();
                var invSizeField = definitionType.GetField("InventorySize");
                var inventoryMaxVolumeField = definitionType.GetField("InventoryMaxVolume");
                if (invSizeField != null)
                {
                    var invSize = (Vector3)invSizeField.GetValue(definition);
                    volumeMultiplier = invSize.X * invSize.Y * invSize.Z;
                }
                if (inventoryMaxVolumeField != null)
                {
                    var maxSize = (float)inventoryMaxVolumeField.GetValue(definition);
                    volumeMultiplier = MathHelper.Min(volumeMultiplier, maxSize);
                }
            }

            var settings = SpaceEngineersCore.WorldResource.Checkpoint.Settings;
            return new InventoryEditorModel(inventory, volumeMultiplier * 1000 * settings.InventorySizeMultiplier, null) { Name = inventory.InventoryFlags.ToString(), IsValid = true };
        }