예제 #1
0
 protected override bool CreateUserRole(out IUser user)
 {
     user = null;
     if (UserName.Length < 2 || UserName.Length > 12)
     {
         ErrorCode = Language.Instance.ErrorCode;
         ErrorInfo = Language.Instance.St1005_UserNameNotEnough;
         return false;
     }
     var userCache = new PersonalCacheStruct<GameUser>();
     var roleCache = new PersonalCacheStruct<UserRole>();
     GameUser gameUser;
     if (userCache.TryFindKey(Uid, out gameUser) == LoadingStatus.Success)
     {
         if (gameUser == null)
         {
             gameUser = new GameUser
             {
                 UserId = UserId,
                 PassportId = Pid,
                 RetailId = RetailID,
                 NickName = Pid
             };
             userCache.Add(gameUser);
         }
         user = gameUser;
         UserRole role;
         if (roleCache.TryFind(gameUser.PersonalId, r => r.RoleName == UserName, out role) == LoadingStatus.Success)
         {
             if (role == null)
             {
                 role = new UserRole()
                 {
                     RoleId = (int)roleCache.GetNextNo(),
                     UserId = UserId,
                     RoleName = UserName,
                     HeadImg = HeadID,
                     Sex = Sex.ToBool(),
                     LvNum = 1,
                     ExperienceNum = 0,
                     LifeNum = 100,
                     LifeMaxNum = 100
                 };
                 roleCache.Add(role);
             }
             gameUser.CurrRoleId = role.RoleId;
             var notifyUsers = new List<GameUser>();
             notifyUsers.Add(gameUser);
             ActionFactory.SendAsyncAction(notifyUsers, (int)ActionType.World, null, null);
             return true;
         }
     }
     return false;
 }
예제 #2
0
        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            GameUser user = Current.User as GameUser;
            if (user == null) return false;

            var roleCache = new PersonalCacheStruct<UserRole>();
            _role = roleCache.FindKey(user.PersonalId, user.CurrRoleId);
            if (_role == null)
            {
                return false;
            }
            return true;
        }
예제 #3
0
        /// <summary>
        /// 业务逻辑处理
        /// </summary>
        /// <returns>false:中断后面的方式执行并返回Error</returns>
        public override bool TakeAction()
        {
            var user = PersonalCacheStruct.Get<GameUser>(UserId.ToString());
            if (user == null)
            {
                ErrorCode = Language.Instance.ErrorCode;
                return false;
            }

            var roleCache = new PersonalCacheStruct<UserRole>();
            _role = roleCache.FindKey(user.PersonalId, user.CurrRoleId, user.UserId);
            if (_role == null)
            {
                ErrorCode = Language.Instance.ErrorCode;
                return false;
            }
            return true;
        }
예제 #4
0
        protected override bool CreateUserRole(out IUser user)
        {
            user = null;
            if (UserName.Length < 2 || UserName.Length > 12)
            {
                ErrorCode = Language.Instance.ErrorCode;
                ErrorInfo = Language.Instance.St1005_UserNameNotEnough;
                return false;
            }
            var userCache = new PersonalCacheStruct<GameUserCopy>();
            var roleCache = new PersonalCacheStruct<UserRole>();
            var userNameCache = new PersonalCacheStruct<UserDescription>();
            GameUserCopy gameUser;

            if (userCache.TryFindKey(Pid, out gameUser) == LoadingStatus.Success)
            {
                if (gameUser == null)
                {
                    gameUser = new GameUserCopy
                    {
                        UserId = UserId,
                        PassportId = Pid,
                        RetailId = RetailID,
                        NickName = Pid
                    };
                    userCache.Add(gameUser);
                }
                user =new SessionUser(gameUser);

                /////////////////Test////////////////////////////
                UserDescription description;
                if (userNameCache.TryFind(gameUser.PersonalId, r => r.UserId == gameUser.UserId, out description) == LoadingStatus.Success)
                {

                    if (description == null)
                    {

                    }

                }

                ////////////////////////////////////////////////////

                UserRole role;
                if (roleCache.TryFind(gameUser.PersonalId, r => r.RoleName == UserName, out role) == LoadingStatus.Success)
                {
                    if (role == null)
                    {
                        role = new UserRole()
                        {
                            RoleId = (int)roleCache.GetNextNo(),
                            UserId = UserId,
                            RoleName = UserName,
                            HeadImg = HeadID,
                            Sex = Sex.ToBool(),
                            LvNum = 1,
                            ExperienceNum = 0,
                            LifeNum = 100,
                            LifeMaxNum = 100
                        };
                        roleCache.Add(role);
                        gameUser.CurrRoleId = role.RoleId;
                    }
                    return true;
                }
            }
            return false;
        }