コード例 #1
0
        public void InitFromCheckpoint(MyObjectBuilder_Checkpoint checkpoint)
        {
            var cooldowns = checkpoint.RespawnCooldowns;

            m_lastUpdate = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            m_globalRespawnTimesMs.Clear();

            if (cooldowns == null)
            {
                return;
            }

            foreach (var item in cooldowns)
            {
                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);
            }
        }
コード例 #2
0
        private SyncCooldownResponseMessage SyncCooldownResponse(SyncCooldownResponseMessage msg)
        {
            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;
            return(msg);
        }
コード例 #3
0
        public 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));
        }
コード例 #4
0
        public 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);
                }
            }
        }
コード例 #5
0
        private void SyncCooldownResponse(List <RespawnCooldownEntry> entries)
        {
            int currentTime = MySandboxGame.TotalTimeInMilliseconds;

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

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

            m_synced = true;
        }