Example #1
0
        private void HandleActionRequest(GamePeer gamePeer, OperationRequest operationRequest, SendParameters sendParameters)
        {
            var room = FindPeerRoom(gamePeer) as BlackjackGameRoom;

            var actionRequest = new ActionRequest(gamePeer.Protocol, operationRequest);

            if (room != null)
            {
                room.OnPlayerAction(gamePeer, actionRequest);
            }
        }
Example #2
0
        public void OnPlayerAction(GamePeer peer, ActionRequest action)
        {
            if (peer.ValidateOperation(action, new SendParameters()) == false)
            {
                return;
            }

            BlackjackPlayer player = playerManager.GetPlayer(peer) as BlackjackPlayer;

            if (player.status != PlayerStatus.Playing)
            {
                return;
            }

            if (playerCards[player][action.DeckIndex].Finished)
            {
                return;
            }

            BlackjackBet bet = playerBetsDic[player];

            ActionEvent actionEvent = new ActionEvent();

            actionEvent.Actor      = player.key.ID;
            actionEvent.ActionType = action.ActionType;
            actionEvent.DeckIndex  = action.DeckIndex;

            switch (action.ActionType)
            {
            case BlackjackActionType.Hit:
                PlayerHit(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;

            case BlackjackActionType.Split:
                if (AddBet(player, bet.initialBet) == false)
                {
                    return;
                }
                Card originalDeckCard;
                Card newDeckCard;
                Split(player, action.DeckIndex, out originalDeckCard, out newDeckCard);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex, playerCards[player].Count - 1);
                break;

            case BlackjackActionType.Stand:
                Finish(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;

            case BlackjackActionType.DoubleDown:
                if (AddBet(player, bet.initialBet) == false)
                {
                    return;
                }
                DoubleDown(player, action.DeckIndex);
                PlayerHit(player, action.DeckIndex);
                FillActionEventDeck(ref actionEvent, player, action.DeckIndex);
                break;
            }

            EventData eventData = new EventData(EventCode.BlackjackAction, actionEvent);

            BroadcastMessage(peer, eventData, new SendParameters());

            var response = new OperationResponse(CommonOperationCode.BlackjackAction, actionEvent);

            peer.SendOperationResponse(response, new SendParameters());

            PlayerActionDone(player, action.DeckIndex);
        }