Ejemplo n.º 1
0
        /// <summary>
        /// 处理cs通知开始战斗
        /// </summary>
        public ErrorCode OnCs2BsBattleInfo(NetSessionBase session, Google.Protobuf.IMessage message)
        {
            Protos.CS2BS_BattleInfo battleInfo = (Protos.CS2BS_BattleInfo)message;

            BS.instance.battleMgr.CreateBattle(battleInfo, (bid, success) =>
            {
                Protos.BS2CS_BattleInfoRet battleInfoRet = ProtoCreator.R_CS2BS_BattleInfo(battleInfo.Opts.Pid);
                battleInfoRet.Bid    = bid;
                battleInfoRet.Result = success
                                                                                   ? Protos.Global.Types.ECommon.Success
                                                                                   : Protos.Global.Types.ECommon.Failed;
                session.Send(battleInfoRet);
            });

            return(ErrorCode.Success);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 处理回应
        /// </summary>
        private void OnBattleInfoRet(NetSessionBase session_, Google.Protobuf.IMessage ret, object[] args)
        {
            BattleUser[]   users  = ( BattleUser[] )args[0];
            BattleUser[][] tUsers = ( BattleUser[][] )args[1];
            string         bsIP   = ( string )args[2];
            int            bsPort = ( int )args[3];
            uint           bsSID  = ( uint )args[4];
            uint           bsLID  = ( uint )args[5];

            Protos.BS2CS_BattleInfoRet battleInfoRet = (Protos.BS2CS_BattleInfoRet)ret;
            //检查是否成功创建战场
            if (battleInfoRet.Result != Protos.Global.Types.ECommon.Success)
            {
                this.NotifyGCEnterBattleFailed(users, Protos.CS2GC_EnterBattle.Types.Result.BattleCreateFailed);
                return;
            }

            Logger.Log($"battle:{battleInfoRet.Bid} created");

            CS.instance.battleStaging.OnBattleCreated(bsLID, battleInfoRet.Bid);

            //把所有玩家移动到战场暂存器里
            int count = users.Length;

            for (int i = 0; i < count; i++)
            {
                BattleUser matchUser = users[i];
                CSUser     user      = CS.instance.userMgr.GetUser(matchUser.id);
                CS.instance.battleStaging.Add(user, bsLID, bsSID, battleInfoRet.Bid);
            }

            //广播给玩家
            Protos.CS2GC_EnterBattle enterBattle = ProtoCreator.Q_CS2GC_EnterBattle();
            enterBattle.Ip   = bsIP;
            enterBattle.Port = bsPort;
            for (int i = 0; i < count; i++)
            {
                BattleUser matchUser = users[i];
                CSUser     user      = CS.instance.userMgr.GetUser(matchUser.id);
                enterBattle.GcNID = user.ukey | ( ulong )bsLID << 32;
                user.Send(enterBattle);
            }
        }