Exemple #1
0
        public MyPlayer GetPlayer(int serialId)
        {
            var controllerId = new MyPlayer.PlayerId()
            {
                SteamId = m_steamUserId, SerialId = serialId
            };

            return(Sync.Players.GetPlayerById(controllerId));
        }
Exemple #2
0
        public static int GetRespawnCooldownSeconds(MyPlayer.PlayerId controllerId, string respawnShipId)
        {
            var respawnShip = MyDefinitionManager.Static.GetRespawnShipDefinition(respawnShipId);

            System.Diagnostics.Debug.Assert(respawnShip != null);
            if (respawnShip == null)
            {
                return(0);
            }

            var key = new RespawnKey()
            {
                ControllerId = controllerId, RespawnShipId = respawnShipId
            };
            int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            int time        = currentTime;

            m_globalRespawnTimesMs.TryGetValue(key, out time);
            return(Math.Max((time - currentTime) / 1000, 0));
        }
Exemple #3
0
        public static void ResetRespawnCooldown(MyPlayer.PlayerId controllerId)
        {
            var   respawnShips = MyDefinitionManager.Static.GetRespawnShipDefinitions();
            int   currentTime  = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            float multiplier   = MySession.Static.Settings.SpawnShipTimeMultiplier;

            foreach (var pair in respawnShips)
            {
                var key = new RespawnKey()
                {
                    ControllerId = controllerId, RespawnShipId = pair.Key
                };
                if (multiplier != 0)
                {
                    m_globalRespawnTimesMs.Add(key, currentTime + (int)(pair.Value.Cooldown * 1000 * multiplier), immediate: true);
                }
                else
                {
                    m_globalRespawnTimesMs.Remove(key);
                }
            }
        }
Exemple #4
0
        public static void InitFromCheckpoint(List <Common.ObjectBuilders.MyObjectBuilder_Checkpoint.RespawnCooldownItem> list)
        {
            m_lastUpdate = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_globalRespawnTimesMs.Clear();

            if (list == null)
            {
                return;
            }

            foreach (var item in list)
            {
                var controllerId = new MyPlayer.PlayerId()
                {
                    SteamId = item.PlayerSteamId, SerialId = item.PlayerSerialId
                };
                var key = new RespawnKey()
                {
                    ControllerId = controllerId, RespawnShipId = item.RespawnShipId
                };
                m_globalRespawnTimesMs.Add(key, item.Cooldown + m_lastUpdate, immediate: true);
            }
        }
Exemple #5
0
        static void SyncCooldownResponse(ref SyncCooldownResponseMessage msg, MyNetworkClient sender)
        {
            int currentTime = MySandboxGame.TotalGamePlayTimeInMilliseconds;

            // msg.respawnTimes can be null, if the server sent empty list
            if (msg.RespawnTimes != null)
            {
                foreach (var respawnTime in msg.RespawnTimes)
                {
                    var controllerId = new MyPlayer.PlayerId()
                    {
                        SteamId = MySteam.UserId, SerialId = respawnTime.ControllerId
                    };
                    var key = new RespawnKey()
                    {
                        ControllerId = controllerId, RespawnShipId = respawnTime.ShipId
                    };

                    m_globalRespawnTimesMs.Add(key, currentTime + respawnTime.RelativeRespawnTime, immediate: true);
                }
            }

            m_synced = true;
        }
Exemple #6
0
 public MyIdentity CreateNewIdentity(string identityName, MyPlayer.PlayerId playerId, string modelName)
 {
     return(Sync.Players.CreateNewIdentity(identityName, "Default_Astronaut"));
 }
Exemple #7
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);
        }