private IEnumerator InitGameGlobals()
    {
        string configText = "";

        GameProperties.configurableProperties = new DynamicallyConfigurableGameProperties();


        //Assign configurable game properties from file if any
        //Application.ExternalEval("console.log('streaming assets: "+ Application.streamingAssetsPath + "')");

        string path = Application.streamingAssetsPath + "/config.cfg";

        if (path.Contains("://") || path.Contains(":///")) //url instead of path
        {
            WWW www = new WWW(path);
            yield return(www);

            configText = www.text;
        }
        else
        {
            configText = File.ReadAllText(path);
        }

        UpdateGameConfig(configText);


        GameGlobals.numberOfSpeakingPlayers = 0;
        GameGlobals.currGameId++;
        GameGlobals.currGameRoundId = 0;
        GameGlobals.albumIdCount    = 0;

        GameGlobals.gameDiceNG   = new RandomDiceNG();
        GameGlobals.audioManager = new AudioManager();


        //GameGlobals.playerIdCount = 0;
        //GameGlobals.albumIdCount = 0;

        GameGlobals.albums = new List <Album>(GameProperties.configurableProperties.numberOfAlbumsPerGame);

        //destroy UIs if any
        if (GameGlobals.players != null && GameGlobals.players.Count > 0)
        {
            UIPlayer firstUIPlayer = null;
            int      pIndex        = 0;
            while (firstUIPlayer == null && pIndex < GameGlobals.players.Count)
            {
                firstUIPlayer = (UIPlayer)GameGlobals.players[pIndex++];
                if (firstUIPlayer != null)
                {
                    firstUIPlayer.GetWarningScreenRef().DestroyPoppupPanel();
                    Destroy(firstUIPlayer.GetPlayerCanvas());
                }
            }
        }
        GameGlobals.players = new List <Player>(GameProperties.configurableProperties.numberOfPlayersPerGame);


        GameGlobals.gameLogManager = new MongoDBLogManager();
        GameGlobals.gameLogManager.InitLogs();

        //only generate session data in the first game
        if (GameGlobals.currGameId == 1)
        {
            //GameGlobals.gameLogManager = new DebugLogManager();


            string date = System.DateTime.Now.ToString("ddHHmm");

            //generate external game code from currsessionid and lock it in place
            //gamecode is in the format ddmmhhmmss<3RandomLetters>[TestGameCondition]

            string generatedCode = date; //sb.ToString();

            //generate 3 random letters
            for (int i = 0; i < 3; i++)
            {
                generatedCode += (char)('A' + Random.Range(0, 26));
            }

            GameGlobals.currSessionId = generatedCode;

            //update the gamecode UI
            //GameObject UIGameCodeDisplay = Object.Instantiate(UIGameCodeDisplayPrefab);
            //UIGameCodeDisplay.GetComponentInChildren<Text>().text = "Game Code: " + GameGlobals.currSessionId;
            //Object.DontDestroyOnLoad(UIGameCodeDisplay);
        }
        else
        {
            this.UIStartGameButton.interactable = true;
        }

        if (GameProperties.configurableProperties.isAutomaticalBriefing)                       //generate condition automatically (asynchronous)
        {
            GameGlobals.gameLogManager.GetLastSessionConditionFromLog(YieldedActionsAfterGet); //changes session code
        }
        else
        {
            //create session parameterization
            SessionParameterization mock = new SessionParameterization("mock");
            GameProperties.configurableProperties.possibleParameterizations.Add(mock);
            this.UIStartGameButton.interactable = true;

            GameProperties.configurableProperties.numSessionGames = 0; //not used
        }


        //init fatima strings
        GameGlobals.FAtiMAScenarioPath = "/Scenarios/ForTheRecord-EN.iat";

        AssetManager.Instance.Bridge = new AssetManagerBridge();
        GameGlobals.FAtiMAIat        = IntegratedAuthoringToolAsset.LoadFromFile(GameGlobals.FAtiMAScenarioPath);
    }
Exemple #2
0
    public void InitGame()
    {
        interruptionRequests = 0;
        InterruptGame(); //interrupt game update while loading...

        choosePreferedInstrumentResponseReceived = false;
        playForInstrumentResponseReceived        = false;
        levelUpResponseReceived      = false;
        lastDecisionResponseReceived = false;
        currPlayerIndex = 0;


        //get player poppups (can be from any player) and set methods
        if (GameGlobals.players.Count > 0)
        {
            UIPlayer firstUIPlayer = null;
            int      pIndex        = 0;
            while (firstUIPlayer == null && pIndex < GameGlobals.players.Count)
            {
                firstUIPlayer = (UIPlayer)GameGlobals.players[pIndex++];
                if (firstUIPlayer != null)
                {
                    firstUIPlayer.GetWarningScreenRef().AddOnShow(InterruptGame);
                    firstUIPlayer.GetWarningScreenRef().AddOnHide(ContinueGame);
                }
            }
        }
        infoPoppupLossRef    = new PoppupScreenFunctionalities(false, InterruptGame, ContinueGame, poppupPrefab, canvas, GameGlobals.monoBehaviourFunctionalities, Resources.Load <Sprite>("Textures/UI/Icons/InfoLoss"), new Color(0.9f, 0.8f, 0.8f), "Audio/albumLoss");
        infoPoppupWinRef     = new PoppupScreenFunctionalities(false, InterruptGame, ContinueGame, poppupPrefab, canvas, GameGlobals.monoBehaviourFunctionalities, Resources.Load <Sprite>("Textures/UI/Icons/InfoWin"), new Color(0.9f, 0.9f, 0.8f), "Audio/albumVictory");
        infoPoppupNeutralRef = new PoppupScreenFunctionalities(false, InterruptGame, ContinueGame, poppupPrefab, canvas, GameGlobals.monoBehaviourFunctionalities, Resources.Load <Sprite>("Textures/UI/Icons/Info"), new Color(0.9f, 0.9f, 0.9f), "Audio/snap");

        //these poppups load the end scene
        endPoppupLossRef = new PoppupScreenFunctionalities(false, InterruptGame, ContinueGame, poppupPrefab, canvas, GameGlobals.monoBehaviourFunctionalities, Resources.Load <Sprite>("Textures/UI/Icons/InfoLoss"), new Color(0.9f, 0.8f, 0.8f), delegate() { /*end game*/ if (this.gameMainSceneFinished)
                                                                                                                                                                                                                                                                             {
                                                                                                                                                                                                                                                                                 GameSceneManager.LoadEndScene();
                                                                                                                                                                                                                                                                             }
                                                                                                                                                                                                                                                                             return(0); });
        endPoppupWinRef = new PoppupScreenFunctionalities(false, InterruptGame, ContinueGame, poppupPrefab, canvas, GameGlobals.monoBehaviourFunctionalities, Resources.Load <Sprite>("Textures/UI/Icons/InfoWin"), new Color(0.9f, 0.9f, 0.8f), delegate() { /*end game*/ if (this.gameMainSceneFinished)
                                                                                                                                                                                                                                                                           {
                                                                                                                                                                                                                                                                               GameSceneManager.LoadEndScene();
                                                                                                                                                                                                                                                                           }
                                                                                                                                                                                                                                                                           return(0); });

        ChangeActivePlayerUI(((UIPlayer)(GameGlobals.players[0])), 2.0f);


        gameMainSceneFinished       = false;
        preferredInstrumentsChoosen = false;

        //diceRollDelay = UIRollDiceForInstrumentOverlay.GetComponent<Animator>().GetCurrentAnimatorStateInfo(0).length;
        diceRollDelay = 4.0f;

        canCheckAlbumResult         = false;
        checkedAlbumResult          = false;
        canSelectToCheckAlbumResult = true;
        int numPlayers = GameGlobals.players.Count;

        Player currPlayer = null;

        for (int i = 0; i < numPlayers; i++)
        {
            currPlayer = GameGlobals.players[i];
            currPlayer.ReceiveGameManager(this);
            currPlayer.ReceiveTokens(1);
        }

        GameGlobals.currGameRoundId = 0; //first round
        numMegaHits = 0;

        marketLimit             = Mathf.FloorToInt(GameProperties.configurableProperties.numberOfAlbumsPerGame * 4.0f / 5.0f) - 1;
        currNumberOfMarketDices = GameProperties.configurableProperties.initNumberMarketDices;

        rollDiceForInstrumentOverlayAnimator = UIRollDiceForInstrumentOverlay.GetComponent <Animator>();

        ContinueGame();
    }