示例#1
0
        public void enter(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetId(client);
                //正常匹配
                _21MutiFightRoom room = fightCache.GetRoom(userId);

                /*//广播给房间内除了当前客户端的其他用户,有新玩家计入了  参数:新进入的玩家的用户id
                 #region 构造一个UserDto  Dto就是针对UI定义的 UI需要什么我们就加什么字段
                 * UserModel model = userCache.GetModelById(userId);
                 * UserDto userDto = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp);
                 #endregion
                 * room.Brocast(OpCode._21Multi, _21MultiCode.ENTER_BRO, userDto, client);
                 */
                //返回给当前客户端 给他房间的数据模型
                MutiRoomDto dto = makeRoomDto(room);
                client.Send(OpCode._21Multi, _21MultiCode.ENTER_SRES, dto);


                Console.WriteLine("有玩家进入了房间");
            }
                );
        }
示例#2
0
        private MutiRoomDto makeRoomDto(_21MutiFightRoom room)
        {
            MutiRoomDto dto = new MutiRoomDto();

            //给 UIdClientDict 赋值
            foreach (var uid in room.UIdClientDict.Keys)
            {
                UserModel model   = userCache.GetModelById(uid);
                UserDto   userDto = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp);
                dto.UIdUserDict.Add(uid, userDto);
            }

            dto.UIdPositionDict = room.UIdPositionDict;
            dto.ReadyUIdList    = room.ReadyUIdList;
            return(dto);
        }
示例#3
0
        /// <summary>
        /// 匹配
        /// </summary>
        /// <param name="client"></param>
        public void match(ClientPeer client)
        {
            SingleExecute.Instance.Execute(
                delegate()
            {
                if (!userCache.IsOnline(client))
                {
                    return;
                }
                int userId = userCache.GetId(client);

                //if (userId != id)
                //    return;

                //如果用户已经在匹配房间等待了 那就无视
                if (fightCache.IsInRoom(userId))
                {
                    client.Send(OpCode._21Multi, _21MultiCode.MATCH_SRES, -1);    //重复匹配
                    return;
                }
                //正常匹配
                _21MutiFightRoom room = fightCache.Match(userId, client);

                //广播给房间内除了当前客户端的其他用户,有新玩家计入了  参数:新进入的玩家的用户id
                #region 构造一个UserDto  Dto就是针对UI定义的 UI需要什么我们就加什么字段
                UserModel model = userCache.GetModelById(userId);
                UserDto userDto = new UserDto(model.Id, model.Name, model.Been, model.WinCount, model.LoseCount, model.RunCount, model.Lv, model.Exp);
                int position    = room.getPosition(userId);

                MultiEnterDto edto = new MultiEnterDto(userDto, position);
                #endregion
                room.Brocast(OpCode._21Multi, _21MultiCode.ENTER_BRO, edto, client);


                MutiRoomDto dto = makeRoomDto(room);
                client.Send(OpCode._21Multi, _21MultiCode.MATCH_SRES, dto);
                Console.WriteLine("有玩家进行了匹配");
            }
                );
        }
示例#4
0
    protected override void Start()
    {
        base.Start();

        int userId = -1;
        //如果!= -1 就代表 有角色
        MutiRoomDto room = Models.GameModel.MutiRoomDto;

        foreach (KeyValuePair <int, int> up in room.UIdPositionDict)
        {
            if (up.Value == 4)
            {
                userId = up.Key;
                break;
            }
        }

        if (userId != -1)
        {
            this.userDto = room.UIdUserDict[userId];
            if (Models.GameModel.UserDto.Id == userDto.Id)
            {
                imgIdentity.sprite = Resources.Load <Sprite>("Identity/Landlord");
            }
            //fixbug923
            if (room.ReadyUIdList.Contains(userId))
            {
                readyState();
            }
            else
            {
                //nothing 可以显示一个未准备
            }
        }
        else
        {
            setPanelActive(false);
        }
    }
示例#5
0
    private void enterBro(MultiEnterDto multiEnterDto)
    {
        if (isEnter)
        {
            //更新房间数据
            MutiRoomDto room = Models.GameModel.MutiRoomDto;
            room.Add(multiEnterDto.userDto, multiEnterDto.position);

            //给UI绑定数据
            switch (multiEnterDto.position)
            {
            case 1:
                Dispatch(AreaCode.UI, UIEvent.SET_1_PLAYER_DATA, multiEnterDto.userDto);
                break;

            case 2:
                Dispatch(AreaCode.UI, UIEvent.SET_2_PLAYER_DATA, multiEnterDto.userDto);
                break;

            case 3:
                Dispatch(AreaCode.UI, UIEvent.SET_3_PLAYER_DATA, multiEnterDto.userDto);
                break;

            case 4:
                Dispatch(AreaCode.UI, UIEvent.SET_4_PLAYER_DATA, multiEnterDto.userDto);
                break;

            default:
                break;
            }
            //发消息 显示玩家的状态面板所有游戏物体
            Dispatch(AreaCode.UI, UIEvent.MULTI_PLAYER_ENTER, multiEnterDto.userDto.Id);

            //给用户一个提示
            promptMsg.Change("有新玩家 ( " + multiEnterDto.userDto.Name + " )进入", UnityEngine.Color.blue);
            Dispatch(AreaCode.UI, UIEvent.PROMPT_MSG, promptMsg);
        }
        //进来一个显示一个
    }
示例#6
0
 private void enterResponse(MutiRoomDto multiRoomDto)
 {
     isEnter = true;
     //Models.GameModel.MutiRoomDto = multiRoomDto;
     //todo 显示房间里的人 显示豆子
 }
示例#7
0
 private void matchResponse(MutiRoomDto multiRoomDto)
 {
     Models.GameModel.MutiRoomDto = multiRoomDto;
     //显示进入房间的按钮
     Dispatch(AreaCode.UI, UIEvent.MULTI_SHOW_ENTER_ROOM_BUTTON, null);
 }