Пример #1
0
        private static void SpawnInMedicalRoom(MyPlayer player, MyMedicalRoom medical, bool joiningGame)
        {
            if (MySession.Static.Settings.EnableOxygen)
            {
                player.Identity.ChangeToOxygenSafeSuit();
            }

            if (medical.HasSpawnPosition())
            {
                Matrix matrix = medical.GetSpawnPosition();
                player.SpawnAt(matrix, medical.Parent.Physics.LinearVelocity, false);
            }
            else if (joiningGame)
            {
                Vector3 medicalPosition = medical.PositionComp.GetPosition();
                medicalPosition += -medical.WorldMatrix.Up + medical.WorldMatrix.Right;
                Matrix matrix = medical.WorldMatrix;
                matrix.Translation = medicalPosition;
                player.SpawnAt(matrix, medical.Parent.Physics.LinearVelocity);
            }
            else
            {
                Matrix  invWorldRot      = Matrix.Invert(medical.WorldMatrix.GetOrientation());
                Vector3 relativeVelocity = Vector3.Transform(medical.Parent.Physics.LinearVelocity, invWorldRot);
                player.SpawnAtRelative(medical, MyMedicalRoom.GetSafePlaceRelative(), relativeVelocity);
            }
        }
Пример #2
0
        public bool HandleRespawnRequest(bool joinGame, bool newIdentity, long medicalRoomId, string respawnShipId, MyPlayer.PlayerId playerId, Vector3D?spawnPosition)
        {
            MyPlayer player = Sync.Players.TryGetPlayerById(playerId);

            bool spawnAsNewPlayer = newIdentity || player == null;

            Debug.Assert(player == null || player.Identity != null, "Respawning player has no identity!");

            Vector3D currentPosition = Vector3D.Zero;

            if (player != null && player.Character != null)
            {
                currentPosition = player.Character.PositionComp.GetPosition();
            }

            if (TryFindCryoChamberCharacter(player))
            {
                //Player found in chamber;
                return(true);
            }

            if (!spawnAsNewPlayer)
            {
                // Find medical room to spawn at
                MyMedicalRoom medicalRoom = null;
                if (medicalRoomId == 0 || !MyFakes.SHOW_FACTIONS_GUI)
                {
                    List <MyMedicalRoom> medRooms = new List <MyMedicalRoom>();
                    medicalRoom = GetNearestMedRoom(currentPosition, out medRooms, MySession.Static.CreativeMode ? (long?)null : player.Identity.IdentityId);
                    if (joinGame && medRooms.Count > 0)
                    {
                        medicalRoom = medRooms[MyRandom.Instance.Next(0, medRooms.Count)];
                    }
                }
                else
                {
                    medicalRoom = FindRespawnMedicalRoom(medicalRoomId, player);
                    if (medicalRoom == null)
                    {
                        return(false);
                    }
                }

                // If spawning in medical room fails, we will spawn as a new player
                if (medicalRoom != null)
                {
                    SpawnInMedicalRoom(player, medicalRoom, joinGame);
                }
                else
                {
                    spawnAsNewPlayer = true;
                }
            }

            if (spawnAsNewPlayer)
            {
                bool resetIdentity = MySession.Static.Settings.PermanentDeath.Value;
                if (player == null)
                {
                    var identity = Sync.Players.CreateNewIdentity(player.DisplayName);
                    player        = Sync.Players.CreateNewPlayer(identity, playerId, player.DisplayName);
                    resetIdentity = false;
                }

                if (MySession.Static.CreativeMode)
                {
                    Vector3D?correctedPos = MyEntities.FindFreePlace(currentPosition, 1, 200);
                    if (correctedPos.HasValue)
                    {
                        currentPosition = correctedPos.Value;
                    }
                    player.SpawnAt(Matrix.CreateTranslation(currentPosition), Vector3.Zero);
                }
                else
                {
                    player.SpawnAsNewPlayer(currentPosition, respawnShipId, resetIdentity);
                }
            }

            return(true);
        }