示例#1
0
        private void gameOver(_21MutiFightRoom room)
        {
            //给庄家发牌
            brocast(room, OpCode._21Multi, _21MultiCode.TURN_DEALER_BRO, null, null);
            //把所有的state遍历一遍,都爆牌了就不用要了
            while (room.GetDealerWeight() < 17)
            {
                CardDto card = room.DealerHit();
                brocast(room, OpCode._21Multi, _21MultiCode.DEALER_HIT_BRO, card, null);
            }

            //结算
            //结算对象
            GameOverDto gameOverDto = new GameOverDto();
            //todo 写一个总结算的对象,把玩家信息和这轮游戏的信息都发过去 状态 1 2 3 4 5
            //庄家的权值
            int dealerWeight = room.GetDealerWeight();

            gameOverDto.dealerWeight = dealerWeight;
            for (int i = 0; i < 4; i++)
            {
                //不为空
                if (room.PlayerList[i] != null)
                {
                    List <int> StateList   = new List <int>();
                    List <int> WeightList  = new List <int>();
                    List <int> WinBeenList = new List <int>();

                    UserModel um = userCache.GetModelById(room.PlayerList[i].UserId);
                    //ClientPeer client = userCache.GetClientPeer(room.PlayerList[i].UserId);
                    int wager = room.PlayerList[i].Wager;

                    //一名掉线玩家
                    if (room.LeaveUIdList.Contains(room.PlayerList[i].UserId))
                    {
                        //扣双倍豆
                        um.Been -= wager * 2;
                        gameOverDto.isLeaveList[i] = true;
                        WinBeenList.Add(-wager * 2);
                        gameOverDto.playerWinBeenListList[i] = WinBeenList;
                    }
                    //正常玩家
                    else
                    {
                        //每一把牌经验豆子结算
                        for (int j = 0; j < room.PlayerList[i].CardListList.Count; j++)
                        {
                            int multi = 1;

                            PlayerCardDto tempPlayerCardDto = room.PlayerList[i].CardListList[j];
                            int           tempWeight        = tempPlayerCardDto.Weight;
                            WeightList.Add(tempWeight);
                            int  tempState    = tempPlayerCardDto.CardState;
                            bool tempIsDouble = tempPlayerCardDto.isDouble;
                            if (tempIsDouble)
                            {
                                multi = 2;
                            }


                            //21点
                            if (tempState == 1)
                            {
                                um.Been += (int)(wager * 1.5);
                                WinBeenList.Add((int)(wager * 1.5));
                                StateList.Add(1);
                                um.Exp += 150;
                            }
                            //闲家爆牌
                            else if (tempState == 2)
                            {
                                um.Been -= wager * multi;
                                WinBeenList.Add(-wager * multi);
                                if (multi == 1)
                                {
                                    StateList.Add(2);
                                }
                                else
                                {
                                    StateList.Add(3);
                                }
                                um.Exp += 50;
                            }
                            //不要 权值小于
                            else if (tempState == 3)
                            {
                                //庄家爆牌
                                if (dealerWeight > 21)
                                {
                                    um.Been += wager * multi;
                                    WinBeenList.Add(wager * multi);
                                    if (multi == 1)
                                    {
                                        StateList.Add(6);
                                    }
                                    else
                                    {
                                        StateList.Add(4);
                                    }

                                    um.Exp += 100;
                                }
                                //闲家点大
                                else if (dealerWeight < tempWeight)
                                {
                                    um.Been += wager * multi;
                                    WinBeenList.Add(wager * multi);
                                    if (multi == 1)
                                    {
                                        StateList.Add(6);
                                    }
                                    else
                                    {
                                        StateList.Add(4);
                                    }
                                    um.Exp += 100;
                                }
                                //庄家点大
                                else if (dealerWeight > tempWeight)
                                {
                                    um.Been -= wager * multi;
                                    WinBeenList.Add(-wager * multi);
                                    if (multi == 1)
                                    {
                                        StateList.Add(7);
                                    }
                                    else
                                    {
                                        StateList.Add(5);
                                    }
                                    um.Exp += 50;
                                }
                                //平局
                                else
                                {
                                    WinBeenList.Add(0);
                                    StateList.Add(8);

                                    um.Exp += 75;
                                }
                            }
                        }
                    }
                    gameOverDto.playerWeightListList[i]  = WeightList;
                    gameOverDto.playerStateListList[i]   = StateList;
                    gameOverDto.playerWinBeenListList[i] = WinBeenList;

                    int maxExp = um.Lv * 100;
                    while (maxExp <= um.Exp)
                    {
                        um.Lv++;
                        um.Exp -= maxExp;
                        maxExp  = um.Lv * 100;
                    }
                    userCache.Update(um);
                    UserDto dto = new UserDto(um.Id, um.Name, um.Been, um.WinCount, um.LoseCount, um.RunCount, um.Lv, um.Exp);
                    gameOverDto.userDtoList[i] = dto;
                }
            }

            //掉线的 不用发了,改一下这个函数 主要用在overpanel
            brocast(room, OpCode._21Multi, _21MultiCode.OVER_BRO, gameOverDto, null);

            //房间设置为等待
            fightCache.SetRoomWait(room);
            //删除离开列表里的用户
            foreach (int uid in room.LeaveUIdList)
            {
                fightCache.Leave(uid);
            }
            //重置房间
            room.resetRoom();
        }