public void Awake() { ReferenceCollector rc = this.GetParent <UI>().GameObject.GetComponent <ReferenceCollector>(); quitButton = rc.Get <GameObject>("QuitButton"); readyButton = rc.Get <GameObject>("ReadyButton"); //GameObject multiplesObj = rc.Get<GameObject>("Multiples"); //multiples = multiplesObj.GetComponent<Text>(); //绑定事件 quitButton.GetComponent <Button>().onClick.Add(OnQuit); readyButton.GetComponent <Button>().onClick.Add(OnReady); //默认隐藏UI //multiplesObj.SetActive(false); readyButton.SetActive(false); //rc.Get<GameObject>("Desk").SetActive(false); //添加玩家面板 GameObject gamersPanel = rc.Get <GameObject>("Gamers"); this.GamersPanel[0] = gamersPanel.Get <GameObject>("Left2"); this.GamersPanel[1] = gamersPanel.Get <GameObject>("Left1"); this.GamersPanel[2] = gamersPanel.Get <GameObject>("Local"); this.GamersPanel[3] = gamersPanel.Get <GameObject>("Right1"); this.GamersPanel[4] = gamersPanel.Get <GameObject>("Right2"); //添加本地玩家 User localPlayer = ClientComponent.Instance.LocalPlayer; Gamer localGamer = GamerFactory.Create(localPlayer.UserID, false); AddGamer(localGamer, 2); this.GetParent <UI>().GetComponent <GamerComponent>().LocalGamer = localGamer; }
/// <summary> /// 加入房间 /// </summary> /// <param name="self"></param> /// <param name="room"></param> /// <param name="matcher"></param> public static async void JoinRoom(this MatchComponent self, Room room, Matcher matcher) { //玩家加入房间,移除匹配队列 self.Playing[matcher.UserID] = room.Id; self.MatchSuccessQueue.Enqueue(matcher); //向房间服务器发送玩家进入请求 ActorProxy actorProxy = Game.Scene.GetComponent <ActorProxyComponent>().Get(room.Id); Actor_PlayerEnterRoom_Ack actor_PlayerEnterRoom_Ack = await actorProxy.Call(new Actor_PlayerEnterRoom_Req() { PlayerID = matcher.PlayerID, UserID = matcher.UserID, SessionID = matcher.GateSessionID }) as Actor_PlayerEnterRoom_Ack; Gamer gamer = GamerFactory.Create(matcher.PlayerID, matcher.UserID, actor_PlayerEnterRoom_Ack.GamerID); room.Add(gamer); //向玩家发送匹配成功消息 ActorProxyComponent actorProxyComponent = Game.Scene.GetComponent <ActorProxyComponent>(); ActorProxy gamerActorProxy = actorProxyComponent.Get(gamer.PlayerID); gamerActorProxy.Send(new Actor_MatchSucess_Ntt() { GamerID = gamer.Id }); }
public Gamer AddGamerUI(GamerInfo info) { if (gamers.ContainsKey(info.SeatID)) { return(null); } Gamer gamer = GamerFactory.Create(info); Add(gamer, info.SeatID); return(gamer); }
protected override async Task Run(Room room, Actor_PlayerEnterRoom_Ntt message) { try { DBProxyComponent dbProxy = Game.Scene.GetComponent <DBProxyComponent>(); Gamer gamer = room.Get(message.UserID); if (gamer == null) { //创建房间玩家对象 gamer = GamerFactory.Create(message.PlayerID, message.UserID, room.RoomId, (ushort)room.Count); await gamer.AddComponent <MailBoxComponent>().AddLocation(); gamer.AddComponent <UnitGateComponent, long>(message.SessionID); //设置转接ID Session session = Game.Scene.GetComponent <NetOuterComponent>().Get(message.SessionID); session.GetUser().ActorID = gamer.Id; room.Add(gamer); Actor_GamerEnterRoom_Ntt broadcastMessage = new Actor_GamerEnterRoom_Ntt(); foreach (Gamer item in room.GetAll()) { if (item == null) { //添加空位 broadcastMessage.users.Add(null); continue; } UserInfo userInfo = await dbProxy.Query <UserInfo>(item.UserID, false); GamerInfo info = new GamerInfo() { ChairID = item.uChairID, NickName = userInfo.NickName, Loses = userInfo.Loses, Money = userInfo.Money, Wins = userInfo.Wins }; broadcastMessage.users.Add(info); } room.Broadcast(broadcastMessage); Log.Info($"玩家{message.UserID}进入房间"); } else { Log.Info("断线重连?????"); } } catch (Exception e) { Log.Info($"创建房间错误:{e.Message}"); } }
public async void OnLogin() { try { if (string.IsNullOrEmpty(this.Filed_Account.text) || string.IsNullOrEmpty(this.Filed_PassWord.text)) { txt_LoginState.text = "请输入正确的账号和密码"; return; } IPEndPoint connetEndPoint = NetworkHelper.ToIPEndPoint(GlobalConfigComponent.Instance.GlobalProto.Address); // 创建一个ETModel层的Session ETModel.Session session = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); // 创建一个ETHotfix层的Session, ETHotfix的Session会通过ETModel层的Session发送消息 Session realmSession = ComponentFactory.Create <Session, ETModel.Session>(session); R2C_Login r2CLogin = (R2C_Login)await realmSession.Call(new C2R_Login() { Account = Filed_Account.text, Password = Filed_PassWord.text }); realmSession.Dispose(); connetEndPoint = NetworkHelper.ToIPEndPoint(r2CLogin.Address); // 创建一个ETModel层的Session,并且保存到ETModel.SessionComponent中 ETModel.Session gateSession = ETModel.Game.Scene.GetComponent <NetOuterComponent>().Create(connetEndPoint); ETModel.Game.Scene.AddComponent <ETModel.SessionComponent>().Session = gateSession; // 创建一个ETHotfix层的Session, 并且保存到ETHotfix.SessionComponent中 Game.Scene.AddComponent <SessionComponent>().Session = ComponentFactory.Create <Session, ETModel.Session>(gateSession); G2C_LoginGate g2CLoginGate = (G2C_LoginGate)await SessionComponent.Instance.Session.Call(new C2G_LoginGate() { Key = r2CLogin.Key }); Log.Info("登陆gate成功!"); Gamer gamer = GamerFactory.Create(g2CLoginGate.UserID, false); Game.Scene.AddComponent <GameDataComponent, Gamer>(gamer); Game.Scene.GetComponent <UIComponent>().CreateOrShow(UIType.UILobby); Close(); } catch (Exception e) { Log.Error(e); } }
public void Awake(GameObject parent, GamerInfo info, int posIndex) { res = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); res.LoadBundle(UICowCowAB.CowCow_Texture); res.LoadBundle(UICowCowAB.CowCow_SoundOther); microphone = Game.Scene.GetComponent <MicrophoneComponent>(); this.Status = (UIGamerStatus)info.Status; this.gamerName = info.Name; UIGameInfo = GamerFactory.Create(UICowCowType.CowCowGamerInfo); UIGameInfo.transform.SetParent(parent.transform, false); UIGameInfo.name = UICowCowType.CowCowGamerInfo; ReferenceCollector rc = UIGameInfo.GetComponent <ReferenceCollector>(); Image headIcon = rc.Get <GameObject>("HeadIcon").GetComponent <Image>(); headIcon.transform.localPosition = GamerData.Pos[posIndex].HeadPos; Text gamerNames = rc.Get <GameObject>("Names").GetComponent <Text>(); coin = rc.Get <GameObject>("Coin").GetComponent <Text>(); status = rc.Get <GameObject>("Status").GetComponent <Text>(); cowType = rc.Get <GameObject>("CowType").GetComponent <Text>(); HandCard = rc.Get <GameObject>("HandCard").GetComponent <CanvasGroup>(); HandCard.transform.localPosition = GamerData.Pos[posIndex].CardPos; for (int i = 0; i < cards.Length; i++) { cards[i] = rc.Get <GameObject>("Card" + i).GetComponent <Image>(); } promptBtn = rc.Get <GameObject>("PromptBtn").GetComponent <Button>(); submitBtn = rc.Get <GameObject>("SubmitBtn").GetComponent <Button>(); emoji = rc.Get <GameObject>("Emoji").GetComponent <Image>(); chatBG = rc.Get <GameObject>("ChatBG").GetComponent <CanvasGroup>(); chatText = rc.Get <GameObject>("ChatText").GetComponent <Text>(); bankerIcon = rc.Get <GameObject>("BankerIcon").GetComponent <Image>(); chatBG.transform.localPosition = GamerData.Pos[posIndex].ChatPosData.Pos; chatBG.transform.Rotate(GamerData.Pos[posIndex].ChatPosData.Rotate); chatText.transform.Rotate(GamerData.Pos[posIndex].ChatPosData.Rotate); promptBtn.onClick.Add(OnPrompt); submitBtn.onClick.Add(OnSubmit); gamerNames.text = info.Name; this.SetCoin(info.Coin.ToString()); this.Sex = info.Sex; //headIcon.sprite = info.HeadIcon; }
protected override async void Run(ETModel.Session session, Actor_GamerJionRoom message) { try { Log.Debug("有人加入:"); UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); UI uiReady = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady); if (uiReady == null) { return; } GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); UIRoomComponent roomComponent = uiRoom.GetComponent <UIRoomComponent>(); UIReadyComponent uiReadyComponent = uiReady.GetComponent <UIReadyComponent>(); Gamer gamer = GamerFactory.Create(message.Gamer.UserID, message.Gamer.IsReady, message.Gamer.playerInfo); GamerUIComponent gamerUiComponent = gamer.GetComponent <GamerUIComponent>(); //排序 int index = message.Gamer.SeatIndex - roomComponent.localGamer.SeatIndex; if (index < 0) { index += 4; } //设置准备 if (uiReadyComponent != null) { // await gamerUiComponent.GetPlayerInfo(); if (gamer?.PlayerInfo != null) { gamerUiComponent?.SetHeadPanel(uiReadyComponent.HeadPanel[index], index); gamerUiComponent?.SetFace(roomComponent.FacePanel[index]); uiReady?.GetComponent <UIReadyComponent>()?.SetPanel(gamer, index); //根据座位的indax添加玩家 roomComponent?.AddGamer(gamer, index); } } } catch (Exception e) { Log.Error(e); } }
public void Awake(GameObject parent) { GameObject BSGamerResult = GamerFactory.Create(UICowCowType.CowCowBSPlayerResult); BSGamerResult.transform.SetParent(parent.transform, false); ReferenceCollector rc = BSGamerResult.GetComponent <ReferenceCollector>(); headIcon = rc.Get <GameObject>("HeadIcon").GetComponent <Image>(); banker = rc.Get <GameObject>("Banker").GetComponent <Text>(); fiveSmallCow = rc.Get <GameObject>("FiveSmallCow").GetComponent <Text>(); fiveFlowerCow = rc.Get <GameObject>("FiveFlowerCow").GetComponent <Text>(); bombCow = rc.Get <GameObject>("FiveBombCow").GetComponent <Text>(); doubleCow = rc.Get <GameObject>("DoubleCow").GetComponent <Text>(); haveCow = rc.Get <GameObject>("HaveCow").GetComponent <Text>(); notCow = rc.Get <GameObject>("NotCow").GetComponent <Text>(); totleScore = rc.Get <GameObject>("TotalScroe").GetComponent <Text>(); }
protected override void Run(ETModel.Session session, Actor_GamerEnterRoom_Ntt message) { UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.LandlordsRoom); LandlordsRoomComponent landlordsRoomComponent = uiRoom.GetComponent <LandlordsRoomComponent>(); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); //从匹配状态中切换为准备状态 if (landlordsRoomComponent.Matching) { landlordsRoomComponent.Matching = false; GameObject matchPrompt = uiRoom.GameObject.Get <GameObject>("MatchPrompt"); if (matchPrompt.activeSelf) { matchPrompt.SetActive(false); uiRoom.GameObject.Get <GameObject>("ReadyButton").SetActive(true); } } int localGamerIndex = message.Gamers.FindIndex(info => info.UserID == gamerComponent.LocalGamer.UserID); //添加未显示玩家 for (int i = 0; i < message.Gamers.Count; i++) { GamerInfo gamerInfo = message.Gamers[i]; if (gamerInfo.UserID == 0) { continue; } if (gamerComponent.Get(gamerInfo.UserID) == null) { Gamer gamer = GamerFactory.Create(gamerInfo.UserID, gamerInfo.IsReady); if ((localGamerIndex + 1) % 3 == i) { //玩家在本地玩家右边 landlordsRoomComponent.AddGamer(gamer, 2); } else { //玩家在本地玩家左边 landlordsRoomComponent.AddGamer(gamer, 0); } } } }
public void Awake(GameObject parent) { res = ETModel.Game.Scene.GetComponent <ResourcesComponent>(); GameObject SSGamerResult = GamerFactory.Create(UICowCowType.CowCowSSPlayerResult); SSGamerResult.transform.SetParent(parent.transform, false); ReferenceCollector rc = SSGamerResult.GetComponent <ReferenceCollector>(); banker = rc.Get <GameObject>("Banker").GetComponent <CanvasGroup>(); gamerName = rc.Get <GameObject>("Name").GetComponent <Text>(); bets = rc.Get <GameObject>("Bets").GetComponent <Text>(); cardType = rc.Get <GameObject>("CardType").GetComponent <Text>(); score = rc.Get <GameObject>("Score").GetComponent <Text>(); for (int i = 0; i < cards.Length; i++) { cards[i] = rc.Get <GameObject>("Card" + i).GetComponent <Image>(); } }
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); } }
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); } }
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); } }
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); } }
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); } }
public static async Task GamerEnterRoom(Actor_GamerEnterRoom message) { try { //玩家还在结算画面 if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIGameResult) != null || UIRoomComponent.ISGaming) { return; } Log.Info($"收到玩家进入"); //第一次进入创建UIRoom if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom) == null) { CommonUtil.ShowUI(UIType.UIRoom); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIMain); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UICreateFriendRoom); Game.Scene.GetComponent <UIComponent>().Remove(UIType.UIJoinRoom); } if (Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady) == null) { CommonUtil.ShowUI(UIType.UIReady); } UINetLoadingComponent.closeNetLoading(); UI uiRoom = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIRoom); UI uiReady = Game.Scene.GetComponent <UIComponent>().Get(UIType.UIReady); GamerComponent gamerComponent = uiRoom.GetComponent <GamerComponent>(); UIRoomComponent roomComponent = uiRoom.GetComponent <UIRoomComponent>(); roomComponent.ContinueGamer(); roomComponent.enterRoomMsg = message; roomComponent.SetRoomType(message.RoomType, message.Multiples); Gamer[] gamers = gamerComponent.GetAll(); //清空座位 for (int i = 0; i < gamers.Length; i++) { if (gamers[i] == null) { continue; } if (gamers[i].UserID != 0) { Log.Debug("删除gamer"); roomComponent.RemoveGamer(gamers[i].UserID); } } GamerInfo localGamer = null; for (int i = 0; i < message.Gamers.Count; i++) { if (message.Gamers[i].UserID == PlayerInfoComponent.Instance.uid) { localGamer = message.Gamers[i]; gamerComponent.LocalGamer = GamerFactory.Create(localGamer.UserID, localGamer.IsReady, localGamer.playerInfo); break; } } if (localGamer == null) { return; } roomComponent.localGamer = localGamer; //好友房处理 if (message.RoomType == 3) { UIRoomComponent.IsFriendRoom = true; roomComponent.JuCount = message.JuCount; uiReady?.GetComponent <UIReadyComponent>()?.ClosePropt(); uiReady?.GetComponent <UIReadyComponent>()?.SetFriendRoom(true); uiReady?.GetComponent <UIReadyComponent>()?.ShowWeChat(message.RoomId.ToString()); roomComponent.RoomConfig.Multiples = message.Multiples; roomComponent.SetFriendSetting(message.MasterUserId); if (message.CurrentJuCount > 0) { uiReady?.GetComponent <UIReadyComponent>()?.CloseBtn(); roomComponent.exitBtn.interactable = false; } } else { uiReady?.GetComponent <UIReadyComponent>()?.SetFriendRoom(false); UIRoomComponent.IsFriendRoom = false; } for (int i = 0; i < message.Gamers.Count; i++) { GamerInfo gamerInfo = message.Gamers[i]; Gamer gamer; if (gamerInfo.UserID == localGamer.UserID) { gamer = gamerComponent.LocalGamer; } else { gamer = GamerFactory.Create(gamerInfo.UserID, gamerInfo.IsReady, gamerInfo.playerInfo); } UIReadyComponent uiReadyComponent = uiReady.GetComponent <UIReadyComponent>(); GamerUIComponent gamerUiComponent = gamer.GetComponent <GamerUIComponent>(); //排序 int index = gamerInfo.SeatIndex - localGamer.SeatIndex; if (index < 0) { index += 4; } //设置准备 if (uiReadyComponent != null) { if (gamer?.PlayerInfo != null) { gamerUiComponent?.SetHeadPanel(uiReadyComponent.HeadPanel[index], index); gamerUiComponent?.SetFace(roomComponent.FacePanel[index]); uiReady?.GetComponent <UIReadyComponent>()?.SetPanel(gamer, index); //根据座位的indax添加玩家 roomComponent?.AddGamer(gamer, index); } } } SoundsHelp.Instance.playSound_JinRu(); } catch (Exception e) { Log.Error(e); } }