public bool CanBeTalkedEvent(GameObject triggerer = null)
        {
            if (NarrativeManager.Get() == null)
            {
                return(false);
            }

            if (!gameObject.activeSelf || NarrativeManager.Get().IsRunning() || !NarrativeManager.Get().CanInteract())
            {
                return(false);
            }

            if (is_player)
            {
                return(false);
            }

            bool can_be_talked = false;

            foreach (DialogueEvent evt in events_list)
            {
                if (evt.AreConditionsMet(triggerer))
                {
                    can_be_talked = active;
                }
            }

            return(can_be_talked);
        }
        public void Trigger(GameObject triggerer = null)
        {
            if (NarrativeManager.Get().GetCurrent() != this)
            {
                NarrativeManager manager = NarrativeManager.Get();
                if (manager.GetCurrent() != this && !manager.IsInCinematicQueue(this))
                {
                    if (AreConditionsMet(triggerer) && timer >= 0f)
                    {
                        trigger_count++;
                        timer = -trigger_cooldown;
                        NarrativeData.Get().SetTriggerCount(event_id, trigger_count);

                        if (priority)
                        {
                            manager.StartEvent(this);
                        }
                        else
                        {
                            manager.AddCinematicToQueue(this);
                        }
                    }
                }
            }
        }
        public bool CanBeTalkedChoices(GameObject triggerer = null)
        {
            if (NarrativeManager.Get() == null)
            {
                return(false);
            }

            if (!gameObject.activeSelf || NarrativeManager.Get().IsRunning() || !NarrativeManager.Get().CanInteract())
            {
                return(false);
            }

            if (is_player)
            {
                return(false);
            }

            bool can_be_talked = false;

            foreach (DialogueChoice choice in choices_list)
            {
                if (choice.AreConditionsMet(triggerer))
                {
                    can_be_talked = active && !is_player;
                }
            }

            return(can_be_talked);
        }
        void Update()
        {
            if (NarrativeManager.Get().IsPaused())
            {
                return;
            }

            transform.position = new Vector3(-9999f, -9999f, -9999f);

            if (actor == null)
            {
                return;
            }

            GameObject target = NarrativeManager.Get().GetNearestPlayer(actor.transform.position, actor.trigger_radius);

            if (target != null)
            {
                float dist = (target.transform.position - actor.transform.position).magnitude;
                if (dist < actor.trigger_radius && actor.CanBeTalked(target))
                {
                    transform.position = actor.transform.position + offset;

                    if (ButtonIconUI.IsUsingController())
                    {
                        render.sprite = controller_icon;
                    }
                    else
                    {
                        render.sprite = keyboard_icon;
                    }
                }
            }
        }
        private void Awake()
        {
            _instance = this;
            audio_source = GetComponent<AudioSource>();

            if (dialogue_data == null)
                LoadData();
            if (dialogue_data == null)
                dialogue_data = new NarrativeData();
            dialogue_data.FixData();
        }
        public void Trigger(GameObject triggerer)
        {
            if (triggerer == null && actor_player_trigger != null)
            {
                triggerer = actor_player_trigger.gameObject;
            }

            timer = -trigger_cooldown;
            actor_player_trigger = triggerer.GetComponent <DialogueActor>();

            NarrativeManager.Get().StartDiagChoice(this, actor_player_trigger);
        }
        protected override void Update()
        {
            base.Update();

            if (NarrativeManager.Get() == null)
            {
                return;
            }

            if (NarrativeManager.Get().IsPaused())
            {
                return;
            }

            if (current_choices == null)
            {
                return;
            }

            timer += Time.deltaTime;
            if (timer < 1f)
            {
                return;
            }

            bool diag1 = Input.GetKeyDown(NarrativeManager.Get().choice1_button);
            bool diag2 = Input.GetKeyDown(NarrativeManager.Get().choice2_button);
            bool diag3 = Input.GetKeyDown(NarrativeManager.Get().choice3_button);
            bool diag4 = Input.GetKeyDown(NarrativeManager.Get().choice4_button);

            if (diag1)
            {
                SelectChoice(button_map[0]);
            }
            if (diag2)
            {
                SelectChoice(button_map[1]);
            }
            if (diag3)
            {
                SelectChoice(button_map[2]);
            }
            if (diag4)
            {
                SelectChoice(button_map[3]);
            }
            if (Input.GetKeyDown(KeyCode.Return))
            {
                CancelChoice();
            }
        }
        void Update()
        {
            if (NarrativeManager.Get().IsPaused())
            {
                return;
            }

            if (IsRunning())
            {
                DialogueActor player = actor_player_trigger;

                //Check for cancel
                if (player != null)
                {
                    float dist = (player.transform.position - actor_trigger.transform.position).magnitude;
                    if (dist > actor_trigger.trigger_radius)
                    {
                        NarrativeManager.Get().CancelDiagChoice();
                    }
                }
            }

            else
            {
                timer += Time.deltaTime;
                if (timer > 0f)
                {
                    //Trigger cinematic with actor
                    if (actor_trigger != null && actor_trigger.CanBeTalkedChoices())
                    {
                        GameObject player         = NarrativeManager.Get().GetNearestPlayer(actor_trigger.transform.position, actor_trigger.trigger_radius, true);
                        bool       accept_pressed = Input.GetKeyDown(NarrativeManager.Get().talk_button);

                        if (player != null && accept_pressed)
                        {
                            float dist = (player.transform.position - actor_trigger.transform.position).magnitude;
                            if (dist < actor_trigger.trigger_radius)
                            {
                                if (AreConditionsMet())
                                {
                                    Trigger(player);
                                }
                            }
                        }
                    }
                }
            }
        }
        void Update()
        {
            if (NarrativeManager.Get().IsPaused())
            {
                return;
            }

            timer += Time.deltaTime;

            if (execList.Count > 0)
            {
                if (timer >= 0f)
                {
                    NarrativeEffect effect = execList[0];
                    execList.RemoveAt(0);

                    if (effect.enabled)
                    {
                        effect.Trigger(last_triggerer);
                        timer = -effect.GetWaitTime();
                    }

                    CheckIfEnd();
                }
            }
            else if (childExecList.Count > 0)
            {
                //Still running
                if (timer >= 0f)
                {
                    NarrativeChild child = childExecList[0];
                    childExecList.RemoveAt(0);

                    float wait = child.RunIfMet(last_triggerer);
                    timer = -wait;

                    CheckIfEnd();
                }
            }
            else
            {
                if (trigger_type == NarrativeEventType.AutoTrigger && AreConditionsMet())
                {
                    Run();
                }
            }
        }
        public void SelectChoice(int choice)
        {
            if (current_choices == null)
            {
                return;
            }

            if (choice < 0)
            {
                return;
            }

            if (choice < current_choices.GetChoices().Length)
            {
                NarrativeManager.Get().DoDiagChoice(choice);
            }
        }
Exemple #11
0
        void Start()
        {
            choices_list = DialogueChoice.GetAllOf(this);
            events_list  = DialogueEvent.GetAllOf(this);

            if (portrait_zoomed_prefab)
            {
                GameObject portrait = Instantiate(portrait_zoomed_prefab);
                portrait_instance = portrait.GetComponent <CinematicActorPortrait>();
                portrait.SetActive(false);
            }

            if (NarrativeManager.Get() != null)
            {
                GameObject tbtn = Instantiate(NarrativeManager.Get().talk_button_prefab, transform.position, Quaternion.identity);
                tbtn.GetComponent <ButtonDisplayTalk>().actor = this;
            }
        }
Exemple #12
0
        void Update()
        {
            if (NarrativeManager.Get().IsPaused())
            {
                return;
            }

            timer += Time.deltaTime;

            if (timer > 0.25f)
            {
                timer = 0f;

                //Trigger cinematic with actor
                if (actor_trigger != null && actor_trigger.active)
                {
                    GameObject player = NarrativeManager.Get().GetNearestPlayer(actor_trigger.transform.position, actor_trigger.trigger_radius);

                    //Start auto
                    if (player != null && auto_start && AreConditionsMet())
                    {
                        Trigger(player);
                    }
                }
            }

            bool accept_pressed = Input.GetKeyDown(NarrativeManager.Get().talk_button);

            if (actor_trigger != null && actor_trigger.active && accept_pressed)
            {
                GameObject player = NarrativeManager.Get().GetNearestPlayer(actor_trigger.transform.position, actor_trigger.trigger_radius);

                //Start with button
                if (player != null && !auto_start && actor_trigger.CanBeTalkedEvent())
                {
                    if (AreConditionsMet())
                    {
                        Trigger(player);
                    }
                }
            }
        }
Exemple #13
0
        public void TriggerSkipConditions(GameObject triggerer = null)
        {
            NarrativeManager manager = NarrativeManager.Get();

            if (manager.GetCurrent() != this)
            {
                trigger_count++;
                timer = -trigger_cooldown;
                NarrativeData.Get().SetTriggerCount(event_id, trigger_count);

                if (priority)
                {
                    manager.StartEvent(this);
                }
                else
                {
                    manager.AddCinematicToQueue(this);
                }
            }
        }
 public bool IsRunning()
 {
     return(NarrativeManager.Get().GetCurrentChoice() == this);
 }
Exemple #15
0
 public static NarrativeData Get()
 {
     return(NarrativeManager.Get().dialogue_data);
 }
 public void CancelChoice()
 {
     NarrativeManager.Get().CancelDiagChoice();
 }
        public void Trigger(GameObject triggerer)
        {
            if (type == NarrativeEffectType.CustomInt)
            {
                NarrativeData.Get().SetCustomInt(target_id, value_int);
            }

            if (type == NarrativeEffectType.CustomFloat)
            {
                NarrativeData.Get().SetCustomFloat(target_id, value_float);
            }

            if (type == NarrativeEffectType.CustomString)
            {
                NarrativeData.Get().SetCustomString(target_id, value_string);
            }

            if (type == NarrativeEffectType.Move)
            {
                GameObject targ     = target.GetTargetObject();
                GameObject targ_pos = value_object;
                if (targ != null && targ_pos != null)
                {
                    targ.transform.position = targ_pos.transform.position;
                }
            }

            if (type == NarrativeEffectType.Show)
            {
                GameObject targ = target.GetTargetObject();
                if (targ)
                {
                    targ.SetActive(true);
                }
            }

            if (type == NarrativeEffectType.Hide)
            {
                GameObject targ = target.GetTargetObject();
                if (targ)
                {
                    targ.SetActive(false);
                }
            }

            if (type == NarrativeEffectType.Spawn)
            {
                GameObject targ = target.GetTargetObject();
                if (targ != null)
                {
                    GameObject.Instantiate(targ, triggerer.transform.position, Quaternion.identity);
                }
            }

            if (type == NarrativeEffectType.Destroy)
            {
                GameObject targ = target.GetTargetObject(triggerer);
                Destroy(targ);
            }

            if (type == NarrativeEffectType.DestroyHeld)
            {
                GameObject targ = target.GetTargetObject(triggerer);
                if (targ && targ.GetComponent <CharacterHoldItem>())
                {
                    CarryItem item = targ.GetComponent <CharacterHoldItem>().GetHeldItem();
                    if (item)
                    {
                        Destroy(item.gameObject);
                    }
                }
            }

            if (type == NarrativeEffectType.StartDialogue)
            {
                GameObject targ = target.GetTargetObject(triggerer);
                if (targ && targ.GetComponent <DialogueEvent>())
                {
                    if (targ.GetComponent <DialogueEvent>().AreConditionsMet())
                    {
                        NarrativeManager.Get().StartEvent(targ.GetComponent <DialogueEvent>());
                    }
                }
                if (targ && targ.GetComponent <DialogueChoice>())
                {
                    if (targ.GetComponent <DialogueChoice>().AreConditionsMet())
                    {
                        targ.GetComponent <DialogueChoice>().Trigger(triggerer);
                    }
                }
            }

            if (type == NarrativeEffectType.LockCamera)
            {
                FollowCamera pcam = FollowCamera.Get();
                if (pcam != null)
                {
                    pcam.LockCameraOn(value_object);
                }
            }

            if (type == NarrativeEffectType.UnlockCamera)
            {
                FollowCamera pcam = FollowCamera.Get();
                if (pcam != null)
                {
                    pcam.UnlockCamera();
                }
            }

            if (type == NarrativeEffectType.LockGameplay)
            {
                foreach (PlayerControls controls in PlayerControls.GetAll())
                {
                    controls.disable_controls = true;
                }
            }

            if (type == NarrativeEffectType.UnlockGameplay)
            {
                foreach (PlayerControls controls in PlayerControls.GetAll())
                {
                    controls.disable_controls = false;
                }
            }

            if (type == NarrativeEffectType.StartQuest)
            {
                NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>();
                NarrativeData.Get().StartQuest(quest.quest_id);
                if (QuestBox.Get())
                {
                    QuestBox.Get().ShowBox(quest, "New Quest");
                }
            }

            if (type == NarrativeEffectType.CancelQuest)
            {
                NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>();
                NarrativeData.Get().CancelQuest(quest.quest_id);
                if (QuestBox.Get())
                {
                    QuestBox.Get().ShowBox(quest, "Quest Failed");
                }
            }

            if (type == NarrativeEffectType.CompleteQuest)
            {
                NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>();
                NarrativeData.Get().CompleteQuest(quest.quest_id);
                if (QuestBox.Get())
                {
                    QuestBox.Get().ShowBox(quest, "Quest Completed");
                }
            }

            if (type == NarrativeEffectType.RunEvent)
            {
                GameObject targ = target.GetTargetObject(triggerer);
                if (targ && targ.GetComponent <NarrativeEvent>())
                {
                    targ.GetComponent <NarrativeEvent>().Run(triggerer);
                }
            }

            if (type == NarrativeEffectType.RunEventIfMet)
            {
                GameObject targ = target.GetTargetObject(triggerer);
                if (targ && targ.GetComponent <NarrativeEvent>())
                {
                    targ.GetComponent <NarrativeEvent>().RunIfConditionsMet(triggerer);
                }
            }

            if (type == NarrativeEffectType.CallFunction)
            {
                if (callfunc_evt != null)
                {
                    callfunc_evt.Invoke();
                }
            }
        }
        void Update()
        {
            if (NarrativeManager.Get().IsPaused())
                return;

            interact_timer += Time.deltaTime;

            if (current_event != null)
            {
                cinematic_timer += Time.deltaTime;
                dialogue_timer += Time.deltaTime;

                //Stop dialogue
                if (current_message != null)
                {
                    bool auto_stop = !current_event.zoomed_in || (current_actor == null);
                    if (auto_stop)
                    {
                        if (dialogue_timer > current_message.duration + current_message.pause)
                        {
                            StopDialogue();
                        }
                        else if (dialogue_timer > current_message.duration)
                        {
                            HideDialogue();
                        }
                    }
                }

                //Skip to next
                if (Input.GetKeyDown(talk_button) && CanInteract())
                {
                    SkipDialogue();
                }

                //Next Dialogue
                if (current_message == null)
                {
                    int index = 0;
                    foreach (DialogueMessage dialogue in current_event.GetDialogues())
                    {
                        if (current_message == null && index > dialogue_index)
                        {
                            dialogue_index = index;
                            if (dialogue.AreConditionsMet())
                                StartDialogue(dialogue);
                        }
                        index++;
                    }

                    //If still null, stop cinematic
                    if (current_message == null)
                        StopEvent();
                }
                
                //Follow dialogue
                UpdateTalkBubble();
            }

            if (current_event == null && cinematic_queue.Count > 0)
            {
                DialogueEvent next = cinematic_queue[0];
                cinematic_queue.RemoveAt(0);
                StartEvent(next);
            }
        }