Exemplo n.º 1
0
        /// <summary>
        /// 客户端的加注处理
        /// </summary>
        /// <param name="client"></param>
        /// <param name="value"></param>
        private void AddStakes(ClientPeer client, int multiple)
        {
            SingleExecute.Instance.Exeecute(() => {
                if (fightCache.IsFighting(client.Id) == false)
                {
                    return;
                }

                FightRoom room         = fightCache.GetFightRoomByUserId(client.Id);
                room.lastPlayerStakes *= multiple;
                if (room.lastPlayerStakes > room.topStakes)   // 顶注
                {
                    room.lastPlayerStakes = room.topStakes;
                }
                room.stakesSum += room.lastPlayerStakes;
                int stakesSum   = room.UpdatePlayerStakesSum(client.Id, room.lastPlayerStakes);
                int remainCoin  = DatabaseManager.UpdateCoin(client.Id, -room.lastPlayerStakes);

                stakesDto.Change(client.Id, remainCoin, room.lastPlayerStakes, stakesSum, StakesDto.StakesType.NoLook);
                room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto);
                // 剩余金币不够
                if (remainCoin < room.lastPlayerStakes)
                {
                    GiveUpCard(client);
                    return;
                }

                Turn(client);
            });
        }
Exemplo n.º 2
0
        /// <summary>
        /// 客户端跟注请求的处理
        /// </summary>
        /// <param name="client"></param>
        private void Follow(ClientPeer client)
        {
            SingleExecute.Instance.Execute(() =>
            {
                if (fightCache.IsFighting(client.Id) == false)
                {
                    return;
                }

                FightRoom room  = fightCache.GetFightRoomByUserId(client.Id);
                room.stakesSum += room.lastPlayerStakesCount;
                int stakesSum   = room.UpdatePlayerStakesSum(client.Id, room.lastPlayerStakesCount);
                int remainCoin  = DatabaseManager.UpdateCoinCount(client.Id, -(room.lastPlayerStakesCount));
                stakesDto.Change(client.Id, remainCoin, room.lastPlayerStakesCount, stakesSum, StakesDto.StakesType.NoLook);
                room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto);

                if (remainCoin < room.lastPlayerStakesCount)
                {
                    GiveUpCard(client);
                    return;
                }

                //轮到下一个玩家下注
                Turn(client);
            });
        }
Exemplo n.º 3
0
        /// <summary>
        /// 开始战斗
        /// </summary>
        /// <param name="clientList"></param>
        /// <param name="roomType"></param>
        public void StartFight(List <ClientPeer> clientList, int roomType)
        {
            SingleExecute.Instance.Execute(() =>
            {
                FightRoom room = fightCache.CreatRoom(clientList);
                switch (roomType)
                {
                case 0:
                    room.bottomStakes          = 10;
                    room.topStakes             = 100;
                    room.lastPlayerStakesCount = 10;
                    break;

                case 1:
                    room.bottomStakes          = 20;
                    room.topStakes             = 200;
                    room.lastPlayerStakesCount = 20;
                    break;

                case 2:
                    room.bottomStakes          = 50;
                    room.topStakes             = 500;
                    room.lastPlayerStakesCount = 50;
                    break;

                default:
                    break;
                }
                foreach (var client in clientList)
                {
                    room.UpdatePlayerStakesSum(client.Id, room.bottomStakes);
                }
                //选择庄家
                ClientPeer bankerClient = room.SetBanker();
                //重置位置,排序
                room.ResetPosition(bankerClient.Id);
                //发牌
                room.DealCards();
                //对手牌排序
                room.SortAllPlayerCard();
                //获得牌型
                room.GetAllPlayerCardType();

                room.Broadcast(OpCode.Fight, FightCode.StartFight_BRO, room.playerList);
                //转换下注,换到庄家下一位玩家下注
                Turn(bankerClient);
            });
        }
Exemplo n.º 4
0
        /// <summary>
        /// 客户端比牌的处理
        /// </summary>
        /// <param name="compareClient"></param>
        /// <param name="comparedID"></param>
        private void CompareCard(ClientPeer compareClient, int comparedID)
        {
            SingleExecute.Instance.Exeecute(() => {
                if (fightCache.IsFighting(compareClient.Id) == false)
                {
                    return;
                }

                FightRoom room  = fightCache.GetFightRoomByUserId(compareClient.Id);
                room.stakesSum += room.lastPlayerStakes;
                int stakesSum   = room.UpdatePlayerStakesSum(compareClient.Id, room.lastPlayerStakes);
                int remainCoin  = DatabaseManager.UpdateCoin(compareClient.Id, -room.lastPlayerStakes);
                stakesDto.Change(compareClient.Id, remainCoin, room.lastPlayerStakes, stakesSum, StakesDto.StakesType.Look);
                room.Broadcast(OpCode.Fight, FightCode.PutStakes_BRO, stakesDto);

                // 拿到 3 个玩家的 DTO
                PlayerDto c1Dto = null, c2Dto = null, otherDto = null;
                foreach (var player in room.playerList)
                {
                    if (player.id == compareClient.Id)
                    {
                        c1Dto = player;
                    }
                    else if (player.id == comparedID)
                    {
                        c2Dto = player;
                    }
                    else
                    {
                        otherDto = player;
                    }
                }
                ClientPeer otherClient = DatabaseManager.GetClientPeerByUserId(otherDto.id);
                // 比牌
                CompareCard(room, compareClient, c1Dto, c2Dto, otherClient);
            });
        }