Exemplo n.º 1
0
        public void TryIncrement()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            if (DialogueManager.MasterDatabase == null)
            {
                return;
            }
            if (!(listenForOnDestroy && condition.IsTrue(null)))
            {
                return;
            }
            int oldValue = DialogueLua.GetVariable(ActualVariableName).AsInt;
            int newValue = Mathf.Clamp(oldValue + increment, min, max);

            DialogueLua.SetVariable(ActualVariableName, newValue);
            DialogueManager.SendUpdateTracker();
            if (!(string.IsNullOrEmpty(alertMessage) || DialogueManager.Instance == null))
            {
                if (Mathf.Approximately(0, alertDuration))
                {
                    DialogueManager.ShowAlert(alertMessage);
                }
                else
                {
                    DialogueManager.ShowAlert(alertMessage, alertDuration);
                }
            }
            onIncrement.Invoke();
        }
        /// <summary>
        /// Restarts the game.
        /// </summary>
        public void RestartGame()
        {
            LevelManager levelManager = FindLevelManager();

            if (SaveSystem.instance != null)
            {
                var startingSceneName = (levelManager != null && !string.IsNullOrEmpty(levelManager.defaultStartingLevel)) ? levelManager.defaultStartingLevel : startingLevel;
                SaveSystem.RestartGame(startingSceneName);
            }
            else
            {
                if (levelManager != null)
                {
                    levelManager.RestartGame();
                }
                else
                {
                    DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
                    if (string.IsNullOrEmpty(startingLevel))
                    {
                        Tools.LoadLevel(0);
                    }
                    else
                    {
                        Tools.LoadLevel(startingLevel);
                    }
                    // Update quest tracker HUD:
                    DialogueManager.SendUpdateTracker();
                }
            }
        }
 public void DoAction(LuaAction action, Transform actor)
 {
     if (action == null)
     {
         return;
     }
     Lua.Run(action.luaCode, debugLua);
     DialogueManager.SendUpdateTracker();
 }
Exemplo n.º 4
0
 /// <summary>
 /// Sends the OnApplyPersistentData message to all game objects in the scene to give them an
 /// opportunity to retrieve their state from the Lua environment. If calling this after loading
 /// a new scene, you may want to wait one frame to allow other GameObject's Start methods
 /// to complete first. You can limit which GameObjects receive messages by changing
 /// recordPersistentDataOn.
 /// </summary>
 public static void Apply()
 {
     if (DialogueDebug.logInfo)
     {
         Debug.Log(string.Format("{0}: Applying persistent data from Lua environment.", new System.Object[] { DialogueDebug.Prefix }));
     }
     SendPersistentDataMessage("OnApplyPersistentData");
     DialogueManager.SendUpdateTracker(); // Update quest tracker HUD.
 }
Exemplo n.º 5
0
        /// <summary>
        /// Call this method to manually run the action.
        /// </summary>
        public void Fire()
        {
            // Quest:
            if (!string.IsNullOrEmpty(questName))
            {
                QuestLog.SetQuestState(questName, questState);
            }

            // Lua:
            if (!string.IsNullOrEmpty(luaCode))
            {
                Lua.Run(luaCode, DialogueDebug.logInfo);
                DialogueManager.CheckAlerts();
            }

            // Sequence:
            if (!string.IsNullOrEmpty(sequence))
            {
                DialogueManager.PlaySequence(sequence);
            }

            // Alert:
            if (!string.IsNullOrEmpty(alertMessage))
            {
                string localizedAlertMessage;
                if ((textTable != null) && textTable.HasFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable)))
                {
                    localizedAlertMessage = textTable.GetFieldTextForLanguage(alertMessage, Localization.GetCurrentLanguageID(textTable));
                }
                else
                {
                    localizedAlertMessage = DialogueManager.GetLocalizedText(alertMessage);
                }
                DialogueManager.ShowAlert(localizedAlertMessage);
            }

            // Send Messages:
            foreach (var sma in sendMessages)
            {
                if (sma.gameObject != null && !string.IsNullOrEmpty(sma.message))
                {
                    sma.gameObject.SendMessage(sma.message, sma.parameter, SendMessageOptions.DontRequireReceiver);
                }
            }

            DialogueManager.SendUpdateTracker();

            if (once)
            {
                StopObserving();
                enabled = false;
            }
        }
 public void DoAction(SetQuestStateAction action, Transform actor)
 {
     if ((action != null) && !string.IsNullOrEmpty(action.questName))
     {
         QuestLog.SetQuestState(action.questName, action.questState);
         if (!string.IsNullOrEmpty(action.alertMessage))
         {
             DialogueManager.ShowAlert(action.alertMessage);
         }
         DialogueManager.SendUpdateTracker();
     }
 }
Exemplo n.º 7
0
        private IEnumerator LoadLevelCoroutine(string levelName, int levelIndex)
        {
            PersistentDataManager.Record();

            // Load the level:
            PersistentDataManager.LevelWillBeUnloaded();
            if (CanLoadAsync())
            {
                AsyncOperation async = !string.IsNullOrEmpty(levelName) ? Tools.LoadLevelAsync(levelName) : Tools.LoadLevelAsync(levelIndex);
                isLoading = true;
                while (!async.isDone)
                {
                    yield return(null);
                }
                isLoading = false;
            }
            else
            {
                if (!string.IsNullOrEmpty(levelName))
                {
                    Tools.LoadLevel(levelName);
                }
                else
                {
                    Tools.LoadLevel(levelIndex);
                }
            }

            // Wait two frames for objects in the level to finish their Start() methods:
            yield return(null);

            yield return(null);

            // Apply position data, but don't apply player's position:
            var player        = GameObject.FindGameObjectWithTag("Player");
            var persistentPos = (player != null) ? player.GetComponent <PersistentPositionData>() : null;
            var originalValue = false;

            if (persistentPos != null)
            {
                originalValue = persistentPos.restoreCurrentLevelPosition;
                persistentPos.restoreCurrentLevelPosition = false;
            }

            PersistentDataManager.Apply();
            if (persistentPos != null)
            {
                persistentPos.restoreCurrentLevelPosition = originalValue;
            }

            // Update quest tracker HUD:
            DialogueManager.SendUpdateTracker();
        }
        public void Fire()
        {
            if (DialogueDebug.logInfo)
            {
                Debug.Log(string.Format("{0}: Setting quest '{1}' state to '{2}'", new System.Object[] { DialogueDebug.Prefix, questName, QuestLog.StateToString(questState) }));
            }

            // Quest states:
            if (!string.IsNullOrEmpty(questName))
            {
                if (setQuestState)
                {
                    QuestLog.SetQuestState(questName, questState);
                }
                if (setQuestEntryState)
                {
                    QuestLog.SetQuestEntryState(questName, questEntryNumber, questEntryState);
                }
            }

            // Lua:
            if (!string.IsNullOrEmpty(luaCode))
            {
                Lua.Run(luaCode, DialogueDebug.logInfo);
            }

            // Alert:
            if (!string.IsNullOrEmpty(alertMessage))
            {
                string localizedAlertMessage = alertMessage;
                if ((localizedTextTable != null) && localizedTextTable.ContainsField(alertMessage))
                {
                    localizedAlertMessage = localizedTextTable[alertMessage];
                }
                DialogueManager.ShowAlert(localizedAlertMessage);
            }

            // Send Messages:
            foreach (var sma in sendMessages)
            {
                if (sma.gameObject != null && !string.IsNullOrEmpty(sma.message))
                {
                    sma.gameObject.SendMessage(sma.message, sma.parameter, SendMessageOptions.DontRequireReceiver);
                }
            }

            DialogueManager.SendUpdateTracker();

            // Once?
            DestroyIfOnce();
        }
Exemplo n.º 9
0
        /// <summary>
        /// When this object is destroyed, increment the counter and update the quest tracker.
        /// </summary>
        public void OnDestroy()
        {
            if (!listenForOnDestroy)
            {
                return;
            }
            int oldValue = DialogueLua.GetVariable(ActualVariableName).AsInt;
            int newValue = Mathf.Clamp(oldValue + increment, min, max);

            DialogueLua.SetVariable(ActualVariableName, newValue);
            DialogueManager.SendUpdateTracker();
            if (!(string.IsNullOrEmpty(alertMessage) || DialogueManager.Instance == null))
            {
                DialogueManager.ShowAlert(alertMessage);
            }
        }
        /// <summary>
        /// Loads the game from the data saved under the PlayerPrefs key.
        /// </summary>
        public void LoadGame(int slot)
        {
            if (SaveSystem.instance != null)
            {
                SaveSystem.LoadFromSlot(slot);
            }
            else
            {
                if (string.IsNullOrEmpty(playerPrefsKey))
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(string.Format("{0}: PlayerPrefs Key isn't set. Not loading.", new System.Object[] { DialogueDebug.Prefix }));
                    }
                    return;
                }
                string key = playerPrefsKey + slot.ToString();
                if (!PlayerPrefs.HasKey(key))
                {
                    if (DialogueDebug.logWarnings)
                    {
                        Debug.LogWarning(string.Format("{0}: No saved game in PlayerPrefs key '{1}'. Not loading.", new System.Object[] { DialogueDebug.Prefix, key }));
                    }
                    return;
                }
                if (DialogueDebug.logInfo)
                {
                    Debug.Log(string.Format("{0}: Loading save data from slot {1} and applying it.", new System.Object[] { DialogueDebug.Prefix, slot }));
                }

                // Load using the LevelManager if available; otherwise just apply saved-game data:
                string       saveData     = PlayerPrefs.GetString(key);
                LevelManager levelManager = FindLevelManager();
                if (levelManager != null)
                {
                    levelManager.LoadGame(saveData);
                }
                else
                {
                    PersistentDataManager.ApplySaveData(saveData, DatabaseResetOptions.KeepAllLoaded);
                    DialogueManager.SendUpdateTracker(); // Update quest tracker HUD.
                }
            }
        }
Exemplo n.º 11
0
 public void Fire(Transform actor)
 {
     if (DialogueDebug.logInfo)
     {
         Debug.Log("Dialogue System: Dialogue System Trigger is firing " + trigger + ".", this);
     }
     DoQuestAction();
     DoLuaAction();
     DoSequenceAction(actor);
     DoAlertAction();
     DoSendMessageActions();
     DoBarkAction(actor);
     DoConversationAction(actor);
     DoSetActiveActions(actor);
     DoSetEnabledActions(actor);
     DoSetAnimatorStateActions(actor);
     onExecute.Invoke((actor != null) ? actor.gameObject : null);
     DialogueManager.SendUpdateTracker();
 }
Exemplo n.º 12
0
 /// <summary>
 /// Runs the Lua code if the condition is true.
 /// </summary>
 public void TryStart(Transform actor)
 {
     if (tryingToStart)
     {
         return;
     }
     tryingToStart = true;
     try
     {
         if (((condition == null) || condition.IsTrue(actor)) && !string.IsNullOrEmpty(luaCode))
         {
             Lua.Run(luaCode, DialogueDebug.logInfo);
             DialogueManager.CheckAlerts();
             DialogueManager.SendUpdateTracker();
             DestroyIfOnce();
         }
     }
     finally
     {
         tryingToStart = false;
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Restarts the game.
        /// </summary>
        public void RestartGame()
        {
            LevelManager levelManager = FindLevelManager();

            if (levelManager != null)
            {
                levelManager.RestartGame();
            }
            else
            {
                DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
                if (string.IsNullOrEmpty(startingLevel))
                {
                    Tools.LoadLevel(0);
                }
                else
                {
                    Tools.LoadLevel(startingLevel);
                }
                // Update quest tracker HUD:
                DialogueManager.SendUpdateTracker();
            }
        }
Exemplo n.º 14
0
        private IEnumerator LoadLevelFromSaveData(string saveData)
        {
            if (DialogueDebug.logInfo)
            {
                Debug.Log("Dialogue System: LevelManager: Starting LoadLevelFromSaveData coroutine");
            }
            string levelName = defaultStartingLevel;

            if (string.IsNullOrEmpty(saveData))
            {
                // If no saveData, reset the database.
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: LevelManager: Save data is empty, so just resetting database");
                }
                DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
            }
            else
            {
                // Put saveData in Lua so we can get Variable["SavedLevelName"]:
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: LevelManager: Applying save data to get value of 'SavedLevelName' variable");
                }
                Lua.Run(saveData, DialogueDebug.logInfo);
                levelName = DialogueLua.GetVariable("SavedLevelName").asString;
                if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil"))
                {
                    levelName = defaultStartingLevel;
                    if (DialogueDebug.logInfo)
                    {
                        Debug.Log("Dialogue System: LevelManager: 'SavedLevelName' isn't defined. Using default level " + levelName);
                    }
                }
                else
                {
                    if (DialogueDebug.logInfo)
                    {
                        Debug.Log("Dialogue System: LevelManager: SavedLevelName = " + levelName);
                    }
                }
            }

            // Load the level:
            PersistentDataManager.LevelWillBeUnloaded();

            if (CanLoadAsync())
            {
                AsyncOperation async = Tools.LoadLevelAsync(levelName);
                isLoading = true;
                while (!async.isDone)
                {
                    yield return(null);
                }
                isLoading = false;
            }
            else
            {
                Tools.LoadLevel(levelName);
            }

            // Wait two frames for objects in the level to finish their Start() methods:
            if (DialogueDebug.logInfo)
            {
                Debug.Log("Dialogue System: LevelManager finished loading level " + levelName + ". Waiting 2 frames for scene objects to start.");
            }
            yield return(null);

            yield return(null);

            // Then apply saveData to the objects:
            if (!string.IsNullOrEmpty(saveData))
            {
                if (DialogueDebug.logInfo)
                {
                    Debug.Log("Dialogue System: LevelManager waited 2 frames. Appling save data: " + saveData);
                }
                PersistentDataManager.ApplySaveData(saveData);
            }

            // Update quest tracker HUD:
            DialogueManager.SendUpdateTracker();
        }