Exemple #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);
        }