Exemple #1
0
 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);
     }
 }
Exemple #2
0
        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 ProxyRoom[] GetAllRoomUnsafe()
        {
            ProxyRoom[] list = new ProxyRoom[m_rooms.Values.Count];

            m_rooms.Values.CopyTo(list, 0);

            return(list);
        }
Exemple #4
0
        public static ProxyRoom[] GetAllRoomUnsafe()
        {
            ProxyRoom[] list = new ProxyRoom[m_rooms.Values.Count];

            m_rooms.Values.CopyTo(list, 0);

            return list;
        }
Exemple #5
0
 public static bool AddRoomUnsafe(ProxyRoom room)
 {
     if (!m_rooms.ContainsKey(room.RoomId))
     {
         m_rooms.Add(room.RoomId, room);
         return true;
     }
     return false;
 }
 public static bool AddRoomUnsafe(ProxyRoom room)
 {
     if (!m_rooms.ContainsKey(room.RoomId))
     {
         m_rooms.Add(room.RoomId, room);
         return(true);
     }
     return(false);
 }
        public void Execute()
        {
            ProxyRoom room = ProxyRoomMgr.GetRoom(m_roomId);

            if (room != null)
            {
                bool result = ProxyRoomMgr.RemoveRoom(m_roomId);
                room.SendCancelPickUp(result);
            }
        }
Exemple #8
0
        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);
        }
        private static void StartMatchGame(ProxyRoom red, ProxyRoom blue)
        {
            int       mapIndex = MapMgr.GetMapIndex(0, 0, ProxyRoomMgr.m_serverId);
            eGameType gameType = eGameType.Free;

            if (red.GameType == blue.GameType)
            {
                gameType = red.GameType;
            }
            BaseGame baseGame = GameMgr.StartBattleGame(red.GetPlayers(), red, blue.GetPlayers(), blue, mapIndex, eRoomType.Match, gameType, 2);

            if (baseGame != null)
            {
                blue.StartGame(baseGame);
                red.StartGame(baseGame);
            }
            if (baseGame.GameType == eGameType.Guild)
            {
                red.Client.SendConsortiaAlly(red.GetPlayers()[0].PlayerCharacter.ConsortiaID, blue.GetPlayers()[0].PlayerCharacter.ConsortiaID, baseGame.Id);
            }
        }
Exemple #10
0
        public void RemoveRoom(int orientId, ProxyRoom room)
        {
            bool result = false;
            lock (m_rooms)
            {
                if (m_rooms.ContainsKey(orientId) && m_rooms[orientId] == room)
                {
                    result = m_rooms.Remove(orientId);
                }
            }

            if (result)
            {
                SendRemoveRoom(orientId);
            }
        }
 public AddRoomAction(ProxyRoom room)
 {
     this.m_room = room;
 }
Exemple #12
0
 public AddRoomAction(ProxyRoom room)
 {
     m_room = room;
 }
Exemple #13
0
        public void HandleGameRoomCreate(GSPacketIn pkg)
        {
            int roomId = pkg.ReadInt();
            int gameType = pkg.ReadInt();
            int guildId = pkg.ReadInt();

            int count = pkg.ReadInt();
            int totalLevel = 0;
            IGamePlayer[] players = new IGamePlayer[count];
            for (int i = 0; i < count; i++)
            {
                PlayerInfo info = new PlayerInfo();
                info.ID = pkg.ReadInt();
                info.NickName = pkg.ReadString();
                info.Sex = pkg.ReadBoolean();
                info.Hide = pkg.ReadInt();
                info.Style = pkg.ReadString();
                info.Colors = pkg.ReadString();
                info.Skin = pkg.ReadString();
                info.Offer = pkg.ReadInt();
                info.GP = pkg.ReadInt();
                info.Grade = pkg.ReadInt();
                info.Repute = pkg.ReadInt();
                info.ConsortiaID = pkg.ReadInt();
                info.ConsortiaName = pkg.ReadString();
                info.ConsortiaLevel = pkg.ReadInt();
                info.ConsortiaRepute = pkg.ReadInt();

                info.Attack = pkg.ReadInt();
                info.Defence = pkg.ReadInt();
                info.Agility = pkg.ReadInt();
                info.Luck = pkg.ReadInt();

                double baseAttack = pkg.ReadDouble();
                double baseDefence = pkg.ReadDouble();
                double baseAgility = pkg.ReadDouble();
                double baseBlood = pkg.ReadDouble();
                int templateId = pkg.ReadInt();
                bool canUserProp = pkg.ReadBoolean();
                int secondWeapon = pkg.ReadInt();
                int strengthLevel = pkg.ReadInt();


                double gprate = pkg.ReadDouble();
                double offerrate = pkg.ReadDouble();
                double rate = pkg.ReadDouble();
                int serverid = pkg.ReadInt();

                ItemTemplateInfo itemTemplate = ItemMgr.FindItemTemplate(templateId);
                ItemInfo item = null;
                if (secondWeapon != 0)
                {
                    ItemTemplateInfo secondWeaponTemp = ItemMgr.FindItemTemplate(secondWeapon);
                    item = ItemInfo.CreateFromTemplate(secondWeaponTemp, 1, 1);
                    item.StrengthenLevel = strengthLevel;
                }

                List<BufferInfo> infos = new List<BufferInfo>();

                int buffercout = pkg.ReadInt();
                for (int j = 0; j < buffercout; j++)
                {
                    BufferInfo buffinfo = new BufferInfo();
                    buffinfo.Type = pkg.ReadInt();
                    buffinfo.IsExist = pkg.ReadBoolean();
                    buffinfo.BeginDate = pkg.ReadDateTime();
                    buffinfo.ValidDate = pkg.ReadInt();
                    buffinfo.Value = pkg.ReadInt();
                    if (info != null)
                        infos.Add(buffinfo);
                }

                players[i] = new ProxyPlayer(this, info, itemTemplate, item, baseAttack, baseDefence, baseAgility, baseBlood, gprate, offerrate, rate, infos, serverid);
                players[i].CanUseProp = canUserProp;

                int ec = pkg.ReadInt();
                for (int j = 0; j < ec; j++)
                {
                    players[i].EquipEffect.Add(pkg.ReadInt());
                }
                totalLevel += info.Grade;
            }

            ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomId(), roomId, players, this);
            room.GuildId = guildId;
            room.GameType = (eGameType)gameType;

            lock (m_rooms)
            {
                if (!m_rooms.ContainsKey(roomId))
                {
                    m_rooms.Add(roomId, room);
                }
                else
                {
                    room = null;
                }
            }

            if (room != null)
            {
                ProxyRoomMgr.AddRoom(room);
            }
            else
            {
                log.ErrorFormat("Room already exists:{0}", roomId);
            }
        }
 public static void RemoveRoom(ProxyRoom room)
 {
     AddAction(new RemoveRoomAction(room));
 }
Exemple #15
0
 public BattleGame(int id, List<IGamePlayer> red, ProxyRoom roomRed, List<IGamePlayer> blue, ProxyRoom roomBlue, Map map, eRoomType roomType, eGameType gameType, int timeType)
     : base(id, roomBlue.RoomId, red, blue, map, roomType, gameType, timeType)
 {
     m_roomRed = roomRed;
     m_roomBlue = roomBlue;
 }
Exemple #16
0
 public static void AddRoom(ProxyRoom room)
 {
     AddAction(new AddRoomAction(room));
 }
Exemple #17
0
        public static BattleGame StartBattleGame(List<IGamePlayer> red, ProxyRoom roomRed, List<IGamePlayer> blue, ProxyRoom roomBlue, int mapIndex, eRoomType roomType, eGameType gameType, int timeType)
        {
            try
            {
                int index = MapMgr.GetMapIndex(mapIndex, (byte)roomType, m_serverId);
                Map map = MapMgr.CloneMap(index);

                if (map != null)
                {
                    BattleGame game = new BattleGame(m_gameId++, red, roomRed, blue, roomBlue, map, roomType, gameType, timeType);

                    lock (m_games)
                    {
                        m_games.Add(game.Id, game);
                    }
                    game.Prepare();
                    SendStartMessage(game);
                    return game;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception e)
            {
                log.Error("Create battle game error:", e);
                return null;
            }
        }
        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;
            }
        }
Exemple #19
0
 public static void FightWithNPC(ProxyRoom room)
 {
     ProxyRoomMgr.AddAction(new RandomNPCAction(room));
 }
Exemple #20
0
 public RemoveRoomAction(ProxyRoom room)
 {
     this.m_room = room;
 }
Exemple #21
0
 public RandomNPCAction(ProxyRoom room)
 {
     this.m_room = room;
 }
        public void Execute()
        {
            ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomIdUnsafe(), m_orientRoomId, m_players, m_client);

            ProxyRoomMgr.AddRoomUnsafe(room);
        }
Exemple #23
0
 public static void RemoveRoom(ProxyRoom room)
 {
     AddAction(new RemoveRoomAction(room));
 }
 public static ProxyRoom[] GetAllRoomUnsafe()
 {
     ProxyRoom[] array = new ProxyRoom[ProxyRoomMgr.m_rooms.Values.Count];
     ProxyRoomMgr.m_rooms.Values.CopyTo(array, 0);
     return(array);
 }
Exemple #25
0
        private static void StartMatchGame(ProxyRoom red, ProxyRoom blue)
        {
            int mapId = MapMgr.GetMapIndex(0, (byte)eRoomType.Match, m_serverId);

            eGameType gameType = eGameType.Free;//= red.GuildId != 0 && blue.GuildId != 0 ? eGameType.Guild : eGameType.Free;
            if (red.GameType == blue.GameType)
            {
                gameType = red.GameType;
            }
            BaseGame game = GameMgr.StartBattleGame(red.GetPlayers(), red, blue.GetPlayers(), blue, mapId, eRoomType.Match, gameType, 2);
            if (game != null)
            {
                blue.StartGame(game);
                red.StartGame(game);
            }
            if (game.GameType == eGameType.Guild)
            {
                red.Client.SendConsortiaAlly(red.GetPlayers()[0].PlayerCharacter.ConsortiaID, blue.GetPlayers()[0].PlayerCharacter.ConsortiaID, game.Id);
            }
        }
 public void Execute()
 {
     ProxyRoom room = new ProxyRoom(ProxyRoomMgr.NextRoomIdUnsafe(),m_orientRoomId, m_players, m_client);
     ProxyRoomMgr.AddRoomUnsafe(room);
 }
        private static void PickUpRooms(long tick)
        {
            List <ProxyRoom> rooms = GetWaitMatchRoomUnsafe();

            foreach (ProxyRoom red in rooms)
            {
                int       maxScore  = int.MinValue;
                ProxyRoom matchRoom = null;
                if (red.IsPlaying)
                {
                    break;
                }

                if (red.GameType == eGameType.ALL)
                {
                    foreach (ProxyRoom blue in rooms)
                    {
                        if (blue.GuildId != 0 && blue.GuildId == red.GuildId)
                        {
                            continue;
                        }

                        if (blue != red && !blue.IsPlaying && blue.PlayerCount == red.PlayerCount)
                        {
                            int guildRelation = GuildMgr.FindGuildRelationShip(red.GuildId, blue.GuildId) + 1;
                            int gameType      = (int)blue.GameType;
                            int level         = Math.Abs(red.AvgLevel - blue.AvgLevel);
                            int Property      = Math.Abs(red.FightPower - blue.FightPower);
                            int score         = guildRelation * 10000 + gameType * 1000 + Property + level;

                            if (score > maxScore)
                            {
                                matchRoom = blue;
                            }
                        }
                    }
                }
                else if (red.GameType == eGameType.Guild)
                {
                    foreach (ProxyRoom blue in rooms)
                    {
                        if (blue.GuildId != 0 && blue.GuildId == red.GuildId)
                        {
                            continue;
                        }

                        if (blue != red && blue.GameType != eGameType.Free && blue.IsPlaying == false && blue.PlayerCount == red.PlayerCount)
                        {
                            int guildRelation = GuildMgr.FindGuildRelationShip(red.GuildId, blue.GuildId) + 1;
                            int gameType      = (int)blue.GameType;
                            int Property      = Math.Abs(red.FightPower - blue.FightPower);
                            int level         = Math.Abs(red.AvgLevel - blue.AvgLevel);

                            int score = guildRelation * 10000 + gameType * 1000 + Property + level;

                            if (score > maxScore)
                            {
                                matchRoom = blue;
                            }
                        }
                    }
                }
                else
                {
                    foreach (ProxyRoom blue in rooms)
                    {
                        //TrieuLSL ngan khoong cho cung guild choi
                        //if (blue.GuildId != 0 && blue.GuildId == red.GuildId)
                        //    continue;

                        if (blue != red && blue.GameType != eGameType.Guild && blue.IsPlaying == false && blue.PlayerCount == red.PlayerCount)
                        {
                            int gameType = (int)blue.GameType;
                            int level    = Math.Abs(red.AvgLevel - blue.AvgLevel);
                            int Property = Math.Abs(red.FightPower - blue.FightPower);
                            int score    = gameType * 1000 + Property + level;

                            if (score > maxScore)
                            {
                                matchRoom = blue;
                            }
                        }
                    }
                }

                if (matchRoom != null)
                {
                    StartMatchGame(red, matchRoom);
                }
            }
        }
 public static void AddRoom(ProxyRoom room)
 {
     AddAction(new AddRoomAction(room));
 }
 public RemoveRoomAction(ProxyRoom room)
 {
     m_room = room;
 }
Exemple #30
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);
            }
        }