private static void StartMatchGame(ProxyRoom red, ProxyRoom blue) { try { int mapId = MapMgr.GetMapIndex((red.AvgLevel + blue.AvgLevel) / 2, ProxyRoomMgr.m_serverId); eGameType gameType = eGameType.Free; if (red.GameType == blue.GameType) { gameType = red.GameType; } else { if ((red.GameType == eGameType.ALL && blue.GameType == eGameType.Guild) || (blue.GameType == eGameType.ALL && red.GameType == eGameType.Guild)) { gameType = eGameType.Guild; } } BaseGame game = GameMgr.StartBattleGame(red.GetPlayers(), red, blue.GetPlayers(), blue, mapId, eRoomType.Match, gameType, 3); if (game != null) { blue.StartGame(game); red.StartGame(game); } } catch (Exception e) { ProxyRoomMgr.log.Error("Start Match Game Error:", e); } }
private static int CalculateScore(ProxyRoom red, ProxyRoom blue) { int gameType = (int)blue.GameType; int power = Math.Abs(red.FightPower - blue.FightPower); int level = Math.Abs(red.AvgLevel - blue.AvgLevel); return(gameType * 100000 - power); }
public static bool AddRoomUnsafe(ProxyRoom room) { bool result; if (!ProxyRoomMgr.m_rooms.ContainsKey(room.RoomId)) { ProxyRoomMgr.m_rooms.Add(room.RoomId, room); result = true; } else { result = false; } return(result); }
public RandomNPCAction(ProxyRoom room) { this.m_room = room; }
public AddRoomAction(ProxyRoom room) { this.m_room = room; }
public RemoveRoomAction(ProxyRoom room) { this.m_room = room; }
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)); }
public static ProxyRoom[] GetAllRoomUnsafe() { ProxyRoom[] list = new ProxyRoom[ProxyRoomMgr.m_rooms.Values.Count]; ProxyRoomMgr.m_rooms.Values.CopyTo(list, 0); return(list); }
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); } }