Exemplo n.º 1
0
        protected override void Run(Session session, C2G_ExitRoom message, Action <G2C_ExitRoom> reply)
        {
            G2C_ExitRoom response = new G2C_ExitRoom();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                long roomId = message.Id;

                Room room = Game.Scene.GetComponent <RoomComponent>().Get(roomId);

                room.Remove(player.Id);

                if (room.Count == 0)
                {
                    Game.Scene.GetComponent <RoomComponent>().Remove(roomId);
                }
                else
                {
                    room.BroadcastRoomDetailInfo();
                }


                reply(response);

                BroadcastMessage.Send_G2C_Rooms();
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemplo n.º 2
0
        protected override void Run(Session session, B2G_BattleEnd message)
        {
            Room room = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomId);

            room.State = 1;

            // 房间内信息
            room.BroadcastRoomDetailInfo();

            // 房间外状态
            BroadcastMessage.Send_G2C_Rooms();
        }
Exemplo n.º 3
0
        protected async ETVoid RunAsync(Session session, C2G_EnterRoom message, Action <G2C_EnterRoom> reply)
        {
            G2C_EnterRoom response = new G2C_EnterRoom();

            try
            {
                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();

                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                Room room = roomComponent.Get(message.RoomId);

                if (room == null)
                {
                    Log.Error($"不存在房间{message.RoomId}");

                    response.Error = ErrorCode.ERR_RpcFail;
                }

                if (room.Add(player) == null)
                {
                    Log.Error($"房间已满,或者玩家{player.UserDB.GetComponent<UserBaseComponent>().UserName}已经存在房间{room.RoomName}中");

                    response.Error = ErrorCode.ERR_RpcFail;
                }

                room.BroadcastRoomDetailInfo();

                BroadcastMessage.Send_G2C_Rooms();

                await ETTask.CompletedTask;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Exemplo n.º 4
0
        protected async ETVoid RunAsync(Session session, C2G_StartGame message)
        {
            long roomId = message.RoomId;

            Room room = Game.Scene.GetComponent <RoomComponent>().Get(roomId);

            int errCode = 0;

            if (!room.CanStartGame(ref errCode))
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                player.Send_PopMessage(errCode);

                return;
            }

            IPEndPoint mapAddress = StartConfigComponent.Instance.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint;

            Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapAddress);

            G2B_CreateBattle msg = new G2B_CreateBattle();

            msg.RoomId = roomId;

            msg.LeftCamp = new List <RoomOnePeople>();

            msg.RightCamp = new List <RoomOnePeople>();

            foreach (RoomOnePeople onePeople in room.GetLeftCamp())
            {
                RoomOnePeople tmp = new RoomOnePeople(onePeople);

                msg.LeftCamp.Add(tmp);
            }

            foreach (RoomOnePeople onePeople in room.GetRightCamp())
            {
                RoomOnePeople tmp = new RoomOnePeople(onePeople);

                msg.RightCamp.Add(tmp);
            }

            if (true)
            {
                msg.RoomSimpleInfo = new RoomSimpleInfo();

                RoomSimpleInfo roomSimpleInfo = msg.RoomSimpleInfo;

                roomSimpleInfo.RoomId = room.Id;

                roomSimpleInfo.PeopleNum = room.PeopleNum;

                roomSimpleInfo.MapId = room.MapTableId;

                roomSimpleInfo.BigModel = (int)room.BigModel;

                roomSimpleInfo.SmallModel = room.SmallMode;

                roomSimpleInfo.RoomName = room.RoomName;

                roomSimpleInfo.State = room.State;

                roomSimpleInfo.SerialNumber = room.SerialNumber;

                roomSimpleInfo.RoomOwnerId = room.OwnerId;
            }

            await mapSession.Call(msg);

            room.State = 2;

            room.GetAll();

            room.BroadCastStartGame();

            BroadcastMessage.Send_G2C_Rooms();
        }
Exemplo n.º 5
0
        protected async ETVoid RunAsync(Session session, C2G_CreateRoom message, Action <G2C_CreateRoom> reply)
        {
            G2C_CreateRoom response = new G2C_CreateRoom();

            try
            {
                Player player = session.GetComponent <SessionPlayerComponent>().Player;

                if (!this.CheckRoomName(message.RoomNam))
                {
                    response.Error = ErrorCode.ERR_RpcFail;

                    response.Message = Message.Get(player, 1044);

                    reply(response);

                    A2C_PopMessage msg = new A2C_PopMessage();

                    msg.Text = response.Message;

                    msg.Type = PopMessageType.Float;

                    session.Send(msg);

                    return;
                }

                RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();


                Room room = ComponentFactory.CreateWithId <Room>(IdGenerater.GenerateId());

                room.SerialNumber = roomComponent.GetSerialNum();

                room.PeopleNum = message.PeopleNum;

                room.MapTableId = message.MapId;

                room.BigModel = (BigModel)message.BigModel;

                room.SmallMode = message.SmallModel;

                room.RoomName = message.RoomNam;

                room.OwnerId = player.Id;

                //room.AddComponent<PlayerComponent>().Add(player);

                room.Add(player);

                room.BroadcastRoomDetailInfo();

                //player.RoomId = room.Id;

                roomComponent.Add(room);

                reply(response);

                BroadcastMessage.Send_G2C_Rooms();

                await ETTask.CompletedTask;
            }
            catch (Exception e)
            {
                Log.Error(e);
                ReplyError(response, e, reply);
            }
        }