Exemple #1
0
 private void OnStartGame(TexasStartGame texasStartGame)
 {
     Log.DebugFormat("TEXAS ON START GAME: " + this.States.State);
     SendNotification(TexasTrigger.state_start_game.ToString("G"), texasStartGame);
     Log.DebugFormat("READ");
     this.States.Fire(TexasTrigger.state_play);
 }
Exemple #2
0
        public override bool OnHandleMessage(IMessage message, IServerPeer sPeer)
        {
            Log.DebugFormat("OnHandleMessage:TexasStartGameHandler");

            var errorParam = new Dictionary <byte, object>
            {
                { (byte)ServerParameterCode.PeerId, message.Parameters[(byte)ServerParameterCode.PeerId] },
                { (byte)ClientParameterCode.SubOperationCode, message.Parameters[(byte)ClientParameterCode.SubOperationCode] },
            };

            var serverPeer = sPeer as ServerOutbouncePeer;
            var operation  = new StartGameOperator(serverPeer.Protocol, message);


            if (!operation.IsValid)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, operation.GetErrorMessage(), (int)RoomErrorCode.OperationInvalid));
                return(false);
            }
            var peerId = new Guid((Byte[])operation.PeerId);

            var roomID = operation.RoomID;

            errorParam.Add((byte)RoomParameterCode.RoomID, roomID);
            var facade = TexasApplication.GetRoom(roomID);

            if (facade == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, "RoomId Not Found", (int)RoomErrorCode.RoomIdNotFound));
                return(false);
            }
            var userItem = TexasApplication.GetRoomUser(roomID, peerId);

            if (userItem == null)
            {
                serverPeer.SendMessage(new Response((byte)TexasOperationCode.StartGame, null, errorParam, "User Not Yet Join Room", (int)RoomErrorCode.UserNotYetJoinRoom));
                return(false);
            }

            // check 4 man
            string         json           = operation.TexasStartGame;
            TexasStartGame texasStartGame = JsonConvert.DeserializeObject <TexasStartGame>(json) as TexasStartGame;

            // Log.DebugFormat("TEXAS GAME VALIDATE");

            // var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            var stateMachine = facade.RetrieveMediator(TexasStateMachine.NAME) as TexasStateMachine;

            stateMachine.StartGame(texasStartGame);
            return(true);
        }
Exemple #3
0
        public void StartGame(TexasStartGame texasStartGame)
        {
            //
            Log.DebugFormat("TEXAS GAME FIRE START: " + this.States.State);
            SendNotification(TexasTrigger.state_start_game.ToString("G"), texasStartGame);

            var texasModel = this.Facade.RetrieveProxy(TexasModel.NAME) as TexasModel;

            if (texasModel.isPlaying && this.States.State == StateCode.StartGame)
            {
                Log.DebugFormat("READY NEXT STATE TO PLAY: " + this.States.State);
                States.Fire(TexasTrigger.state_play);
                SendNotification(TexasTrigger.state_play.ToString("G"), texasStartGame);
            }
            // States.Fire(_startGameTrigger, texasStartGame);
            //
            // stateChanged();
        }
        private void sendStartGame(TexasModel texasModel)
        {
            Log.DebugFormat("SEND START GAME");
            // send start game
            TexasStartGame texasStartgame = new TexasStartGame();

            texasStartgame.BigBlindIndex   = texasModel.BigBlindIndex;
            texasStartgame.DealderIndex    = texasModel.DealerIndex;
            texasStartgame.SmallBlindIndex = texasModel.SmallBlindIndex;
            texasStartgame.TableState      = texasModel.TableState;

            var param2 = new Dictionary <byte, object>()
            {
                { (byte)ParameterCode.TexasStart, JsonConvert.SerializeObject(texasStartgame) },
            };

            var eevent2 = new Event((byte)TexasEventCode.StartGame, null, param2);

            this.SendNotification(RoomNotification.SEND_EVENT_TO_ALL_USER, eevent2);
        }