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!"); if (!MySessionComponentMissionTriggers.CanRespawn(playerId)) { return(false); } 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 { SpawnAsNewPlayer(player, currentPosition, respawnShipId, resetIdentity); } } return(true); }
public override bool HandleRespawnRequest(bool joinGame, bool newIdentity, long medicalRoomId, string respawnShipId, MyPlayer.PlayerId playerId, Vector3D?spawnPosition, VRage.ObjectBuilders.SerializableDefinitionId?botDefinitionId) { MyPlayer player = Sync.Players.GetPlayerById(playerId); bool spawnAsNewPlayer = newIdentity || player == null; Debug.Assert(player == null || player.Identity != null, "Respawning player has no identity!"); if (!MySessionComponentMissionTriggers.CanRespawn(playerId)) { return(false); } Vector3D currentPosition = Vector3D.Zero; if (player != null && player.Character != null) { currentPosition = player.Character.PositionComp.GetPosition(); } if (TryFindCryoChamberCharacter(player)) { //Player found in chamber; return(true); } MyBotDefinition botDefinition = null; if (botDefinitionId != null) { MyDefinitionManager.Static.TryGetBotDefinition((MyDefinitionId)botDefinitionId, out botDefinition); } if (!spawnAsNewPlayer) { if (respawnShipId != null) { SpawnAtShip(player, respawnShipId, botDefinition); return(true); } if (spawnPosition.HasValue) { Vector3D gravity = MyGravityProviderSystem.CalculateTotalGravityInPoint(spawnPosition.Value); if (Vector3D.IsZero(gravity)) { gravity = Vector3D.Down; } else { gravity.Normalize(); } Vector3D perpendicular; gravity.CalculatePerpendicularVector(out perpendicular); player.SpawnAt(MatrixD.CreateWorld(spawnPosition.Value, perpendicular, -gravity), Vector3.Zero, null, botDefinition, true); return(true); } // Find respawn block to spawn at MyRespawnComponent foundRespawn = null; if (medicalRoomId == 0 || !MyFakes.SHOW_FACTIONS_GUI) { List <MyRespawnComponent> respawns = null; var nearestRespawn = GetNearestRespawn(currentPosition, out respawns, MySession.Static.CreativeMode ? (long?)null : player.Identity.IdentityId); if (joinGame && respawns.Count > 0) { foundRespawn = respawns[MyRandom.Instance.Next(0, respawns.Count)]; } } else { foundRespawn = FindRespawnById(medicalRoomId, player); if (foundRespawn == null) { return(false); } } // If spawning in respawn block fails, we will spawn as a new player if (foundRespawn != null) { SpawnInRespawn(player, foundRespawn, botDefinition); } else { spawnAsNewPlayer = true; } } if (spawnAsNewPlayer) { bool resetIdentity = false; if (MySession.Static.Settings.PermanentDeath.Value) { var oldIdentity = Sync.Players.TryGetPlayerIdentity(playerId); resetIdentity = oldIdentity.FirstSpawnDone; } 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, 2, 200); if (correctedPos.HasValue) { currentPosition = correctedPos.Value; } player.SpawnAt(Matrix.CreateTranslation(currentPosition), Vector3.Zero, null, botDefinition); } else { SpawnAsNewPlayer(player, currentPosition, respawnShipId, resetIdentity, botDefinition); } } return(true); }