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); } } } } }
//Call if you want to reset the trigger count of all events public static void ResetAll() { foreach (NarrativeEvent evt in GetAll()) { evt.trigger_count = 0; NarrativeData.Get().SetTriggerCount(evt.event_id, 0); } }
public void StartDialogue(DialogueMessage dialogue) { //Debug.Log("Start Dialogue " + dialogue_index); current_message = dialogue; current_actor = dialogue.actor; interact_timer = 0f; Sprite portrait = default_portrait; Sprite portrait_zoom = default_portrait_zoomed; string title = ""; CinematicActorPortrait zoom_portrait = null; int side = 1; bool flipped = false; if (current_actor != null) { portrait = current_actor.portrait; portrait_zoom = current_actor.portrait_zoomed; zoom_portrait = current_actor.GetPortrait(); title = current_actor.title; side = current_message.side != 0 ? current_message.side : (current_actor.is_player ? -1 : 1); flipped = side >= 1; talk_bubble_inst.SetActive(true); } bool display_dialogue = (current_actor != null); if (current_event.zoomed_in) { if (display_dialogue) { DialogueZoomPanel.Get().SetDialogue(title, portrait_zoom, zoom_portrait, current_message.text, side, "", flipped); DialogueZoomPanel.Get().Show(); //TheGame.Instance.LockGameplay(); } } else { DialoguePanel.Get().Set(portrait, title, current_message.text); DialoguePanel.Get().Show(); } if (display_dialogue) NarrativeData.Get().AddToHistory(new DialogueMessageData(title, portrait, current_message.text)); UpdateTalkBubble(); dialogue_timer = 0f; if (audio_source != null && dialogue.voice_clip != null) audio_source.PlayOneShot(dialogue.voice_clip, 0.8f); if (current_message.OnStart != null) { current_message.OnStart.Invoke(); } }
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 Run(GameObject triggerer = null) { //Increment int cur_val = NarrativeData.Get().GetTriggerCount(event_id); NarrativeData.Get().SetTriggerCount(event_id, cur_val + 1); last_triggerer = triggerer; trigger_count++; //Add to exec list execList.AddRange(effects); childExecList.AddRange(childs); }
void Start() { trigger_count = NarrativeData.Get().GetTriggerCount(event_id); //Load dialogues duration = 0f; for (int i = 0; i < transform.childCount; i++) { GameObject child = transform.GetChild(i).gameObject; if (child && child.activeSelf && child.GetComponent <DialogueMessage>()) { DialogueMessage dialogue = child.GetComponent <DialogueMessage>(); dialogues.Add(dialogue); duration += dialogue.duration + dialogue.pause; } } }
public bool AreConditionsMet(GameObject triggerer = null) { bool conditions_met = true; foreach (NarrativeCondition condition in conditions) { if (condition.enabled && !condition.IsMet(triggerer)) { conditions_met = false; } } int game_trigger_count = NarrativeData.Get().GetTriggerCount(event_id); bool below_max = (trigger_limit == 0 || game_trigger_count < trigger_limit) && (trigger_limit == 0 || trigger_count < trigger_limit); return(conditions_met && below_max); }
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 IsMet(GameObject triggerer) { bool condition_met = false; if (type == NarrativeConditionType.None) { condition_met = true; } if (type == NarrativeConditionType.CustomInt) { int i1 = NarrativeData.Get().GetCustomInt(target_id); int i2 = target_type == NarrativeConditionTargetType.Target ? NarrativeData.Get().GetCustomInt(other_target_id) : value_int; condition_met = CompareInt(i1, i2); } if (type == NarrativeConditionType.CustomFloat) { float f1 = NarrativeData.Get().GetCustomFloat(target_id); float f2 = target_type == NarrativeConditionTargetType.Target ? NarrativeData.Get().GetCustomFloat(other_target_id) : value_float; condition_met = CompareFloat(f1, f2); } if (type == NarrativeConditionType.CustomString) { string s1 = NarrativeData.Get().GetCustomString(target_id); string s2 = target_type == NarrativeConditionTargetType.Target ? NarrativeData.Get().GetCustomString(other_target_id) : value_string; condition_met = CompareString(s1, s2); } if (type == NarrativeConditionType.IsVisible) { GameObject targ = target.GetTargetObject(triggerer); condition_met = (targ != null && targ.activeSelf); if (targ != null) { condition_met = targ.activeSelf; } if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } if (type == NarrativeConditionType.HoldItem) { GameObject targ = target.GetTargetObject(triggerer); if (targ && targ.GetComponent <CharacterHoldItem>()) { CharacterHoldItem character = targ.GetComponent <CharacterHoldItem>(); CarryItem item = character.GetHeldItem(); condition_met = (item != null && (item.item_type == value_string || value_string == "")); } if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } if (type == NarrativeConditionType.InsideRegion) { GameObject targ = target.GetTargetObject(triggerer); if (targ && value_object) { if (value_object.GetComponent <Region>()) { condition_met = value_object.GetComponent <Region>().IsInside(targ); } } if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } if (type == NarrativeConditionType.QuestStarted) { if (value_object && value_object.GetComponent <NarrativeQuest>()) { NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>(); condition_met = NarrativeData.Get().IsQuestStarted(quest.quest_id); if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } } if (type == NarrativeConditionType.QuestStartedActive) { if (value_object && value_object.GetComponent <NarrativeQuest>()) { NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>(); condition_met = NarrativeData.Get().IsQuestActive(quest.quest_id); if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } } if (type == NarrativeConditionType.QuestCompleted) { if (value_object && value_object.GetComponent <NarrativeQuest>()) { NarrativeQuest quest = value_object.GetComponent <NarrativeQuest>(); condition_met = NarrativeData.Get().IsQuestCompleted(quest.quest_id); if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } } if (type == NarrativeConditionType.DialogueTriggered) { GameObject targ = target.GetTargetObject(); if (targ && targ.GetComponent <DialogueEvent>()) { DialogueEvent cinema = targ.GetComponent <DialogueEvent>(); condition_met = cinema.GetTriggerCount() >= 1; if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } } if (type == NarrativeConditionType.CustomFunction) { if (custom_condition != null) { if (custom_condition.GetComponent <CustomContidion>() != null) { condition_met = custom_condition.GetComponent <CustomContidion>().IsMet(); } if (oper2 == NarrativeConditionOperator2.IsFalse) { condition_met = !condition_met; } } } return(condition_met); }
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(); } } }