示例#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;
                }
            }
        }
示例#3
0
        public void Update10()
        {
            if (Globals.ElapsedTime < m_nextHack)
            {
                return;
            }
            if (!m_hackBlock.IsWorking)
            {
                m_strengthLeft = 0f;
                return;
            }
            IMyCubeGrid attached = m_hackBlock.GetAttachedEntity() as IMyCubeGrid;

            if (attached == null)
            {
                m_strengthLeft = 0f;
                return;
            }

            // break force might be removed from game entirely
            //if (m_hackBlock.BreakForce > allowedBreakForce)
            //{
            //	Log.DebugLog("break force too high: " + m_hackBlock.BreakForce);
            //	ITerminalProperty<float> prop = m_hackBlock.GetProperty("BreakForce") as ITerminalProperty<float>;
            //	if (prop == null)
            //	{
            //		Log.DebugLog("break force is disabled in SE", Logger.severity.INFO);
            //		allowedBreakForce = float.PositiveInfinity;
            //	}
            //	else
            //		prop.SetValue(m_hackBlock, allowedBreakForce);
            //}
            //if (allowedBreakForce == float.PositiveInfinity)

            // landing gear is unbreakable, disconnect / fail if not otherwise attached
            if (!AttachedGrid.IsGridAttached(m_hackBlock.CubeGrid as IMyCubeGrid, attached, AttachedGrid.AttachmentKind.Physics))
            {
                Log.DebugLog("no other connection to attached, hacker must disconnect", Logger.severity.DEBUG);
                ITerminalProperty <bool> autolock = m_hackBlock.GetProperty("Autolock") as ITerminalProperty <bool>;
                if (autolock.GetValue(m_hackBlock))
                {
                    autolock.SetValue(m_hackBlock, false);
                }
                m_hackBlock.GetActionWithName("Unlock").Apply(m_hackBlock);
                return;
            }

            m_nextHack = Globals.ElapsedTime + s_hackFrequency;

            m_strengthLeft += s_hackStrength;

            foreach (int i in Enumerable.Range(0, 8).OrderBy(x => Globals.Random.Next()))
            {
                Disruption disrupt;
                switch (i)
                {
                case 0:
                    disrupt = new AirVentDepressurize();
                    break;

                case 1:
                    disrupt = new DoorLock();
                    break;

                case 2:
                    disrupt = new GravityReverse();
                    break;

                case 3:
                    disrupt = new DisableTurret();
                    break;

                case 4:
                    disrupt = new TraitorTurret();
                    break;

                case 5:
                    disrupt = new CryoChamberMurder();
                    break;

                case 6:
                    disrupt = new JumpDriveDrain();
                    break;

                case 7:
                    disrupt = new MedicalRoom();
                    break;

                default:
                    Log.AlwaysLog("Case not implemented: " + i, Logger.severity.FATAL);
                    continue;
                }
                foreach (IMyCubeGrid grid in AttachedGrid.AttachedGrids(attached, AttachedGrid.AttachmentKind.Terminal, true))
                {
                    disrupt.Start(grid, s_hackLength, ref m_strengthLeft, m_hackBlock.OwnerId);
                }
            }
        }
示例#4
0
        public UnLander(Pathfinder pathfinder, PseudoBlock unlandBlock = null)
            : base(pathfinder)
        {
            this.m_unlandBlock = unlandBlock ?? m_navSet.Settings_Current.LandingBlock ?? m_navSet.LastLandingBlock;

            if (this.m_unlandBlock == null)
            {
                Log.DebugLog("No unland block", Logger.severity.INFO);
                return;
            }
            Log.DebugLog("Unland block is missing Block property", Logger.severity.FATAL, condition: this.m_unlandBlock.Block == null);

            IMyLandingGear asGear = m_unlandBlock.Block as IMyLandingGear;

            if (asGear != null)
            {
                m_destination.Entity = asGear.GetAttachedEntity();
                Log.DebugLog("m_destination.Entity: " + m_destination.Entity);
                if (m_destination.Entity == null)
                {
                    Log.DebugLog("Not attached: " + m_unlandBlock.Block.DisplayNameText, Logger.severity.INFO);
                    return;
                }
                Log.DebugLog("Got attached entity from Landing Gear : " + m_unlandBlock.Block.DisplayNameText, Logger.severity.DEBUG);
            }
            else
            {
                IMyShipConnector asConn = m_unlandBlock.Block as IMyShipConnector;
                if (asConn != null)
                {
                    Log.DebugLog("connector");
                    IMyShipConnector other = asConn.OtherConnector;
                    if (other == null)
                    {
                        Log.DebugLog("Not connected: " + m_unlandBlock.Block.DisplayNameText, Logger.severity.INFO);
                        return;
                    }
                    Log.DebugLog("Got attached connector from Connector : " + m_unlandBlock.Block.DisplayNameText, Logger.severity.DEBUG);
                    m_destination.Entity = other.CubeGrid;
                }
                else
                {
                    Log.DebugLog("Cannot unland block: " + m_unlandBlock.Block.DisplayNameText, Logger.severity.INFO);
                    m_unlandBlock.Block.EnableGameThread(false);
                }
            }

            MyLandingGear landingGear = this.m_unlandBlock.Block as MyLandingGear;

            if (landingGear != null)
            {
                MyAPIGateway.Utilities.TryInvokeOnGameThread(() => {
                    landingGear.Enabled  = true;
                    landingGear.AutoLock = true;
                });
            }

            m_detachOffset = m_unlandBlock.Block.GetPosition() - m_destination.Entity.GetPosition();

            //m_detachDirection = m_unlandBlock.WorldMatrix.Backward;
            //m_detachLength = 2f;
            //m_detatchedOffset = attachOffset + leaveDirection * (20f + m_navSet.Settings_Current.DestinationRadius);
            //Log.DebugLog("m_detatchedOffset: " + m_detatchedOffset, "UnLander()", Logger.severity.DEBUG);
            //m_detatchDirection = attachOffset + leaveDirection

            //Log.DebugLog("offset: " + m_detachOffset + ", direction: " + m_detachDirection);

            m_destination.Position = m_unlandBlock.WorldMatrix.Backward * 100f;

            m_navSet.Settings_Task_NavMove.NavigatorMover   = this;
            m_navSet.Settings_Task_NavMove.NavigatorRotator = this;
        }