コード例 #1
0
        /// <summary>
        /// Adds the PlayerEntity to the RecentlyOnlinePlayers dictionary by its CharacterID Note: CharacterId is the ID from the database, CharacterId not equals to ID.
        /// Removes the requested PlayerEntity from the PlayersById, PlayersByUid dictionaries, and the containing GridCell.
        /// </summary>
        /// <param name="requestedCharacter"></param>
        /// <returns></returns>
        public bool RemovePlayer(PlayerEntity requestedCharacter)
        {
            if (requestedCharacter.Connection != null && requestedCharacter.Connection.Status != Lidgren.Network.NetConnectionStatus.Disconnected)
            {
                requestedCharacter.Connection.Disconnect("Removed");
            }
            RecentlyOnlinePlayers.TryAdd(requestedCharacter.CharacterId, requestedCharacter);

            if (PlayersByUid.TryRemove(requestedCharacter.Uid, out _))
            {
                Console.WriteLine("Player removed from PlayersById");
            }
            else
            {
                Console.WriteLine("Character can not be removed or not exists!");
            }

            if (PlayersById.TryRemove(requestedCharacter.Id, out _))
            {
                Console.WriteLine("Player removed from PlayersByUid");
            }
            else
            {
                Console.WriteLine("Character can not be removed or not exists!");
            }

            return(requestedCharacter.GridCell.Remove(requestedCharacter));
        }
コード例 #2
0
 /// <summary>
 /// Adds a PlayerEntity to the PlayersByid, and PlayersByUid dictionary, also adds to the GridCell according to its position
 /// </summary>
 /// <param name="player">The PlayerEntity thats going to be added</param>
 public void Add(PlayerEntity player)
 {
     //player.SetId((ushort)(PlayersById.Count + 10000));
     GetGridCellByPosition(player.Position).Add(player);
     PlayersByUid.TryAdd(player.Uid, player);
     PlayersById.TryAdd(player.Id, player);
 }
コード例 #3
0
        /// <summary>
        /// Sets the ID of the PlayerEntity based on the last added entity ID.
        /// Adds a PlayerEntity to the PlayersByid, and PlayersByUid dictionary, also adds to the GridCell according to its position
        /// </summary>
        /// <param name="player"></param>
        /// <param name="position"></param>
        public void Add(PlayerEntity player, Vector3 position)
        {
            player.SetId((ushort)(PlayersById.Count + 20000));
            player.SetPositionWithoutGridCellCheck(position);

            GetGridCellByPosition(player.Position).Add(player);
            PlayersByUid.TryAdd(player.Uid, player);
            PlayersById.TryAdd(player.Id, player);
        }
コード例 #4
0
        public void FullRemovePlayer(PlayerEntity player)
        {
            if (PlayersByUid.TryRemove(player.Uid, out _))
            {
                Console.WriteLine("Player removed from PlayersById");
            }
            else
            {
                Console.WriteLine("Character can not be removed or not exists!");
            }

            if (PlayersById.TryRemove(player.Id, out _))
            {
                Console.WriteLine("Player removed from PlayersByUid");
            }
            else
            {
                Console.WriteLine("Character can not be removed or not exists!");
            }

            player.GridCell.Remove(player);
        }
コード例 #5
0
 /// <summary>
 /// Returns PlayerEntity by its UID
 /// </summary>
 /// <param name="uid"></param>
 /// <returns></returns>
 public PlayerEntity Get(long uid)
 {
     return(PlayersByUid.ContainsKey(uid) ? PlayersByUid[uid] : null);
 }