public bool RemovePlayer(IGamePlayer player) { bool result = false; List <IGamePlayer> players; Monitor.Enter(players = this.m_players); try { if (this.m_players.Remove(player)) { result = true; } } finally { Monitor.Exit(players); } if (this.PlayerCount == 0) { ProxyRoomMgr.RemoveRoom(this); this.Dispose(); } else { this.m_client.SendRemovePlayer(player.PlayerCharacter.ID, this.m_orientRoomId); } return(result); }
private static void RoomThread() { long balance = 0L; ProxyRoomMgr.m_nextClearTick = TickHelper.GetTickCount(); ProxyRoomMgr.m_nextPickTick = TickHelper.GetTickCount(); while (ProxyRoomMgr.m_running) { long start = TickHelper.GetTickCount(); try { ProxyRoomMgr.ExecuteActions(); if (ProxyRoomMgr.m_nextPickTick <= start) { ProxyRoomMgr.m_nextPickTick += (long)ProxyRoomMgr.PICK_UP_INTERVAL; ProxyRoomMgr.PickUpRooms(start); } if (ProxyRoomMgr.m_nextClearTick <= start) { ProxyRoomMgr.m_nextClearTick += (long)ProxyRoomMgr.CLEAR_ROOM_INTERVAL; ProxyRoomMgr.ClearRooms(start); } } catch (Exception ex) { ProxyRoomMgr.log.Error("Room Mgr Thread Error:", ex); } long end = TickHelper.GetTickCount(); balance += (long)ProxyRoomMgr.THREAD_INTERVAL - (end - start); if (balance > 0L) { Thread.Sleep((int)balance); balance = 0L; } else { if (balance < -1000L) { ProxyRoomMgr.log.WarnFormat("Room Mgr is delay {0} ms!", balance); balance += 1000L; } } if (ProxyRoomMgr.DELAY_TIME > 0) { ProxyRoomMgr.log.ErrorFormat("Delay for {0} ms!", ProxyRoomMgr.DELAY_TIME); Thread.Sleep(ProxyRoomMgr.DELAY_TIME); } } }
public static ProxyRoom[] GetAllRoom() { Dictionary <int, ProxyRoom> rooms; Monitor.Enter(rooms = ProxyRoomMgr.m_rooms); ProxyRoom[] allRoomUnsafe; try { allRoomUnsafe = ProxyRoomMgr.GetAllRoomUnsafe(); } finally { Monitor.Exit(rooms); } return(allRoomUnsafe); }
public static List <ProxyRoom> GetWaitMatchRoom() { Dictionary <int, ProxyRoom> rooms; Monitor.Enter(rooms = ProxyRoomMgr.m_rooms); List <ProxyRoom> waitMatchRoomUnsafe; try { waitMatchRoomUnsafe = ProxyRoomMgr.GetWaitMatchRoomUnsafe(); } finally { Monitor.Exit(rooms); } return(waitMatchRoomUnsafe); }
public static void SendInfoToAllGameServer() { GSPacketIn pkg = null; ServerClient[] clientlist = CrossFightServer.Instance.GetAllClients(); ServerClient[] array = clientlist; for (int i = 0; i < array.Length; i++) { ServerClient client = array[i]; if (pkg == null) { pkg = client.SendInfoToGameServer(ProxyRoomMgr.GetAllRoomCount(), ProxyRoomMgr.GetWaitingRoomCount(), CrossFightServer.Instance.Configuration.ServerType); } else { client.SendTCP(pkg); } } }
public void Execute() { ProxyRoomMgr.RemoveRoomUnsafe(this.m_room.RoomId); this.m_room.CancelPickUp(); }
public void Execute() { ProxyRoomMgr.AddRoomUnsafe(this.m_room); }
public void Execute() { ProxyRoomMgr.RemoveRoomUnsafe(this.m_room.RoomId); this.m_room.Dispose(); }
public static void FightWithNPC(ProxyRoom room) { ProxyRoomMgr.AddAction(new RandomNPCAction(room)); }
public static void RemoveRoom(ProxyRoom room) { ProxyRoomMgr.AddAction(new RemoveRoomAction(room)); }
public static void AddRoom(ProxyRoom room) { ProxyRoomMgr.AddAction(new AddRoomAction(room)); }
private static void PickUpRooms(long tick) { List <ProxyRoom> rooms = ProxyRoomMgr.GetWaitMatchRoomUnsafe(); rooms.Sort(); int pairs = 0; long begin = TickHelper.GetTickCount(); if (ProxyRoomMgr.ShowTick) { log.DebugFormat("-----begin pickup----tick:{0}-----rooms:{1}", begin, rooms.Count); } foreach (ProxyRoom red in rooms) { red.PickUpCount++; int maxScore = -2147483648; ProxyRoom matchRoom = null; if (!red.IsPlaying) { if (red.GameType == eGameType.ALL) { foreach (ProxyRoom blue in rooms) { //判断是不是同一个公会或不是同一个区 if (blue.GuildId != red.GuildId || blue.AreaID != red.AreaID) { if (blue != red && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score > maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } else { if (red.GameType == eGameType.Guild) { foreach (ProxyRoom blue in rooms) { if (blue.GuildId == 0 || blue.AreaID != red.AreaID || blue.GuildId != red.GuildId) { if (blue != red && blue.GameType != eGameType.Free && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score >= maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } else { foreach (ProxyRoom blue in rooms) { if (blue.GuildId == 0 || blue.GuildId != red.GuildId || blue.AreaID != red.AreaID) { if (blue != red && blue.GameType != eGameType.Guild && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount) { int score = ProxyRoomMgr.CalculateScore(red, blue); if (score >= maxScore || matchRoom == null) { if (red.AreaID == blue.AreaID || red.IsArea && blue.IsArea) { maxScore = score; matchRoom = blue; } } } } } } } if (matchRoom != null) { if (red.PickUpCount >= 2) { pairs++; ProxyRoomMgr.StartMatchGame(red, matchRoom); } } } } ProxyRoomMgr.SendInfoToAllGameServer(); if (ProxyRoomMgr.ShowTick) { long end = TickHelper.GetTickCount(); Console.WriteLine("-----end pickup----tick:{0}-----spends:{1} --- pairs:{2}", end, end - begin, pairs); } }