protected async ETTask RunAsync(Session session, L2M_MapUnitCreate message, Action <M2L_MapUnitCreate> reply) { M2L_MapUnitCreate response = new M2L_MapUnitCreate(); try { MapUnitComponent mapUnitComponent = Game.Scene.GetComponent <MapUnitComponent>(); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); MapUnit mapUnit = mapUnitComponent.GetByUid(message.Uid); if (mapUnit != null) { mapUnitComponent.Remove(mapUnit.Id); } // 建立MapUnit mapUnit = ComponentFactory.CreateWithId <MapUnit, MapUnitType>(IdGenerater.GenerateId(), MapUnitType.Hero); mapUnit.Uid = message.Uid; await mapUnit.AddComponent <MailBoxComponent>().AddLocation(); mapUnit.AddComponent <MapUnitGateComponent, long>(message.GateSessionId); mapUnitComponent.Add(mapUnit); mapUnit.SetInfo(message.MapUnitInfo); await mapUnit.EnterRoom(message.MapUnitInfo.RoomId); await roomComponent.Update(mapUnit.Room); // 回傳MapUnitId給進入者 response.MapUnitId = mapUnit.Id; reply(response); } catch (Exception e) { ReplyError(response, e, reply); } }
public static void RoomDispose(Room room) { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); roomComponent.RemoveRoom(room); room?.Dispose(); }
/// <summary> /// 根据房间id获取房间 /// </summary> /// <param name="self"></param> /// <param name="id"></param> /// <returns></returns> public static Room Get(this RoomComponent self, long id) { Room room; self.rooms.TryGetValue(id, out room); return(room); }
public static async ETTask DestroyRoom(this RoomComponent self, long id) { Room room = self.Get(id); if (room == null) { return; } switch (room.Type) { case RoomType.Roaming: { self.RoamingSettingDict.Remove(room.info.RoadSettingId); self.RoamingList.Remove(room); await self.MemorySync.Delete <Room>(id); } break; case RoomType.Team: { self.TeamList.Remove(room); await self.MemorySync.Delete <Room>(id); } break; } }
/// <summary> /// 从空闲房间中获得一个有位置的房间 /// </summary> /// <param name="self"></param> /// <param name="roomType"></param> /// <returns></returns> public static Room GetIdleRoomById(this RoomComponent self, int roomType) { if (self.IdleRoomCount > 0) { foreach (var room in self.idleRooms.Values) { if (!room.IsFriendRoom) { GameControllerComponent controllerComponent = room.GetComponent <GameControllerComponent>(); if (controllerComponent == null) { Log.Warning("room的GameControllerComponent为null"); continue; } if (controllerComponent.RoomConfig.Id == roomType && room.Count < 3) { return(room); } } } return(null); } else { return(null); } }
protected override async Task Run(Gamer gamer, Actor_GamerCancelRoomDismiss message) { try { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || !room.IsFriendRoom || gamer.DismissState != DismissState.None) { return; } gamer.DismissState = DismissState.Cancel; room.Broadcast(new Actor_GamerCancelRoomDismiss() { UserId = gamer.UserID }); Gamer[] gamers = room.GetAll(); if (gamers.Count(g => g.DismissState == DismissState.Cancel) == 2) { room.roomDismissTokenSource?.Cancel(); foreach (var _gamer in gamers) { _gamer.DismissState = DismissState.None; } } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
public static string Remove(this RoomComponent self, long id) { string roomId = self.roomIds[id]; self.roomIds.Remove(id); return(roomId); }
protected override async Task Run(Gamer gamer, Actor_GamerCancelTrusteeship message) { Log.Info($"玩家{gamer.UserID}取消托管"); try { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null) { return; } gamer.IsTrusteeship = false; //在自己出牌的时候取消托管 OrderControllerComponent orderControllerComponent = room.GetComponent <OrderControllerComponent>(); //当前出牌是自己,并且外面没有碰刚 Log.Info($"IsNeedWaitOperate:{room.IsNeedWaitOperate}"); if (orderControllerComponent.CurrentAuthority == gamer.UserID && !room.IsNeedWaitOperate) { room.StartTime(8); } room.Broadcast(new Actor_GamerCancelTrusteeship() { Uid = gamer.UserID }); } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
public static int JionRoom(int gameId, int areaId, long userId, long sessionId, int RoomId, out string message) { if (!RoomMap.ContainsKey(gameId)) { message = "没有找到该游戏"; return(-1); } if (!RoomMap[gameId].ContainsKey(areaId)) { message = "没有找到该场次"; return(-1); } var roomDict = RoomMap[gameId][areaId]; RoomComponent roomComponen = null; if (RoomId != 0) { if (!roomDict.ContainsKey(RoomId)) { message = "加入房间失败,房间已经退出"; return(-1); } roomComponen = roomDict[RoomId]; } else { foreach (var room in roomDict) { if (!room.Value.IsFull) { roomComponen = room.Value; break; } else { continue; } } if (roomComponen == null) { roomComponen = CreateNewRoom(gameId, areaId, roomDict); } } var result = roomComponen.roomBehaviorCpt.JionRoom(userId, sessionId).Result; if (result != "0") { message = result; return(-1); } else { message = "0"; return(roomComponen.RoomId); } }
private static RoomComponent CreateNewRoom(int gameId, int areaId, Dictionary <int, RoomComponent> roomDict) { RoomInfo _roomInfo = Game.Scene.GetComponent <LobbyManagerCpt>() .GetComponent <RoomManagerCpt>().roomList.First(u => u.AreaId == areaId); RoomComponent roomComponen = CreateRoomComponent(gameId, _roomInfo, roomDict); return(roomComponen); }
public static void RemoveRoom(this RoomComponent self, Room room, bool isTimeout = false) { self.rooms.Remove(room.Id); Log.Info("self.rooms:" + self.rooms.Count); self.idleRooms.Remove(room.Id); Log.Info("idleRooms:" + self.idleRooms.Count); self.gameRooms.Remove(room.Id); Log.Info("gameRooms:" + self.gameRooms.Count); }
protected override async Task Run(Gamer gamer, Actor_GamerCheat message) { try { Log.Info("收到作弊:" + JsonHelper.ToJson(message)); if (string.IsNullOrEmpty(message.Info)) { return; } string[] split = message.Info.Split(' '); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); HandCardsComponent handCardsComponent = gamer.GetComponent <HandCardsComponent>(); if (handCardsComponent == null) { handCardsComponent = gamer.AddComponent <HandCardsComponent>(); } if (split.Length == 13) { List <MahjongInfo> mahjongInfos = new List <MahjongInfo>(); foreach (var item in split) { mahjongInfos.Add(new MahjongInfo() { m_weight = (Consts.MahjongWeight)Convert.ToInt32(item), weight = (byte)Convert.ToInt32(item) }); } handCardsComponent.library = mahjongInfos; Logic_NJMJ.getInstance().SortMahjong(handCardsComponent.library); Actor_GamerCheat actorCheat = new Actor_GamerCheat(); actorCheat.handCards = mahjongInfos; room.GamerBroadcast(gamer, actorCheat); } else if (split.Length == 1) { int num = Convert.ToInt32(split[0]); room.NextGrabCard = new MahjongInfo() { m_weight = (Consts.MahjongWeight)num, weight = (byte)num }; } } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 返回地图房间 /// </summary> public static Room GetMapRoom(this RoomComponent self, long roomId) { Room room; if (!self.mapRooms.TryGetValue(roomId, out room)) { Log.Error("玩家不在已经开始游戏的房间中"); } return(room); }
/// <summary> /// 返回副本房间 /// </summary> public static Instance GetCopyRoom(this RoomComponent self, long roomId) { Instance room; if (!self.copyRooms.TryGetValue(roomId, out room)) { Log.Error("玩家不在待机的房间中"); } return(room); }
public static Room Get(this RoomComponent self, long id) { Room room; if (self.roomIds.TryGetValue(id, out string roomId)) { self.rooms.TryGetValue(roomId, out room); return(room); } return(null); }
public static int[] ChangerRoom(int gameId, int areaId, int roomId, long sessionId) { int[] restul = new int[2]; if (!RoomMap.ContainsKey(gameId)) { restul[0] = -1; return(restul); } if (!RoomMap[gameId].ContainsKey(areaId)) { restul[0] = -1; return(restul); } var roomDict = RoomMap[gameId][areaId]; if (roomDict == null) { restul[0] = -1; return(restul); } RoomComponent roomComponen = null; if (roomDict.Count > 1) { foreach (var room in roomDict) { if (room.Key == roomId || room.Value.IsFull) { restul[1]++; continue; } roomComponen = room.Value; break; } if (roomComponen == null) { roomComponen = CreateNewRoom(gameId, areaId, roomDict); } } else { roomComponen = CreateNewRoom(gameId, areaId, roomDict); restul[1] = roomDict.Count - 1; } restul[0] = roomComponen.RoomId; return(restul); }
public static void Add(this RoomComponent self, long id, string roomId) { if (!self.roomIds.ContainsKey(id)) { self.roomIds.Add(id, roomId); } else { self.roomIds[id] = roomId; } }
public static void Add(this RoomComponent self, Room room) { if (!self.rooms.ContainsKey(room.RoomID)) { self.rooms.Add(room.RoomID, room); } else { throw new System.Exception("RoomID Already Exist"); } }
/// <summary> /// 匹配队列广播 /// </summary> public static void QueueBroadcast(this RoomComponent self, Queue <Gamer> matchingQueue, IActorMessage message) { foreach (Gamer gamer in matchingQueue) { //向客户端User发送Actor消息 ActorMessageSenderComponent actorProxyComponent = Game.Scene.GetComponent <ActorMessageSenderComponent>(); ActorMessageSender actorProxy = actorProxyComponent.Get(gamer.CActorId); Log.Debug("转发给了客户端一条消息,客户端Session:" + gamer.CActorId.ToString()); actorProxy.Send(message); } }
/// <summary> /// 从空闲集合中随机返回一个列表 /// </summary> /// <param name="self"></param> /// <returns></returns> public static Room GetIdleRoom(this RoomComponent self) { if (self.IdleRoomCount > 0) { Room room = self.idleRooms[RandomHelper.RandomNumber(0, self.idleRooms.Count)]; return(room); } else { return(null); } }
public static Room Remove(this RoomComponent self, string id) { Room room = self.Get(id); self.rooms.Remove(id); Dictionary <int, Gamer> gamers = room.GetAll(); foreach (var gamer in gamers.Values) { self.Remove(gamer.UserID); } return(room); }
public static async ETTask RemoveMapUnitByUid(this Room self, long uid) { RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); if (!self.UidDict.TryGetValue(uid, out MapUnit mapUnit)) { return; } self.MapUnitList.Remove(mapUnit); self.IdDict.Remove(mapUnit.Id); self.UidDict.Remove(uid); self.info.NowMemberCount = self.MapUnitList.Count; // block var blockComponent = self.GetComponent <RoomBlockComponent>(); blockComponent.Leave(mapUnit); switch (self.Type) { case RoomType.Roaming: // TODO RemoveMapUnit Roaming break; case RoomType.Team: { var teamComponent = self.GetComponent <RoomTeamComponent>(); if (teamComponent != null) { teamComponent.RemoveMember(uid); // (非預約房間)沒有人就自動解散 if (!teamComponent.Data.IsReservation && self.MemberCount <= 0) { await roomComponent.DestroyRoom(self.Id); } } } break; } // 同步房間資訊 await roomComponent.Update(self); // Destroy GlobalInfo self._m2C_MapUnitGlobalDestroy.MapUnitId = mapUnit.Id; MapMessageHelper.BroadcastTarget(self._m2C_MapUnitGlobalDestroy, self.MapUnitList); }
protected override async Task Run(Gamer gamer, Actor_GamerApplyRoomDismiss message) { try { Log.Info($"玩家{gamer.UserID}申请解散房间"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null) { return; } if (!room.IsFriendRoom) { return; } GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); if (room.State == RoomState.Idle) { if (gamer.UserID != gameControllerComponent.RoomConfig.MasterUserId) { Log.Warning($"准备阶段只有房主才能解散,房主:{gameControllerComponent.RoomConfig.MasterUserId},gamer:{gamer.UserID}"); return; } else { if (room.CurrentJuCount > 0) { return; } room.Broadcast(new Actor_GamerReadyTimeOut() { Message = "房主解散房间" }); GameHelp.RoomDispose(room); return; } } room.Broadcast(new Actor_GamerApplyRoomDismiss()); room.WaitDismiss(60); } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
protected override async Task Run(Gamer gamer, Actor_GamerKickOff message) { try { Log.Info($"收到房主{gamer.UserID}踢人 {message.KickedUserId}"); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); if (room == null || room.State == RoomState.Game || !room.IsFriendRoom) { return; } long masterUserId = room.GetComponent <GameControllerComponent>().RoomConfig.MasterUserId; if (masterUserId != gamer.UserID) { Log.Error("只有房主才能踢人"); return; } Gamer kickedGamer = room.Get(message.KickedUserId); if (kickedGamer == null) { return; } room.GamerBroadcast(kickedGamer, new Actor_GamerReadyTimeOut() { Message = "被房主踢出" }); //房间移除玩家 Log.Info($"{kickedGamer.UserID}被房主踢出,移除玩家"); room.Remove(kickedGamer.UserID); //消息广播给其他人 room.Broadcast(new Actor_GamerExitRoom() { Uid = kickedGamer.UserID }); kickedGamer.Dispose(); } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
/// <summary> /// 加入房间 /// </summary> public static void JoinRoom(this RoomComponent self, Room room, Gamer gamer) { if (gamer == null) { return; } room.Add(gamer); //房间广播 Log.Info($"玩家{gamer.UserId}进入房间"); //向Gate发送消息,玩家进入地图房间 // ... // 向玩家客户端发送消息进入游戏地图 // ... }
/// <summary> /// 根据房间号获得房间 /// </summary> /// <param name="self"></param> /// <param name="roomId"></param> /// <returns></returns> public static Room GetFriendRoomById(this RoomComponent self, int roomId) { foreach (var room in self.rooms.Values) { if (!room.IsFriendRoom) { continue; } GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); if (gameControllerComponent.RoomConfig.FriendRoomId == roomId) { return(room); } } return(null); }
public static async ETTask <Room> CreateTeamRoom(this RoomComponent self, RoomInfo roomInfo, TeamRoomData teamRoomData) { Room room = ComponentFactory.CreateWithId <Room, RoomType>(IdGenerater.GenerateId(), RoomType.Team); room.SetData(roomInfo); room = await self.MemorySync.Create(room); room.AddComponent <RoomTeamComponent, TeamRoomData>(teamRoomData); room.AddComponent <RoomBlockComponent, Room>(room); var first = OtherHelper.Search(self.TeamList, r => r.Id == room.Id); if (first == null) { self.TeamList.Add(room); } return(room); }
protected override async Task Run(Gamer gamer, Actor_Chat message) { try { Log.Debug("收到表情:" + JsonHelper.ToJson(message)); RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); Room room = roomComponent.Get(gamer.RoomID); room.Broadcast(new Actor_Chat { ChatType = message.ChatType, Value = message.Value, UId = message.UId }); } catch (Exception e) { Log.Error(e); } await Task.CompletedTask; }
protected override async void Run(Session session, G2M_FriendRoomInfo message, Action <M2G_FriendRoomInfo> reply) { M2G_FriendRoomInfo response = new M2G_FriendRoomInfo(); //Log.Info("G2M_FriendRoomInfo"); try { //获取房间信息 { //获取所有空闲房间接口 RoomComponent roomComponent = Game.Scene.GetComponent <RoomComponent>(); foreach (var room in roomComponent.rooms.Values) { if (!room.IsFriendRoom) { continue; } GameControllerComponent gameControllerComponent = room.GetComponent <GameControllerComponent>(); FriendRoomInfo friendRoomInfo = new FriendRoomInfo(); friendRoomInfo.Hua = gameControllerComponent.RoomConfig.Multiples; friendRoomInfo.Ju = gameControllerComponent.RoomConfig.JuCount; friendRoomInfo.RoomId = gameControllerComponent.RoomConfig.FriendRoomId; friendRoomInfo.IsPublic = gameControllerComponent.RoomConfig.IsPublic ? 1 : 2; //设置头像 foreach (var gamer in room.GetAll()) { if (gamer == null) { continue; } friendRoomInfo.Icons.Add(gamer.playerBaseInfo.Icon); } response.Info.Add(friendRoomInfo); } } reply(response); } catch (Exception e) { ReplyError(response, e, reply); } await Task.CompletedTask; }
public static void CheckAndDestoryRoom(this RoomComponent roomComponent, long Roomid, long Userid) { Room room = roomComponent.Get(Roomid); if (room == null) { return; } if (room.Count <= 1) { roomComponent.Remove(Roomid); room.Dispose(); } else { room.Delete(Userid); } }