Ejemplo n.º 1
0
 /// <summary>
 /// 桌子对象
 /// </summary>
 /// <param name="roomId"></param>
 /// <param name="tableId"></param>
 /// <param name="playerNum">人数</param>
 /// <param name="anteNum">底注</param>
 /// <param name="multipleNum">倍数</param>
 /// <param name="callback"></param>
 /// <param name="packNum">几副牌</param>
 public TableData(int roomId, int tableId, int playerNum, int anteNum, int multipleNum, TimerCallback callback, int packNum = 1)
 {
     _roomId = roomId;
     _tableId = tableId;
     _playerNum = playerNum;
     _anteNum = anteNum;
     _multipleNum = multipleNum;
     _packNum = packNum;
     _cardList = new List<int>(PackMaxNum * packNum);
     _backCardData = new List<int>();
     _callOperation = new bool[playerNum + 1];
     _outCardList = new List<CardData>();
     _positions = new PositionData[playerNum];
     for (int i = 0; i < playerNum; i++)
     {
         _positions[i] = new PositionData(i);
     }
     _timer = new Timer(callback, this, -1, -1);
     Init();
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 桌子对象
 /// </summary>
 /// <param name="roomId"></param>
 /// <param name="tableId"></param>
 /// <param name="playerNum">人数</param>
 /// <param name="anteNum">底注</param>
 /// <param name="multipleNum">倍数</param>
 /// <param name="callback"></param>
 /// <param name="packNum">几副牌</param>
 public TableData(int roomId, int tableId, int playerNum, int anteNum, int multipleNum, TimerCallback callback, int packNum = 1)
 {
     _roomId        = roomId;
     _tableId       = tableId;
     _playerNum     = playerNum;
     _anteNum       = anteNum;
     _multipleNum   = multipleNum;
     _packNum       = packNum;
     _cardList      = new List <int>(PackMaxNum * packNum);
     _backCardData  = new List <int>();
     _callOperation = new bool[playerNum + 1];
     _outCardList   = new List <CardData>();
     _positions     = new PositionData[playerNum];
     for (int i = 0; i < playerNum; i++)
     {
         _positions[i] = new PositionData(i);
     }
     _timer = new Timer(callback, this, -1, -1);
     Init();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查逃跑,并结束当局游戏,扣分两家平分
        /// </summary>
        /// <param name="user"></param>
        /// <param name="table"></param>
        /// <param name="userPos"></param>
        private void CheckFlee(GameUser user, TableData table, PositionData userPos)
        {
            table.IsClosed = true;
            if (table.IsStarting)
            {
                int multipleMinNum = ConfigEnvSet.GetInt("Game.FleeMultipleNum", 10);
                PositionData pos = null;
                List<PositionData> posList = new List<PositionData>();
                //计算炸弹数量
                foreach (PositionData position in table.Positions)
                {
                    if (position.UserId == user.UserId)
                    {
                        pos = position;
                    }
                    else
                    {
                        posList.Add(position);
                    }
                    var obj = _cardRole.ParseCardGroup(position.CardData.ToArray());
                    for (int i = 0; i < obj.Count; i++)
                    {
                        var item = obj.GetSame(i);
                        if (item.Length == 4 || (item.Length == 2 && _cardRole.GetCardSize(item[0]) > (int)CardSize.C_2))
                        {
                            table.DoDouble();
                        }
                    }
                }
                table.IsFlee = true;
                if (table.MultipleNum < multipleMinNum)
                {
                    table.SetDouble(multipleMinNum);
                }
                DoSettlement(table, false, pos, posList);
                var param = new Parameters();
                param.Add("FleeUserId", user.UserId);
                var userList = ClientNotifier.GetUserList(table, user.UserId);
                SyncNotifyAction(ActionIDDefine.Cst_Action2013, userList, param,
                    c =>
                    {
                        DoComplatedSettlement(table);
                        //
                        TraceLog.WriteComplement("桌子:{0}玩家{1}逃跑通知", table.TableId, user.UserId);
                    });

                NotifyUserChange(user.UserId);
            }
            else
            {
                //还没有开始时,可以离开位置等待新玩家
                user.Property.InitTablePos();
                userPos.Init();
                table.IsClosed = false;
                int periodAiStart = ConfigEnvSet.GetInt("Game.Table.AIIntoTime", 5000);
                table.ReStartTimer(periodAiStart);
                var userList = ClientNotifier.GetUserList(table, user.UserId);
                SyncNotifyAction(ActionIDDefine.Cst_Action2003, userList, null, null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 结算积分
        /// </summary>
        /// <param name="tableData"></param>
        /// <param name="isLandlordWin"></param>
        /// <param name="landPos"></param>
        /// <param name="posList"></param>
        private void DoSettlement(TableData tableData, bool isLandlordWin, PositionData landPos, List<PositionData> posList)
        {
            //都有加积分
            GameUser user;
            if (isLandlordWin)
            {
                foreach (PositionData pos in posList)
                {
                    user = GetUser(pos.UserId);
                    if (user != null)
                    {
                        pos.CoinNum = tableData.AnteNum / 2;
                        pos.ScoreNum = tableData.MultipleNum / 2;
                        pos.CoinNum = user.GameCoin > pos.CoinNum ? pos.CoinNum : user.GameCoin;
                        landPos.CoinNum += pos.CoinNum;
                        landPos.ScoreNum += pos.ScoreNum;
                        pos.ScoreNum = user.ScoreNum > pos.ScoreNum ? pos.ScoreNum : user.ScoreNum;

                        TraceLog.WriteComplement("桌子:{0}玩家(农):{1}败,结算:-{2}金豆,-{3}积分,之前剩余:{4}-{5}",
                            tableData.TableId, user.UserId, pos.CoinNum, pos.ScoreNum, user.GameCoin, user.ScoreNum);
                        user.GameCoin = MathUtils.Subtraction(user.GameCoin, pos.CoinNum);
                        user.ScoreNum = MathUtils.Subtraction(user.ScoreNum, pos.ScoreNum);
                        user.FailNum = MathUtils.Addition(user.FailNum, 1);
                    }
                    else
                    {
                        landPos.CoinNum += tableData.AnteNum / 2;
                        landPos.ScoreNum += tableData.MultipleNum / 2;
                    }
                }
                user = GetUser(landPos.UserId);
                if (user != null)
                {
                    TraceLog.WriteComplement("桌子:{0}玩家(主):{1}胜,结算:+{2}金豆,+{3}积分,之前剩余:{4}-{5}",
                        tableData.TableId, user.UserId, landPos.CoinNum, landPos.ScoreNum, user.GameCoin, user.ScoreNum);
                    user.GameCoin = MathUtils.Addition(user.GameCoin, landPos.CoinNum);
                    user.ScoreNum = MathUtils.Addition(user.ScoreNum, landPos.ScoreNum);
                    user.WinNum = MathUtils.Addition(user.WinNum, 1);
                    AchieveTask.SaveUserTask(user.UserId.ToString(), TaskClass.HuanLe, 1);
                    AchieveTask.SaveUserTask(user.UserId.ToString(), TaskClass.HuanLeJiFen, landPos.ScoreNum);
                }
            }
            else
            {
                user = GetUser(landPos.UserId);
                if (user != null)
                {
                    landPos.CoinNum = user.GameCoin > tableData.AnteNum ? tableData.AnteNum : user.GameCoin;
                    landPos.ScoreNum = tableData.MultipleNum;

                    TraceLog.WriteComplement("桌子:{0}玩家(主):{1}败,结算:-{2}金豆,-{3}积分,之前剩余:{4}-{5}",
                        tableData.TableId, user.UserId, landPos.CoinNum, landPos.ScoreNum, user.GameCoin, user.ScoreNum);
                    user.GameCoin = MathUtils.Subtraction(user.GameCoin, landPos.CoinNum);
                    user.ScoreNum = MathUtils.Subtraction(user.ScoreNum, user.ScoreNum > tableData.MultipleNum ? tableData.MultipleNum : user.ScoreNum);
                    user.FailNum = MathUtils.Addition(user.FailNum, 1);
                }
                else
                {
                    landPos.CoinNum += tableData.AnteNum;
                    landPos.ScoreNum += tableData.MultipleNum;
                }

                foreach (PositionData pos in posList)
                {
                    user = GetUser(pos.UserId);
                    if (user != null)
                    {
                        pos.CoinNum = landPos.CoinNum / 2;
                        pos.ScoreNum = landPos.ScoreNum / 2;

                        TraceLog.WriteComplement("桌子:{0}玩家(农):{1}胜,结算:+{2}金豆,+{3}积分,之前剩余:{4}-{5}",
                            tableData.TableId, user.UserId, pos.CoinNum, pos.ScoreNum, user.GameCoin, user.ScoreNum);
                        user.GameCoin = MathUtils.Addition(user.GameCoin, pos.CoinNum);
                        user.ScoreNum = MathUtils.Addition(user.ScoreNum, pos.ScoreNum);
                        user.WinNum = MathUtils.Addition(user.WinNum, 1);
                        AchieveTask.SaveUserTask(user.UserId.ToString(), TaskClass.HuanLe, 1);
                        AchieveTask.SaveUserTask(user.UserId.ToString(), TaskClass.HuanLeJiFen, pos.ScoreNum);
                    }
                }

            }
            _userCacheSet.Update();
            tableData.IsSettlemented = true;
            //出牌记录
            StringBuilder sb = new StringBuilder();
            foreach (var card in tableData.OutCardList)
            {
                sb.AppendLine();
                sb.AppendFormat("User:{0}\t->{1}", card.UserId, string.Join(",", card.Cards));
            }
            TraceLog.WriteComplement("房间:{0}桌子:{1}出牌记录:{2}", tableData.RoomId, tableData.TableId, sb);
        }
Ejemplo n.º 5
0
 /// <summary>
 /// 桌子占位
 /// </summary>
 /// <param name="table"></param>
 /// <param name="pos"></param>
 /// <param name="user"></param>
 /// <param name="roomId"></param>
 private static void SetTablePosition(int roomId, TableData table, PositionData pos, GameUser user)
 {
     pos.Init(user);
     user.Property.InitTablePos(roomId, table.TableId, pos.Id);
 }