Ejemplo n.º 1
0
        protected void Initi(ConcurrentDictionary <int, BaseUser> _pos2user, int minnum, int maxnum, int gameid, BaseSendDataServer _bsds, TimerCallback callback)
        {
            lock (objLock)
            {
                _tablRecord = new tb_tablerecord();
                Interlocked.Exchange(ref _userTokenPos, 0);
                MoneyRecordList = new ConcurrentQueue <MoneyRecord>();
                //记录
                DateTime tempDT = DateTime.Now;

                _tableMathCode     = ToolsEx.GetRoomEnterSixID();
                _guid              = Guid.NewGuid().ToString("N");
                _haveCheckRoomCard = false;
                _applyExitTable    = false;
                _pos2userbase      = _pos2user;
                _num_max           = maxnum;
                _num_min           = minnum;
                _gameid            = gameid;
                _tablestatus       = TableStatusEnum.Initi;
                _bsDataServer      = _bsds;
                ForeashAllDoBase((i) =>
                {
                    _pos2userbase[i]._WaitSecond = _TurnWaitTime;  //20
                });
                _tableSendData.Clear();
                _tableEnterSendData.Clear();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 返回用户信息,只有当前玩家需要处理   同时返回是否为断线重连,后续处理
        /// </summary>
        /// <returns></returns>
        public string Login(tb_User _tempuser, string accountid)
        {
            sc_login _senddata = new sc_login()
            {
                result = 1, fn = "sc_login", user = new PlayerInfoSD()
            };

            var cacheSet = new PersonalCacheStruct <tb_User>();

            _senddata.user.userid    = _tempuser.UserID;
            _senddata.user.uName     = _tempuser.wechatName;
            _senddata.user.Money     = (float)_tempuser.UserMoney;
            _senddata.user.accountId = accountid;
            _senddata.user.isagent   = _tempuser.isagent;
            _senddata.user._wechat   = new WechatInfoSD()
            {
                HeadIconURL = ToolsEx.IsHandlePhoto(_tempuser.isRobot, _tempuser.wechatHeadIcon), Sex = _tempuser.Sex, wechatName = _tempuser.wechatName
            };
            _tempuser.LastLotinTime2 = _tempuser.LastLotinTime1;
            _tempuser.LastLotinTime1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff");
            _tempuser.IP             = _strIPandPort;
            UserStatus _us = BaseLobby.instanceBase.GetUserStatusbyUserID(_tempuser.UserID);//获取是否需要断线重连

            if (_us != null)
            {
                _senddata.user.state = (int)_us.Status;
                _senddata.gameid     = _us.Gameid;
            }
            tb_UserEx.UpdateData(_tempuser);  //更新登录时间与IP
            return(JsonUtils.Serialize(_senddata));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取一张无牛牌组的牌
        /// </summary>
        /// <param name="filterNum">不能要的数字</param>
        /// <returns>一张牌</returns>
        public static int GetNullNum(List <int> filterNum)
        {
            int result = filterNum[0];

            while (filterNum.Contains(result))
            {
                result = ToolsEx.GetRandomSys(1, 11);
            }
            return(result);
        }
Ejemplo n.º 4
0
 private string IsHandlePhoto(int _isRobot, string wechatHeadIcon)
 {
     if (_isRobot == 1)
     {
         var serverIp = ToolsEx.GetIpAddress();
         return("" + serverIp + "/fordlc/wechat/" + wechatHeadIcon.Trim());
     }
     else
     {
         return(wechatHeadIcon.Trim());
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// 随机排列数组元素
        /// </summary>
        /// <param name="myList"></param>
        /// <returns></returns>
        public static List <int> ListRandom(List <int> myList)
        {
            int index = 0;
            int temp  = 0;

            for (int i = 0; i < myList.Count; i++)
            {
                index = ToolsEx.GetRandomSys(1, myList.Count - 1);
                if (index != i)
                {
                    temp          = myList[i];
                    myList[i]     = myList[index];
                    myList[index] = temp;
                }
            }
            return(myList);
        }
Ejemplo n.º 6
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();
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 给机器配置胜率后,机器人拿大牌,有多个机器时,以早大POS的机器人为准
        /// 如果有多个设置胜率帐号在同一桌,则会只有一个机率有效。
        /// </summary>
        /// <param name="pos2RobotAI"></param>
        /// <param name="_pos2Poker"></param>
        /// <returns></returns>
        public Dictionary <int, List <int> > ChangePokerByRobotAI(Dictionary <int, int> pos2RobotAI, Dictionary <int, List <int> > _pos2Poker)
        {
            Dictionary <int, PokerBullFightType> _pbftype = new Dictionary <int, PokerBullFightType>();

            _myTable.ForeashAllDo((i) =>
            {
                _pbftype.Add(i, BullFight.GetBullType(_pos2Poker[i]));
            });
            int _maxpos = _myTable._masterPos;
            PokerBullFightType maxvalue = PokerBullFightType.Bull_No;

            _myTable.ForeashAllDo((i) =>
            {
                if (maxvalue < _pbftype[i])
                {
                    maxvalue = _pbftype[i];
                    _maxpos  = i;
                }
            });
            int _RobotRatePos = _maxpos;

            _myTable.ForeashAllDo((i) =>
            {
                int _AIRate = pos2RobotAI[i];
                if (_AIRate == 0)
                {
                    return;
                }
                int _tempRate = ToolsEx.GetRandomSys(0, 100);
                if (_tempRate <= _AIRate)
                {
                    _RobotRatePos = i;
                }
            });
            List <int> _tempChange = new List <int>();//把最大的牌换给机器人最高胜率的人

            _tempChange = _pos2Poker[_RobotRatePos];
            _pos2Poker[_RobotRatePos] = _pos2Poker[_maxpos];
            _pos2Poker[_maxpos]       = _tempChange;

            return(_pos2Poker);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 根据牛牛类型传出牛牛的值
        /// </summary>
        /// <param name="_type">牛的类型</param>
        /// <returns>对应的一组牛的牌</returns>
        public static List <int> GetPokerbyBullFightType(PokerBullFightType _type)
        {
            int type = _type.GetHashCode();

            int[] allCards  = new int[5];
            int[] bullcrads = new int[3];
            int[] spotcrads = new int[2];
            if (type >= 1 && type <= 10)
            {
                Random rd = new Random();
                bullcrads[0] = rd.Next(1, 11);
                bullcrads[1] = rd.Next(1, 11);
                int remainnum = (bullcrads[0] + bullcrads[1]) % 10;
                bullcrads[2] = 10 - remainnum;

                spotcrads[0] = rd.Next(1, 11);
                if (type > spotcrads[0])
                {
                    spotcrads[1] = type - spotcrads[0];
                }
                else
                {
                    spotcrads[1] = 10 + type - spotcrads[0];
                }
            }
            else if (type == 11)
            {
                bullcrads = new int[] { 10, 10, 10 };
                spotcrads = new int[] { 10, 10 };
            }
            else if (type == 0)
            {
                Random rd = new Random();
                bullcrads[0] = rd.Next(1, 11);
                bullcrads[1] = rd.Next(1, 11);
                List <int> havaNum = new List <int>();
                havaNum.Add(bullcrads[0]);
                havaNum.Add(bullcrads[1]);
                List <int> filterNum = new List <int>();
                //// 生成第三个数
                filterNum    = GetFilterList(havaNum);
                bullcrads[2] = GetNullNum(filterNum);
                havaNum.Add(bullcrads[2]);
                //// 生成第四个数
                filterNum    = GetFilterList(havaNum);
                spotcrads[0] = GetNullNum(filterNum);
                havaNum.Add(spotcrads[0]);
                //// 生成第五个数,注意无牛的时候可能出现五个一样的数字
                filterNum = GetFilterList(havaNum);
                if (havaNum.FindAll(p => p == havaNum[0]).Count == 4)
                {
                    filterNum.Add(havaNum[0]);
                }
                spotcrads[1] = GetNullNum(filterNum);
            }

            bullcrads.CopyTo(allCards, 0);
            spotcrads.CopyTo(allCards, bullcrads.Length);

            //// 替换10, 注意牛牛替换以后不能是五花牛,也不能出现5个10;五花牛替换以后不能出现10,也不能出现5个一样的数字
            List <int> flowerCards = new List <int>();

            for (int i = 0; i < 5; i++)
            {
                //// 替换 10
                if (allCards[i] == 10)
                {
                    if (type < 10)
                    {
                        allCards[i] = ToolsEx.GetRandomSys(10, 14);
                    }
                    else if (type == 10)
                    {
                        if (i == 4 && allCards.ToList().FindAll(p => p > 10).Count == 4)
                        {
                            allCards[i] = 10;
                        }
                        else
                        {
                            allCards[i] = ToolsEx.GetRandomSys(10, 14);
                        }
                    }
                    else if (type == 11)
                    {
                        if (i == 4 && allCards.ToList().FindAll(p => p == allCards[0]).Count == 4)
                        {
                            int fivenum = allCards[0];
                            while (fivenum == allCards[0])
                            {
                                allCards[i] = ToolsEx.GetRandomSys(11, 14);
                            }
                        }
                        else
                        {
                            allCards[i] = ToolsEx.GetRandomSys(11, 14);
                        }
                    }
                }

                //// 替换花色
                int num = ToolsEx.GetRandomSys(1, 5) * 100 + allCards[i];
                flowerCards[i] = num;
                while (flowerCards.Contains(num))
                {
                    num = ToolsEx.GetRandomSys(1, 5) * 100 + allCards[i];
                }

                flowerCards[i] = num;
            }


            flowerCards = ListRandom(flowerCards);
            return(flowerCards);;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 返回游戏列表,只有当前玩家需要处理
        /// </summary>
        /// <returns></returns>
        public string GetLevelList(tb_User _user, int gameid)
        {
            sc_getgamelevel _senddata = new sc_getgamelevel()
            {
                result = 1, fn = "sc_getgamelevel", levellist = new List <RoomInfoSD>()
            };

            switch (gameid)
            {
            case 42:
                var _roomlist = BullFight100Room.roomCache.FindAll();
                var tempInfo  = _roomlist;
                List <RoomInfoSD> roomInfoList = new List <RoomInfoSD>();
                foreach (var level in tempInfo)
                {
                    RoomInfoSD infoSd = new RoomInfoSD()
                    {
                        baserate = level._currRoomInfo.Baserate,
                        gameid   = level._currRoomInfo.gameid,
                        gametype = level._currRoomInfo.gametype,
                        id       = level.mRoomID,
                        name     = level._currRoomInfo.Name,
                        _max     = level._currRoomInfo._max,
                        _min     = level._currRoomInfo._min
                    };

                    var onlineCount = level._curNumberInRoom + (level.DicTable.Count * 4 + level.DicUser.Count + ToolsEx.GetRandomSys(1, 20));
                    infoSd.onlineCount = onlineCount;
                    roomInfoList.Add(infoSd);
                }
                _senddata.levellist = roomInfoList;
                break;

            case 41:
            {
                ////var _roomlist =  BullColorRoom.roomCache.FindAll();
                ////var tempInfo = _roomlist;
                ////List<RoomInfoSD> roomInfoList = new List<RoomInfoSD>();
                ////foreach (var level in tempInfo)
                ////{

                ////    RoomInfoSD infoSd = new RoomInfoSD()
                ////    {
                ////        baserate = level._currRoomInfo.Baserate,
                ////        gameid = level._currRoomInfo.gameid,
                ////        gametype = level._currRoomInfo.gametype,
                ////        id = level.RoomId,
                ////        name = level._currRoomInfo.Name,
                ////        _max = level._currRoomInfo._max,
                ////        _min = level._currRoomInfo._min
                ////    };

                ////    var onlineCount = level._curNumberInRoom + (level.DicTable.Count * 4 + level.DicUser.Count + ToolsEx.GetRandomSys(1, 20));
                ////    infoSd.onlineCount = onlineCount;
                ////    roomInfoList.Add(infoSd);
                ////}
                ////_senddata.levellist = roomInfoList;
            }
            break;

            default:
                break;
            }
            return(JsonUtils.Serialize(_senddata));
        }
Ejemplo n.º 10
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已释放
            }
            BullColorUser myu = BullColorLobby.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;
            }
            int _waittime3000 = 4000;

            switch (_csdata.fn)
            {
            case "sc_entertable_n":     //自动 准备
                //Thread.Sleep(900);
                sc_entertable_n _entertable = JsonUtils.Deserialize <sc_entertable_n>(strMSG);
                BullColorTable  myt001      = BullColorLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);
                if (myt001 != null && myu._Pos == _entertable.pos)
                {
                    //// myt001.GetReady(myu._userid); //  自己的进房间通知才准备
                }
                break;

            case "sc_ready_bf_n":     //
                break;

            case "sc_tablestart_bf_n":
                int _waittimeStart = ToolsEx.GetRandomSys(600, 3000);
                Thread.Sleep(_waittimeStart);
                sc_tablestart_bfc_n _tablestart = JsonUtils.Deserialize <sc_tablestart_bfc_n>(strMSG);
                BullColorTable      myt         = BullColorLobby.instance.GetTableByRoomIDandTableID(myu._roomid, myu._tableID);

                //根据需求判断 是否抢庄
                if (myt != null && !_tablestart.closefun && _tablestart._canGetBanker)
                {
                }
                break;

            case "sc_gambleone_bfc_n":
                break;

            case "sc_setbulltype_bfc_n":         //无AI处理 直接等待摊牌

                break;

            case "sc_showone_bfc_n": break;

            case "sc_showdown_bfc_n":
                //Thread.Sleep(410);
                break;

            case "sc_end_bfc_n":
                break;

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

            case "sc_dealexittable_n": break;

            case "sc_one_exittable_n": break;

            case "sc_exittable_n":    //AI 在有人退出的情况下,全都退出
                ////sc_exittable  _exittable = JsonUtils.Deserialize<sc_exittable>(strMSG);
                ////Thread.Sleep(10);
                ////BullFightUser myu_exit;
                ////DicIDtoUser.TryGetValue(UserID, out myu_exit);
                ////if (_exittable.pos != myu_exit._Pos)
                ////{   //自己的退出消息不再处理  但是只能处理一次
                ////    ////BullColorTable mytexit = BullColorLobby.GetTableByRoomIDandTableID(myu_exit._roomid, _exittable.tableid);
                ////    ////if (mytexit != null) mytexit.ExitTable(myu_exit._userid); //
                ////}
                break;

            case "sc_chat_n": break;

            case "sc_disconnect_n": break;

            case "sc_warning_n": break;

            case "020":      //此桌结束了,正常结束
                break;

            default:
                ErrorRecord.Record("201206190957BF AI 未处理,strSID:" + _csdata.fn);
                break;
            }
        }
Ejemplo n.º 11
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;
            }
        }
Ejemplo n.º 12
0
        public static List <RankInfoSD> GetRankList()
        {
            List <RankInfoSD> _rankinfolist = new List <RankInfoSD>();
            var userCache = new GameDataCacheSet <tb_User>();

            tb_UserEx.RecoverFromDb("==", 0);
            var            userIds  = tb_UserEx.GetUserIdListByRobot(0);
            List <tb_User> userList = new List <tb_User>();

            foreach (var item in userIds)
            {
                tb_User user;
                userCache.TryFindKey(item.ToString(), out user);
                if (user != null)
                {
                    userList.Add(user);
                }
            }
            if (userList.Any())
            {
                var tempList = userList.OrderByDescending(w => w.diamond).Take(20).ToList();
                _rankinfolist = tempList.Select(w => new RankInfoSD {
                    userid = w.UserID, winScore = (int)w.diamond, uName = w.wechatName, rank = tempList.IndexOf(w) + 1, headurl = ToolsEx.IsHandlePhoto(w.isRobot, w.wechatHeadIcon)
                }).ToList();
            }
            return(_rankinfolist);
        }