public override void ProcessPacket(StationUIInitialSync packet, NebulaConnection conn)
        {
            StationComponent stationComponent = null;

            StationComponent[] stationPool = GameMain.data.galaxy.PlanetById(packet.PlanetId).factory.transport.stationPool;
            // Assume the requesting station is on a loaded planet
            stationComponent = stationPool?[packet.StationId];

            if (stationComponent == null)
            {
                Log.Error($"StationUIInitialSyncProcessor: Unable to find requested station on planet {packet.PlanetId} with id {packet.StationId} and gid of {packet.StationGId}");
                return;
            }
            if (stationComponent.gid > 0 && stationComponent.gid != packet.StationGId)
            {
                Log.Error($"StationGid desync! Host:{packet.StationGId} Local:{stationComponent.gid}");
            }

            stationComponent.tripRangeDrones       = packet.TripRangeDrones;
            stationComponent.tripRangeShips        = packet.TripRangeShips;
            stationComponent.deliveryDrones        = packet.DeliveryDrones;
            stationComponent.deliveryShips         = packet.DeliveryShips;
            stationComponent.warpEnableDist        = packet.WarperEnableDistance;
            stationComponent.warperNecessary       = packet.WarperNecessary;
            stationComponent.includeOrbitCollector = packet.IncludeOrbitCollector;
            stationComponent.energy        = packet.Energy;
            stationComponent.energyPerTick = packet.EnergyPerTick;
            stationComponent.pilerCount    = packet.PilerCount;

            for (int i = 0; i < packet.ItemId.Length; i++)
            {
                if (stationComponent.storage == null)
                {
                    stationComponent.storage = new StationStore[packet.ItemId.Length];
                }

                stationComponent.storage[i].itemId      = packet.ItemId[i];
                stationComponent.storage[i].max         = packet.ItemCountMax[i];
                stationComponent.storage[i].count       = packet.ItemCount[i];
                stationComponent.storage[i].inc         = packet.ItemInc[i];
                stationComponent.storage[i].remoteOrder = packet.RemoteOrder[i];
                stationComponent.storage[i].localLogic  = (ELogisticStorage)packet.LocalLogic[i];
                stationComponent.storage[i].remoteLogic = (ELogisticStorage)packet.RemoteLogic[i];
            }

            UIStationWindow stationWindow = UIRoot.instance.uiGame.stationWindow;

            if (stationWindow.active && stationWindow.factory?.planetId == packet.PlanetId && stationWindow.stationId == packet.StationId)
            {
                //Trigger OnStationIdChange() to refresh window
                stationWindow.OnStationIdChange();
            }
        }
Ejemplo n.º 2
0
        private void OpenStation(int factoryIndex, int stationId)
        {
            if (factoryIndex < 0 || stationId < 0)
            {
                return;
            }
            if (!GameMain.isRunning || GameMain.instance.isMenuDemo)
            {
                return;
            }
            _lastFactoryIndex        = factoryIndex;
            _lastStationFactoryIndex = stationId;
            if (_uiGame == null || (_uiStation) == null)
            {
                _uiGame    = UIRoot.instance.uiGame;
                _uiStation = _uiGame.stationWindow;
            }

            if (!_uiStation.inited)
            {
                return;
            }

            if (_uiStation.active)
            {
                UIRealtimeTip.Popup("请先关闭目前物流站".Translate());
                return;
            }

            if (GameMain.data.factories != null &&
                GameMain.data.factories.Length > factoryIndex &&
                GameMain.data.factories[factoryIndex] != null)
            {
                try
                {
                    var factory   = GameMain.data.factories[factoryIndex];
                    var transport = factory.transport;
                    if (transport.stationPool != null &&
                        transport.stationPool.Length >= stationId &&
                        transport.stationPool[stationId] != null
                        )
                    {
                        _uiStation.stationId = stationId;
                        _uiStation.active    = true;
                        if (!_uiStation.gameObject.activeSelf)
                        {
                            _uiStation.gameObject.SetActive(true);
                        }

                        _uiStation.factory     = factory;
                        _uiStation.transport   = factory.transport;
                        _uiStation.powerSystem = factory.powerSystem;
                        _uiStation.player      = GameMain.mainPlayer;
                        _uiStation.OnStationIdChange();

                        _uiStation.nameInput.onValueChanged.AddListener(_uiStation.OnNameInputSubmit);
                        _uiStation.nameInput.onEndEdit.AddListener(_uiStation.OnNameInputSubmit);
                        _uiStation.player.onIntendToTransferItems += _uiStation.OnPlayerIntendToTransferItems;

                        _uiStation.transform.SetAsLastSibling();
                        _uiGame.OpenPlayerInventory();
                        _inspectingStation = true;
                    }
                    else
                    {
                        UIRealtimeTip.Popup("物流站ID不存在".Translate());
                    }
                }
                catch (Exception message)
                {
                    _inspectingStation = false;
                    Debug.Log(message.StackTrace);
                }
            }
            else
            {
                UIRealtimeTip.Popup("工厂不存在".Translate());
            }
        }