Пример #1
0
        private void gameOver(DebugGameRoom room)
        {
            ServerLogger.LogDebug("game real over", room);

            myServerManager.SendUpdateState(room);

            myServerManager.SendGameOver(room);

            rooms.Remove(room);
            room.Fiber.Reset();
        }
Пример #2
0
        private void askPlayerQuestion(DebugGameRoom room, DebugFiberYieldResponse answer)
        {
            gameData.TotalQuestionsAnswered++;

            var answ = answer.Question;

            if (answ == null)
            {
                ServerLogger.LogDebug("game question over", room);
                myServerManager.SendGameOver(room);
                room.Fiber.Run<DebugFiberYieldResponse>();
                //     profiler.takeSnapshot('game over ' + room.roomID);
                return;
            }
            askQuestion(answ, room);
            //ServerLogger.Log(gameData.toString());

            var dt = new DateTime();
            var then = dt.GetMilliseconds();
            //ServerLogger.Log(then - now + " Milliseconds");
            //  ServerLogger.Log(gameData.TotalQuestionsAnswered / ((dt.GetTime() - startTime.GetTime()) / 1000d) + " Answers per seconds", LogLevel.DebugInformation);
        }
Пример #3
0
        private void breakGameExecution(DebugGameRoom room, DebugFiberYieldResponse response)
        {

            var ganswer = new DebugGameBreakModel(response.LineNumber, response.Value);

            myServerManager.SendDebugBreak(room, ganswer);
        }
Пример #4
0
        private void logGameConsoleLine(DebugGameRoom room, DebugFiberYieldResponse answer)
        {
            var answ2 = room.Fiber.Run<DebugFiberYieldResponse>();
            processGameResponse(room, answ2);

            if (!room.Game.CardGame.Emulating)
            { 
                myServerManager.SendDebugLog(room, new DebugGameLogModel(answer.Contents));
            }
        }
Пример #5
0
        private void processGameResponse(DebugGameRoom room, DebugFiberYieldResponse response)
        {
            if (response == null)
            {
                ServerLogger.LogDebug("game request over", room);

                myServerManager.SendGameOver(room);
                room.Fiber.Run<DebugFiberYieldResponse>();
                rooms.Remove(room);
                room.Unwind(room.Players);
                return;
            }


            switch (response.Type)
            {
                case DebugFiberYieldResponseType.AskQuestion:
                    askPlayerQuestion(room, response);
                    break;

                case DebugFiberYieldResponseType.PlayersLeft:
                    didPlayersLeave(room, response);
                    break;
                case DebugFiberYieldResponseType.GameOver:
                    gameOver(room);
                    break;
                case DebugFiberYieldResponseType.Log:
                    logGameConsoleLine(room, response);
                    break;
                case DebugFiberYieldResponseType.VariableLookup:
                    Console.WriteLine("vlook  " + Json.Stringify(response));
                    breakGameExecution(room, response);
                    break;
                case DebugFiberYieldResponseType.Break:
                    Console.WriteLine("broke  " + Json.Stringify(response));
                    breakGameExecution(room, response);
                    break;
            }
        }
Пример #6
0
        private void didPlayersLeave(DebugGameRoom room, DebugFiberYieldResponse response)
        {
            room.Fiber.Run<DebugFiberYieldResponse>(room.PlayersLeft);

            room.PlayersLeft.Clear();
        }
Пример #7
0
        private void startGame(DebugGameRoom room)
        {
            if (!room.Started)
            {
                myServerManager.SendGameStarted(room);

                room.Started = true;
            }


            var answer = room.Fiber.Run<DebugFiberYieldResponse>(room.Players);
            processGameResponse(room, answer);
        }
 public void SendGameStarted(DebugGameRoom room)
 {
     SendMessageToTester(room, "Area.Debug.Started", new GameRoomModel() { RoomID = room.RoomID });
 }
 public void SendDebugBreak(DebugGameRoom room, DebugGameBreakModel ganswer)
 {
     qManager.SendMessage(room.DebuggingSender.Gateway, "Area.Debug.Break", room.DebuggingSender, ganswer);
 }
Пример #10
0
        public void CreateGame(UserLogicModel user, CreateDebugGameRequest data)
        {
            ServerLogger.LogDebug("--debug game created ", data);
            dataManager.SiteData.Game_GetGamesByName(data.GameName, (game) =>
            {
                if (game == null)
                {
                    ServerLogger.LogDebug("--game not found " + data.GameName, user);
                    return;
                }
                ServerLogger.LogDebug("--game found " + game.Name, game);

                DebugGameRoom room;
                rooms.Add(room = new DebugGameRoom());
                room.MaxUsers = data.NumberOfPlayers; //todo idk
                room.GameType = data.GameName;
                room.Started = false;
                for (int i = 0; i < data.NumberOfPlayers; i++)
                {
                    room.Players.Add(user);

                }
                room.DebuggingSender = user;
                
                GameObject evaluated_game = null;
                Script.Eval("evaluated_game=" + processor.ProcessJSFile(game.GameCode.Code));
                GameObject gameObject;
                gameObject = evaluated_game;


                room.Fiber = CreateFiber(room, gameObject, true, game, data.Breakpoints);
                room.Unwind = players =>
                {
                    gameData.FinishedGames++;
                    ServerLogger.LogDebug("--game closed", game);
                };
                room.PlayerLeave += (player) =>
                {
                    //todo laeve player api in the game
                    ////i think an action that it calls

                    room.Players.Remove(player);
                    room.PlayersLeft.Add(player);


                    if (room.Players.Count == 0)
                    { 
                        rooms.Remove(room);
                        room.Fiber.Reset();
                    }
                };

                myServerManager.RegisterGameServer(user);


                startGame(room);
            });
        }
 public void SendDebugLog(DebugGameRoom room, DebugGameLogModel ganswer)
 {
     qManager.SendMessage(room.DebuggingSender.Gateway, "Area.Debug.Log", room.DebuggingSender, ganswer);
 }
 public void SendUpdateState(DebugGameRoom room)
 {
     SendMessageToTester(room, "Area.Debug.UpdateState", new Compressor().CompressText(Json.Stringify(room.Game.CardGame.CleanUp())));
 }
        public void SendGameOver(DebugGameRoom room) 
        {
            SendMessageToTester(room, "Area.Debug.GameOver", "a");

        }
Пример #14
0
        private void askQuestion(CardGameQuestion answ, DebugGameRoom room)
        {
            var user = getPlayerByUsername(room, answ.User.UserName);
            myServerManager.SendAskQuestion(user, new DebugGameSendAnswerModel(answ.Question, answ.Answers));
            myServerManager.SendUpdateState(room);


            ServerLogger.LogDebug("Ask question   ", answ);
        }
Пример #15
0
        private Fiber<List<UserLogicModel>> CreateFiber(DebugGameRoom room, GameObject gameObject, bool emulating, GameDataModel game, List<int> breakpoints)
        {
            return new Fiber<List<UserLogicModel>>(players =>
            {
                if (players == null || players.Count == 0) return true;
                room.Players = players;
                ServerLogger.LogDebug("game started", room);
                GameObject sev = null;

                Script.Eval("sev = new gameObject();");
                room.PlayersLeft = new List<UserLogicModel>();
                sev.CardGame=new GameCardGame();
                sev.CardGame.Emulating = emulating;
                room.Game = sev;
                sev.CardGame.DebugInfo = new DebugInfo() { Breakpoints = breakpoints ?? new List<int>() };
                sev.CardGame.SetEmulatedAnswers(room.EmulatedAnswers);
                sev.CardGame.SetPlayers(players);
                sev.CardGame.Size = new Size(game.GameLayout.Width, game.GameLayout.Height);

                foreach (var gameTextModel in game.GameLayout.Texts)
                {
                    sev.CardGame.TextAreas.Add(new GameCardGameTextArea(new GameCardGameTextAreaOptions()
                    {
                        X = gameTextModel.Left,
                        Y = gameTextModel.Top,
                        Name = gameTextModel.Name,
                        Text = gameTextModel.Text,

                    }));
                }


                foreach (var gameSpaceModel in game.GameLayout.Spaces)
                {
                    sev.CardGame.Spaces.Add(new CardGameTableSpace(new CardGameTableSpaceOptions()
                    {
                        X = gameSpaceModel.Left,
                        Y = gameSpaceModel.Top,
                        Height = gameSpaceModel.Height,
                        Width = gameSpaceModel.Width,
                        Name = gameSpaceModel.Name,
                        Vertical = gameSpaceModel.Vertical,
                        ResizeType = gameSpaceModel.ResizeType
                    }));
                }

                foreach (var gameEffect in game.Effects)
                {
                    sev.CardGame.Effects.Add(new CardGameEffect(new CardGameEffectOptions()
                    {
                        Name = gameEffect.Name,
                        Type = gameEffect.Type,
                        Properties = gameEffect.Properties.Map(a => new CardGameEffectProperty() { Name = a.Name, Value = a.Value })
                    }));
                }

                gameData.TotalGames++;
                gameData.TotalPlayers += players.Count;
                sev.CardGame.EmulatedAnswerIndex = 0;

                //todo to data
                sev.CardGame.NumberOfCards = 52;
                sev.CardGame.NumberOfJokers = 0;

                sev.CardGame.ConfigurationCompleted();
                sev.Constructor();
                sev.RunGame();
                ServerLogger.LogDebug("Doneski", gameData);

                room.Unwind(players);
                return true;
            });
        }
Пример #16
0
 private UserLogicModel getPlayerByUsername(DebugGameRoom room, string userName)
 {
     foreach (var player in room.Players)
     {
         if (player.UserName == userName)
             return player;
     }
     return null;
 }
 private void SendMessageToTester(DebugGameRoom room, string message, object val)
 {
     qManager.SendMessage(room.DebuggingSender.Gateway, message, room.DebuggingSender, val);
 }