Пример #1
0
    public void Initialize()
    {
        if (player == null)
        {
            player = GameStateManager.Instance.player;
        }

        if (currentEnc != null)
        {
            ui.EncounterImg.sprite = currentEnc.image;
        }


        if (currentEnc.hasCost)
        {
            player.statistics.ModifyHealth(-currentEnc.hpCost);
            player.statistics.ModifyStamina(-currentEnc.staminaCost);
            player.Gold -= currentEnc.goldCost;

            //todo cost item
        }
        if (currentEnc.hasReward)
        {
            player.statistics.ModifyHealth(currentEnc.hpReward);
            player.statistics.ModifyStamina(currentEnc.staminaReward);
            player.Gold += currentEnc.goldReward;

            Debug.Log(currentEnc.rollSleep);
            if (currentEnc.rollSleep != SleepType.none)
            {
                player.statistics.DoSleep(currentEnc.rollSleep);
            }

            if (currentEnc.itemReward != null)
            {
                player.AddCardObject(currentEnc.itemReward);
            }
            //todo reward item
        }

        if (currentEnc.hasCost || currentEnc.hasReward)
        {
            player.UpdateUI();
        }

        if (currentEnc.hasVariable)
        {
            player.EncounterVariable[currentEnc.variableKey] = currentEnc.variableValue;
            Debug.Log(player.EncounterVariable);
        }

        buttons = new List <OptionButton>();

        ui.stateText.text = currentEnc.text;

        if (currentEnc.choices.Count == 0)
        {
            OptionButton tempButton = Instantiate(ui.buttonPrefab, ui.options.transform);
            tempButton.Initialize(0, "Continue");

            buttons.Add(tempButton);
            tempButton.option.onClick.AddListener(() => CloseDialogue());
        }
        else
        {
            for (int i = 0; i < currentEnc.choices.Count; i++)
            {
                if (((currentEnc.choices[i].MustHaveItem && player.HasCard(currentEnc.choices[i].itemName)) ||
                     (currentEnc.choices[i].MustNotHaveItem && !player.HasCard(currentEnc.choices[i].itemName))) || (currentEnc.choices[i].mustHaveVariable &&
                                                                                                                     (player.EncounterVariable.ContainsKey(currentEnc.choices[i].variableKey) &&
                                                                                                                      player.EncounterVariable[currentEnc.choices[i].variableKey] == currentEnc.choices[i].variableValue)) ||
                    (!currentEnc.choices[i].MustHaveItem && !currentEnc.choices[i].mustHaveVariable))
                {
                    OptionButton tempButton = Instantiate(ui.buttonPrefab, ui.options.transform);
                    tempButton.Initialize(i, currentEnc.choices[i].cText);
                    buttons.Add(tempButton);
                    tempButton.option.onClick.AddListener(() => OnClickTask(tempButton.parameter));
                }
            }
        }


        /*
         *
         *
         * for (int i = 0; i < curr.currentState.choices.Count; i++)
         * {
         *  OptionButton tempButton = Instantiate(ui.buttonPrefab, ui.options.transform);
         *  tempButton.Initialize(i, curr.currentState.choices[i].cText);
         *  buttons.Add(tempButton);
         *  tempButton.option.onClick.AddListener(() => OnClickTask(tempButton.parameter));
         *  /*UnityEngine.UI.Text tempText = tempButton.gameObject.transform.GetComponentInChildren<UnityEngine.UI.Text>();
         *  tempText.text = encounters[0].currentState.choices[i].cText;
         *  Debug.Log("i is: " + i);
         *  tempButton.onClick.AddListener(() => OnClickTask(counter));
         *
         * }
         *
         */


        ui.gameObject.SetActive(true);
    }