예제 #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);
        }
예제 #2
0
        private void Disconnect()
        {
            IMyLandingGear asGear = m_unlandBlock.Block as IMyLandingGear;

            if (asGear != null)
            {
                m_attached = asGear.GetAttachedEntity() != null;
                if (m_attached)
                {
                    Log.DebugLog("Unlocking landing gear", Logger.severity.DEBUG);
                    MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                        asGear.ApplyAction("Unlock");
                    });
                }
            }
            else
            {
                MyShipConnector asConn = (MyShipConnector)m_unlandBlock.Block;
                if (asConn != null)
                {
                    m_attached = asConn.Connected;
                    if (m_attached)
                    {
                        MyShipConnector otherConnector = (MyShipConnector)((IMyShipConnector)asConn).OtherConnector;
                        ReserveTarget(otherConnector.EntityId);
                        Log.DebugLog("Unlocking connector", Logger.severity.DEBUG);
                        MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                            asConn.Enabled         = true;
                            otherConnector.Enabled = true;
                            asConn.ApplyAction("Unlock");
                        });
                    }
                }
                else
                {
                    Log.DebugLog("cannot unlock: " + m_unlandBlock.Block.DisplayNameText, Logger.severity.INFO);
                    m_attached = false;
                }
            }
        }