Exemple #1
0
 /// <summary>
 /// Appends the user variable table to a (saved-game) string.
 /// </summary>
 public static void AppendVariableData(StringBuilder sb)
 {
     try
     {
         LuaTableWrapper variableTable = Lua.Run("return Variable").asTable;
         if (variableTable == null)
         {
             if (DialogueDebug.logErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Variable[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         sb.Append("Variable={");
         var first = true;
         foreach (var key in variableTable.keys)
         {
             if (!first)
             {
                 sb.Append(", ");
             }
             first = false;
             var value = variableTable[key.ToString()];
             sb.AppendFormat("{0}={1}", new System.Object[] { GetFieldKeyString(key), GetFieldValueString(value) });
         }
         sb.Append("}; ");
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get variable data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
Exemple #2
0
 /// <summary>
 /// Appends the actor table to a saved-game string.
 /// </summary>
 private static void AppendActorData(StringBuilder sb)
 {
     try {
         LuaTableWrapper actorTable = Lua.Run("return Actor").AsTable;
         if (actorTable == null)
         {
             if (DialogueDebug.LogErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Actor[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         foreach (var key in actorTable.Keys)
         {
             LuaTableWrapper fields = actorTable[key.ToString()] as LuaTableWrapper;
             sb.AppendFormat("Actor[\"{0}\"]={1}", new System.Object[] { DialogueLua.StringToTableIndex(key), '{' });
             try {
                 AppendActorFieldData(sb, fields);
             } finally {
                 sb.Append("}; ");
             }
         }
     } catch (System.Exception e) {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get actor data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
Exemple #3
0
 /// <summary>
 /// Appends an actor record to a saved-game string.
 /// </summary>
 private static void AppendActorFieldData(StringBuilder sb, LuaTableWrapper fields)
 {
     if (fields == null)
     {
         return;
     }
     foreach (var key in fields.Keys)
     {
         var value = fields[key.ToString()];
         sb.AppendFormat("{0}={1}, ", new System.Object[] { DialogueLua.StringToTableIndex(key), GetFieldValueString(value) });
     }
 }
Exemple #4
0
        /// <summary>
        /// Gets an array of all quests matching the specified state bitmask.
        /// </summary>
        /// <returns>
        /// The titles of all quests matching the specified state bitmask.
        /// </returns>
        /// <param name='flags'>
        /// A bitmask of QuestState values.
        /// </param>
        /// <example>
        /// string[] completedQuests = QuestLog.GetAllQuests( QuestState.Success | QuestState.Failure );
        /// </example>
        public static string[] GetAllQuests(QuestState flags)
        {
            List <string>   titles    = new List <string>();
            LuaTableWrapper itemTable = Lua.Run("return Item").AsTable;

            if (!itemTable.IsValid)
            {
                if (DialogueDebug.LogWarnings)
                {
                    Debug.LogWarning(string.Format("{0}: Quest Log couldn't access Lua Item[] table. Has the Dialogue Manager loaded a database yet?", new System.Object[] { DialogueDebug.Prefix }));
                }
                return(titles.ToArray());
            }
            foreach (LuaTableWrapper fields in itemTable.Values)
            {
                string title  = null;
                bool   isItem = false;
                try {
                    object titleObject = fields["Name"];
                    title  = (titleObject != null) ? titleObject.ToString() : string.Empty;
                    isItem = false;
                    object isItemObject = fields["Is_Item"];
                    if (isItemObject != null)
                    {
                        if (isItemObject.GetType() == typeof(bool))
                        {
                            isItem = (bool)isItemObject;
                        }
                        else
                        {
                            isItem = Tools.StringToBool(isItemObject.ToString());
                        }
                    }
                } catch {}
                if (!isItem)
                {
                    if (string.IsNullOrEmpty(title))
                    {
                        if (DialogueDebug.LogWarnings)
                        {
                            Debug.LogWarning(string.Format("{0}: A quest title (item name in Item[] table) is null or empty", new System.Object[] { DialogueDebug.Prefix }));
                        }
                    }
                    else if (IsQuestInStateMask(title, flags))
                    {
                        titles.Add(title);
                    }
                }
            }
            titles.Sort();
            return(titles.ToArray());
        }
Exemple #5
0
        /// <summary>
        /// Instructs the Dialogue System to add any missing variables that are in the master
        /// database but not in Lua.
        /// </summary>
        public static void InitializeNewVariablesFromDatabase()
        {
            try
            {
                LuaTableWrapper variableTable = Lua.Run("return Variable").asTable;
                if (variableTable == null)
                {
                    if (DialogueDebug.logErrors)
                    {
                        Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Variable[] table", new System.Object[] { DialogueDebug.Prefix }));
                    }
                    return;
                }
                var database = DialogueManager.masterDatabase;
                if (database == null)
                {
                    return;
                }
                var inLua = new HashSet <string>(variableTable.keys);
                for (int i = 0; i < database.variables.Count; i++)
                {
                    var variable      = database.variables[i];
                    var variableName  = variable.Name;
                    var variableIndex = DialogueLua.StringToTableIndex(variableName);
                    if (!inLua.Contains(variableIndex))
                    {
                        switch (variable.Type)
                        {
                        case FieldType.Boolean:
                            DialogueLua.SetVariable(variableName, variable.InitialBoolValue);
                            break;

                        case FieldType.Actor:
                        case FieldType.Item:
                        case FieldType.Location:
                        case FieldType.Number:
                            DialogueLua.SetVariable(variableName, variable.InitialFloatValue);
                            break;

                        default:
                            DialogueLua.SetVariable(variableName, variable.InitialValue);
                            break;
                        }
                    }
                }
            }
            catch (System.Exception e)
            {
                Debug.LogError(string.Format("{0}: InitializeNewVariablesFromDatabase() failed to get variable data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
            }
        }
Exemple #6
0
 /// <summary>
 /// Appends all conversation fields to a saved-game string. Note that this doesn't
 /// append the fields inside each dialogue entry, just the fields in the conversation
 /// objects themselves.
 /// </summary>
 private static void AppendAllConversationFields(StringBuilder sb)
 {
     try
     {
         LuaTableWrapper conversationTable = Lua.Run("return Conversation").asTable;
         if (conversationTable == null)
         {
             if (DialogueDebug.logErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Conversation[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         foreach (var convIndex in conversationTable.keys) // Loop through conversations:
         {
             LuaTableWrapper fields = Lua.Run("return Conversation[" + convIndex + "]").asTable;
             if (fields == null)
             {
                 continue;
             }
             sb.Append("Conversation[" + convIndex + "]={");
             try
             {
                 var first = true;
                 foreach (var key in fields.keys)
                 {
                     if (string.Equals(key, "Dialog"))
                     {
                         continue;
                     }
                     if (!first)
                     {
                         sb.Append(", ");
                     }
                     first = false;
                     var value = fields[key.ToString()];
                     sb.AppendFormat("{0}={1}", new System.Object[] { GetFieldKeyString(key), GetFieldValueString(value) });
                 }
             }
             finally
             {
                 sb.Append("}; ");
             }
         }
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get conversation data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
Exemple #7
0
 /// <summary>
 /// Appends the item table to a (saved-game) string.
 /// </summary>
 public static void AppendItemData(StringBuilder sb)
 {
     try
     {
         LuaTableWrapper itemTable = Lua.Run("return Item").asTable;
         if (itemTable == null)
         {
             if (DialogueDebug.logErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Item[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         foreach (var title in itemTable.keys)
         {
             LuaTableWrapper fields            = itemTable[title.ToString()] as LuaTableWrapper;
             bool            onlySaveQuestData = !includeAllItemData && (DialogueManager.masterDatabase.items.Find(i => string.Equals(DialogueLua.StringToTableIndex(i.Name), title)) != null);
             if (fields != null)
             {
                 if (onlySaveQuestData)
                 {
                     // If in the database, just record quest statuses and tracking:
                     foreach (var fieldKey in fields.keys)
                     {
                         string fieldTitle = fieldKey.ToString();
                         if (fieldTitle.EndsWith("State"))
                         {
                             sb.AppendFormat("Item[\"{0}\"].{1}=\"{2}\"; ", new System.Object[] { DialogueLua.StringToTableIndex(title), (System.Object)fieldTitle, (System.Object)fields[fieldTitle] });
                         }
                         else if (string.Equals(fieldTitle, "Track"))
                         {
                             sb.AppendFormat("Item[\"{0}\"].Track={1}; ", new System.Object[] { DialogueLua.StringToTableIndex(title), fields[fieldTitle].ToString().ToLower() });
                         }
                     }
                 }
                 else
                 {
                     // If not in the database, record all fields:
                     sb.AppendFormat("Item[\"{0}\"]=", new System.Object[] { DialogueLua.StringToTableIndex(title) });
                     AppendFields(sb, fields);
                 }
             }
         }
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get item data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
Exemple #8
0
 private static void AppendFields(StringBuilder sb, LuaTableWrapper fields)
 {
     sb.Append("{");
     try {
         if (fields != null)
         {
             foreach (var key in fields.Keys)
             {
                 var value = fields[key.ToString()];
                 sb.AppendFormat("{0}={1}, ", new System.Object[] { DialogueLua.StringToTableIndex(key), GetFieldValueString(value) });
             }
         }
     } finally {
         sb.Append("}; ");
     }
 }
        private string FormatTableResult(Lua.Result result)
        {
            if (!result.isTable)
            {
                return(result.asString);
            }
            LuaTableWrapper table = result.asTable;
            StringBuilder   sb    = new StringBuilder();

            sb.Append("Table:\n");
            foreach (object key in table.keys)
            {
                sb.Append(string.Format("[{0}]: {1}\n", new System.Object[] { key.ToString(), table[key.ToString()].ToString() }));
            }
            return(sb.ToString());
        }
Exemple #10
0
 /// <summary>
 /// Appends the location table to a (saved-game) string. Currently doesn't save anything unless
 /// includeLocationData is true.
 /// </summary>
 public static void AppendLocationData(StringBuilder sb)
 {
     if (!includeLocationData)
     {
         return;
     }
     try
     {
         LuaTableWrapper locationTable = Lua.Run("return Location").asTable;
         if (locationTable == null)
         {
             if (DialogueDebug.logErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Location[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         sb.Append("Location={");
         var first = true;
         foreach (var key in locationTable.keys)
         {
             LuaTableWrapper fields = locationTable[key.ToString()] as LuaTableWrapper;
             if (!first)
             {
                 sb.Append(", ");
             }
             first = false;
             sb.Append(GetFieldKeyString(key));
             sb.Append("={");
             try
             {
                 AppendAssetFieldData(sb, fields);
             }
             finally
             {
                 sb.Append("}");
             }
         }
         sb.Append("}; ");
     }
     catch (System.Exception e)
     {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get location data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
Exemple #11
0
        /// <summary>
        /// Appends an actor record to a saved-game string.
        /// </summary>
        private static void AppendAssetFieldData(StringBuilder sb, LuaTableWrapper fields)
        {
            if (fields == null)
            {
                return;
            }
            var first = true;

            foreach (var key in fields.keys)
            {
                if (!first)
                {
                    sb.Append(", ");
                }
                first = false;
                var value = fields[key.ToString()];
                sb.AppendFormat("{0}={1}", new System.Object[] { GetFieldKeyString(key), GetFieldValueString(value) });
            }
        }
Exemple #12
0
 /// <summary>
 /// Appends the user variable table to a saved-game string.
 /// </summary>
 private static void AppendVariableData(StringBuilder sb)
 {
     try {
         LuaTableWrapper variableTable = Lua.Run("return Variable").AsTable;
         if (variableTable == null)
         {
             if (DialogueDebug.LogErrors)
             {
                 Debug.LogError(string.Format("{0}: Persistent Data Manager couldn't access Lua Variable[] table", new System.Object[] { DialogueDebug.Prefix }));
             }
             return;
         }
         foreach (var key in variableTable.Keys)
         {
             var value = variableTable[key.ToString()];
             sb.AppendFormat("Variable[\"{0}\"]={1}; ", new System.Object[] { DialogueLua.StringToTableIndex(key), GetFieldValueString(value) });
         }
     } catch (System.Exception e) {
         Debug.LogError(string.Format("{0}: GetSaveData() failed to get variable data: {1}", new System.Object[] { DialogueDebug.Prefix, e.Message }));
     }
 }
 /// <summary>
 /// Appends an actor record to a saved-game string.
 /// </summary>
 private static void AppendActorFieldData(StringBuilder sb, LuaTableWrapper fields)
 {
     if (fields == null) return;
     foreach (var key in fields.Keys) {
         var value = fields[key.ToString()];
         sb.AppendFormat("{0}={1}, ", new System.Object[] { DialogueLua.StringToTableIndex(key), GetFieldValueString(value) });
     }
 }
 private static void AppendFields(StringBuilder sb, LuaTableWrapper fields)
 {
     sb.Append("{");
     try {
         if (fields != null) {
             foreach (var key in fields.Keys) {
                 var value = fields[key.ToString()];
                 sb.AppendFormat("{0}={1}, ", new System.Object[] { DialogueLua.StringToTableIndex(key), GetFieldValueString(value) });
             }
         }
     } finally {
         sb.Append("}; ");
     }
 }
Exemple #15
0
 public Result(Language.Lua.LuaValue luaValue)
 {
     this.luaValue = luaValue;
     this.luaTableWrapper = new LuaTableWrapper(luaValue as Language.Lua.LuaTable);
 }
Exemple #16
0
 public Result(object[] retVals)
 {
     this.retVals = retVals; luaTableWrapper = null;
 }
Exemple #17
0
 public Result(Language.Lua.LuaValue luaValue)
 {
     this.luaValue        = luaValue;
     this.luaTableWrapper = new LuaTableWrapper(luaValue as Language.Lua.LuaTable);
 }
Exemple #18
0
 public Result(object[] retVals)
 {
     this.retVals = retVals; luaTableWrapper = null;
 }
Exemple #19
0
 public Result(Language.Lua.LuaValue luaValue)
 {
     this.luaValue        = luaValue;
     this.luaTableWrapper = null;
 }