Пример #1
0
        /// <summary>
        /// 先讲自己克隆出来
        /// </summary>
        public void AddLocalGamer(GamerInfo info)
        {
            if (info.UserID != ETModel.Game.Scene.GetComponent <ClientComponent>().User.UserID)
            {
                return;
            }
            Gamer gamer = GamerComponent.AddGamerUI(info);

            if (gamer != null)
            {
                gamer.AddComponent <UICowCow_GamerInfoComponent, GameObject, GamerInfo, int>(UIRoomGamer, info, 0);
                gamer.AddComponent <UICowCow_SSGamerResultComponent, GameObject>(SmallSettlement.SmallBG);
                gamer.AddComponent <UICowCow_BSGamerResultComponent, GameObject>(BigSettlement.BigBG);
            }
            if (GamerComponent.LocalGamer == null)
            {
                GamerComponent.Init(info.UserID);
                if (GamerComponent.LocalGamer.GetComponent <UICowCow_GamerInfoComponent>().Status == UIGamerStatus.Down)
                {
                    ShowHideReadyButton(true);
                }
            }
        }
Пример #2
0
        protected override async void Run(Session session, G2M_EnterMatch_Landords message)
        {
            //Log.Debug("Map服务器收到第一条消息");
            LandlordsComponent matchComponent = Game.Scene.GetComponent <LandlordsComponent>();

            //玩家是否已经开始游戏
            if (matchComponent.Playing.ContainsKey(message.UserID))
            {
                LandlordsRoom room;
                matchComponent.Playing.TryGetValue(message.UserID, out room);
                Gamer gamer = room.GetGamerFromUserID(message.UserID);

                //更新玩家的属性
                gamer.ActorIDofUser   = message.ActorIDofUser;
                gamer.ActorIDofClient = message.ActorIDofClient;

                //帮助玩家恢复牌桌



                //向Gate上的User发送匹配成功消息 使User更新绑定的ActorID
                //Map上的Gamer需要保存User的InstanceID给其发消息
                //生成Gamer的时候 需要设置ActorIDofUser
                ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(gamer.ActorIDofUser);
                actorProxy.Send(new Actor_LandlordsMatchSucess()
                {
                    ActorIDofGamer = gamer.InstanceId
                });
            }
            else
            {
                //新建玩家
                Gamer newgamer = ComponentFactory.Create <Gamer, long>(message.UserID);
                newgamer.ActorIDofUser   = message.ActorIDofUser;
                newgamer.ActorIDofClient = message.ActorIDofClient;

                //为Gamer添加组件
                await newgamer.AddComponent <MailBoxComponent>().AddLocation();

                //添加玩家到匹配队列 广播一遍正在匹配中的玩家
                matchComponent.AddGamerToMatchingQueue(newgamer);
            }
        }
Пример #3
0
        protected override async ETTask Run(Session session, EnterMatchs_G2M message)
        {
            //Log.Debug("Map服务器收到第一条消息");
            LandMatchComponent matchComponent = Game.Scene.GetComponent <LandMatchComponent>();

            //玩家是否在房间中待机
            if (matchComponent.Waiting.ContainsKey(message.UserID))
            {
                Room room;
                //通过UserID获取matchComponent中相对应的键,即找到此User所在的Room
                matchComponent.Waiting.TryGetValue(message.UserID, out room);
                //房间中的玩家对象,获取获取其UserID的座位索引
                Gamer gamer = room.GetGamerFromUserID(message.UserID);

                //设置GateActorID,ClientActorID
                gamer.GActorID = message.GActorID;
                gamer.CActorID = message.CActorID;

                //向Gate发送消息更新Gate上user的ActorID
                //这样不论玩家到了哪个地图服务器,Gate上的user都持有所在地图服务器上gamer的InstanceId
                ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(gamer.GActorID);
                actorProxy.Send(new Actor_MatchSucess_M2G()
                {
                    GamerID = gamer.InstanceId
                });
            }
            else
            {
                //新建玩家,用UserID构建Gamer
                Gamer newgamer = ComponentFactory.Create <Gamer, long>(message.UserID);
                newgamer.GActorID = message.GActorID;
                newgamer.CActorID = message.CActorID;

                //为Gamer添加MailBoxComponent组件,可以通过MailBox进行actor通信
                await newgamer.AddComponent <MailBoxComponent>().AddLocation();

                //添加玩家到匹配队列 广播一遍正在匹配中的玩家
                matchComponent.AddGamerToMatchingQueue(newgamer);
            }
        }
Пример #4
0
        protected override async void Run(Session session, B1001_CreateRobotMatch5V5_G2M message)
        {
            Moba5V5Component moba = Game.Scene.GetComponent <Moba5V5Component>();

            //创建玩家Entity
            Gamer roomCreater = ComponentFactory.Create <Gamer, long>(message.UserID);

            //设置玩家参数
            roomCreater.ActorIDofUser   = message.ActorIDofUser;
            roomCreater.ActorIDofClient = message.ActorIDofClient;
            await roomCreater.AddComponent <MailBoxComponent>().AddLocation();

            moba.AddGamerToMatchingQueue(roomCreater); //需要先设置ActorIDofClient才能使用Actor消息

            //创建9个机器人加入匹配 机器人的UserID为0
            for (int i = 0; i < 9; i++)
            {
                Gamer robot = ComponentFactory.Create <Gamer, long>(0);
                await robot.AddComponent <MailBoxComponent>().AddLocation();

                moba.AddGamerToMatchingQueue(robot);
            }
        }
Пример #5
0
        protected override async void Run(Session session, G2M_PlayerEnterRoom message, Action <M2G_PlayerEnterRoom> reply)
        {
            M2G_PlayerEnterRoom response = new M2G_PlayerEnterRoom();

            //Log.Info("G2M_GamerEnterRoomHandler" + JsonHelper.ToJson(message));

            try
            {
                RoomComponent roomCompnent = Game.Scene.GetComponent <RoomComponent>();
                Gamer         gamer        = null;
                Room          room         = null;

                foreach (var _room in roomCompnent.rooms.Values)
                {
                    room  = _room;
                    gamer = room.Get(message.UserId);
                    if (gamer != null)
                    {
                        Log.Info("找到房间:" + _room.Id);
                        break;
                    }
                }

                //断线重连
                if (gamer != null)
                {
                    //在空闲房间内
                    if (room.State == RoomState.Idle)
                    {
                        response.Message = "已经进入房间";
                        response.Error   = ErrorCode.ERR_Common;
                        Log.Error("玩家多次进入空闲房间");
                        room.Remove(gamer.UserID);
                        reply(response);
                        return;
                    }
                    DeskComponent deskComponent = room.GetComponent <DeskComponent>();

                    //重新更新actor
                    gamer.PlayerID = message.PlayerId;
                    gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionId;

                    //短线重连
                    Actor_GamerReconnet reconnet = new Actor_GamerReconnet();
                    foreach (var _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            Log.Error($"断线重连后玩家为空");
                            continue;
                        }
                        GamerData gamerData = new GamerData();

                        HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>();
                        if (handCardsComponent == null)
                        {
                            Log.Error($"{_gamer.UserID}断线重连后玩家的手牌为空,移除玩家");
                            continue;
//                            room.Remove(_gamer.UserID);
//			                //房间没人就释放
//			                if (room.seats.Count == 0)
//			                {
//                                roomCompnent.RemoveRoom(room);
//			                    room.Dispose();
//			                }
//                            return;
                        }
                        List <MahjongInfo> handCards = handCardsComponent.GetAll();

                        gamerData.handCards = handCards;
                        gamerData.faceCards = handCardsComponent.FaceCards;
                        gamerData.playCards = handCardsComponent.PlayCards;

                        //添加碰刚的uid
                        foreach (var pengOrBar in handCardsComponent.PengOrBars)
                        {
                            //碰
                            if (pengOrBar.OperateType == OperateType.Peng)
                            {
                                gamerData.pengCards.Add(new MahjongInfo()
                                {
                                    weight = (byte)pengOrBar.Weight
                                });
                                gamerData.OperatedPengUserIds.Add(pengOrBar.UserId);
                            }
                            //杠
                            else
                            {
                                gamerData.gangCards.Add(new MahjongInfo()
                                {
                                    weight = (byte)pengOrBar.Weight
                                });
                                gamerData.OperatedGangUserIds.Add(pengOrBar.UserId);
                            }
                        }

                        gamerData.IsBanker      = handCardsComponent.IsBanker;
                        gamerData.UserID        = _gamer.UserID;
                        gamerData.SeatIndex     = room.GetGamerSeat(_gamer.UserID);
                        gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(_gamer.UserID);

                        gamerData.IsTrusteeship = gamer.IsTrusteeship;
                        PlayerBaseInfo playerBaseInfo = await DBCommonUtil.getPlayerBaseInfo(_gamer.UserID);

                        PlayerInfo playerInfo = PlayerInfoFactory.Create(playerBaseInfo);

                        gamerData.playerInfo = playerInfo;

                        reconnet.Gamers.Add(gamerData);
                    }

                    reconnet.RestCount = deskComponent.RestLibrary.Count;
                    reconnet.RoomType  = (int)room.GetComponent <GameControllerComponent>().RoomConfig.Id;
                    if (room.IsFriendRoom)
                    {
                        GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>();
                        reconnet.RoomId         = gameControllerComponent.RoomConfig.FriendRoomId;
                        reconnet.MasterUserId   = gameControllerComponent.RoomConfig.MasterUserId;
                        reconnet.JuCount        = gameControllerComponent.RoomConfig.JuCount;
                        reconnet.Multiples      = gameControllerComponent.RoomConfig.Multiples;
                        reconnet.CurrentJuCount = room.CurrentJuCount;
                    }
                    room.GamerReconnect(gamer, reconnet);

                    gamer.isOffline = false;
                    gamer.RemoveComponent <TrusteeshipComponent>();
                    Log.Info($"玩家{message.UserId}断线重连");
                    gamer.StartTime = DateTime.Now;
                }
                else
                {
                    Log.Info($"{message.UserId}进入房间");

                    gamer = await GamerFactory.Create(message.PlayerId, message.UserId);

                    await gamer.AddComponent <MailBoxComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionId);

                    RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
                    //获得空闲的房间
                    Room idleRoom;

                    if (message.RoomType == 3)
                    {
                        idleRoom = roomComponent.GetFriendRoomById(message.RoomId);
                        if (idleRoom == null)
                        {
                            response.Error   = ErrorCode.ERR_Common;
                            response.Message = "房间号不存在";
                            reply(response);
                            return;
                        }

                        if (idleRoom.Count == 4)
                        {
                            response.Error   = ErrorCode.ERR_Common;
                            response.Message = "房间人数已满";
                            reply(response);
                            return;
                        }
                    }
                    else
                    {
                        idleRoom = roomComponent.GetIdleRoomById(message.RoomType);
                        if (idleRoom == null)
                        {
                            idleRoom = RoomFactory.Create(message.RoomType);
                            roomComponent.Add(idleRoom);
                        }
                    }
                    idleRoom.Add(gamer);
                    await idleRoom.BroadGamerEnter(gamer.UserID);
                }
                response.GameId = gamer.Id;
                reply(response);

                if (message.RoomType == 3)
                {
                    await Actor_GamerReadyHandler.GamerReady(gamer, new Actor_GamerReady()
                    {
                    });
                }
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }

            await Task.CompletedTask;
        }
        protected override async Task Run(Room room, Actor_PlayerEnterRoom_Req message, Action <Actor_PlayerEnterRoom_Ack> reply)
        {
            Actor_PlayerEnterRoom_Ack response = new Actor_PlayerEnterRoom_Ack();

            try
            {
                Gamer gamer = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID);
                    await gamer.AddComponent <MailBoxComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //加入到房间
                    room.Add(gamer);

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //广播房间内玩家消息
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    //玩家重连
                    gamer.isOffline = false;
                    gamer.PlayerID  = message.PlayerID;
                    gamer.GetComponent <UnitGateComponent>().GateSessionActorId = message.SessionID;

                    //玩家重连移除托管组件
                    gamer.RemoveComponent <TrusteeshipComponent>();

                    Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //发送房间玩家信息
                    ActorMessageSender actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorMessageSender();
                    actorProxy.Send(broadcastMessage);

                    List <GamerCardNum>      gamersCardNum   = new List <GamerCardNum>();
                    List <GamerState>        gamersState     = new List <GamerState>();
                    GameControllerComponent  gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>();
                    DeskCardsCacheComponent  deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();

                    foreach (Gamer _gamer in room.GetAll())
                    {
                        HandCardsComponent handCards = _gamer.GetComponent <HandCardsComponent>();
                        gamersCardNum.Add(new GamerCardNum()
                        {
                            UserID = _gamer.UserID,
                            Num    = _gamer.GetComponent <HandCardsComponent>().GetAll().Length
                        });
                        gamersState.Add(new GamerState()
                        {
                            UserID            = _gamer.UserID,
                            Identity          = (byte)handCards.AccessIdentity,
                            GrabLandlordState = orderController.GamerLandlordState.ContainsKey(_gamer.UserID)
                            ? orderController.GamerLandlordState[_gamer.UserID]
                            : false
                        });
                    }

                    //发送游戏开始消息
                    Actor_GameStart_Ntt gameStartNotice = new Actor_GameStart_Ntt()
                    {
                        HandCards     = gamer.GetComponent <HandCardsComponent>().GetAll(),
                        GamersCardNum = gamersCardNum
                    };
                    actorProxy.Send(gameStartNotice);

                    Card[] lordCards = null;

                    if (gamer.GetComponent <HandCardsComponent>().AccessIdentity == Identity.None)
                    {
                        //广播先手玩家
                        actorProxy.Send(new Actor_AuthorityGrabLandlord_Ntt()
                        {
                            UserID = orderController.CurrentAuthority
                        });
                    }
                    else
                    {
                        if (gamer.UserID == orderController.CurrentAuthority)
                        {
                            //发送可以出牌消息
                            bool isFirst = gamer.UserID == orderController.Biggest;
                            actorProxy.Send(new Actor_AuthorityPlayCard_Ntt()
                            {
                                UserID = orderController.CurrentAuthority, IsFirst = isFirst
                            });
                        }
                        lordCards = deskCardsCache.LordCards.ToArray();
                    }
                    //发送重连数据
                    Actor_GamerReconnect_Ntt reconnectNotice = new Actor_GamerReconnect_Ntt()
                    {
                        Multiples   = room.GetComponent <GameControllerComponent>().Multiples,
                        GamersState = gamersState,
                        DeskCards   = new KeyValuePair <long, Card[]>(orderController.Biggest, deskCardsCache.library.ToArray()),
                        LordCards   = lordCards,
                    };
                    actorProxy.Send(reconnectNotice);

                    Log.Info($"玩家{message.UserID}重连");
                }

                response.GamerID = gamer.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #7
0
        protected override async void Run(Session session, C2G_CreateRoom message, Action <G2C_CreateRoom> reply)
        {
            G2C_CreateRoom response = new G2C_CreateRoom();

            try
            {
                //验证合法性
                if (!GateHelper.SignSession(session))
                {
                    response.Error = ErrorCode.ERR_SignError;
                    reply(response);
                    return;
                }
                DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>();

                User     user     = session.GetUser();
                UserInfo userInfo = await dbProxy.Query <UserInfo>(user.UserID, false);

                if (userInfo.Money < message.Room.GameScore)
                {
                    response.Error = ErrorCode.ERR_UserMoneyLessError;
                    reply(response);
                    return;
                }

                //创建房间
                Room room = await RoomFactory.Create(message.Room.PlayerCount, message.Room.GameCount,
                                                     message.Room.GameScore, session);

                //创建房间玩家对象
                Gamer gamer = GamerFactory.Create(user.Id, user.UserID, room.RoomId, (ushort)room.Count);
                await gamer.AddComponent <MailBoxComponent>().AddLocation();

                gamer.AddComponent <UnitGateComponent, long>(session.Id);

                //房间添加玩家
                room.Add(gamer);

                //网关服务器和玩家对应
                user.ActorID = gamer.Id;

                //返回房间信息给玩家
                response.RoomId  = room.RoomId;
                response.Room    = message.Room;
                response.ChairID = (ushort)(room.Count - 1);
                Log.Info($"创建房间成功:--- {userInfo.NickName} ,房号:{room.RoomId}");
                //返回给客户端
                reply(response);

                //存储该用户房间的创建次数
                RoomHistory roomInfo = await dbProxy.Query <RoomHistory>(user.UserID, false);

                if (roomInfo == null)
                {
                    RoomHistory roomHistory = ComponentFactory.CreateWithId <RoomHistory>(userInfo.Id);
                    roomHistory.CreateCount = 1;
                    roomHistory.NickName    = userInfo.NickName;
                    await dbProxy.Save(roomHistory, false);
                }
                else
                {
                    roomInfo.CreateCount += 1;
                    await dbProxy.Save(roomInfo, false);
                }



                //连接游戏服务器
                //StartConfigComponent config = Game.Scene.GetComponent<StartConfigComponent>();
                //IPEndPoint GameIPEndPoint= config.GameConfig.GetComponent<InnerConfig>().IPEndPoint;
                //Session GameSession = Game.Scene.GetComponent<NetInnerComponent>().Get(GameIPEndPoint);
                //GS2G_EnterRoom gs2g_EnterRoom =await GameSession.Call(new G2GS_EnterRoom()
                //{
                //    PlayerId = user.Id,
                //    UserID = user.UserID,
                //    GateSessionId = session.Id
                //}) as GS2G_EnterRoom;
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #8
0
        protected override async void Run(Session session, C2G_CowCowCreateGameRoomGate message, Action <G2C_CowCowCreateGameRoomGate> reply)
        {
            G2C_CowCowCreateGameRoomGate response = new G2C_CowCowCreateGameRoomGate();

            try
            {
                UserInfo userInfo = Game.Scene.GetComponent <UserInfoComponent>().Get(message.UserID);
                if (userInfo.Diamond < message.Bureau)
                {
                    response.Error   = ErrorCode.ERR_CreateRoomError;
                    response.Message = "房卡不足";
                    reply(response);
                    return;
                }
                userInfo.Diamond -= (message.Bureau + 1);

                string roomId = string.Empty;
                while (true)
                {
                    roomId = RandomHelper.RandomNumber(100000, 999999).ToString();
                    if (!Game.Scene.GetComponent <RoomComponent>().IsExist(roomId))
                    {
                        break;
                    }
                }

                Room room = ComponentFactory.Create <Room>();
                room.UserID      = message.UserID;
                room.RoomID      = roomId;
                room.GameName    = message.Name;
                room.Bureau      = GameInfo.Bureau[message.Bureau];
                room.RuleBit     = message.RuleBit;
                room.PeopleCount = message.People;
                room.CurBureau   = 0;
                Game.Scene.GetComponent <RoomComponent>().Add(room);

                Gamer gamer = GamerFactory.Create(message.UserID, session.InstanceId);
                await gamer.AddComponent <MailBoxComponent>().AddLocation();

                gamer.UserID    = message.UserID;
                gamer.Name      = "房主" + userInfo.NickName;
                gamer.HeadIcon  = userInfo.HeadIcon;
                gamer.RoomID    = room.RoomID;
                gamer.Status    = GamerStatus.Down;
                gamer.IsOffline = false;
                gamer.Identity  = Identity.None;
                gamer.Coin      = 0;
                gamer.Sex       = userInfo.Sex;
                room.Add(gamer);
                Game.Scene.GetComponent <RoomComponent>().Add(gamer.UserID, room.RoomID);

                response.GameName = room.GameName;
                response.Bureau   = room.Bureau;
                response.RuleBit  = room.RuleBit;
                response.RoomID   = room.RoomID;
                response.People   = room.PeopleCount;
                //根据UserID从数据库拿到该用户信息并返回
                response.GamerInfo          = new GamerInfo();
                response.GamerInfo.Name     = gamer.Name;
                response.GamerInfo.HeadIcon = gamer.HeadIcon;
                response.GamerInfo.UserID   = gamer.UserID; //这个ID用于保存?待定
                response.GamerInfo.SeatID   = gamer.SeatID;
                response.GamerInfo.Sex      = gamer.Sex;
                response.GamerInfo.Status   = (int)gamer.Status;
                response.GamerInfo.Coin     = gamer.Coin;
                response.CurBureau          = room.CurBureau;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #9
0
        protected override async Task Run(Room room, MH2MP_PlayerEnterRoom message, Action <MP2MH_PlayerEnterRoom> reply)
        {
            MP2MH_PlayerEnterRoom response = new MP2MH_PlayerEnterRoom();

            try
            {
                Gamer gamer = room.Get(message.UserID);
                if (gamer == null)
                {
                    //创建房间玩家对象
                    gamer = GamerFactory.Create(message.PlayerID, message.UserID);
                    await gamer.AddComponent <ActorComponent>().AddLocation();

                    gamer.AddComponent <UnitGateComponent, long>(message.SessionID);

                    //加入到房间
                    room.Add(gamer);

                    M2C_GamerEnterRoom broadcastMessage = new M2C_GamerEnterRoom();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //广播房间内玩家消息
                    room.Broadcast(broadcastMessage);

                    Log.Info($"玩家{message.UserID}进入房间");
                }
                else
                {
                    //玩家重连 todo处理牛牛玩家重连逻辑
                    gamer.isOffline = false;
                    gamer.PlayerID  = message.PlayerID;
                    gamer.GetComponent <UnitGateComponent>().GateSessionId = message.SessionID;

                    //玩家重连移除托管组件
                    gamer.RemoveComponent <TrusteeshipComponent>();

                    M2C_GamerEnterRoom broadcastMessage = new M2C_GamerEnterRoom();
                    foreach (Gamer _gamer in room.GetAll())
                    {
                        if (_gamer == null)
                        {
                            //添加空位
                            broadcastMessage.Gamers.Add(null);
                            continue;
                        }

                        //添加玩家信息
                        GamerInfo info = new GamerInfo()
                        {
                            UserID = _gamer.UserID, IsReady = _gamer.IsReady
                        };
                        broadcastMessage.Gamers.Add(info);
                    }

                    //发送房间玩家信息
                    ActorProxy actorProxy = gamer.GetComponent <UnitGateComponent>().GetActorProxy();
                    actorProxy.Send(broadcastMessage);

                    Dictionary <long, Identity> gamersIdentity  = new Dictionary <long, Identity>();
                    Dictionary <long, int>      gamersCardsNum  = new Dictionary <long, int>();
                    GameControllerComponent     gameController  = room.GetComponent <GameControllerComponent>();
                    OrderControllerComponent    orderController = room.GetComponent <OrderControllerComponent>();
                    DeskCardsCacheComponent     deskCardsCache  = room.GetComponent <DeskCardsCacheComponent>();

                    foreach (Gamer _gamer in room.GetAll())
                    {
                        HandCardsComponent handCards = _gamer.GetComponent <HandCardsComponent>();
                        gamersCardsNum.Add(_gamer.UserID, handCards.CardsCount);
                        gamersIdentity.Add(_gamer.UserID, handCards.AccessIdentity);
                    }

                    //发送游戏开始消息
                    M2C_GameStart gameStartNotice = new M2C_GameStart()
                    {
                        GamerCards    = gamer.GetComponent <HandCardsComponent>().GetAll(),
                        GamerCardsNum = gamersCardsNum
                    };
                    actorProxy.Send(gameStartNotice);

                    Card[] lordCards = null;
                    if (gamer.GetComponent <HandCardsComponent>().AccessIdentity == Identity.None)
                    {
                        //广播先手玩家
                        actorProxy.Send(new M2C_AuthorityGrabLandlord()
                        {
                            UserID = orderController.CurrentAuthority
                        });
                    }
                    else
                    {
                        if (gamer.UserID == orderController.CurrentAuthority)
                        {
                            //发送可以出牌消息
                            bool isFirst = gamer.UserID == orderController.Biggest;
                            actorProxy.Send(new M2C_AuthorityPlayCard()
                            {
                                UserID = orderController.CurrentAuthority, IsFirst = isFirst
                            });
                        }
                        lordCards = deskCardsCache.LordCards.ToArray();
                    }
                    //发送重连数据
                    M2C_GamerReconnect_ANtt reconnectNotice = new M2C_GamerReconnect_ANtt()
                    {
                        Multiples              = room.GetComponent <GameControllerComponent>().Multiples,
                        GamersIdentity         = gamersIdentity,
                        DeskCards              = new KeyValuePair <long, Card[]>(orderController.Biggest, deskCardsCache.library.ToArray()),
                        LordCards              = lordCards,
                        GamerGrabLandlordState = orderController.GamerLandlordState
                    };
                    actorProxy.Send(reconnectNotice);

                    Log.Info($"玩家{message.UserID}重连");
                }

                response.GamerID = gamer.Id;

                reply(response);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #10
0
        protected override async void Run(Session session, C2G_CowCowJoinGameRoomGate message, Action <G2C_CowCowJoinGameRoomGate> reply)
        {
            G2C_CowCowJoinGameRoomGate response = new G2C_CowCowJoinGameRoomGate();

            try
            {
                Log.WriteLine($"Session:{session.Id},userId:{message.UserID}");
                UserInfo userInfo = Game.Scene.GetComponent <UserInfoComponent>().Get(message.UserID);
                Room     room     = Game.Scene.GetComponent <RoomComponent>().Get(message.RoomID);
                if (room == null)
                {
                    response.Error   = ErrorCode.ERR_NotRoomNumberError;
                    response.Message = "房间号不存在";
                    reply(response);
                    return;
                }

                //超过七个人
                if (room.GamerCount >= room.PeopleCount)
                {
                    response.Error   = ErrorCode.ERR_RoomPeopleFullError;
                    response.Message = "房间人已满";
                    reply(response);
                    return;
                }

                response.GameName  = room.GameName;
                response.Bureau    = room.Bureau;
                response.RuleBit   = room.RuleBit;
                response.RoomID    = room.RoomID;
                response.CurBureau = room.CurBureau;

                Gamer gamer = GamerFactory.Create(message.UserID, session.InstanceId);
                await gamer.AddComponent <MailBoxComponent>().AddLocation();

                gamer.UserID    = message.UserID; //玩家账号
                gamer.Name      = "闲家" + userInfo.NickName;
                gamer.HeadIcon  = userInfo.HeadIcon;
                gamer.Sex       = userInfo.Sex;
                gamer.Coin      = 0;
                gamer.RoomID    = room.RoomID;
                gamer.Status    = GamerStatus.Down;
                gamer.IsOffline = false;
                gamer.Identity  = Identity.None;
                room.Add(gamer);
                Game.Scene.GetComponent <RoomComponent>().Add(gamer.UserID, room.RoomID);

                Dictionary <int, Gamer>           gamers   = room.GetAll();
                Actor_CowCowJoinGameRoomGroupSend allGamer = new Actor_CowCowJoinGameRoomGroupSend();
                allGamer.LocalGamerInfo          = new GamerInfo();
                allGamer.LocalGamerInfo.Coin     = gamer.Coin;
                allGamer.LocalGamerInfo.Name     = gamer.Name;
                allGamer.LocalGamerInfo.HeadIcon = gamer.HeadIcon;
                allGamer.LocalGamerInfo.SeatID   = gamer.SeatID;
                allGamer.LocalGamerInfo.Sex      = gamer.Sex;
                allGamer.LocalGamerInfo.Status   = (int)gamer.Status;
                allGamer.LocalGamerInfo.UserID   = gamer.UserID;
                allGamer.GamerInfo = new RepeatedField <GamerInfo>();
                foreach (Gamer g in gamers.Values)
                {
                    GamerInfo gamerInfo = new GamerInfo();
                    gamerInfo.Coin     = g.Coin;
                    gamerInfo.Name     = g.Name;
                    gamerInfo.HeadIcon = g.HeadIcon;
                    gamerInfo.SeatID   = g.SeatID;
                    gamerInfo.Sex      = g.Sex;
                    gamerInfo.Status   = (int)g.Status;
                    gamerInfo.UserID   = g.UserID;

                    allGamer.GamerInfo.Add(gamerInfo);
                }

                reply(response);

                room.Broadcast(allGamer);
            }
            catch (Exception e)
            {
                ReplyError(response, e, reply);
            }
        }
Пример #11
0
        protected override async ETTask Run(Session session, CreateUnit_G2M message)
        {
            // 查询玩家角色信息中是否已有地图与位置坐标数据
            // ...

            Unit unit = ComponentFactory.CreateWithId <Unit>(IdGenerater.GenerateId());

            unit.GActorId = message.GActorId;
            unit.CActorId = message.CActorId;
            unit.Position = new Vector3(-10, 0, -10);

            // 给unit添加unit状态组件与角色移动组件
            unit.AddComponent <UnitStateComponent>();
            unit.AddComponent <CharacterMoveComponent>();

            // unit添加到UnitComponet,添加MailBoxComponent
            await unit.AddComponent <MailBoxComponent>().AddLocation();

            Game.Scene.GetComponent <UnitComponent>().Add(unit);


            //创建地图房间的玩家,用UserID构建Gamer
            Gamer gamer = ComponentFactory.Create <Gamer, long>(message.UserId);

            gamer.GActorId = message.GActorId;
            gamer.CActorId = message.CActorId;

            // 更新gamer的UnitId
            gamer.UnitId  = unit.Id;
            gamer.CharaId = message.CharaId;

            //为Gamer添加组件
            await gamer.AddComponent <MailBoxComponent>().AddLocation();

            //更新网关user的ActorID
            ActorMessageSender actorProxy = Game.Scene.GetComponent <ActorMessageSenderComponent>().Get(gamer.GActorId);

            actorProxy.Send(new Actor_EnterMapSucess_M2G()
            {
                GamerId = gamer.InstanceId, UnitId = unit.Id
            });

            // 将gamer添加到地图房间
            RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>();
            Room          room          = roomComponent.GetMapRoom(1001); // 暂时用黎明镇的地图编号

            room.Add(gamer);

            unit.gamer = gamer;
            unit.room  = room;

            // 广播创建的units
            CreateUnits_M2C createUnits = new CreateUnits_M2C();

            Unit[] units = Game.Scene.GetComponent <UnitComponent>().GetAll();
            foreach (Unit u in units)
            {
                UnitInfo unitInfo = new UnitInfo();
                unitInfo.X       = u.Position.x;
                unitInfo.Y       = u.Position.y;
                unitInfo.Z       = u.Position.z;
                unitInfo.UnitId  = u.Id;
                unitInfo.UserId  = u.gamer.UserId;
                unitInfo.CharaId = u.gamer.CharaId;
                createUnits.Units.Add(unitInfo);
            }

            // 应该是只向玩家可见范围的其它玩家广播,目前还没实现暂时向整个地图房间广播
            room.Broadcast(createUnits);
        }
        protected override async void Run(ETModel.Session session, A1010_NewArmyWave_M2C message)
        {
            //服务端通知客户端刷新一波士兵 1坦克 战士 1法师
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //创建3个蓝方坦克 配置编号37-39
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 37);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方坦克 配置编号46-48
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 46);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 31);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 40);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }

            await timerComponent.WaitAsync(1000);

            //创建3个蓝方法师 配置编号34-36
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 34);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
            //创建3个红方法师 配置编号43-45
            for (int i = 0; i < 3; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 43);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
            }
        }
        protected override async void Run(ETModel.Session session, A1004_CreateMoba5V5Secene_M2C message)
        {
            //开启加载界面 切换UI
            UIComponent uiComponent = Game.Scene.GetComponent <UIComponent>();
            UI          ui          = uiComponent.Get(UIType.SekiaLobby);

            if (ui == null)
            {
                return;
            }
            if (ui.GetComponent <SekiaLobbyComponent>().isMatching == false)
            {
                return;
            }
            uiComponent.Create(UIType.Moba5V5UI);
            uiComponent.Remove(UIType.SekiaLobby);

            //切换场景
            using (SceneChangeComponent sceneChangeComponent = ETModel.Game.Scene.AddComponent <SceneChangeComponent>())
            {
                await sceneChangeComponent.ChangeSceneAsync(SceneType.Moba5V5Map);
            }

            //加载配置
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            await resourcesComponent.LoadBundleAsync($"unit.unity3d");

            GameObject       bundleGameObject = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent  config           = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component moba             = Game.Scene.AddComponent <Moba5V5Component>();

            //创建空气墙 编号73和74
            for (int i = 0; i < 2; i++)
            {
                Moba5V5Config qiang       = (Moba5V5Config)config.Get(typeof(Moba5V5Config), 73 + i);
                GameObject    qiangPrefab = bundleGameObject.Get <GameObject>(qiang.Prefab);
                qiangPrefab.transform.position    = new Vector3((float)qiang.Position[0], (float)qiang.Position[1], (float)qiang.Position[2]);
                qiangPrefab.transform.eulerAngles = new Vector3(0, qiang.Rotation, 0);
                qiangPrefab.name = $"Qiang{(i + 1).ToString()}";
                UnityEngine.Object.Instantiate(qiangPrefab).transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
            }

            //创建10个英雄的GameObject和Gamer MobaID编号1-10
            for (int i = 0; i < message.Gamers.Count; i++)
            {
                //获取英雄配置 角色配置 技能配置
                HeroConfig    heroConfig    = (HeroConfig)config.Get(typeof(HeroConfig), message.Gamers[i].HeroID);
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 1);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(heroConfig.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer, long>(message.Gamers[i].UserID);
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                GamerAnimatorComponent anime = gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
                character.route  = moba5V5Config.Route; //默认导航线路
                character.anime  = anime;

                //确认本地玩家
                if (gamer.UserID == GamerComponent.Instance.MyUser.UserID)
                {
                    gamer.AddComponent <GamerCameraComponent>();
                    moba.myGamer = gamer;
                }
            }

            //创建攻击类建筑 MobaID编号11-30
            for (int i = 0; i < 20; i++)
            {
                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + 11);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = GameObject.Find($"/World/5v5_Map/mobaTower{i+1}");
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();

                //设置角色
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }

            //初始加载完成
            SessionComponent.Instance.Session.Send(new A1007_GamerReadyMoba5V5_C2M());
            //等待服务端通知游戏计时开始
            //等待服务端通知刷新第一波小兵
            //等待服务端通知刷新普通野怪
            //等待服务端通知刷新大龙
        }
        protected override void Run(ETModel.Session session, Actor_GameStart_Ntt message)
        {
            UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom);
            LandlordsRoomComponent room = uiRoom.GetComponent <LandlordsRoomComponent>();

            //初始化玩家UI
            foreach (GamerCardNum gamerCardNum in message.GamersCardNum)
            {
                Gamer gamer = room.GetGamer(gamerCardNum.UserID);
                LandlordsGamerPanelComponent gamerUI = gamer.GetComponent <LandlordsGamerPanelComponent>();
                gamerUI.GameStart();

                HandCardsComponent handCards = gamer.GetComponent <HandCardsComponent>();
                if (handCards != null)
                {
                    handCards.Reset();
                }
                else
                {
                    //Log.Debug("没有可以复用的HandCardsComponent,创建一个。");
                    handCards = gamer.AddComponent <HandCardsComponent, GameObject>(gamerUI.Panel);
                }

                //显示牌背面或者手牌
                handCards.Appear();

                if (gamer.UserID == LandlordsRoomComponent.LocalGamer.UserID)
                {
                    //本地玩家添加手牌
                    Card[] Tcards = new Card[message.HandCards.Count];
                    for (int i = 0; i < message.HandCards.Count; i++)
                    {
                        Tcards[i] = message.HandCards[i];
                    }
                    //Log.Debug("当前玩家手牌数量"+message.HandCards.array.Length.ToString());
                    //array的数量为32 与牌数不符合
                    handCards.AddCards(Tcards);
                }
                else
                {
                    //设置其他玩家手牌数
                    handCards.SetHandCardsNum(gamerCardNum.Num);
                }
            }

            //显示牌桌UI
            GameObject desk = uiRoom.GameObject.Get <GameObject>("Desk");

            desk.SetActive(true);
            GameObject lordPokers = desk.Get <GameObject>("LordPokers");

            //重置地主牌
            Sprite lordSprite = CardHelper.GetCardSprite("None");

            for (int i = 0; i < lordPokers.transform.childCount; i++)
            {
                lordPokers.transform.GetChild(i).GetComponent <Image>().sprite = lordSprite;
            }

            LandlordsRoomComponent uiRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>();

            //清空选中牌
            uiRoomComponent.Interaction.Clear();
            //设置初始倍率
            uiRoomComponent.SetMultiples(1);
        }
Пример #15
0
 public void AddGamer(Gamer gamer, int index)
 {
     seats[gamer.UserID] = index;
     gamer.AddComponent <LandlordsGamerPanelComponent>().SetPanel(GamersPanel[index]);
     gamers[index] = gamer;
 }
Пример #16
0
        protected override void Run(ETModel.Session session, A1012_NewMonster_M2C message)
        {
            //服务端通知客户端刷新一窝野怪
            TimerComponent     timerComponent     = ETModel.Game.Scene.GetComponent <TimerComponent>();
            ResourcesComponent resourcesComponent = ETModel.Game.Scene.GetComponent <ResourcesComponent>();
            GameObject         bundleGameObject   = (GameObject)resourcesComponent.GetAsset("Unit.unity3d", "Unit");
            ConfigComponent    config             = Game.Scene.GetComponent <ConfigComponent>();
            Moba5V5Component   moba = Moba5V5Component.instance;

            //野怪点ID 编号分别为:49 51 52 54 57 58 59 60 61 62 63 64 65 68 70 71
            int configID;      //配置编号
            int monsterNumber; //野怪数量

            switch (message.MonsterID)
            {
            case 49:     //蜥蜴
                configID      = 49;
                monsterNumber = 2;
                break;

            case 51:     //蓝Buff
                configID      = 51;
                monsterNumber = 1;
                break;

            case 52:     //狼
                configID      = 52;
                monsterNumber = 2;
                break;

            case 54:     //熊
                configID      = 54;
                monsterNumber = 3;
                break;

            case 57:     //红Buff
                configID      = 57;
                monsterNumber = 1;
                break;

            case 58:     //鸟
                configID      = 58;
                monsterNumber = 1;
                break;

            case 59:     //河道蟹
                configID      = 59;
                monsterNumber = 1;
                break;

            case 60:     //河道蟹
                configID      = 60;
                monsterNumber = 1;
                break;

            case 61:     //大Boss
                configID      = 61;
                monsterNumber = 1;
                break;

            case 62:     //小Boss
                configID      = 62;
                monsterNumber = 1;
                break;

            case 63:     //鸟
                configID      = 63;
                monsterNumber = 1;
                break;

            case 64:     //红buff
                configID      = 64;
                monsterNumber = 1;
                break;

            case 65:     //熊
                configID      = 65;
                monsterNumber = 3;
                break;

            case 68:     //狼
                configID      = 68;
                monsterNumber = 2;
                break;

            case 70:     //蓝Buff
                configID      = 70;
                monsterNumber = 1;
                break;

            case 71:     //蜥蜴
                configID      = 71;
                monsterNumber = 2;
                break;

            default:
                throw new Exception("未知野怪点");
            }

            for (int i = 0; i < monsterNumber; i++)
            {
                if (i == 12)
                {
                    continue;
                }

                //获取角色配置
                Moba5V5Config moba5V5Config = (Moba5V5Config)config.Get(typeof(Moba5V5Config), i + configID);
                GameObject    prefab        = bundleGameObject.Get <GameObject>(moba5V5Config.Prefab);
                prefab.transform.position    = new Vector3((float)moba5V5Config.Position[0], (float)moba5V5Config.Position[1], (float)moba5V5Config.Position[2]);
                prefab.transform.eulerAngles = new Vector3(0, moba5V5Config.Rotation, 0);

                //创建角色
                Gamer gamer = ETModel.ComponentFactory.Create <Gamer>();
                gamer.GameObject = UnityEngine.Object.Instantiate(prefab);
                gamer.GameObject.transform.SetParent(GameObject.Find($"/Global/Unit").transform, false);
                int mobaID = moba.MobaID;             //获取ID
                moba.mobaIDGamers.Add(mobaID, gamer); //添加到词典

                //添加Unity组件
                NavMeshAgent navMeshAgent = gamer.GameObject.AddComponent <NavMeshAgent>();
                navMeshAgent.radius                = 0.2f;
                navMeshAgent.height                = 0.8f;
                navMeshAgent.angularSpeed          = 360f;
                navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.NoObstacleAvoidance;

                //添加ET组件
                gamer.AddComponent <GamerAnimatorComponent>();
                gamer.AddComponent <GamerMoveComponent>();
                gamer.AddComponent <GamerTurnComponent>();
                gamer.AddComponent <GamerPathComponent>();

                //设置角色
                CharacterComponent character = gamer.AddComponent <CharacterComponent>();
                character.mobaID = mobaID;
                character.group  = moba5V5Config.Group; //阵营
                character.type   = moba5V5Config.Type;  //类型
            }
        }