public static async Task GamerReady(Gamer gamer, Actor_GamerReady message) { try { Log.Info($"收到玩家{gamer.UserID}准备"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || gamer == null || gamer.IsReady || room.State == RoomState.Game) { return; } gamer.IsReady = true; //消息广播给其他人 room?.Broadcast(new Actor_GamerReady() { Uid = gamer.UserID }); Gamer[] gamers = room.GetAll(); //房间内有4名玩家且全部准备则开始游戏 if (room.Count == 4 && gamers.Where(g => g.IsReady).Count() == 4) { room.State = RoomState.Game; room.CurrentJuCount++; room.IsGameOver = false; room.RoomDispose(); #region 好友房扣钥匙 if (room.IsFriendRoom && room.CurrentJuCount == 1) { RoomConfig roomConfig = room.GetComponent <GameControllerComponent>().RoomConfig; await DBCommonUtil.DeleteFriendKey(roomConfig.MasterUserId, roomConfig.KeyCount, "好友房房主扣除钥匙"); } #endregion //设置比下胡 if (room.LastBiXiaHu) { room.IsBiXiaHu = true; } else { room.IsBiXiaHu = false; } room.LastBiXiaHu = false; if (roomComponent.gameRooms.TryGetValue(room.Id, out var itemRoom)) { roomComponent.gameRooms.Remove(room.Id); } roomComponent.gameRooms.Add(room.Id, room); roomComponent.idleRooms.Remove(room.Id); //添加用户 room.UserIds.Clear(); //初始玩家开始状态 foreach (var _gamer in gamers) { room.UserIds.Add(_gamer.UserID); if (_gamer.GetComponent <HandCardsComponent>() == null) { _gamer.AddComponent <HandCardsComponent>(); } _gamer.IsReady = false; } Log.Info($"{room.Id}房间开始,玩家:{JsonHelper.ToJson(room.UserIds)}"); GameControllerComponent gameController = room.GetComponent <GameControllerComponent>(); OrderControllerComponent orderController = room.GetComponent <OrderControllerComponent>(); DeskComponent deskComponent = room.GetComponent <DeskComponent>(); Gamer bankerGamer = null; HandCardsComponent bankerHandCards = null; if (room.IsLianZhuang) { if (room.huPaiUid != 0 && room.huPaiUid == room.BankerGamer?.UserID) { bankerGamer = room.Get(room.huPaiUid); bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; //连庄 room.LastBiXiaHu = true; } else { int gamerSeat = room.GetGamerSeat(room.BankerGamer.UserID); int currentSeat; if (gamerSeat == 3) { currentSeat = 0; } else { currentSeat = ++gamerSeat; } bankerGamer = room.gamers[currentSeat]; bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } } else { if (room.IsFriendRoom) { GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>(); long masterUserId = controllerComponent.RoomConfig.MasterUserId; bankerGamer = room.Get(masterUserId); } else { //随机庄家 int number = RandomHelper.RandomNumber(0, 12); int i = number % 4; bankerGamer = room.gamers[i]; } bankerHandCards = bankerGamer.GetComponent <HandCardsComponent>(); bankerHandCards.IsBanker = true; room.BankerGamer = bankerGamer; } //发牌 gameController.DealCards(); orderController.Start(bankerGamer.UserID); //去除花牌 foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> handCards = handCardsComponent.GetAll(); for (int j = handCards.Count - 1; j >= 0; j--) { MahjongInfo mahjongInfo = handCards[j]; if (mahjongInfo.m_weight >= Consts.MahjongWeight.Hua_HongZhong) { handCards.RemoveAt(j); mahjongInfo.weight = (byte)mahjongInfo.m_weight; handCardsComponent.FaceCards.Add(mahjongInfo); handCardsComponent.FaceGangCards.Add(mahjongInfo); } } //加牌 int handCardsCount = handCards.Count; for (int j = 0; j < 13 - handCardsCount; j++) { GetCardNotFace(deskComponent, handCardsComponent); } } //庄家多发一张牌 GetCardNotFace(deskComponent, bankerHandCards); // List<MahjongInfo> infos = bankerHandCards.GetAll(); // bankerHandCards.library = new List<MahjongInfo>(list); //给客户端传送数据 Actor_StartGame actorStartGame = new Actor_StartGame(); foreach (var itemGame in gamers) { GamerData gamerData = new GamerData(); HandCardsComponent handCardsComponent = itemGame.GetComponent <HandCardsComponent>(); List <MahjongInfo> mahjongInfos = handCardsComponent.library; foreach (var mahjongInfo in mahjongInfos) { mahjongInfo.weight = (byte)mahjongInfo.m_weight; } gamerData.UserID = itemGame.UserID; gamerData.handCards = mahjongInfos; gamerData.faceCards = handCardsComponent.FaceCards; if (handCardsComponent.IsBanker) { gamerData.IsBanker = true; } gamerData.SeatIndex = room.seats[itemGame.UserID]; gamerData.OnlineSeconds = await DBCommonUtil.GetRestOnlineSeconds(itemGame.UserID); actorStartGame.GamerDatas.Add(gamerData); } actorStartGame.restCount = deskComponent.RestLibrary.Count; GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); if (room.IsFriendRoom) { actorStartGame.RoomType = 3; actorStartGame.CurrentJuCount = room.CurrentJuCount; } else { actorStartGame.RoomType = (int)gameControllerComponent.RoomConfig.Id; } //发送消息 room.Broadcast(actorStartGame); // Log.Debug("发送开始:" + JsonHelper.ToJson(actorStartGame)); //排序 var startTime = DateTime.Now; foreach (var _gamer in gamers) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); //排序 handCardsComponent.Sort(); handCardsComponent.GrabCard = handCardsComponent.GetAll()[handCardsComponent.GetAll().Count - 1]; //设置玩家在线开始时间 _gamer.StartTime = startTime; //await DBCommonUtil.RecordGamerTime(startTime, true, _gamer.UserID); } foreach (var _gamer in room.GetAll()) { HandCardsComponent handCardsComponent = _gamer.GetComponent <HandCardsComponent>(); List <MahjongInfo> cards = handCardsComponent.GetAll(); if (handCardsComponent.IsBanker) { if (Logic_NJMJ.getInstance().isHuPai(cards)) { //ToDo 胡牌 Actor_GamerCanOperation canOperation = new Actor_GamerCanOperation(); canOperation.Uid = _gamer.UserID; _gamer.IsCanHu = true; canOperation.OperationType = 2; room.GamerBroadcast(_gamer, canOperation); _gamer.isGangFaWanPai = true; } } else { //检查听牌 List <MahjongInfo> checkTingPaiList = Logic_NJMJ.getInstance().checkTingPaiList(cards); if (checkTingPaiList.Count > 0) { Log.Info($"{_gamer.UserID}听牌:"); _gamer.isFaWanPaiTingPai = true; } } } //等客户端掷骰子 //是否超时 await Game.Scene.GetComponent <TimerComponent>().WaitAsync(10 * 1000); room.StartTime(); //扣服务费 if (!room.IsFriendRoom) { //不要动画 GameHelp.CostServiceCharge(room, false); } } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
//1,刷新所有配置表 2,发送邮件 3,解散房间 4,增减黑名单 5,生成报表 6,查看用户信息 7,强制离线 8,修改用户信息 9,查看游戏内信息 protected override async void Run(Session session, C2G_GM message, Action <G2C_GM> reply) { G2C_GM response = new G2C_GM(); try { DBProxyComponent proxyComponent = Game.Scene.GetComponent <DBProxyComponent>(); if (Game.Scene.GetComponent <ConfigComponent>() != null) { Game.Scene.RemoveComponent <ConfigComponent>(); } Game.Scene.AddComponent <ConfigComponent>(); ConfigComponent configCom = Game.Scene.GetComponent <ConfigComponent>(); StartConfigComponent _config = Game.Scene.GetComponent <StartConfigComponent>(); IPEndPoint mapIPEndPoint = _config.MapConfigs[0].GetComponent <InnerConfig>().IPEndPoint; Session mapSession = Game.Scene.GetComponent <NetInnerComponent>().Get(mapIPEndPoint); switch (message.Type) { case 1: { //刷新所有配置表 List <PlayerBaseInfo> allInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); { //商城 List <ShopConfig> shopList = new List <ShopConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ShopConfig)).Length + 1; ++i) { int id = 1000 + i; ShopConfig config = (ShopConfig)configCom.Get(typeof(ShopConfig), id); shopList.Add(config); } ShopData.getInstance().getDataList().Clear(); ShopData.getInstance().getDataList().AddRange(shopList); } { //任务 List <TaskConfig> taskList = new List <TaskConfig>(); for (int i = 1; i < configCom.GetAll(typeof(TaskConfig)).Length + 1; ++i) { int id = 100 + i; TaskConfig config = (TaskConfig)configCom.Get(typeof(TaskConfig), id); taskList.Add(config); } TaskData.getInstance().getDataList().Clear(); TaskData.getInstance().getDataList().AddRange(taskList); for (int i = 0; i < allInfos.Count; ++i) { List <TaskProgressInfo> taskInfos = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id}}}"); //无论删减任务 都要刷新一下任务的数据库 for (int j = 0; j < taskInfos.Count; ++j) { TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId); if (config != null) { taskInfos[j].Name = config.Name; taskInfos[j].Target = config.Target; taskInfos[j].Reward = config.Reward; taskInfos[j].Desc = config.Desc; await proxyComponent.Save(taskInfos[j]); } } #region 增加任务先不管 update时会重新添加 //if (TaskData.getInstance().getDataList().Count > taskInfos.Count) //{ // //增加了新任务 // for (int j = 0; j < TaskData.getInstance().getDataList().Count; ++j) // { // List<TaskProgressInfo> progresses = await proxyComponent.QueryJson<TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{TaskData.getInstance().getDataList()[j].Id}}}"); // if (progresses.Count <= 0) // { // TaskProgressInfo progress = // ComponentFactory.CreateWithId<TaskProgressInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = allInfos[i].Id; // progress.Name = TaskData.getInstance().getDataList()[j].Name; // progress.TaskId = (int)TaskData.getInstance().getDataList()[j].Id; // progress.IsComplete = false; // progress.Target = TaskData.getInstance().getDataList()[j].Target; // progress.Reward = TaskData.getInstance().getDataList()[j].Reward; // progress.Desc = TaskData.getInstance().getDataList()[j].Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // } //} #endregion if (TaskData.getInstance().getDataList().Count < taskInfos.Count) { for (int j = 0; j < taskInfos.Count; ++j) { TaskConfig config = TaskData.getInstance().GetDataByTaskId(taskInfos[j].TaskId); List <TaskProgressInfo> progresses = await proxyComponent.QueryJson <TaskProgressInfo>($"{{UId:{allInfos[i].Id},TaskId:{taskInfos[j].TaskId}}}"); if (config == null) { if (progresses.Count > 0) { //删除该任务 await proxyComponent.Delete <TaskProgressInfo>(progresses[0].Id); } } } } } { //成就 List <ChengjiuConfig> chengjiuList = new List <ChengjiuConfig>(); for (int i = 1; i < configCom.GetAll(typeof(ChengjiuConfig)).Length + 1; ++i) { int id = 100 + i; ChengjiuConfig config = (ChengjiuConfig)configCom.Get(typeof(ChengjiuConfig), id); chengjiuList.Add(config); } ChengjiuData.getInstance().getDataList().Clear(); ChengjiuData.getInstance().getDataList().AddRange(chengjiuList); for (int i = 0; i < allInfos.Count; ++i) { List <ChengjiuInfo> chengjiuInfos = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id}}}"); //无论删减任务 都要刷新一下任务的数据库 for (int j = 0; j < chengjiuInfos.Count; ++j) { ChengjiuConfig config = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId); if (config != null) { chengjiuInfos[j].Name = config.Name; chengjiuInfos[j].Target = config.Target; chengjiuInfos[j].Reward = config.Reward; chengjiuInfos[j].Desc = config.Desc; await proxyComponent.Save(chengjiuInfos[j]); } } #region 增加(暂时先不管 Update时会新加) //if (ChengjiuData.getInstance().getDataList().Count > chengjiuInfos.Count) //{ // //增加了新成就 // for (int j = chengjiuInfos.Count; j < ChengjiuData.getInstance().getDataList().Count; ++j) // { // List<ChengjiuInfo> progresses = await proxyComponent.QueryJson<ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{ChengjiuData.getInstance().getDataList()[j].Id}}}"); // if (progresses.Count <= 0) // { // Log.Debug("增加新成就"); // ChengjiuInfo progress = // ComponentFactory.CreateWithId<ChengjiuInfo>(IdGenerater.GenerateId()); // progress.IsGet = false; // progress.UId = allInfos[i].Id; // progress.Name = ChengjiuData.getInstance().getDataList()[j].Name; // progress.TaskId = (int)ChengjiuData.getInstance().getDataList()[j].Id; // progress.IsComplete = false; // progress.Target = ChengjiuData.getInstance().getDataList()[j].Target; // progress.Reward = ChengjiuData.getInstance().getDataList()[j].Reward; // progress.Desc = ChengjiuData.getInstance().getDataList()[j].Desc; // progress.CurProgress = 0; // await proxyComponent.Save(progress); // } // } //} #endregion if (ChengjiuData.getInstance().getDataList().Count < chengjiuInfos.Count) { for (int j = 0; j < chengjiuInfos.Count; ++j) { ChengjiuConfig config = ChengjiuData.getInstance().GetDataByChengjiuId(chengjiuInfos[j].TaskId); List <ChengjiuInfo> progresses = await proxyComponent.QueryJson <ChengjiuInfo>($"{{UId:{allInfos[i].Id},TaskId:{chengjiuInfos[j].TaskId}}}"); if (config == null) { if (progresses.Count > 0) { //删除该成就 await proxyComponent.Delete <ChengjiuInfo>(progresses[0].Id); } } } } } } } } break; case 2: { //发送邮件 uid为空则为给全部玩家发送邮件 if (message.UId != -1) { Log.Debug("Mail" + message.UId + message.Title + message.Content + message.Reward); await DBCommonUtil.SendMail(message.UId, message.Title, message.Content, message.Reward); } else { //分批发还是全部一次性发 List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); if (playerBaseInfos.Count > 0) { for (int i = 0; i < playerBaseInfos.Count; ++i) { await DBCommonUtil.SendMail(playerBaseInfos[i].Id, message.Title, message.Content, message.Reward); } } } } break; case 3: { //解散房间 M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo() { Type = 3, Uid = message.UId }); response.Error = m2G_GMInfo.Error; response.Message = m2G_GMInfo.Message; } break; case 4: { //增减黑名单(根据玩家IP) List <BlackList> blackList = await proxyComponent.QueryJson <BlackList>($"{{ip:'{message.IP}'}}"); if (string.IsNullOrEmpty(message.EndTime)) { //删除黑名单 if (blackList.Count > 0) { blackList[0].EndTime = "2000-01-01 00:00:00"; await proxyComponent.Save(blackList[0]); } } else { if (blackList.Count > 0) { blackList[0].EndTime = message.EndTime; await proxyComponent.Save(blackList[0]); } else { BlackList list = ComponentFactory.CreateWithId <BlackList>(IdGenerater.GenerateId()); list.Uid = message.UId; list.ip = message.IP; list.EndTime = message.EndTime; list.Reason = message.Reason; await proxyComponent.Save(list); } } } break; case 5: { //生成报表 string logData = await DataStatistics.Start(message.CreateBaobiaoTime, message.Content); response.LogData = logData; } break; case 6: //查看用户信息 List <PlayerBaseInfo> infos = new List <PlayerBaseInfo>(); AccountInfo accountInfo = null; List <Log_Login> logLogins = new List <Log_Login>(); if (message.UId != 0) { infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}"); accountInfo = await DBCommonUtil.getAccountInfo(message.UId); logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{message.UId}}}"); } else if (!string.IsNullOrEmpty(message.Name)) { infos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{Name:'{message.Name}'}}"); if (infos.Count > 0) { accountInfo = await DBCommonUtil.getAccountInfo(infos[0].Id); logLogins = await proxyComponent.QueryJson <Log_Login>($"{{Uid:{infos[0].Id}}}"); } } if (infos.Count > 0) { PlayerInfo info = new PlayerInfo(); info.Name = infos[0].Name; info.GoldNum = infos[0].GoldNum; info.WingNum = infos[0].WingNum; info.HuaFeiNum = infos[0].HuaFeiNum; info.IsRealName = infos[0].IsRealName; info.VipTime = infos[0].VipTime; info.EmogiTime = infos[0].EmogiTime; info.MaxHua = infos[0].MaxHua; info.TotalGameCount = infos[0].TotalGameCount; info.WinGameCount = infos[0].WinGameCount; response.UId = infos[0].Id; M2G_GMInfo m2G_GMInfo = (M2G_GMInfo)await mapSession.Call(new G2M_GMInfo() { Type = 6, Uid = message.UId }); Log.Debug(m2G_GMInfo.Type + ""); response.IsInGame = m2G_GMInfo.Type; if (logLogins.Count > 0) { response.LastOnlineTime = logLogins[logLogins.Count - 1].CreateTime; } if (accountInfo != null) { info.Phone = accountInfo.Phone; response.RegisterTime = accountInfo.CreateTime; response.Channel = accountInfo.ChannelName; } response.Info = info; response.Ip = logLogins[logLogins.Count - 1].ip; } else { response.Message = "不存在该用户信息"; response.Error = ErrorCode.ERR_Exception; response.Info = null; } break; case 7: { //强制玩家离线 UserComponentSystem.ForceOffline(message.UId, message.Reason); } break; case 8: { //更改用户信息 if (message.UId == -1) { List <PlayerBaseInfo> playerBaseInfos = await proxyComponent.QueryJsonDBInfos <PlayerBaseInfo>(); if (playerBaseInfos.Count > 0) { for (int i = 0; i < playerBaseInfos.Count; ++i) { if (!message.Icon.Equals("0")) { playerBaseInfos[0].Icon = message.Icon; await proxyComponent.Save(playerBaseInfos[0]); } if (message.RestChangeNameCount != 0) { playerBaseInfos[0].RestChangeNameCount = message.RestChangeNameCount; await proxyComponent.Save(playerBaseInfos[0]); } if (!message.Prop.Equals("0")) { await DBCommonUtil.changeWealthWithStr(playerBaseInfos[i].Id, message.Prop, "GM中增加玩家道具"); } } } } else { List <PlayerBaseInfo> playerInfos = await proxyComponent.QueryJson <PlayerBaseInfo>($"{{_id:{message.UId}}}"); if (playerInfos.Count > 0) { if (!message.Icon.Equals("0")) { playerInfos[0].Icon = message.Icon; await proxyComponent.Save(playerInfos[0]); } if (message.RestChangeNameCount != 0) { playerInfos[0].RestChangeNameCount = message.RestChangeNameCount; await proxyComponent.Save(playerInfos[0]); } if (!message.Prop.Equals("0")) { await DBCommonUtil.changeWealthWithStr(message.UId, message.Prop, "GM中增加玩家道具"); } } else { response.Error = ErrorCode.ERR_Exception; response.Message = "用户不存在,请检查UID是否正确"; } } } break; case 9: { //查看游戏内信息 M2G_GetRoomInfo getRoomInfo = (M2G_GetRoomInfo)await mapSession.Call(new G2M_GetRoomInfo()); response.Room = new RoomInfo(); response.Room.NewRoomCount = getRoomInfo.NewRoomCount; response.Room.NewTotalPlayerInGameCount = getRoomInfo.NewTotalPlayerInGameCount; response.Room.JingRoomCount = getRoomInfo.JingRoomCount; response.Room.JingTotalPlayerInGameCount = getRoomInfo.JingTotalPlayerInGameCount; } break; case 10: { // 发送通知 UserComponentSystem.EmergencyNotice(message.UId, message.Content); } break; case 11: { //session int count = Game.Scene.GetComponent <NetOuterComponent>().sessions.Count; response.Channel = count.ToString(); } break; case 12: { //改变玩家好友房钥匙 long uid = message.UId; // -1代表给所有人发 int num = message.RestChangeNameCount; string endTime = message.EndTime; // 如果是删除钥匙,此参数可以为空 string reason = message.Reason; if (uid != -1) { if (num > 0) { await DBCommonUtil.AddFriendKey(uid, num, endTime, reason); } else if (num < 0) { await DBCommonUtil.DeleteFriendKey(uid, -num, reason); } } else { List <AccountInfo> listData = await proxyComponent.QueryJsonDBInfos <AccountInfo>(); for (int i = 0; i < listData.Count; i++) { if (num > 0) { await DBCommonUtil.AddFriendKey(listData[i].Id, num, endTime, reason); } else if (num < 0) { await DBCommonUtil.DeleteFriendKey(listData[i].Id, -num, reason); } } } } break; } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }