예제 #1
0
    // Presents the desired dialogue to the user and adds/deducts from player resources accordingly
    void ActivateDialogue()
    {
        // Get selected dialogue from button
        GameObject buttonpressed = EventSystem.current.currentSelectedGameObject;
        string     buttonName    = buttonpressed.GetComponentInChildren <Text>().text;

        Dialogue selectedDialogue = null;

        // Find dialogue
        foreach (Dialogue d in _dialogue)
        {
            if (d.DialogueName == buttonName)
            {
                selectedDialogue = d;
            }
        }

        if (selectedDialogue == null)
        {
            Debug.LogError("No dialogue found that matched button selection!");
            return;
        }

        // Get bot probability of success for selected category
        BotController botController = null;

        if (_isManager)
        {
            foreach (GameObject manager in _gameManager.Managers)
            {
                if (manager.GetComponent <BotController>().GetCharacterName() == _bot)
                {
                    botController = manager.GetComponent <BotController>();
                    break;
                }
            }
        }
        else
        {
            foreach (GameObject bot in _gameManager.Bots)
            {
                if (bot.GetComponent <BotController>().GetCharacterName() == _bot)
                {
                    botController = bot.GetComponent <BotController>();
                    break;
                }
            }
        }

        if (botController == null)
        {
            Debug.LogError("Couldn't find bot object with name: " + _bot);
            return;
        }

        int probOfSuccess = botController.GetProbabilityOfSuccess(_dialogueType);

        if (probOfSuccess < 0)
        {
            Debug.LogError("Invalid type key: " + _dialogueType);
            return;
        }

        // Spend money on selection
        _gameManager.SpendMoney(selectedDialogue.Price);

        // Insult player and/or bot accordingly
        if (_insultedBot != null && _insultedBot == _bot)
        {
            DisplayDialogue(_insultedBot + " " + selectedDialogue.PlayerMessage, selectedDialogue.ErrorInsultResponse);
            _gameManager.IncrementInfluence(-10);
        }
        else if (IsSuccessful(probOfSuccess))
        {
            if (_insultedBot != null)
            {
                _gameManager.IncrementBotInfluence(_insultedBot, -1 * selectedDialogue.BotInfluenceDamage);
                DisplayDialogue(_insultedBot + " " + selectedDialogue.PlayerMessage, selectedDialogue.SuccessResponse);
            }
            else
            {
                DisplayDialogue(selectedDialogue.PlayerMessage, selectedDialogue.SuccessResponse);
            }

            _gameManager.IncrementInfluence(selectedDialogue.InfluenceChange);
            _gameManager.IncrementMultiplier(selectedDialogue.MultiplierChange);
        }
        else
        {
            if (_insultedBot != null)
            {
                _gameManager.IncrementBotInfluence(_insultedBot, selectedDialogue.BotInfluenceDamage);
                DisplayDialogue(_insultedBot + " " + selectedDialogue.PlayerMessage, selectedDialogue.FailureResponse);
                _gameManager.IncrementInfluence(-2 * selectedDialogue.InfluenceChange);
            }
            else
            {
                DisplayDialogue(selectedDialogue.PlayerMessage, selectedDialogue.FailureResponse);
                _gameManager.IncrementInfluence(-1 * selectedDialogue.InfluenceChange);
                _gameManager.IncrementMultiplier(-1 * selectedDialogue.MultiplierChange);
            }
        }
    }