protected AbstractQuantumIoMachine(MachineEntityCreationParameters parameters) : base(parameters)
 {
     mbNeedsLowFrequencyUpdate = true;
     mbNeedsUnityUpdate        = true;
     PositionUtils.SetupSidesPositions(parameters.Flags, MachineSides);
     StorageIoService = new StorageIoService(this, MachineSides);
 }
        public override string GetPopupText()
        {
            var txt = DisplayUtils.MachineDisplay(MachineName);
            var quantumStorageController = StorageIoService.GetStorageController();

            if (quantumStorageController != null && quantumStorageController.IsOperating())
            {
                txt += DisplayUtils.StorageDisplay(quantumStorageController.GetMachineStorage());
            }
            if (ControllerPos[0] == 0 && ControllerPos[1] == 0 && ControllerPos[2] == 0 ||
                quantumStorageController == null)
            {
                txt += "QUANTUM STORAGE CONTROLLER NOT FOUND.\n";
            }

            if (quantumStorageController != null && !quantumStorageController.HasPower())
            {
                txt += "QUANTUM STORAGE CONTROLLER HAS NO POWER.\n";
            }

            if (Input.GetButtonDown("Interact") && UIManager.AllowInteracting)
            {
                UIManager.ForceNGUIUpdate = 0.1f;
                AudioHUDManager.instance.HUDIn();
            }

            return(txt);
        }
Exemple #3
0
        public bool TryTakeItem(StorageUserInterface sourceEntity, out ItemBase item, out ushort cubeType,
                                out ushort cubeValue, bool sendImmediateNetworkUpdate)
        {
            item      = null;
            cubeType  = 0;
            cubeValue = 0;

            if (!Enabled)
            {
                return(false);
            }

            if (Exemplar == null)
            {
                return(false);
            }

            var exemplarCopy = Exemplar.NewInstance();

            exemplarCopy.SetAmount(1);
            var itemBase = StorageIoService.GetStorageController().GetItems()
                           .Find(x => x.mnItemID == exemplarCopy.mnItemID);

            if (itemBase != null && itemBase.GetAmount() > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemple #4
0
        private void UpdateOutput()
        {
            var itemConsumer      = StorageIoService.GetItemConsumer();
            var storageController = StorageIoService.GetStorageController();

            if (storageController == null || !storageController.IsOperating() ||
                !storageController.IsOutputEnabled() || !Enabled ||
                itemConsumer == null || Exemplar == null)
            {
                return;
            }

            var exemplarCopy = Exemplar.NewInstance();
            var itemToGive   = Exemplar.NewInstance();

            exemplarCopy.SetAmount(1);
            itemToGive.SetAmount(1);

            if (exemplarCopy == null || exemplarCopy.GetAmount() <= 0)
            {
                return;
            }

            if (!ItemTaken)
            {
                var itemInStorage = StorageIoService.GetStorageController().GetItems()
                                    .Find(x => x.Compare(exemplarCopy));
                if (itemInStorage == null || itemInStorage.GetAmount() <= 0)
                {
                    return;
                }

                exemplarCopy.SetAmount(1);
                ItemTaken = StorageIoService.GetStorageController().TakeItem(ref exemplarCopy);
                if (!ItemTaken)
                {
                    return;
                }
            }

            if (itemConsumer.TryDeliverItem(this, itemToGive, 0, 0, true))
            {
                ItemTaken = false;
                MarkDirtyDelayed();
            }
        }
Exemple #5
0
        public override void LowFrequencyUpdate()
        {
            if (!WorldScript.mbIsServer)
            {
                return;
            }

            var storageController = StorageIoService.GetStorageController();

            if (storageController == null || _incomingItem == null || !storageController.IsOperating() || !storageController.IsInputEnabled())
            {
                return;
            }

            var itemLimit          = storageController.GetItemLimit(_incomingItem);
            var itemInStorage      = storageController.GetItems().Find(x => x.Compare(_incomingItem));
            var itemCountInStorage = 0;

            if (itemInStorage != null)
            {
                itemCountInStorage = itemInStorage.GetAmount();
            }

            var itemCountInStorageAfterAdd = _incomingItem.GetAmount() + itemCountInStorage;

            if (itemLimit > 0 && itemCountInStorageAfterAdd > itemLimit)
            {
                return;
            }

            storageController.AddItem(ref _incomingItem);
            if (_incomingItem == null || _incomingItem.GetAmount() == 0)
            {
                _incomingItem = null;
                MarkDirtyDelayed();
                RequestImmediateNetworkUpdate();
                return;
            }
        }
Exemple #6
0
        public bool TryDeliverItem(StorageUserInterface sourceEntity, ItemBase item, ushort cubeType, ushort cubeValue,
                                   bool sendImmediateNetworkUpdate)
        {
            if (!WorldScript.mbIsServer)
            {
                return(false);
            }
            if (_incomingItem != null || sourceEntity == null || (item == null && cubeType == 0 && cubeValue == 0))
            {
                return(false);
            }

            if (item == null)
            {
                item = ItemManager.SpawnCubeStack(cubeType, cubeValue, 1);
            }

            var storageController = StorageIoService.GetStorageController();

            if (storageController == null || !storageController.HasPower())
            {
                return(false);
            }

            if (_nextInsertDirection == Direction.LEFT)
            {
                _nextInsertDirection = Direction.RIGHT;
            }
            else if (_nextInsertDirection == Direction.RIGHT)
            {
                _nextInsertDirection = Direction.FRONT;
            }
            else if (_nextInsertDirection == Direction.FRONT)
            {
                _nextInsertDirection = Direction.LEFT;
            }

            SegmentEntity segment = (SegmentEntity)sourceEntity;

            PositionUtils.GetSegmentPos(MachineSides.Left, mnX, mnY, mnZ, out long x, out long y, out long z);
            if (_nextInsertDirection == Direction.LEFT && PositionUtils.IsSegmentPositionEqual(segment, x, y, z))
            {
                _incomingItem = item;
            }

            PositionUtils.GetSegmentPos(MachineSides.Right, mnX, mnY, mnZ, out x, out y, out z);
            if (_nextInsertDirection == Direction.RIGHT && PositionUtils.IsSegmentPositionEqual(segment, x, y, z))
            {
                _incomingItem = item;
            }

            PositionUtils.GetSegmentPos(MachineSides.Front, mnX, mnY, mnZ, out x, out y, out z);
            if (_nextInsertDirection == Direction.FRONT && PositionUtils.IsSegmentPositionEqual(segment, x, y, z))
            {
                _incomingItem = item;
            }

            MarkDirtyDelayed();
            if (_incomingItem == null)
            {
                return(false);
            }

            if (sendImmediateNetworkUpdate)
            {
                RequestImmediateNetworkUpdate();
            }

            return(true);
        }