/// <summary>
        /// 处理的所有人的摊牌与结算了,
        /// 结算规则,所有人与庄家进行比较牌的大小,然后 按倍率赔钱,
        /// </summary>
        private void DoExecuteDealShowDown()
        {
            lock (objLock)
            {
                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];
                    //if (!tempUser._isBanker) return;//只给庄发通知消息
                    sc_showdown_bf100_n _showdown_n = new sc_showdown_bf100_n()
                    {
                        fn = "sc_showdown_bf100_n", result = 1, _msgid = _TurnWaitTime
                    };

                    _showdown_n.sdlist   = _judge.GetShowDownList(i);
                    _showdown_n._curGold = tempUser._CurrentGold;

                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_showdown_n), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);

                _DicPos2User[_bankpos].SetTimeOutAction(1, "sc_showdown_bf100_n", 3);//处理超时的 UserEnd();
            }
        }
        /// <summary>
        /// 庄赢X局后奖池中还有钱,可以选择手动下庄,
        /// </summary>
        public bool BankerGetBonusPot(int userid)
        {
            BullFight100User myu = GetUserByID(userid);

            if (myu == null)
            {
                return(false);
            }
            if (myu.CheckisWatch())
            {
                return(false);
            }
            if (!_quePosGetBanker.Contains(myu._Pos))
            {
                return(false);
            }
            int _firstPos = 0;

            if (!_quePosGetBanker.TryPeek(out _firstPos))
            {
                return(false);
            }
            if (_firstPos != myu._Pos)
            {
                return(false);
            }
            _quePosGetBanker.TryDequeue(out _firstPos);

            return(true);
        }
        /// <summary>
        ///
        /// 进入2~6人后处理的
        /// </summary>
        /// <param name="tablenum"></param>
        /// <param name="userList"></param>
        public BullFight100Table(int gameid, BaseRoom _room2, int tablenum, BullFight100User _firstUser, cs_enterroom _data)
        {
            _numpertable = 1;
            _roomid      = _room2.mRoomID;
            _room        = _room2 as BullFight100Room;
            _tableid     = tablenum;
            _baseMoney   = 1;
            _bankpos     = 1;
            if (_DicPos2User == null)
            {
                _DicPos2User = new ConcurrentDictionary <int, BullFight100User>();
            }
            ConcurrentDictionary <int, BaseUser> _temppos2user = new ConcurrentDictionary <int, BaseUser>();

            _quePosGetBanker = new ConcurrentQueue <int>();
            _quePosGetBanker.Enqueue(_bankpos); //================测试数据
            _firstUser._tableID = tablenum;     //赋值桌子号

            _DicPos2User.TryAdd(1, _firstUser); //1~3表示位置
            _temppos2user.TryAdd(1, _firstUser);
            _masterPos = 1;                     //房主,只做建房用

            _judge = new BullFight100Judge(this);
            _judge.InitiArgs(_data);
            base._gametype = _judge._gametype;
            _tableMaxCount = _judge.GetTableorBankerMaxCount;

            _TurnWaitTime = 15;

            base.Initi(_temppos2user, _judge._minLimit, _judge._maxLimit, gameid, BF100SendDataServer.instance, DoTableTimer);
            base.EnterTable();

            _strStatus = "BullFightTable...1";
        }
        /// <summary>
        /// 分配到 桌子上的空位,
        /// </summary>
        public void AllocationtoTable(BullFight100User _adduser)
        {
            _adduser._tableID = _tableid;
            _numpertable     += 1;
            int key = -1;

            for (int i = 1; i <= _num_max; i++)
            {
                if (_DicPos2User.ContainsKey(i))
                {
                    continue;
                }
                key = i;
                break;
            }
            _adduser._WaitSecond = _TurnWaitTime;  //20
            _DicPos2User.TryAdd(key, _adduser);
            if (key == -1)
            {
                ErrorRecord.Record("201611172219 fetal error!!!");
                return;
            }
            base.InitiAdd(key, _adduser as BaseUser);
            base.EnterTableAdditive(key);
            //金币模式1秒后自动准备 大于2人就开始游戏
            if (_tablestatus != TableStatusEnum.Playing)
            {
                _tablestatus = TableStatusEnum.Playing;

                _DicPos2User[_masterPos].SetTimeOutAction(1, "sc_tablestart_bf100_n", _judge._gameCoin2Room1 == 1 ? _TurnWaitTime : 1);
                //自动开始下一步 Start();
                _strStatus = "BullFightTable...1.1 for auto ready...";
            }
        }
 /// <summary>
 /// 重置此桌信息
 /// </summary>
 public void Reset(bool _no_again)
 {
     lock (objLock)
     {
         _strStatus = "Reset...     ";
         ForeashAllDo((i) =>
         {
             BullFight100User _tempuser     = _DicPos2User[i];
             _tempuser._isBanker            = false;
             _tempuser._isGetBanker         = false;
             _tempuser._bulltype            = PokerBullFightType.Bull_No;
             _tempuser._pos2Gameble         = new Dictionary <int, int>();
             _tempuser._gambleTotal         = 0;
             _tempuser._showCardList        = new List <int>();
             _tempuser._SysDealTimeOutCount = 0;
             _tempuser._gambletime          = DateTime.Now.AddYears(100);
             // _tempuser._WaitClientLimitCount = 0;
         });
         base.ResetBase(_no_again);
         ForeashAllDo((i) =>
         {
             if (i <= 2)
             {
                 return;
             }
             BullFight100User _tempu;
             _DicPos2User.TryRemove(i, out _tempu);
         });
         //不在的用户处理掉
         ForeashAllDo((i) =>
         {
             if (!_pos2userbase.ContainsKey(i))
             {
                 BullFight100User _tempu;
                 _DicPos2User.TryRemove(i, out _tempu);
             }
         });
         if (_numpertable < base._num_min)
         {
             _tablestatus = TableStatusEnum.WaitforReady;  //人数不够了,,停止下局的自动准备
         }
         if (_no_again)
         {
             _DicPos2User = null;
             _judge       = null;
             BullFight100Room myr = BullFight100Lobby.instance.GetRoomByRoomID(_roomid);
             if (myr != null)
             {
                 myr.ResetTableByTableID(_tableid);
             }
             _tableid = 0;
         }
         else
         {                                                                                              //金币模式 才需要自动开始
             ForeashAllDo((i) => { _DicPos2User[i].SetTimeOutAction(1, "sc_tablestart_bf100_n", 1); }); //自动开始下一步         Start();
         }
     }
 }
        /// <summary>
        /// 获取断线前的所有进入人的消息列表
        /// </summary>
        /// <param name="userid"></param>
        public string GetEnterDisList(int userid)
        {
            BullFight100User _userbf = GetUserByID(userid);

            if (_userbf == null)
            {
                return("");
            }
            return(base.GetEnterDisListBase(_userbf._Pos));
        }
        /// <summary>
        /// 下注   1次
        /// </summary>
        public bool GambleOne(int userid, int _targetpos, int _gamble)
        {
            BullFight100User myu = GetUserByID(userid);

            if (myu == null)
            {
                return(false);
            }
            if (_DicPos2User[myu._Pos]._isBanker)
            {
                return(false);                                      //庄不能下注
            }
            if (myu.CheckisWatch())
            {
                return(false);
            }
            if (!_judge.CheckGambleMaxLimit())
            {
                return(false);
            }
            //if (!myu.CheckFirstDeal()) return; //可以下多次
            if (_targetpos > 4 || _targetpos < 2)
            {
                return(false);
            }
            if (_gamble < 1)
            {
                return(false);
            }
            if (myu._CurrentGold < _gamble)
            {
                return(false);
            }
            myu._CurrentGold -= _gamble;

            _dicPokerGambleTotal[_targetpos] += _gamble;
            _allGambleTotal += _gamble;
            if (_pos2GambleTable.ContainsKey(_targetpos))
            {
                _pos2GambleTable[_targetpos] += _gamble;
            }
            else
            {
                _pos2GambleTable.Add(_targetpos, _gamble);
            }

            _DicPos2User[myu._Pos].AddorUpdateGamble(_targetpos, _gamble);
            _DicPos2User[myu._Pos]._gambletime = DateTime.Now;
            NotifyGambleOne(myu._Pos, myu._Pos, _gamble);
            _strStatus = "GambleOver...5    ";
            return(true);
        }
        /// <summary>
        /// 非房主进入桌子 房间模式的
        /// </summary>
        /// <param name="userid"></param>
        public bool EnterTableAdditive(tb_User tbUser)
        {
            //不限制客户端的个数 可能 有破坏的外挂===========
            if (_numpertable >= _num_max)
            {
                return(false);
            }
            BullFight100User myu = new BullFight100User();

            myu.Initi(tbUser.IP, _roomid, tbUser, false);// 当成客户端 的IP:Port用
            AllocationtoTable(myu);
            return(true);
        }
Ejemplo n.º 9
0
        public bool CheckDiamond(int pos)
        {
            BullFight100User _tempUser = _myTable.GetUserByPos(pos);

            if (_tempUser == null)
            {
                return(false);
            }
            if (_tempUser._tbUser.diamond >= _roomcard)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 自动分配 1个人机器人创建一个桌子 仅金币模式
        /// </summary>
        /// <returns></returns>
        public int CreateTableByRobot()
        {
            lock (objLock)
            {
                if (GMService.isStop)
                {
                    return(0);
                }
                BullFight100Room roomData;
                roomCache.TryGet(mRoomID + "", out roomData);
                if (roomData == null)
                {
                    return(0);
                }

                int _tid = 0;
                //只有一个桌子 所有不用生产桌子
                if (!unusedTableQue.TryDequeue(out _tid))
                {
                    ErrorRecord.Record("201704011350BFC unusedQue.Count <= 0   桌子不够了,,只是能等待排队...");
                    DicUser = new ConcurrentDictionary <int, BullFight100User>();
                    return(0);
                }
                tb_User tbuser = tb_UserEx.GetFromCachebyUserID(2000000);
                if (tbuser == null)
                {
                    ErrorRecord.Record("没有特殊机器人了系 统不能开始牛牛时时彩");
                    return(0);
                }
                tbuser.UserMoney = 2345;                                            //===================================测试
                BullFight100User tempU = new BullFight100User();
                tempU.Initi(tbuser.UserID + "", mRoomID, tbuser, true);             // 当成客户端 的IP:Port用
                roomData.EnterRoomBase(tempU._tbUser.UserID, _currRoomInfo.gameid); //处理状态的,不然一直找不到用户
                cs_enterroom _data = new cs_enterroom()
                {
                    baserate = _currRoomInfo.Baserate, gametype = _currRoomInfo.gametype, gameid = 42, gamemodel = 2, levelid = mRoomID, numpertable = 500, roomcard = 0, rankertype = 1, tableCount = 1
                };


                BullFight100Table tab = new BullFight100Table(_currRoomInfo.gameid, this, _tid, tempU, _data);
                //添加到当前桌子列表,以便打牌过程好使用
                if (!DicTable.TryAdd(_tid, tab))
                {
                    ErrorRecord.Record("add _tableid fial maybe have exist... 201208241601BF");
                }
                return(_tid);
            }
        }
 /// <summary>
 /// 此桌结束了,一次比完牌就结束
 /// </summary>
 private void UserEnd(int userid)
 {
     lock (objLock)
     {
         BullFight100User myu = GetUserByID(userid);
         if (myu == null)
         {
             return;
         }
         if (!myu.CheckFirstDeal())
         {
             return;
         }
         //if (HaveSomeBodyUnDeal()) return;
         DoExecuteAllEnd(false);
     }
 }
        /// <summary>
        ///  设置自己要抢庄,等judge处理
        /// </summary>
        /// <param name="userid"></param>
        public bool ApplyGetBanker(int userid, bool getbanker)
        {
            lock (objLock)
            {
                BullFight100User myu = GetUserByID(userid);
                if (myu == null)
                {
                    return(false);
                }
                if (myu.CheckisWatch())
                {
                    return(false);
                }
                //if (!myu.CheckFirstDeal()) return false;
                if (myu._CurrentGold < 1000)
                {
                    return(false);                         //1000才能申请上庄
                }
                if (_quePosGetBanker.Contains(myu._Pos))
                {
                    return(false);                  //已在申请列表中的人不能再申请了
                }
                _quePosGetBanker.Enqueue(myu._Pos); //放入抢庄列表设置抢庄标识

                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];

                    sc_getbankerone_bf100_n _getbanker_n = new sc_getbankerone_bf100_n()
                    {
                        fn = "sc_getbankerone_bf100_n", result = 1, _msgid = _TurnWaitTime
                    };
                    _getbanker_n.pos = myu._Pos;
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_getbanker_n), tempUser._isRobot, tempUser._isDisconnet));
                });
                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);

                // if (HaveSomeBodyUnDeal()) return false;
                _strStatus = "GetBanker...4 all getbanker  ";
                return(true);
            }
        }
        /// <summary>
        /// 断线重连     暂时
        /// </summary>
        public void NotifyReConnect(int userid)
        {
            UserStatus _us = BaseLobby.instanceBase.GetUserStatusbyUserID(userid);

            if (_us == null)
            {
                return;
            }
            _us.Status = UserStatusEnum.InTableDaiPai;
            BullFight100User myu = GetUserByID(userid);

            if (myu == null)
            {
                return;
            }
            myu._isDisconnet = false;
            //通知其他人有人上线了
            base.NotifyDisBase(userid, 1);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 自动分配人 到一桌  1.玩家进入房间触发。 分配机器人也在这儿处理
        /// </summary>
        /// <returns></returns>
        private void AutoAlloc2TableByRobot(BullFight100Table _bftable)
        {
            lock (objLock)
            {
                if (!_openRobot)
                {
                    return;
                }

                //一次性分配足额机器人
                int _needCount = _bftable._num_min - _bftable._pos2userbase.Count;//一般最多为2人
                if (BF100SendDataServer.instance.QueRobotUser.Count < _needCount)
                {
                    return;
                }
                for (int i = 0; i < _needCount; i++)
                {
                    tb_User tbRobotuser;
                    if (!BF100SendDataServer.instance.QueRobotUser.TryDequeue(out tbRobotuser))
                    {
                        return;
                    }
                    //把tbuser 机器在的金币限制在当前Level内,,,
                    if (tbRobotuser.UserMoney < _currRoomInfo._min || tbRobotuser.UserMoney > _currRoomInfo._max)
                    {
                        if (tbRobotuser.isRobot == 1)
                        {
                            var temp    = tbRobotuser.UserMoney;
                            var raMoney = ToolsEx.GetRandomSys(_currRoomInfo._min, _currRoomInfo._max);
                            tbRobotuser.UserMoney = raMoney;
                            ////var cacheUserSet = new ShareCacheStruct<tb_User>();  //100MS会自动存库
                            ////cacheUserSet.AddOrUpdate(tbuser);
                        }
                    }

                    BullFight100User tempU = new BullFight100User();
                    tempU.Initi(tbRobotuser.UserID + "", mRoomID, tbRobotuser, true);// 当成客户端 的IP:Port用
                    base.EnterRoomBase(tbRobotuser.UserID, _gameid);
                    _bftable.AllocationtoTable(tempU);
                    BF100SendDataServer.instance.RobotExistNumAddOne();
                }
            }
        }
        private void NotifyGambleOne(int _pos, int _targetpos, int _gamble)
        {
            lock (objLock)
            {
                List <UserIDMSG> imList = new List <UserIDMSG>();

                List <CommonPosValSD> _pos2GambleTotal = new List <CommonPosValSD>();
                foreach (var _key in _pos2GambleTable.Keys)
                {
                    _pos2GambleTotal.Add(new CommonPosValSD()
                    {
                        pos = _key, val = _pos2GambleTable[_key]
                    });
                }

                List <CommonPosValSD> _pos2Gamble = new List <CommonPosValSD>();
                //ForeashAllDo((i) => {
                BullFight100User tempUser = _DicPos2User[_pos];
                foreach (var _key in tempUser._pos2Gameble.Keys)
                {
                    _pos2Gamble.Add(new CommonPosValSD()
                    {
                        pos = _key, val = tempUser._pos2Gameble[_key]
                    });
                }

                sc_gambleone_bf100_n _gambleone_n = new sc_gambleone_bf100_n()
                {
                    fn = "sc_gambleone_bf100_n", result = 1, _msgid = _TurnWaitTime
                };
                _gambleone_n.pos              = _pos;
                _gambleone_n.allrate          = tempUser._gambleTotal;
                _gambleone_n._curGold         = _DicPos2User[_pos]._CurrentGold;
                _gambleone_n._pos2Gamble      = _pos2Gamble;
                _gambleone_n._pos2GambleTotal = _pos2GambleTotal;

                imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_gambleone_n), tempUser._isRobot, tempUser._isDisconnet));
                //});
                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        ///  用户登录房间时调用
        /// </summary>
        /// <param name="roomID"></param>
        /// <param name="UserID"></param>
        /// <param name="ipport"></param>
        /// <returns></returns>
        public int EnterRoom(cs_enterroom _data, int UserID, string ipport)
        {
            lock (objLock)
            {
                if (GMService.isStop)
                {
                    return(-99);
                }
                base.EnterRoomBase(UserID, _data.gameid);

                tb_User tbuser = tb_UserEx.GetFromCachebyUserID(UserID);
                if (tbuser == null)
                {
                    ErrorRecord.Record("201208241558BF tbuser == null  userID:" + UserID);
                    return(0);
                }

                if (tbuser.UserMoney > _currRoomInfo._max || tbuser.UserMoney < _currRoomInfo._min)
                {
                    return(-99);
                }

                UserStatus _us = BaseLobby.instanceBase.GetUserStatusbyUserID(UserID);
                if (_us != null)
                {
                    if (_us.Status == UserStatusEnum.InTableDaiPai || _us.Status == UserStatusEnum.InTableDaiPaiDis || _us.Status == UserStatusEnum.InTableWaiting)
                    {
                        return(-1);
                    }
                }
                BullFight100User tempU = new BullFight100User();
                tempU.Initi(ipport, mRoomID, tbuser, false);// 当成客户端 的IP:Port用

                ////if (!DicUser.TryAdd(UserID, tempU)) ErrorRecord.Record("201208241155BF 已经存在ROOM内了, 添加不成功 逻辑需要处理");
                if (!DicUser.ContainsKey(UserID))
                {
                    DicUser.TryAdd(UserID, tempU);
                }

                return(DicUser.Count);//直接进入 空桌子
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 自动分配人 到一桌  1.玩家进入房间触发。
        /// </summary>
        /// <returns></returns>
        private void AutoAlloc2TableForHuman(BullFight100Table _bftable, BullFight100User tempU)
        {
            lock (objLock)
            {
                if (!_openRobot)
                {
                    return;
                }

                if (_bftable._judge._gameCoin2Room1 == 1)
                {
                    return;                                      //房卡模式不能进机器人了
                }
                base.EnterRoomBase(tempU._tbUser.UserID, _gameid);

                //移出已经分配了的用户
                BullFight100User temp02 = null;// new BullFightUser();
                DicUser.TryRemove(tempU._userid, out temp02);
                _bftable.AllocationtoTable(tempU);
                BF100SendDataServer.instance.RobotExistNumAddOne();
            }
        }
        /// <summary>
        /// 处理谁的庄   通知每个人的下注列表
        /// </summary>
        private void DoExecuteSetBanker()
        {
            lock (objLock)
            {
                _judge.GetBankerPos(); //实际抢庄逻辑处理
                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser           = _DicPos2User[i];
                    sc_applybanker_bf100_n _getbanker_n = new sc_applybanker_bf100_n()
                    {
                        fn = "sc_applybanker_bf100_n", result = 1
                    };
                    tempUser.gamblelist = _judge.GetGambleList(_bankpos, i);
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_getbanker_n), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);

                _DicPos2User[_bankpos].SetTimeOutAction(1, "sc_applybanker_bf100_n", _TurnWaitTime);      //处理超时的 DoExecuteDealShowDown();
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// 自动分配 3个人 到一桌  1.玩家进入房间触发。2.系统增加机器人触发
        /// 分配机器人也在这儿处理
        /// </summary>
        /// <returns></returns>
        private int CreateTableByHuman(BullFight100User tempU, int _tid, cs_enterroom _data)
        {
            lock (objLock)
            {
                ////if (GMService.isStop)
                ////    return -1;
                ////BullFight100Table _bftable;
                ////if (DicTable.TryGetValue(_tid, out _bftable))
                ////{//已存在流程是错误的
                ////    ErrorRecord.Record("fetal error 201601101429BF 必须处理 ");
                ////    return -1;
                ////}
                ////BullFight100Table tab = new BullFight100Table(_gameid, this, _tid, tempU, _data);
                ////int _checkCode = tab.CheckRoomCard(tempU._userid);
                ////if (_checkCode != 1) return _checkCode;
                ////  //移出已经分配了的用户
                ////    BullFight100User temp02 = null;// new BullFightUser();
                ////    DicUser.TryRemove(tempU._userid, out temp02);

                //////添加到当前桌子列表,以便打牌过程好使用
                ////if (!DicTable.TryAdd(_tid, tab)) ErrorRecord.Record("add _tableid fial maybe have exist... 201208241601BF");
                return(1);
            }
        }
        //===========================================================================================================================
        /// <summary>
        /// 循环当前桌的每一个人   Write by jsw 201208011539
        /// </summary>
        public override void DealEveryUser()
        {
            //return;//测试专用 没和限制功能
            lock (objLock)
            {
                if (_DicPos2User == null)
                {
                    return;
                }
                ForeashAllDo((i) =>
                {
                    BullFight100User _bfuser = null;
                    if (!_DicPos2User.TryGetValue(i, out _bfuser))
                    {
                        ErrorRecord.Record(" 201611051939BF this is not enough  _numpertable" + _numpertable); return;
                    }
                    if (_bfuser._waitUserAction == "0")
                    {
                        return;
                    }
                    switch (_bfuser._waitUserAction)
                    {
                    case "sc_tablestart_bf100_n":
                        Start(_bfuser._userid);
                        break;

                    case "sc_applybanker_bf100":     //定庄后需要通知下注

                        break;

                    case "sc_applybanker_bf100_n":     //定庄后需要通知下注  系统执行结算
                        DoExecuteDealShowDown();
                        break;

                    case "sc_showdown_bf100_n":
                        UserEnd(_bfuser._userid);
                        break;

                    case "sc_end_bf100_n":    //自动下一局
                        ////GetReady(_bfuser._userid);
                        break;

                    case "sc_applyexittable_n":     //暂时不处理超时功能
                        break;

                    case "sc_bankergetbonuspot_bf100_n":
                        ////GetReady(_bfuser._userid);
                        break;

                    case "sc_exittable_n_delay":
                        base.ExitTableall(new List <int>(), true);
                        break;

                    default:      //没得状态 不处理
                        ErrorRecord.Record(" 201206171026BF _UserDic[i]._userAction:" + _DicPos2User[i]._waitUserAction);
                        break;
                    }
                    _bfuser.RecordTimeoutCount();
                });
                base.DealAliveTime();
            }
        }
        /// <summary>
        /// 用户申请解散游戏      游戏已开始需要处理结算面板
        /// </summary>
        /// <param name="userID"></param>
        public void DealExitTable(int userid, bool _isagree)
        {
            lock (objLock)
            {
                BullFight100User myu = GetUserByID(userid);
                if (myu == null)
                {
                    return;
                }
                if (!_applyExitTable)
                {
                    return;                  //状态都不对
                }
                if (myu._isAgreeExit != 2)
                {
                    return;                       //表示已处理了状态不能重复处理 同CheckFirstDeal
                }
                myu._isAgreeExit = _isagree ? 1 : 0;
                //如果同意则重置定时器时间拒绝则关闭定时器
                if (_isagree)
                {
                    ReStartTimer(120000);
                }
                else
                {
                    StopTimer();
                }
                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];

                    sc_dealexittable_n _gamble_n = new sc_dealexittable_n()
                    {
                        fn = "sc_dealexittable_n", result = 1, _msgid = _TurnWaitTime
                    };

                    _gamble_n.pos   = myu._Pos;
                    _gamble_n.agree = _isagree ? 1 : 0;
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_gamble_n), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);

                bool _allreply = true;
                ForeashAllDo((i) =>
                {
                    if (_DicPos2User[i]._isWatch)
                    {
                        return;                          //输了的人没有资格回复
                    }
                    if (_DicPos2User[i]._isAgreeExit == 2)
                    {
                        _allreply = false;                                    //至少有一个人未回复
                    }
                });
                if (!_allreply)
                {
                    return;                 //等所有人回复 同HaveSomeBodyUnDeal
                }
                DoExecuteExitTable(true);
            }
        }
        /// <summary>
        /// 用户申请解散游戏
        /// </summary>
        /// <param name="userID"></param>
        public void ApplyExitTable(int userid)
        {
            lock (objLock)
            {
                BullFight100User myu = GetUserByID(userid);
                if (myu == null)
                {
                    return;
                }
                if (myu.CheckisWatch())
                {
                    return;                         //爆分的人不能申请
                }
                ExcuteDelayedLogic();
                if (_applyExitTable && myu._isAgreeExit != 2)
                {           //有可能在有人申请解散后,其他人没有收到消息,然后就出现所有人卡死在房间的  myu._isAgreeExit != 2 补丁,允许自己申请当成同意解散。
                    return; //如果 有人申请解散了 就不处理了,
                }
                //申请游戏解散想其它用户发送消息过后执行定时任务超过指定时间没人反应则强制解散房间
                ExcuteDelayedLogic();
                _applyExitTable = true;

                myu._isAgreeExit = 1;
                if (!_haveCheckRoomCard)
                {   //未开时扣房卡之前   1.如果是房主可以直接解散。2.非房主直接退出个人自己
                    if (_masterPos == myu._Pos)
                    {
                        DoExecuteExitTable(false, true);
                    }
                    else
                    {
                        base.ExitTableOne(myu._Pos, userid);//仅发送了消息,未处理逻辑,需要移出
                        BaseUser mybu;
                        base._pos2userbase.TryRemove(myu._Pos, out mybu);
                        _DicPos2User.TryRemove(myu._Pos, out myu);
                        _applyExitTable = false;
                        StopTimer();
                    }
                    return;
                }

                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];

                    sc_applyexittable_n _gamble_n = new sc_applyexittable_n()
                    {
                        fn = "sc_applyexittable_n", result = 1, _msgid = _TurnWaitTime
                    };
                    _gamble_n.gameid = _gameid;
                    _gamble_n.pos    = myu._Pos;
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_gamble_n), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);

                //处理超时的动作      由_isAgreeExit状态自行处理
            }
        }
        /// <summary>
        /// 如果是强制结束此桌,此桌不会记录与结处
        /// </summary>
        /// <param name="_forceOver"></param>
        private void DoExecuteAllEnd(bool _forceOver)
        {
            lock (objLock)
            {
                ForeashAllDo((i) =>
                {   //更新数据
                    tb_UserEx.UpdateData(_DicPos2User[i]._tbUser);
                });

                List <CommonPosValSD> _watchlist = new List <CommonPosValSD>();
                //写入此桌的金钱交易记录
                if (!_forceOver)
                {
                    _pos2CardList = new Dictionary <int, List <int> >(_dicPokerList);//记录手牌
                    ForeashAllDo((i) =>
                    {
                        _pos2Money.Add(i, _DicPos2User[i]._CurrentGold);
                        _pos2Win.Add(i, _judge.CheckGameOverWin(_DicPos2User[i]._CurrentGold));
                        int _bfRate = BullFight._dicbullfightRate[_DicPos2User[i]._bulltype];
                        _pos2BullRate.Add(i, _bfRate);

                        //更新数据
                        tb_UserEx.UpdateData(_DicPos2User[i]._tbUser);
                    });
                    ForeashAllDo((i) =>
                    {
                        //低于一定分数就当观众了
                        if (_judge.MinLimitMoney((int)_DicPos2User[i]._tbUser.UserMoney))
                        {
                            _DicPos2User[i]._isWatch = true;
                        }
                        else
                        {
                            _DicPos2User[i]._isWatch = false; //金币模式中上局没开始成功的
                        }
                        _watchlist.Add(new CommonPosValSD()
                        {
                            pos = i, val = _DicPos2User[i]._isWatch ? 1 : 0
                        });
                        _pos2Watch.Add(i, _DicPos2User[i]._isWatch ? 1 : 0);
                    });
                }
                else
                {
                    _gameover = _forceOver;
                }

                _tablRecord.ActionList = "";     //写入此桌的录相 记录
                _tablRecord.EndTime    = DateTime.Now;
                _tablRecord.gameid     = _gameid;
                _tablRecord._isover    = (_judge._gameCoin2Room1 == 2 ? true : _gameover);
                LogWriteToDB(_tablRecord);

                bool _bankerCanGetBonusPot = _judge.CheckCanBankerGetBonusPot();   //必须在结算了后面


                tb_TableMoneyLogEx.SetRateDataByTableNum(_guid, _gameover, _numpertable);

                List <CommonPosValSD> _pos2Gold1 = _judge.GetCurrentPosGold();
                //向X家返回结果 通知 结束
                List <UserIDMSG> imList = new List <UserIDMSG>();
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];

                    sc_end_bf100_n _end_n = new sc_end_bf100_n()
                    {
                        fn = "sc_end_bf100_n", result = 1, _msgid = _TurnWaitTime
                    };                                                                                                         // 显示结束面板就行

                    _end_n.gamemodel  = _judge._gameCoin2Room1;
                    _end_n._OverTable = _gameover ? 1 : 0;
                    _end_n.createpos  = _masterPos;
                    _end_n._pos2Watch = _watchlist;
                    _end_n._pos2Gold  = _pos2Gold1;

                    _end_n.closefun = _bankerCanGetBonusPot ? true : false;// 能收取奖池的时候   客户端不自动走准备方法,等下一个命令
                    if (_judge._gameCoin2Room1 == 2 && tempUser._isRobot)
                    {
                        return;                                                  //结束不发给机器人
                    }
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_end_n), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);
                ForeashAllDo((i) => { _DicPos2User[i].SetTimeOutAction(1, "sc_end_bf100_n", _bankerCanGetBonusPot  ? _TurnWaitTime : 6); }); //下把的自动开始功能        ReStart();

                Reset(_gameover);                                                                                                            //准备下局, 重置此桌信息
            }
        }
        /// <summary>
        /// 至少两人到位了进行 开局 ,开局就会扣掉配置钱===============================================
        /// </summary>
        private void Start(int userid)
        {
            lock (objLock)
            {
                BullFight100User myu = GetUserByID(userid);
                if (myu == null)
                {
                    return;
                }
                if (myu.CheckisWatch())
                {
                    return;
                }
                if (!myu.CheckFirstDeal())
                {
                    return;
                }
                //if (HaveSomeBodyUnDeal()) return;
                if (_numpertable < _num_min)
                {
                    return;
                }

                base.StartBase(60 * 4);
                _pos2UserID   = new Dictionary <int, int>();
                _pos2IPPort   = new Dictionary <int, string>();
                _pos2Money    = new Dictionary <int, decimal>();
                _pos2Win      = new Dictionary <int, bool>();
                _pos2CardList = new Dictionary <int, List <int> >();
                _pos2BullRate = new Dictionary <int, int>();
                _pos2Watch    = new Dictionary <int, int>();

                Queue <int> _tcardLeft = new Queue <int>();
                var         type       = _judge._gametype;
                _dicPokerList        = new Dictionary <int, List <int> >();
                _dicPokerBFType      = new Dictionary <int, PokerBullFightType>();
                _dicPokerGambleTotal = new Dictionary <int, int>();
                _pos2GambleTable     = new Dictionary <int, int>();

                _allGambleTotal = 0;
                _dicPokerList   = BullFight.DistributePoker(out _tcardLeft, 4);
                foreach (int key in _dicPokerList.Keys)
                {
                    _dicPokerBFType.Add(key, BullFight.GetBullType(_dicPokerList[key]));
                    _dicPokerGambleTotal.Add(key, 0);
                }

                ////Dictionary<int, int> _pos2RobotAI = new Dictionary<int, int>();
                ////ForeashAllDo((i) =>
                ////{
                ////    _pos2RobotAI.Add(i, _DicPos2User[i]._tbUser.winpercent); //_pos2RobotAI.Add(i, i == 1 ? 101 : 0);
                ////});
                ////_judge.ChangePokerByRobotAI(_pos2RobotAI, _dicPokerList);

                List <int> _temppoker0 = new List <int>()
                {
                    0, 0, 0, 0, 0
                };
                List <UserIDMSG>      imList  = new List <UserIDMSG>();
                List <CommonPosValSD> _uplist = new List <CommonPosValSD>();

                _judge.DealReduceDiamond();//执行扣房卡 已处理只扣一次
                _judge.SetCurTableorBankerCount();

                //同时把每位玩家的数据确认修改了 //发送消息到所有玩家
                ForeashAllDo((i) =>
                {
                    BullFight100User tempUser = _DicPos2User[i];

                    tempUser._isPlaying = true;
                    //tempUser._shouPaiArr = _pokerList[i];
                    tempUser._pos2Gameble  = new Dictionary <int, int>();
                    tempUser._showCardList = new List <int>()
                    {
                        0, 0, 0, 0, 0
                    };
                    _DicPos2User[i] = tempUser;//必须要赋值回去 要求有3个返馈才处理

                    _tablRecord.MatchCode = _tableMathCode;
                    _tablRecord._guid     = _guid;
                    _tablRecord.StartTime = DateTime.Now;
                    _pos2UserID.Add(i, tempUser._userid);
                    _pos2IPPort.Add(i, tempUser._IPandPort);
                    //发送通知消息
                    sc_tablestart_bf100_n _start = new sc_tablestart_bf100_n()
                    {
                        result = 1, fn = "sc_tablestart_bf100_n", _msgid = _TurnWaitTime
                    };
                    _start.tableid = _tableid;
                    _start.pos     = i;

                    _start._canGetBanker   = false;
                    _start._pos2userid     = _uplist;//所有玩家及对应 的位置信息
                    _start._curTableCount  = _judge._curTableOverCount;
                    _start._curBankerCount = 1;
                    _start.ShowCardList    = _temppoker0;
                    _start.closefun        = true;//需要抢庄,不关闭自动显示功能
                    imList.Add(new UserIDMSG(tempUser._userid, JsonUtils.Serialize(_start), tempUser._isRobot, tempUser._isDisconnet));
                });

                BF100SendDataServer.instance.SendDataDelay(imList);
                _tableSendData.Add(imList);
                _strStatus = "Start...3  ";

                DoExecuteSetBanker();
            }
        }
Ejemplo n.º 25
0
        /// <summary>
        ///  不同游戏类型结算方法不一样
        /// </summary>
        /// <returns></returns>
        public ShowDownSD100 GetShowDownList(int _pos)
        {
            int _bankerPos = _myTable._bankpos;
            List <CommonPosValListSD> _pos2CardList = new List <CommonPosValListSD>();

            foreach (var pokerlist in _myTable._dicPokerList)
            {
                _pos2CardList.Add(new CommonPosValListSD()
                {
                    pos = pokerlist.Key, vallist = pokerlist.Value
                });
            }

            ShowDownSD100 _tempdicpos2SD = new ShowDownSD100()
            {
                bulltype      = (int)_myTable._DicPos2User[_pos]._bulltype,
                gamble        = _myTable._DicPos2User[_pos]._gambleTotal,
                money         = 0,
                pos           = _pos,
                _pos2CardList = _pos2CardList
            };

            BullFight100User   _tempBankerUser = _myTable._DicPos2User[_bankerPos];
            List <int>         _bankerCardList = _myTable._dicPokerList[1];
            PokerBullFightType _bankderType    = _myTable._dicPokerBFType[1];

            foreach (int key in _myTable._dicPokerList.Keys)
            {
                if (key == 1)
                {
                    continue;          //固定1号位为庄
                }
                bool _tempBankerWin = BullFight.ComparePoker(_bankerCardList, _bankderType, _myTable._dicPokerList[key], _myTable._dicPokerBFType[key]);
                int  _gambleRate    = 1;
                if (_tempBankerWin)
                {
                    _gambleRate = BullFight._dicbullfightRate[_bankderType];
                }
                else
                {
                    _gambleRate = BullFight._dicbullfightRate[_myTable._dicPokerBFType[key]];
                }

                _myTable.ForeashAllDo((i) =>
                {
                    if (_myTable._masterPos == i)
                    {
                        return;                          //房主不计算
                    }
                    if (_myTable._bankpos == i)
                    {
                        return;                        //庄家不计算
                    }
                    if (_tempBankerWin)
                    {
                        int _tempvar = _myTable._baseMoney * _myTable._DicPos2User[i].GetGambleByPos(key) * _gambleRate;
                        _myTable._DicPos2User[_bankerPos]._CurrentGold += _tempvar;       //扣出5%费用 只要是赢了的人
                        _myTable._DicPos2User[i]._CurrentGold          -= _tempvar;
                    }
                    else
                    {
                        int _tempvar = _myTable._baseMoney * _myTable._DicPos2User[i].GetGambleByPos(key) * _gambleRate;
                        _myTable._DicPos2User[_bankerPos]._CurrentGold -= _tempvar;
                        _myTable._DicPos2User[i]._CurrentGold          += _tempvar;//扣出5%费用 只要是赢了的人
                    }
                });
            }

            return(_tempdicpos2SD);
        }
Ejemplo n.º 26
0
        /// <summary>
        /// 摹仿客户端 消息处理  不加锁
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="strMSG"></param>
        private static void RobotDealMSG(int UserID, string strMSG)
        {
            UserStatus _us = BaseLobby.instanceBase.GetUserStatusbyUserID(UserID);

            if (_us == null)
            {
                ErrorRecord.Record(" 201611301728BF " + UserID);
                return;
            }
            if (_us.Status == UserStatusEnum.InLobby)
            {
                return;                                      //一局结算了,收到的消息需要处理,也处理不了,Table已释放
            }
            BullFight100User myu = BullFight100Lobby.instance.GetUserByRoomIDandTableIDandUserID(_us.RoomID, _us.TableID, UserID);

            if (myu == null)
            {
                ErrorRecord.Record(" 201611301729BF " + UserID + ",_us.Status:" + _us.Status + " strMSG:" + strMSG);
                return;
            }
            sc_base _csdata = JsonUtils.Deserialize <sc_base>(strMSG);

            if (_csdata == null)
            {
                ErrorRecord.Record(" 201206062216BF " + UserID);
                return;
            }

            switch (_csdata.fn)
            {
            case "sc_entertable_n":     //自动 准备
                //Thread.Sleep(900);
                break;

            case "sc_tablestart_bf100_n":
                break;

            case "sc_applybanker_bf100_n":      //如果 自己是庄,需要执行庄下注
                int _waittimeStart = ToolsEx.GetRandomSys(600, 3000);
                Thread.Sleep(_waittimeStart);
                sc_tablestart_bf100_n _tablestart = JsonUtils.Deserialize <sc_tablestart_bf100_n>(strMSG);
                BullFight100Table     myt         = BullFight100Lobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);

                if (myt != null)
                {
                    lock (myt)
                    {
                        myt.GambleOne(myu._userid, 2, 10);     //下注
                    }
                }
                break;

            case "sc_getbankerone_bf_n":      //客户端显示 OK手势
                break;

            case "sc_gambleone_bf100_n":
                break;

            case "sc_end_bf100_n":
                sc_end_bf100_n _showdown = JsonUtils.Deserialize <sc_end_bf100_n>(strMSG);
                if (_showdown._OverTable == 1 || _showdown.gamemodel == 2)
                {
                    return;                                                           //OVer了
                }
                BullFight100Table _myt_showdown = BullFight100Lobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);
                BullFight100Table myt0014       = BullFight100Lobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);

                if (myt0014 != null && myt0014._judge._gameCoin2Room1 == 1)
                {
                }
                break;

            case "cs_bankergetbonuspot_bf100":     //有人下庄了

                break;

            case "sc_applyexittable_n":    //AI 都同意所有游戏解散
                Thread.Sleep(550);
                sc_applyexittable_n _applyExit      = JsonUtils.Deserialize <sc_applyexittable_n>(strMSG);
                BullFight100Table   _applyexitTable = BullFight100Lobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);
                if (_applyexitTable != null)
                {
                    lock (_applyexitTable)
                    {
                        _applyexitTable.DealExitTable(myu._userid, true);
                    }
                }
                break;

            case "sc_showdown_bf100_n": break;

            case "sc_dealexittable_n": break;

            case "sc_one_exittable_n": break;

            case "sc_exittable_n":    //AI 在有人退出的情况下,全都退出

                break;

            case "sc_chat_n": break;

            case "sc_disconnect_n": break;

            case "sc_warning_n": break;

            default:
                ErrorRecord.Record("201206190957BF AI 未处理,strSID:" + _csdata.fn);
                break;
            }
        }