Exemplo n.º 1
0
Arquivo: CS.cs Projeto: niuniuzhu/KOW
        /// <summary>
        /// 更新最适合的BS
        /// </summary>
        public void UpdateAppropriateBSInfo()
        {
            this.appropriateBSInfo = null;
            int minState = int.MaxValue;

            foreach (KeyValuePair <uint, BSInfo> kv in this.lIDToBSInfos)
            {
                int state = ( int )kv.Value.state;
                if (state < minState)
                {
                    this.appropriateBSInfo = kv.Value;
                }
            }
        }
Exemplo n.º 2
0
        public void BeginBattle(BattleUser[] users, BattleUser[][] tUsers)
        {
            BSInfo appropriateBSInfo = CS.instance.appropriateBSInfo;

            //没有找到合适的bs,通知客户端匹配失败
            if (appropriateBSInfo == null)
            {
                this.NotifyGCEnterBattleFailed(users, Protos.CS2GC_EnterBattle.Types.Result.BsnotFound);
                return;
            }

            //todo 现在先随机一张地图
            Random rnd      = new Random();
            int    mapCount = Defs.GetMapCount();
            int    mapID    = rnd.Next(0, mapCount);

            Protos.CS2BS_BattleInfo battleInfo = ProtoCreator.Q_CS2BS_BattleInfo();
            battleInfo.MapID       = mapID;
            battleInfo.ConnTimeout = ( int )Consts.WAITING_ROOM_TIME_OUT;
            int c1 = tUsers.Length;

            for (int i = 0; i < c1; i++)
            {
                Protos.CS2BS_TeamInfo ti = new Protos.CS2BS_TeamInfo();
                battleInfo.TeamInfos.Add(ti);
                BattleUser[] roomUsers = tUsers[i];
                int          c2        = roomUsers.Length;
                for (int j = 0; j < c2; j++)
                {
                    BattleUser roomUser        = roomUsers[j];
                    CSUser     user            = CS.instance.userMgr.GetUser(roomUser.id);
                    Protos.CS2BS_PlayerInfo pi = new Protos.CS2BS_PlayerInfo
                    {
                        GcNID        = user.ukey | ( ulong )appropriateBSInfo.lid << 32,
                            ActorID  = user.actorID,
                            Avatar   = user.avatar,
                            Nickname = user.nickname,
                            Gender   = user.gender,
                            Money    = user.money,
                            Diamoned = user.diamoned,
                            Rank     = user.rank,
                            Exp      = user.exp
                    };
                    ti.PlayerInfos.Add(pi);
                }
            }
            CS.instance.netSessionMgr.Send(appropriateBSInfo.sessionID, battleInfo, RPCEntry.Pop(this.OnBattleInfoRet, users, tUsers,
                                                                                                 appropriateBSInfo.ip, appropriateBSInfo.port,
                                                                                                 appropriateBSInfo.sessionID, appropriateBSInfo.lid));
        }