예제 #1
0
        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);
        }
예제 #2
0
        public void Execute()
        {
            ProxyRoom room = ProxyRoomMgr.GetRoom(m_roomId);

            if (room != null)
            {
                bool result = ProxyRoomMgr.RemoveRoom(m_roomId);
                room.SendCancelPickUp(result);
            }
        }
예제 #3
0
        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);
                }
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        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);
        }
예제 #6
0
        public bool RemovePlayer(IGamePlayer player)
        {
            bool result = false;

            lock (m_players)
            {
                if (m_players.Remove(player))
                {
                    result = true;
                }
            }
            if (PlayerCount == 0)
            {
                ProxyRoomMgr.RemoveRoom(this);
            }
            return(result);
        }
예제 #7
0
        private static void RoomThread()
        {
            long num = 0L;

            ProxyRoomMgr.m_nextClearTick = TickHelper.GetTickCount();
            ProxyRoomMgr.m_nextPickTick  = TickHelper.GetTickCount();
            while (ProxyRoomMgr.m_running)
            {
                long tickCount = TickHelper.GetTickCount();
                try
                {
                    ProxyRoomMgr.ExecuteActions();
                    if (ProxyRoomMgr.m_nextPickTick <= tickCount)
                    {
                        ProxyRoomMgr.m_nextPickTick += (long)ProxyRoomMgr.PICK_UP_INTERVAL;
                        ProxyRoomMgr.PickUpRooms(tickCount);
                    }
                    if (ProxyRoomMgr.m_nextClearTick <= tickCount)
                    {
                        ProxyRoomMgr.m_nextClearTick += (long)ProxyRoomMgr.CLEAR_ROOM_INTERVAL;
                        ProxyRoomMgr.ClearRooms(tickCount);
                    }
                }
                catch (Exception exception)
                {
                    ProxyRoomMgr.log.Error("Room Mgr Thread Error:", exception);
                }
                long tickCount2 = TickHelper.GetTickCount();
                num += (long)ProxyRoomMgr.THREAD_INTERVAL - (tickCount2 - tickCount);
                if (num > 0L)
                {
                    Thread.Sleep((int)num);
                    num = 0L;
                }
                else
                {
                    if (num < -1000L)
                    {
                        ProxyRoomMgr.log.WarnFormat("Room Mgr is delay {0} ms!", num);
                        num += 1000L;
                    }
                }
            }
        }
예제 #8
0
        public static void SendInfoToAllGameServer()
        {
            GSPacketIn pkg = null;

            ServerClient[] clientlist = FightServer.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(), FightServer.Instance.Configuration.ServerType);
                }
                else
                {
                    client.SendTCP(pkg);
                }
            }
        }
예제 #9
0
        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);
            }
            return(result);
        }
예제 #10
0
        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);
            }
        }
예제 #11
0
 public void Execute()
 {
     ProxyRoomMgr.AddRoomUnsafe(this.m_room);
 }
예제 #12
0
 public static void FightWithNPC(ProxyRoom room)
 {
     ProxyRoomMgr.AddAction(new RandomNPCAction(room));
 }
예제 #13
0
 public void Execute()
 {
     ProxyRoomMgr.RemoveRoomUnsafe(this.m_room.RoomId);
     this.m_room.Dispose();
 }
예제 #14
0
 public void Execute()
 {
     ProxyRoomMgr.RemoveRoomUnsafe(this.m_room.RoomId);
     this.m_room.CancelPickUp();
 }
예제 #15
0
        public void Execute()
        {
            ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomIdUnsafe(), m_orientRoomId, m_players, m_client);

            ProxyRoomMgr.AddRoomUnsafe(room);
        }
예제 #16
0
        private static void PickUpRooms(long tick)
        {
            List <ProxyRoom> waitMatchRoomUnsafe = ProxyRoomMgr.GetWaitMatchRoomUnsafe();

            foreach (ProxyRoom current in waitMatchRoomUnsafe)
            {
                int       num       = -2147483648;
                ProxyRoom proxyRoom = null;
                if (!current.IsPlaying)
                {
                    if (current.GameType == eGameType.ALL)
                    {
                        using (List <ProxyRoom> .Enumerator enumerator2 = waitMatchRoomUnsafe.GetEnumerator())
                        {
                            while (enumerator2.MoveNext())
                            {
                                ProxyRoom current2 = enumerator2.Current;
                                if ((current2.GuildId == 0 || current2.GuildId != current.GuildId) && current2 != current && !current2.IsPlaying && current2.PlayerCount == current.PlayerCount)
                                {
                                    int num2     = GuildMgr.FindGuildRelationShip(current.GuildId, current2.GuildId) + 1;
                                    int gameType = (int)current2.GameType;
                                    int num3     = Math.Abs(current.AvgLevel - current2.AvgLevel);
                                    int num4     = Math.Abs(current.FightPower - current2.FightPower);
                                    int num5     = num2 * 10000 + gameType * 1000 + num4 + num3;
                                    if (num5 > num)
                                    {
                                        proxyRoom = current2;
                                    }
                                }
                            }
                            goto IL_2A7;
                        }
                        goto IL_114;
                    }
                    goto IL_114;
IL_2A7:
                    if (proxyRoom != null)
                    {
                        ProxyRoomMgr.StartMatchGame(current, proxyRoom);
                        continue;
                    }
                    continue;
IL_114:
                    if (current.GameType == eGameType.Guild)
                    {
                        using (List <ProxyRoom> .Enumerator enumerator3 = waitMatchRoomUnsafe.GetEnumerator())
                        {
                            while (enumerator3.MoveNext())
                            {
                                ProxyRoom current3 = enumerator3.Current;
                                if ((current3.GuildId == 0 || current3.GuildId != current.GuildId) && current3 != current && current3.GameType != eGameType.Free && !current3.IsPlaying && current3.PlayerCount == current.PlayerCount)
                                {
                                    int num6      = GuildMgr.FindGuildRelationShip(current.GuildId, current3.GuildId) + 1;
                                    int gameType2 = (int)current3.GameType;
                                    int num7      = Math.Abs(current.FightPower - current3.FightPower);
                                    int num8      = Math.Abs(current.AvgLevel - current3.AvgLevel);
                                    int num9      = num6 * 10000 + gameType2 * 1000 + num7 + num8;
                                    if (num9 > num)
                                    {
                                        proxyRoom = current3;
                                    }
                                }
                            }
                            goto IL_2A7;
                        }
                    }
                    foreach (ProxyRoom current4 in waitMatchRoomUnsafe)
                    {
                        if (current4 != current && current4.GameType != eGameType.Guild && !current4.IsPlaying && current4.PlayerCount == current.PlayerCount)
                        {
                            int gameType3 = (int)current4.GameType;
                            int num10     = Math.Abs(current.AvgLevel - current4.AvgLevel);
                            int num11     = Math.Abs(current.FightPower - current4.FightPower);
                            int num12     = gameType3 * 1000 + num11 + num10;
                            if (num12 > num)
                            {
                                proxyRoom = current4;
                            }
                        }
                    }
                    goto IL_2A7;
                }
                break;
            }
        }
예제 #17
0
 public static void RemoveRoom(ProxyRoom room)
 {
     ProxyRoomMgr.AddAction(new RemoveRoomAction(room));
 }
예제 #18
0
 public static void AddRoom(ProxyRoom room)
 {
     ProxyRoomMgr.AddAction(new AddRoomAction(room));
 }