Esempio n. 1
0
    void CreateNewCard()
    {
        var gameEvent = sceneData.config.events.ElementAt(Random.Range(0, sceneData.config.events.Count));

        sceneData.cardCurrent          = Instantiate(sceneData.cardPrefab, sceneData.sceneRoot);
        sceneData.cardCurrent.isActive = true;
        sceneData.cardCurrent.SetGameEvent(gameEvent);
        sceneData.textEventInfo.text = gameEvent.eventInfo;

        gameData.cardCount     += 1;
        sceneData.timeInfo.text = "Day : " + gameData.cardCount.ToString();

        var iconPos = sceneData.researchIcon.position;

        iconPos.x = sceneData.research.GetRatio() * 4 - 2f;
        sceneData.researchIcon.position = iconPos;

        var endingReason = "";

        foreach (var res in sceneData.resources)
        {
            res.changeOnLeft  = 0;
            res.changeOnRight = 0;
            if (res.isMakeEnding && res.IsEmpty())
            {
                endingReason = res.gameObject.name;
                gameData.SetState(GameState.GameOver);
            }
        }

        if (sceneData.research.IsFull())
        {
            endingReason  = sceneData.research.gameObject.name;
            endingReason += (Random.value > 0.1f) ? ".Good" : ".Bad";
            gameData.SetState(GameState.GameOver);
        }

        if (gameData.state == GameState.GameOver)
        {
            sceneData.textEventInfo.text = "GAME OVER";
            sceneData.endingInfo.gameObject.SetActive(true);
            var ending = sceneData.config.GetEnding(endingReason);
            if (ending != null)
            {
                sceneData.endingInfo.text = ending.textInfo;
                sceneData.cardCurrent.ShowEnding(ending);
            }
        }

        foreach (var result in gameEvent.answerLeft.results)
        {
            if (!sceneData.DictResources().ContainsKey(result.resource))
            {
                continue;
            }
            var res = sceneData.DictResources()[result.resource];
            res.changeOnLeft = Random.Range(result.min, result.max);
        }

        foreach (var result in gameEvent.answerRight.results)
        {
            if (!sceneData.DictResources().ContainsKey(result.resource))
            {
                continue;
            }
            var res = sceneData.DictResources()[result.resource];
            res.changeOnRight = Random.Range(result.min, result.max);
        }
    }