示例#1
0
        public MyInventory(MyFixedPoint maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
        {
            m_maxVolume = MyPerGameSettings.ConstrainInventory() ? maxVolume * MySession.Static.InventoryMultiplier : MyFixedPoint.MaxValue;
            m_size      = size;
            m_flags     = flags;
            m_owner     = owner;

            Clear();

            SyncObject = new MySyncInventory();
        }
示例#2
0
        public MyInventory(MyFixedPoint maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
        {
            m_maxVolume = MyPerGameSettings.ConstrainInventory() ? maxVolume * MySession.Static.InventoryMultiplier : MyFixedPoint.MaxValue;
            m_size = size;
            m_flags = flags;
            m_owner = owner;

            Clear();

            SyncObject = new MySyncInventory();
        }
示例#3
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
        {
            m_maxVolume = maxVolume;
            m_maxMass   = maxMass;
            m_size      = size;
            m_flags     = flags;
            m_owner     = owner;

            Clear();

            SyncObject = new MySyncInventory();

            //ContentsChanged += OnContentsChanged;
        }
示例#4
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
        {
            m_maxVolume = maxVolume;
            m_maxMass = maxMass;
            m_size = size;
            m_flags = flags;
            m_owner = owner;

            Clear();

            SyncObject = new MySyncInventory();

            //ContentsChanged += OnContentsChanged;
        }
 public void SetFlags(MyInventoryFlags flags)
 {
     m_flags = flags;
 }
示例#6
0
 public MyInventory(MyObjectBuilder_InventoryDefinition definition, MyInventoryFlags flags, IMyInventoryOwner owner)
     : this(definition.InventoryVolume, definition.InventoryMass, new Vector3(definition.InventorySizeX, definition.InventorySizeY, definition.InventorySizeZ), flags, owner)
 {
     myObjectBuilder_InventoryDefinition = definition;
 }
示例#7
0
 public MyInventory(MyObjectBuilder_InventoryDefinition definition, MyInventoryFlags flags)
     : this(definition.InventoryVolume, definition.InventoryMass, new Vector3(definition.InventorySizeX, definition.InventorySizeY, definition.InventorySizeZ), flags)
 {
     myObjectBuilder_InventoryDefinition = definition;
 }
示例#8
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags)
            : base("Inventory")
        {
            m_maxVolume = maxVolume;
            m_maxMass = maxMass;
            m_flags = flags;

            SyncType = SyncHelpers.Compose(this);
            m_currentVolume.ValueChanged += (x) => PropertiesChanged();
            m_currentVolume.ValidateNever();

            m_currentMass.ValueChanged += (x) => PropertiesChanged();
            m_currentMass.ValidateNever();

            m_inventoryNotEmptyNotification = new MyHudNotification(font: MyFontEnum.Red, priority: 2, text: MyCommonTexts.NotificationInventoryNotEmpty);

            Clear();
        }
示例#9
0
 public MyInventory(float maxVolume, Vector3 size, MyInventoryFlags flags)
     : this((MyFixedPoint)maxVolume, MyFixedPoint.MaxValue, size, flags)
 {
 }
示例#10
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
            : base("Inventory")
        {
            m_maxVolume = maxVolume;
            m_maxMass = maxMass;
            m_size = size;
            m_flags = flags;
            m_owner = owner;

            Clear();

            SyncObject = new MySyncInventory();

            var handler = OnCreated;
            if (handler != null && m_owner != null) handler(this);
        }
示例#11
0
 public AddedMassInventory(float maxVolume, Vector3 size, MyInventoryFlags flags) : base(maxVolume, size, flags)
 {
 }
示例#12
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)
                m_maxVolume = objectBuilder.Volume.Value;
            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;
                }

                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();
        }
示例#13
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags, MyEntity owner)
            : base("Inventory")
        {
            m_maxVolume = maxVolume;
            m_maxMass = maxMass;
            m_flags = flags;

            SyncType = SyncHelpers.Compose(this);
            m_currentVolume.ValueChanged += (x) => PropertiesChanged();
            m_currentVolume.ValidateNever();

            m_currentMass.ValueChanged += (x) => PropertiesChanged();
            m_currentMass.ValidateNever();

            Clear();

            //Debug.Assert(owner != null, "Inventory must have always owner!"); - nope, this can be deserialized and therefore owner can be set to null..

            if (owner != null)
            {
                MyInventoryBase inventory;
                if ((owner as MyEntity).Components.TryGet<MyInventoryBase>(out inventory) && inventory is IMyComponentAggregate)
                {
                    IMyComponentAggregate aggregate = inventory as IMyComponentAggregate;
                    if (!aggregate.ChildList.Contains(this))
                    {
                        aggregate.AddComponent(this);
                    }
                }
                else if (inventory != null)
                {
                    MyInventoryAggregate aggregate = new MyInventoryAggregate();
                    (owner as MyEntity).Components.Add<MyInventoryBase>(aggregate);
                    aggregate.AddComponent(inventory);
                    aggregate.AddComponent(this);
                }
                else
                {
                    (owner as MyEntity).Components.Add<MyInventoryBase>(this);
                }
            }
        }
        private static void AddReachableEndpoints(IMyConveyorEndpointBlock processedBlock, List<IMyConveyorEndpointBlock> resultList, MyInventoryFlags flagToCheck, MyDefinitionId? definitionId = null)
        {
            foreach (var conveyorEndpoint in MyGridConveyorSystem.Pathfinding)
            {
                // Ignore originating block
                if (conveyorEndpoint.CubeBlock == processedBlock as MyCubeBlock) continue;

                // Ignore endpoints without a block
                if (conveyorEndpoint.CubeBlock == null) continue;

                // Ignore blocks without inventory
                if (!conveyorEndpoint.CubeBlock.HasInventory) continue;

                // Ignore blocks that do not implement IMyConveyorEndpointBlock interface
                IMyConveyorEndpointBlock endpointBlock = conveyorEndpoint.CubeBlock as IMyConveyorEndpointBlock;
                if (endpointBlock == null) continue;

                MyCubeBlock owner = conveyorEndpoint.CubeBlock;

                // Iterate inventories to make sure they can take the items
                bool isInventoryAvailable = false;
                for (int i = 0; i < owner.InventoryCount; ++i)
                {
                    var inventory = owner.GetInventory(i) as MyInventory;
                    System.Diagnostics.Debug.Assert(inventory != null, "Null or other inventory type!");

                    if ((inventory.GetFlags() & flagToCheck) == 0)
                        continue;

                    // Make sure target inventory can take this item
                    if (definitionId.HasValue && !inventory.CheckConstraint(definitionId.Value))
                        continue;

                    isInventoryAvailable = true;
                    break;
                }

                if (isInventoryAvailable && !resultList.Contains(endpointBlock))
                    resultList.Add(endpointBlock);
            }
        }
示例#15
0
 public MyInventory(float maxVolume, float maxMass, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
     : this((MyFixedPoint)maxVolume, (MyFixedPoint)maxMass, size, flags, owner)
 {
 }
示例#16
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)
            {
                m_maxVolume = objectBuilder.Volume.Value;
            }
            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;
                }

                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();
        }
示例#17
0
 public MyInventory(float maxVolume, Vector3 size, MyInventoryFlags flags, IMyInventoryOwner owner)
     : this((MyFixedPoint)maxVolume, size, flags, owner)
 {
 }
示例#18
0
 public MyInventory(float maxVolume, float maxMass, Vector3 size, MyInventoryFlags flags)
     : this((MyFixedPoint)maxVolume, (MyFixedPoint)maxMass, size, flags)
 {
 }
示例#19
0
        public MyInventory(MyFixedPoint maxVolume, MyFixedPoint maxMass, Vector3 size, MyInventoryFlags flags)
            : base("Inventory")
        {
            m_maxVolume = maxVolume;
            m_maxMass = maxMass;
            m_flags = flags;

#if !XB1 // !XB1_SYNC_NOREFLECTION
            SyncType = SyncHelpers.Compose(this);
#else // XB1
            SyncType = new SyncType(new List<SyncBase>());
            m_currentVolume = SyncType.CreateAndAddProp<MyFixedPoint>();
            m_currentMass = SyncType.CreateAndAddProp<MyFixedPoint>();
#endif // XB1
            m_currentVolume.ValueChanged += (x) => PropertiesChanged();
            m_currentVolume.ValidateNever();

            m_currentMass.ValueChanged += (x) => PropertiesChanged();
            m_currentMass.ValidateNever();

            m_inventoryNotEmptyNotification = new MyHudNotification(font: MyFontEnum.Red, priority: 2, text: MyCommonTexts.NotificationInventoryNotEmpty);

            Clear();
        }
示例#20
0
        public void Init(MyObjectBuilder_Inventory objectBuilder)
        {
            Clear(false);

            if (objectBuilder == null)
            {
                if (myObjectBuilder_InventoryDefinition != null)
                {
                    m_maxMass = (MyFixedPoint)myObjectBuilder_InventoryDefinition.InventoryMass;
                    m_maxVolume = (MyFixedPoint)myObjectBuilder_InventoryDefinition.InventoryVolume;
                    m_maxItemCount = myObjectBuilder_InventoryDefinition.MaxItemCount;
                }
                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.MaxItemCount.HasValue)
                m_maxItemCount = objectBuilder.MaxItemCount.Value;
            if (objectBuilder.InventoryFlags.HasValue)
                m_flags = objectBuilder.InventoryFlags.Value;

            RemoveEntityOnEmpty = objectBuilder.RemoveEntityOnEmpty;

            // 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.Static.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 (item.PhysicalContent == null)
                {
                    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();

                var fittingAmount = ComputeAmountThatFits(contentId);
                var addedAmount = MyFixedPoint.Min(fittingAmount, item.Amount);

                if (addedAmount == MyFixedPoint.Zero)
                    continue;

                var canStackWithItself = item.PhysicalContent.CanStack(item.PhysicalContent);
                if (!canStackWithItself)
                {
                    MyFixedPoint added = 0;
                    while (added < addedAmount)
                    {
                        AddItemsInternal(1, item.PhysicalContent, itemId: !keepIds ? null : (uint?)item.ItemId, index: i);
                        added += 1;
                        ++i;
                    }
                }
                else
                {
                    AddItemsInternal(addedAmount, item.PhysicalContent, itemId: !keepIds ? null : (uint?)item.ItemId, index: i);
                }
                i++;
            }
            VerifyIntegrity();
        }
示例#21
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;

            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();
        }
示例#22
0
 public void SetFlags(MyInventoryFlags flags)
 {
     m_flags = flags;
 }
示例#23
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;

            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();
        }