예제 #1
0
    public void PopulateStateRewardScreen(bool allowCommon, bool allowRare, bool allowBoss)
    {
        Debug.Log("RewardScreen.PopulateStateRewardScreen() called...");

        // get potential state rewards
        List <StateDataSO> viableStates = new List <StateDataSO>();

        if (allowCommon)
        {
            viableStates.AddRange(StateLibrary.Instance.GetAllCommonStates());
        }
        if (allowRare)
        {
            viableStates.AddRange(StateLibrary.Instance.GetAllRareStates());
        }
        if (allowBoss)
        {
            viableStates.AddRange(StateLibrary.Instance.GetAllBossStates());
        }

        // Generate random state for state reward 1
        GameObject newStateOne = Instantiate(PrefabHolder.Instance.StateCard, ChooseStateScreenContent.transform);
        StateCard  stateOne    = newStateOne.GetComponent <StateCard>();

        stateOne.BuildFromStateData(viableStates[Random.Range(0, viableStates.Count)]);
        currentStateOne = newStateOne;

        // Generate random state for state reward 2
        GameObject newStateTwo = Instantiate(PrefabHolder.Instance.StateCard, ChooseStateScreenContent.transform);
        StateCard  stateTwo    = newStateTwo.GetComponent <StateCard>();

        stateTwo.BuildFromStateData(viableStates[Random.Range(0, viableStates.Count)]);
        currentStateTwo = newStateTwo;

        // Prevent duplicate items appearing as reward: Reroll item until we get a non-duplicate
        while (stateTwo.myStateData.stateName == stateOne.myStateData.stateName)
        {
            Debug.Log("RewardScreen.PopulateStateScreen() detected a duplicate state reward, rerolling state two...");
            stateTwo.BuildFromStateData(viableStates[Random.Range(0, viableStates.Count)]);
        }

        // Generate random state for state reward 3
        GameObject newStateThree = Instantiate(PrefabHolder.Instance.StateCard, ChooseStateScreenContent.transform);
        StateCard  stateThree    = newStateThree.GetComponent <StateCard>();

        stateThree.BuildFromStateData(viableStates[Random.Range(0, viableStates.Count)]);
        currentStateThree = newStateThree;

        // Prevent duplicate items appearing as reward: Reroll item until we get a non-duplicate
        while (stateThree.myStateData.stateName == stateOne.myStateData.stateName ||
               stateThree.myStateData.stateName == stateTwo.myStateData.stateName)
        {
            Debug.Log("RewardScreen.PopulateStateScreen() detected a duplicate state reward, rerolling state three...");
            stateThree.BuildFromStateData(viableStates[Random.Range(0, viableStates.Count)]);
        }
    }