Exemple #1
0
        private void ProcessNearbyPlayers()
        {
            List <BasePlayer> nearPlayers = new List <BasePlayer>();

            Vector3 checkPosition = Position + Recycler.transform.up * 0.75f + Recycler.transform.forward * 1f + Recycler.transform.right * -0.2f;
            float   checkRadius   = Constants.CrafterNearRadius;

            Vis.Entities(checkPosition, checkRadius, nearPlayers);

            var previousNearbyPlayers = NearbyPlayers.ToList();             // Nearby players last tick

            // Keep all players that are the following:
            // - Alive and not sleeping
            // - Has codelock access
            // - Can see the recycler from their position, aka not behind a wall or anything
            nearPlayers = nearPlayers.Where(plr => plr.IsAlive() && !plr.IsSleeping() && PlayerCanAccess(plr) && Recycler.IsVisible(plr.ServerPosition)).ToList();

            var playersLeaving  = previousNearbyPlayers.Where(plr => !nearPlayers.Contains(plr)).ToList();
            var playersEntering = nearPlayers.Where(plr => !previousNearbyPlayers.Contains(plr)).ToList();

            foreach (var player in playersLeaving)
            {
                NearbyPlayers.Remove(player);
                OnPlayerLeave(player);
            }

            foreach (var player in playersEntering)
            {
                NearbyPlayers.Add(player);
                OnPlayerEnter(player);
            }

            /*foreach (var player in BasePlayer.activePlayerList)
             * {
             *      player.SendConsoleCommand("ddraw.sphere", 0.5f, Color.red, checkPosition, checkRadius);
             * }*/
        }