Пример #1
0
        private void LandingGearOnStateChanged(bool state)
        {
            if (!state)
            {
                return;
            }

            var ship = _landingGear.GetTopMostParent(typeof(IMyCubeGrid));

            if (ship == null)
            {
                return;
            }

            IMyPlayer player = null;

            foreach (var workingCockpit in _landingGear.CubeGrid.FindWorkingCockpits())
            {
                player = MyAPIGateway.Players.GetPlayerControllingEntity(workingCockpit.Entity);

                if (player != null)
                {
                    break;
                }
            }

            var attachedEntity = _landingGear.GetAttachedEntity() as IMyCubeGrid;

            if (attachedEntity == null)
            {
                return;
            }

            if (!ProtectionHandler.IsProtected(attachedEntity))
            {
                return;
            }

            if (player == null)
            {
                _landingGear.ApplyAction("Unlock");
                // we turn it off to prevent 'spamming'
                _landingGear.RequestEnable(false);
                return;
            }

            if (ProtectionHandler.CanModify(player, attachedEntity))
            {
                return;
            }

            _landingGear.ApplyAction("Unlock");
            // we turn it off to prevent 'spamming'
            _landingGear.RequestEnable(false);
        }
        public override void UpdateBeforeSimulation()
        {
            if (_multiplayerActive && MyAPIGateway.CubeBuilder != null &&
                MyAPIGateway.CubeBuilder.BlockCreationIsActivated && MyAPIGateway.Session.Player != null &&
                MyAPIGateway.Session.Player.Controller.ControlledEntity != null)
            {
                if (ChatCommandLogic.Instance != null && !ChatCommandLogic.Instance.AllowBuilding)
                {
                    MyAPIGateway.CubeBuilder.DeactivateBlockCreation();
                    MyAPIGateway.Utilities.ShowNotification(
                        "Protection is not loaded yet so any building is not allowed. Please try again later.",
                        2000,
                        MyFontEnum.Red);
                }
                else if (ProtectionHandler.Config.ProtectionEnabled)
                {
                    var cubeGrid = Support.FindLookAtEntity(MyAPIGateway.Session.Player.Controller.ControlledEntity, true, false, false, false, false, false) as IMyCubeGrid;

                    if (_cachedGrid == null || (_cachedGrid != null && cubeGrid != _cachedGrid))
                    {
                        if (cubeGrid != null && MyAPIGateway.Session.Player != null)
                        {
                            // TODO consider permission request from server instead of client side check... downside: might take a while
                            if (!ProtectionHandler.CanModify(MyAPIGateway.Session.Player, cubeGrid) &&
                                ProtectionHandler.IsProtected(cubeGrid))
                            {
                                _cachedGrid = cubeGrid;
                                Deactivate();
                            }
                        }
                    }
                    else
                    {
                        Deactivate();
                    }
                }
            }
            else if (!_multiplayerActive && (_multiplayerActive != (MyAPIGateway.Session.OnlineMode != MyOnlineModeEnum.OFFLINE)))
            {
                // we need to update it because it is not correctly initialized if the cube placer is created when the game loads
                _multiplayerActive = MyAPIGateway.Session.OnlineMode != MyOnlineModeEnum.OFFLINE;
            }

            base.UpdateBeforeSimulation();
        }
Пример #3
0
        private void LandingGearOnStateChanged(bool state)
        {
            if (!state)
            {
                return;
            }
            //private void LandingGearOnLockModeChanged(IMyLandingGear myLandingGear, SpaceEngineers.Game.ModAPI.Ingame.LandingGearMode landingGearMode)
            //{
            //    if (landingGearMode != SpaceEngineers.Game.ModAPI.Ingame.LandingGearMode.Locked)
            //        return;

            if (ProtectionHandler.Config == null ||
                !ProtectionHandler.Config.ProtectionEnabled ||
                ProtectionHandler.Config.ProtectionAllowLandingGear)
            {
                return;
            }

            var ship = _landingGear.GetTopMostParent(typeof(IMyCubeGrid));

            if (ship == null)
            {
                return;
            }

            IMyPlayer player = null;

            foreach (var workingCockpit in _landingGear.CubeGrid.FindWorkingCockpits())
            {
                player = MyAPIGateway.Players.GetPlayerControllingEntity(workingCockpit.Entity);

                if (player != null)
                {
                    break;
                }
            }

            var attachedEntity = _landingGear.GetAttachedEntity() as IMyCubeGrid;

            if (attachedEntity == null)
            {
                return;
            }

            if (!ProtectionHandler.IsProtected(attachedEntity))
            {
                return;
            }

            if (player == null)
            {
                _landingGear.Unlock();
                // we turn it off to prevent 'spamming'
                _landingGear.Enabled = false;
                return;
            }

            if (ProtectionHandler.CanModify(player, attachedEntity))
            {
                return;
            }

            _landingGear.Unlock();
            // we turn it off to prevent 'spamming'
            _landingGear.Enabled = false;
        }