Пример #1
0
        /// <summary>
        /// 角色上线
        /// </summary>
        /// <param name="client"></param>
        private void Online(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                //判断是否在线
                if (!accountCache.IsOnline(client))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.OnlineResult;
                    msg.State   = UserCode.AccountNotOnline;
                    client.Send(msg);
                    return;
                }
                int id = accountCache.GetId(client);
                if (!userCache.IsExist(id))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.OnlineResult;
                    msg.State   = UserCode.UserExist;
                    client.Send(msg);
                }
                UserCharacterInfo userId = userCache.GetUserInfo(id);
                userCache.Online(client, userId.Id);

                //msg.OpCode = (int)MsgType.User;
                //msg.SubCode = (int)UserCode.OnlineResult;
                //client.Send(msg);
            });
        }
Пример #2
0
 /// <summary>
 /// 更新用户信息
 /// </summary>
 /// <param name="info"></param>
 public void Update(UserCharacterInfo info)
 {
     if (userInfo.ContainsKey(info.Id))
     {
         userInfo[info.Id] = info;
     }
 }
Пример #3
0
        /// <summary>
        /// 创建角色
        /// </summary>
        /// <param name="name">角色名</param>
        /// <param name="id">账号id</param>
        public void Create(string name, int id)
        {
            UserCharacterInfo user = new UserCharacterInfo
            {
                Id   = this.id.Add_Get(),
                Name = name,
            };

            userInfo.Add(user.Id, user);
        }
Пример #4
0
    void UserInfoSet()
    {
        UserCharacterInfo userCharacterInfo = UserInfo.instance.GetUserCharacterInfo();

        if (currentCharacter == CharacterType.없음)
        {
            currentCharacter = CharacterType.한별;
        }
        gradeType = userCharacterInfo.characterGrade[(int)currentCharacter];
        ImgSet();
        GradeTextSet();
    }
Пример #5
0
        /// <summary>
        /// 游戏结束
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="room"></param>
        private void GameOver(int userId, FightRoom room)
        {
            //获取获胜玩家身份
            Identity   winIdentity = room.GetPlayerIdentity(userId);
            List <int> winUIds     = room.GetSameIdentityUId(winIdentity);
            //豆子
            int winBeen = room.Multiple * 1000;

            //给胜利玩家添加胜场
            for (int i = 0; i < winUIds.Count; i++)
            {
                UserCharacterInfo user = UserCache.GetUserInfo(winUIds[i]);
                user.WinCount++;
                user.Been += winBeen;
                user.Exp  += 100;
                UserCache.Update(user);
            }
            List <int> loseUIds = room.GetDifferentIdentityUId(winIdentity);

            //给失败玩家添加负场
            for (int i = 0; i < loseUIds.Count; i++)
            {
                UserCharacterInfo user = UserCache.GetUserInfo(loseUIds[i]);
                user.LoseCount++;
                user.Been -= winBeen;
                user.Exp  += 10;
                UserCache.Update(user);
            }
            //逃跑玩家添加逃跑场次
            for (int i = 0; i < room.LeaveUIdList.Count; i++)
            {
                UserCharacterInfo user = UserCache.GetUserInfo(loseUIds[i]);
                user.RunCount++;
                user.Been -= (winBeen) * 3;
                user.Exp  += 0;
                UserCache.Update(user);
            }
            //发送广播
            OverDto dto = new OverDto
            {
                WinIdentity = winIdentity,
                WinUIdList  = winUIds,
                BeenCount   = winBeen
            };

            socketMsg.SubCode = FightCode.Over_Bro;
            socketMsg.value   = dto;
            BroCast(room, socketMsg);
            //销毁房间
            FightCache.Destroy(room);
        }
Пример #6
0
 /// <summary>
 /// 用户离开
 /// </summary>
 /// <param name="client"></param>
 private void Leave(ClientPeer client)
 {
     SingleExecute.Instance.Execute(() =>
     {
         if (UserCache.IsOnline(client) == false)
         {
             socketMsg.State = null;
             Console.WriteLine("当前用户不在线,不能从房间中剔除!");
             return;
         }
         int userId = UserCache.GetClientUserId(client);
         if (FightCache.IsFighting(userId) == false)
         {
             return;
         }
         FightRoom room = FightCache.GetRoomByUId(userId);
         //中途退出房间的玩家
         room.LeaveUIdList.Add(userId);
         //
         socketMsg.SubCode = FightCode.Leave_Bro;
         socketMsg.value   = userId;
         BroCast(room, socketMsg);
         //当前房间玩家是否都退出
         if (room.LeaveUIdList.Count == 3)
         {
             for (int i = 0; i < room.LeaveUIdList.Count; i++)
             {
                 UserCharacterInfo user = UserCache.GetUserInfo(room.LeaveUIdList[i]);
                 user.RunCount++;
                 user.Been -= (room.Multiple * 1000) * 3;
                 user.Exp  += 0;
                 UserCache.Update(user);
             }
             FightCache.Destroy(room);
         }
     });
 }
Пример #7
0
        /// <summary>
        /// 获取角色信息
        /// </summary>
        /// <param name="client"></param>
        private void GetCharacterInfo(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                //判断是否在线
                if (!accountCache.IsOnline(client))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.GetInfoResult;
                    msg.State   = UserCode.AccountNotOnline;
                    client.Send(msg);
                    return;
                }
                int id = accountCache.GetId(client);
                if (!userCache.IsExist(id))
                {
                    msg.OpCode  = MsgType.User;
                    msg.SubCode = UserCode.GetInfoResult;
                    msg.State   = UserCode.UserExist;
                    client.Send(msg);
                    return;
                }
                //角色上线
                Online(client);
                //
                UserCharacterInfo user = userCache.GetUserInfo(id);

                UserCharacterDto userCharacter = EntityHelper.Mapping <UserCharacterDto, UserCharacterInfo>(user);

                msg.OpCode  = MsgType.User;
                msg.SubCode = UserCode.GetInfoResult;
                msg.State   = UserCode.Success;
                msg.value   = userCharacter;
                client.Send(msg);
            });
        }