예제 #1
0
        /// <summary>
        /// 尝试设置玩家名称
        /// </summary>
        /// <param name="name">玩家名称</param>
        public bool TrySetName(string name)
        {
            if (!PlayerNameManager.ValidName(name))
            {
                this.WriteSystemMessage("昵称不合法,昵称只能使用 3 - 10 位英文字母或者 2 - 5 个常见汉字");
                return(false);
            }
            if (PlayerNameManager.CanReset(Name, name))
            {
                if (Player != null)
                {
                    Player.GameHost.Game.AnnounceSystemMessage("玩家 {0} 已经更名为 {1}", Name, name);
                }

                Name = name;
                this.WriteSystemMessage("您的昵称已经成功更改为 {0}", Name);

                return(true);
            }

            else
            {
                this.WriteSystemMessage("更改昵称失败,昵称已经被其他用户占用。");
                return(false);
            }
        }
예제 #2
0
 /// <summary>
 /// 创建一个新的玩家宿主
 /// </summary>
 /// <returns>新的玩家宿主</returns>
 public static PlayerHost CreatePlayerHost()
 {
     lock ( sync )
     {
         var instance = new PlayerHost(PlayerNameManager.CreateName());
         players.Add(instance);
         instance.ShowInitializeInfo();
         return(instance);
     }
 }
예제 #3
0
 public static void Release(PlayerHost playerHost)
 {
     players.Remove(playerHost);
     PlayerNameManager.RemoveName(playerHost.Name);
 }