Пример #1
0
    void Update()
    {
        if (player != null)
        {
            closest = null; // get the closest entity
            foreach (IInteractable interactable in AIData.interactables)
            {
                if (interactable as PlayerCore || interactable == null || !interactable.GetInteractible())
                {
                    continue;
                }

                if (closest == null)
                {
                    closest = interactable;
                }
                else if ((interactable.GetTransform().position - player.transform.position).sqrMagnitude <=
                         (closest.GetTransform().position - player.transform.position).sqrMagnitude)
                {
                    closest = interactable;
                }
            }

            if (closest is IVendor vendor)
            {
                var blueprint = vendor.GetVendingBlueprint();
                var range     = blueprint.range;

                if (!player.GetIsDead() && (closest.GetTransform().position - player.transform.position).sqrMagnitude <= range)
                {
                    for (int i = 0; i < blueprint.items.Count; i++)
                    {
                        if (InputManager.GetKey(KeyName.TurretQuickPurchase))
                        {
                            if (Input.GetKeyDown((1 + i).ToString()))
                            {
                                vendorUI.SetVendor(vendor, player);
                                vendorUI.onButtonPressed(i);
                            }
                        }
                    }
                }
            }
        }
    }
Пример #2
0
    public void next(Dialogue dialogue, int ID, Entity speaker)
    {
        if (dialogue.nodes.Count == 0)
        {
            Debug.LogWarning("Empty dialogue: " + dialogue.name);
            endDialogue(0, false);
            return;
        }

        if (player.GetIsDead())
        {
            Debug.Log("Dead player");
            endDialogue(0, false);
            return;
        }

        // clear everything
        if (buttons != null)
        {
            for (int i = 0; i < buttons.Length; i++)
            {
                Destroy(buttons[i]);
            }
        }

        // find dialogue index
        int currentIndex = getNodeIndex(dialogue, ID);

        if (currentIndex == -1)
        {
            Debug.LogWarning("Missing node '" + ID + "' in " + dialogue.name);
            endDialogue();
            return;
        }
        Dialogue.Node current = dialogue.nodes[currentIndex];

        // check if the node has an action
        switch (current.action)
        {
        case Dialogue.DialogueAction.None:
            AudioManager.PlayClipByID("clip_typing", true);
            break;

        case Dialogue.DialogueAction.Outpost:
            endDialogue(0, false);
            if (speaker.faction != player.faction)
            {
                return;
            }
            if (((Vector3)speakerPos - player.transform.position).magnitude < dialogue.vendingBlueprint.range)
            {
                vendorUI.SetVendor(speaker as IVendor, player);
                vendorUI.openUI();
            }
            endDialogue(0, false);
            return;

        case Dialogue.DialogueAction.Shop:
            OpenTrader((Vector3)speakerPos, dialogue.traderInventory);
            endDialogue(0, false);
            return;

        case Dialogue.DialogueAction.Yard:
            OpenBuilder((Vector3)speakerPos);
            endDialogue(0, false);
            return;

        case Dialogue.DialogueAction.Exit:
            endDialogue(0, true);
            return;

        case Dialogue.DialogueAction.Workshop:
            workshop.yardPosition = (Vector3)speakerPos;
            workshop.InitializeSelectionPhase();
            endDialogue(0, false);
            return;

        case Dialogue.DialogueAction.Upgrader:
            upgraderScript.initialize();
            endDialogue(0, false);
            return;

        default:
            break;
        }

        // radio image
        window.GetComponentInChildren <SelectionDisplayHandler>().AssignDisplay(speaker.blueprint, null);
        window.transform.Find("Name").GetComponent <Text>().text = speaker.blueprint.entityName;

        // change text
        text               = current.text.Replace("<br>", "\n");
        characterCount     = 0;
        nextCharacterTime  = (float)(Time.time + timeBetweenCharacters);
        textRenderer.color = current.textColor;

        // create buttons
        buttons = new GameObject[current.nextNodes.Count];

        for (int i = 0; i < current.nextNodes.Count; i++)
        {
            int nextIndex = getNodeIndex(dialogue, current.nextNodes[i]);
            if (nextIndex == -1)
            {
                Debug.LogWarning("Missing node '" + current.nextNodes[i] + "' in " + dialogue.name);
                endDialogue();
                return;
            }
            Dialogue.Node next = dialogue.nodes[nextIndex];

            Transform button = CreateButton(next.buttonText, null, 24 + 16 * (current.nextNodes.Count - (i + 1))).transform;

            button.GetComponent <Button>().onClick.AddListener(() => {
                Next(dialogue, nextIndex, speaker);
            });
            if (dialogue.nodes[nextIndex].action != Dialogue.DialogueAction.Exit)
            {
                button.GetComponent <Button>().onClick.AddListener(() => {
                    AudioManager.PlayClipByID("clip_select", true);
                    // need condition to ensure no sound clashes occur
                });
            }

            buttons[i] = button.gameObject;
        }
    }