示例#1
0
        private MyRespawnComponent GetNearestRespawn(Vector3D position, out List <MyRespawnComponent> respawns, long?identityId = null)
        {
            respawns = new List <MyRespawnComponent>();
            MyRespawnComponent closestRespawn = null;
            float closestDistance             = float.MaxValue;

            foreach (var respawn in MyRespawnComponent.GetAllRespawns())
            {
                float distance = float.MaxValue;
                var   block    = respawn.Entity as MyCubeBlock;
                if (block != null)
                {
                    if (!block.IsWorking)
                    {
                        continue;
                    }
                    if (identityId.HasValue && !block.GetUserRelationToOwner(identityId.Value).IsFriendly())
                    {
                        continue;
                    }

                    float distanceFromCenter = (float)block.PositionComp.GetPosition().Length();

                    //Limit spawn position to be inside the world (with some safe margin)
                    if ((!MyEntities.IsWorldLimited() && distanceFromCenter > MAX_DISTANCE_TO_RESPAWN) ||
                        (MyEntities.IsWorldLimited() && distanceFromCenter > MyEntities.WorldSafeHalfExtent()))
                    {
                        continue;
                    }

                    distance = (float)Vector3D.Distance(position, block.PositionComp.GetPosition());
                }
                else
                {
                    if (respawn.Entity == null)
                    {
                        continue;
                    }
                    if (respawn.Entity.PositionComp == null)
                    {
                        continue;
                    }

                    distance = (float)Vector3D.Distance(position, respawn.Entity.PositionComp.GetPosition());
                }

                if (distance < closestDistance)
                {
                    closestRespawn  = respawn;
                    closestDistance = distance;
                }

                respawns.Add(respawn);
            }

            return(closestRespawn);
        }
        private void SpawnInRespawn(MyPlayer player, MyRespawnComponent respawn, MyBotDefinition botDefinition)
        {
            if (MySession.Static.Settings.EnableOxygen)
            {
                player.Identity.ChangeToOxygenSafeSuit();
            }

            if (respawn.Entity == null)
            {
                Debug.Assert(false, "Respawn does not have entity!");
                SpawnInSuit(player, null, botDefinition);
                return;
            }
            var parent = respawn.Entity.GetTopMostParent();

            if (parent.Physics == null)
            {
                Debug.Assert(false, "Respawn entity parent does not have physics!");
                SpawnInSuit(player, (MyEntity)parent, botDefinition);
                return;
            }

            MatrixD pos;

            var medRoom = respawn.Entity as MyMedicalRoom;

            if (medRoom != null)
            {
                pos = medRoom.GetSpawnPosition();
            }
            else
            {
                pos = respawn.GetSpawnPosition(respawn.Entity.WorldMatrix);
            }

            Vector3 velocity = parent.Physics.GetVelocityAtPoint(pos.Translation);

            MyMultiplayer.ReplicateImmediatelly(MyExternalReplicable.FindByObject(parent), new EndpointId(player.Id.SteamId));

            player.SpawnAt(pos, velocity, (MyEntity)parent, botDefinition, true);

            if (medRoom != null)
            {
                medRoom.TryTakeSpawneeOwnership(player);
                medRoom.TrySetFaction(player);

                if (medRoom.ForceSuitChangeOnRespawn)
                {
                    player.Character.ChangeModelAndColor(medRoom.RespawnSuitName, player.Character.ColorMask);
                }
            }
        }
示例#3
0
 private void UpdateRespawnShipLabel()
 {
     if (m_selectedRespawnShip == null)
     {
         m_multilineRespawnWhenShipReady.Visible = false;
     }
     else
     {
         MyRespawnComponent.GetRespawnCooldownSeconds(MySession.LocalHumanPlayer.Id, m_selectedRespawnShip.Id.SubtypeName);
         m_multilineRespawnWhenShipReady.Text.Clear().AppendFormat(MyTexts.GetString(MySpaceTexts.ScreenMedicals_RespawnWhenShipReady), m_selectedRespawnShip.DisplayNameText);
         m_multilineRespawnWhenShipReady.RefreshText(false);
         m_multilineRespawnWhenShipReady.Visible = true;
     }
 }
示例#4
0
        private static void AddShipRespawnInfo(MyRespawnShipDefinition respawnShip, StringBuilder text)
        {
            int respawnSeconds = MySession.LocalHumanPlayer == null ? 0 : MyRespawnComponent.GetRespawnCooldownSeconds(MySession.LocalHumanPlayer.Id, respawnShip.Id.SubtypeName);

            if (!MyRespawnComponent.IsSynced)
            {
                text.Append(MyTexts.Get(MySpaceTexts.ScreenMedicals_RespawnShipNotReady));
            }
            else if (respawnSeconds != 0)
            {
                MyValueFormatter.AppendTimeExact(respawnSeconds, text);
            }
            else
            {
                text.Append(MyTexts.Get(MySpaceTexts.ScreenMedicals_RespawnShipReady));
            }
        }
示例#5
0
        private void SpawnInRespawn(MyPlayer player, MyRespawnComponent respawn)
        {
            if (MySession.Static.Settings.EnableOxygen)
            {
                player.Identity.ChangeToOxygenSafeSuit();
            }

            if (respawn.Entity == null)
            {
                Debug.Assert(false, "Respawn does not have entity!");
                SpawnInSuit(player);
                return;
            }
            var parent = respawn.Entity.GetTopMostParent();

            if (parent.Physics == null)
            {
                Debug.Assert(false, "Respawn entity parent does not have physics!");
                SpawnInSuit(player);
                return;
            }

            MatrixD pos;

            var medRoom = respawn.Entity as MyMedicalRoom;

            if (medRoom != null)
            {
                pos = medRoom.GetSpawnPosition();
            }
            else
            {
                pos = respawn.GetSpawnPosition(respawn.Entity.WorldMatrix);
            }

            Vector3 velocity = parent.Physics.GetVelocityAtPoint(pos.Translation);

            player.SpawnAt(pos, velocity, false);

            if (medRoom != null)
            {
                medRoom.TryTakeSpawneeOwnership(player);
                medRoom.TrySetFaction(player);
            }
        }
        /// <summary>
        /// Gets entities to pack into the session snapshot, customized for a given user
        /// </summary>
        /// <param name="steamId"></param>
        /// <returns></returns>
        private static MyObjectBuilder_Sector GetClientSector(ulong steamId)
        {
            MyObjectBuilder_Sector ob = MySession.Static.GetSector(false);

            if (EssentialsPlugin.Instance.Config.PackRespawn)
            {
                ob.SectorObjects = new List <MyObjectBuilder_EntityBase>();
                var grids = new HashSet <MyCubeGrid>();

                /*
                 * foreach (IMyMedicalRoomProvider room in MyMedicalRoomsSystem.GetMedicalRoomsInScene())
                 * {
                 *  if (room.Closed || !room.IsWorking || !(room.SetFactionToSpawnee || room.HasPlayerAccess(MySession.Static.Players.TryGetIdentityId(steamId))))
                 *      continue;
                 *
                 *  grids.Add(((MyMedicalRoom)room).CubeGrid);
                 * }
                 */
                foreach (var respawn in MyRespawnComponent.GetAllRespawns())
                {
                    if (respawn.Entity.Closed || !respawn.Entity.IsWorking || !respawn.CanPlayerSpawn(MySession.Static.Players.TryGetIdentityId(steamId), true))
                    {
                        continue;
                    }

                    grids.Add(respawn.Entity.CubeGrid);
                }

                if (EssentialsPlugin.Instance.Config.MaxPackedRespawnSize > 0)
                {
                    foreach (MyCubeGrid spawngrid in grids)
                    {
                        if (spawngrid.BlocksCount > EssentialsPlugin.Instance.Config.MaxPackedRespawnSize)
                        {
                            continue;
                        }

                        ob.SectorObjects.Add(spawngrid.GetObjectBuilder());
                    }
                }
            }

            return(ob);
        }
示例#7
0
        public override bool Update(bool hasFocus)
        {
            if (m_respawnsTable.RowsCount == 0 && State != MyGuiScreenState.CLOSING && MySession.LocalHumanPlayer != null)
            {
                MyPlayerCollection.RespawnRequest(joinGame: true, newPlayer: true, medicalId: 0, shipPrefabId: null);
                CloseScreen();
            }

            UpdateSpawnShipTimes();
            bool retval = base.Update(hasFocus);

            if (m_selectedRespawnShip != null)
            {
                int cooldown = MyRespawnComponent.GetRespawnCooldownSeconds(MySession.LocalHumanPlayer.Id, m_selectedRespawnShip.Id.SubtypeName);
                if (MyRespawnComponent.IsSynced && cooldown == 0)
                {
                    RespawnShipImmediately(m_selectedRespawnShip.Id.SubtypeName);
                }
            }

            return(retval);
        }
示例#8
0
        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);
        }
示例#9
0
        private void RespawnShip(string shipPrefabId)
        {
            int cooldown = (shipPrefabId == null || MySession.LocalHumanPlayer == null) ? 0 : MyRespawnComponent.GetRespawnCooldownSeconds(MySession.LocalHumanPlayer.Id, shipPrefabId);

            if (shipPrefabId == null || MyRespawnComponent.IsSynced && cooldown == 0)
            {
                RespawnShipImmediately(shipPrefabId);
            }
            else
            {
                var respawnShip = MyDefinitionManager.Static.GetRespawnShipDefinition(shipPrefabId);
                m_selectedRespawnShip = respawnShip;
                UpdateRespawnShipLabel();
            }
        }
示例#10
0
        public override 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 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);
                }
                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);
        }