Example #1
0
    public StoryChoiceButton BuildChoiceButtonFromChoiceData(StoryChoiceDataSO data)
    {
        Debug.Log("StoryEventController.BuildChoiceButtonFromChoiceData() called for choice: " + data.description);

        // Create game object, parent to the vertical fitter
        StoryChoiceButton newButton = Instantiate(choiceButtonPrefab, choiceButtonsParent.transform).GetComponent <StoryChoiceButton>();

        // Cache data
        newButton.myChoiceData = data;
        activeChoiceButtons.Add(newButton);

        // Set button main label text
        newButton.descriptionText.text = data.description;

        // set requirment text
        AutoSetChoiceButtonRequirementText(newButton, data);

        // set consequence texts
        AutoSetChoiceButtonSuccessConsequencesText(newButton, data);
        AutoSetChoiceButtonFailureConsequencesText(newButton, data);

        // calculate success chance, set related text values
        newButton.successChanceText.text = CalculateFinalSuccessChanceOfChoiceData(newButton.myChoiceData).ToString() + "%";

        // return the button just made
        return(newButton);
    }
Example #2
0
    public void AutoSetChoiceButtonFailureConsequencesText(StoryChoiceButton button, StoryChoiceDataSO data)
    {
        Debug.Log("StoryEventController.AutoSetChoiceButtonFailureConsequencesText() called for button: '" +
                  data.description + "'");

        string consequencesString = "";

        // Disable the on failure text elements if they are not needed
        if (data.onFailureConsequences.Count == 0)
        {
            button.onFailureTextRowParent.SetActive(false);
        }
        else
        {
            foreach (ChoiceConsequence cc in data.onFailureConsequences)
            {
                // Add the choice requirement to the final string
                consequencesString += ConvertChoiceConsequenceToString(cc);

                // Seperate each requirement with a comma, if it is not the last req in list
                if (cc != data.onFailureConsequences.Last())
                {
                    consequencesString += ", ";
                }
            }
        }

        // Apply generated string to description text component
        button.failureConsequenceText.text = consequencesString;
    }
Example #3
0
    public void AutoSetChoiceButtonRequirementText(StoryChoiceButton button, StoryChoiceDataSO data)
    {
        Debug.Log("StoryEventController.AutoSetChoiceButtonRequirementText() called for button: '" +
                  data.description + "'");

        string requirementString = "";

        // if there are no requirements in choice req list, just set text to 'None'
        if (data.choiceRequirements.Count == 0)
        {
            requirementString = "None";
        }
        else
        {
            foreach (ChoiceRequirment cr in data.choiceRequirements)
            {
                // Add the choice requirement to the final string
                requirementString += ConvertChoiceRequirementToString(cr);

                // Seperate each requirement with a comma, if it is not the last req in list
                if (cr != data.choiceRequirements.Last())
                {
                    requirementString += ", ";
                }
            }
        }

        // Apply generated string to description text component
        button.requirementsText.text = requirementString;
    }
Example #4
0
    // Mouse + Input Logic
    #region
    public void OnChoiceButtonClicked(StoryChoiceButton buttonClicked)
    {
        Debug.Log("StoryEventController.OnChoiceButtonClicked() called for button: " + buttonClicked.myChoiceData.description);

        if (!buttonClicked.locked)
        {
            StartResolveChoiceProcess(buttonClicked);
        }
        else
        {
            Debug.Log("StoryEventController.OnChoiceButtonClicked() detected that button '" + buttonClicked.myChoiceData.description
                      + "' is locked and is an invalid selection, cancelling resolve button process...");
        }
    }
Example #5
0
    public void StartResolveChoiceFailureProcess(StoryChoiceButton choiceButton)
    {
        Debug.Log("StoryEventController.StartResolveChoiceSuccessfulProcess() called...");

        // Resolve player relevant effects (xp rewards, gain gold, etc)
        foreach (ChoiceConsequence consequence in choiceButton.myChoiceData.onFailureConsequences)
        {
            ResolveChoiceConsequence(consequence);
        }

        // Resolve all GUI updates and events
        foreach (ChoiceResolvedGuiEvent guiEvent in choiceButton.myChoiceData.onFailureGuiEvents)
        {
            ResolveChoiceGuiEvent(guiEvent);
        }
    }
Example #6
0
    // Choice buttons logic
    #region
    public void BuildAllChoiceButtonsFromStoryPage(List <StoryChoiceDataSO> choicesList)
    {
        Debug.Log("StoryEventController.BuildAllChoiceButtonsFromStoryPage() called...");

        foreach (StoryChoiceDataSO data in choicesList)
        {
            // Build a new choice button
            StoryChoiceButton newButton = BuildChoiceButtonFromChoiceData(data);

            // Does the player meet the requirements to enable this choice?
            if (!AreChoiceButtonRequirementsMet(data))
            {
                // They don't, lock the choice button
                LockChoiceButton(newButton);
            }
        }
    }
Example #7
0
    // Resolve Events + Choices + Consequences
    #region
    public void StartResolveChoiceProcess(StoryChoiceButton buttonClicked)
    {
        Debug.Log("StoryEventController.StartResolveChoiceProcess() called...");

        // Did we pass the success chance roll?
        if (DidChoicePassSuccessRoll(buttonClicked))
        {
            // we did, start handle pass result process
            Debug.Log("Event roll PASSED, resolving ON SUCCESS events...");
            StartResolveChoiceSuccessfulProcess(buttonClicked);
        }
        else
        {
            // we failed to roll high enough, start handle fail result process
            Debug.Log("Event roll FAILED, resolving ON FAILURE events...");
            StartResolveChoiceFailureProcess(buttonClicked);
        }
    }
Example #8
0
    public bool DidChoicePassSuccessRoll(StoryChoiceButton choiceButton)
    {
        Debug.Log("StoryEventController.DidChoicePassSuccessRoll() called...");

        bool boolReturned = false;

        // Calculate the roll required to pass the success check
        int rollResultRequired = CalculateFinalSuccessChanceOfChoiceData(choiceButton.myChoiceData);

        // Roll for success
        int rollResultActual = GenerateRandomRollResult();

        if (rollResultActual <= rollResultRequired)
        {
            boolReturned = true;
        }

        return(boolReturned);
    }
Example #9
0
    public void AutoSetChoiceButtonSuccessConsequencesText(StoryChoiceButton button, StoryChoiceDataSO data)
    {
        Debug.Log("StoryEventController.AutoSetChoiceButtonSuccessConsequencesText() called for button: '" +
                  data.description + "'");

        string consequencesString = "";

        foreach (ChoiceConsequence cc in data.onSuccessConsequences)
        {
            // Add the choice requirement to the final string
            consequencesString += ConvertChoiceConsequenceToString(cc);

            // Seperate each requirement with a comma, if it is not the last req in list
            if (cc != data.onSuccessConsequences.Last())
            {
                consequencesString += ", ";
            }
        }

        // Apply generated string to description text component
        button.successConsequenceText.text = consequencesString;
    }
Example #10
0
 public void LockChoiceButton(StoryChoiceButton button)
 {
     button.SetPanelColour(button.disabledColour);
     button.locked = true;
 }
    void SetupElements()
    {
        // Delete all old children
        foreach (Transform child in choiceHolder)
        {
            Destroy(child.gameObject);
        }

        // Put all the refreshable items in.
        storyText.text = currentItem.StoryInfo;

        // Spawn them one at a time
        int index = 0;

        foreach (InteractiveStoryItem.StoryChoice item in currentItem.choices)
        {
            // Skip previously visited onetime destinations, or null (removed) destinations
            if ((item.Disabled == true && (item.cascades == null || item.cascades.historyCascades.Length == 0)) || (storyHistory.Contains(item.pointsTo) && item.pointsTo.OneTimeVisit))
            {
                index++;
                continue;
            }


            // Create the choice button
            Transform inst = Instantiate(choiceButtonPrefab, choiceHolder);

            // Assign text
            StoryChoiceButton choice = inst.GetComponent <StoryChoiceButton>();
            choice.choiceID        = index;
            choice.textObject.text = item.ChoiceString;

            // Increment choice index
            index++;
        }

        // Apply audio loop.
        // Do not alter looping sound if current sound matches prior sound.
        if (loopingSource != null && currentItem.LoopSound != null && loopingSource.clip != currentItem.LoopSound)
        {
            loopingSource.Stop();
            loopingSource.clip = currentItem.LoopSound;
            loopingSource.loop = true; // make sure this is always on.
            loopingSource.Play();
        }

        // Apply one-shot sound.
        if (oneShotSource != null && currentItem.EntrySound != null)
        {
            oneShotSource.PlayOneShot(currentItem.EntrySound);
        }

        // Apply background information.
        // In the event there is no background, hide the image component entirely.
        if (BackgroundElement != null)
        {
            BackgroundElement.enabled = (currentItem.BackgroundPicture != null);
            BackgroundElement.sprite  = currentItem.BackgroundPicture;
        }

        // Record this item to history
        storyHistory.Add(currentItem);
    }