コード例 #1
0
        public override void UpdateBeforeSimulation10()
        {
            if (LcdPanel == null)
            {
                return;
            }

            LcdPanel.ShowPublicTextOnScreen();

            if (!NetworkTransmitter.IsSinglePlayerOrServer() ?? true)
            {
                return;
            }

            if (Station == null)
            {
                Station = Load();
                if (Station != null)
                {
                    StationManager.Register(this);
                }
            }

            // if no energy do nothing
            if (!LcdPanel.IsFunctional || !LcdPanel.IsWorking || !LcdPanel.Enabled || Station == null)
            {
                return;
            }

            const double refreshTime = 1f;

            try
            {
                if (DateTime.Now.Subtract(_lastSaved).TotalSeconds > 10f)
                {
                    Save(Station);
                }

                if (DateTime.Now.Subtract(_lastProductionUpdate).TotalSeconds < refreshTime)
                {
                    return;
                }

                Station.HandleProdCycle();
                _lastProductionUpdate = DateTime.Now;
                LcdOutput.UpdateLcdOutput(LcdPanel, Station);

                IMyCubeGrid grid = (IMyCubeGrid)LcdPanel.GetTopMostParent();
                if (grid == null)
                {
                    return;
                }
                List <IMySlimBlock> cargoBlockList = new List <IMySlimBlock>();
                grid.GetBlocks(
                    cargoBlockList,
                    slimBlock => slimBlock?.FatBlock != null &&
                    slimBlock.FatBlock.BlockDefinition.TypeId == typeof(MyObjectBuilder_CargoContainer) &&
                    LcdPanel.CubeGrid.EntityId ==
                    slimBlock.FatBlock.CubeGrid.EntityId              // only station container
                    );

                Station.HandleCargo(cargoBlockList);
            }
            catch (Exception ex)
            {
                MyAPIGateway.Utilities.ShowNotification($"Error: {ex.Message}\n{ex.StackTrace}");
            }
        }