예제 #1
0
        internal bool OnPlayerEnteredRoom(Player player)
        {
            //we already have the player added to the connections list, as it was set when we set the Owner.
            if (Owner == player)
            {
                return(true);
            }

            var vis = CheckVisibility?.Invoke(player) ?? true;

            if (vis)
            {
                ImplObservePlayer(player);
                _visibility.Add(player);
            }
            return(vis);
        }
예제 #2
0
        internal void RebuildVisibility(NetMessage ccMsg)
        {
            var destMsg     = Room.GetDestroyMessage(this, RandPRpcs.Hide);
            var hidePlayers = new List <Player>();
            var showPlayers = new List <Player>();

            foreach (var player in Room.Players)
            {
                if (player == null)
                {
                    continue;
                }
                if (!player.IsValid)
                {
                    continue;
                }
                if (player == Owner)
                {
                    continue;
                }

                var vis = CheckVisibility?.Invoke(player) ?? true;
                if (vis && !_visibility.Contains(player))
                {
                    ImplObservePlayer(player);
                    _visibility.Add(player);
                    showPlayers.Add(player);
                }
                else if (!vis && _visibility.Contains(player))
                {
                    _visibility.Remove(player);
                    ImplIgnorePlayer(player);
                    hidePlayers.Add(player);
                }
            }
            Room.SendToPlayers(hidePlayers.ToArray(), destMsg, ReliabilityMode.Ordered);
            Room.SendToPlayers(showPlayers.ToArray(), ccMsg, ReliabilityMode.Ordered);
        }