private string ApplyScriptWizard()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                if (append && !string.IsNullOrEmpty(savedLuaCode))
                {
                    sb.AppendFormat("{0};\n", savedLuaCode);
                }
                string endText = (scriptItems.Count > 1) ? ";\n" : string.Empty;
                for (int i = 0; i < scriptItems.Count; i++)
                {
                    var item = scriptItems[i];
                    if (item.resourceType == ScriptWizardResourceType.Quest)
                    {
                        // Quest:
                        string questName = GetWizardQuestName(questNames, item.questNamesIndex);
                        if (item.netSetMode == NetSetMode.NetSet)
                        {
                            sb.Append("Net");
                        }
                        sb.AppendFormat("SetQuestState(\"{0}\", \"{1}\")",
                                        questName,
                                        QuestLog.StateToString(item.questState));
                    }
                    else if (item.resourceType == ScriptWizardResourceType.QuestEntry)
                    {
                        // Quest Entry:
                        string questName = GetWizardQuestName(complexQuestNames, item.questNamesIndex);
                        if (item.netSetMode == NetSetMode.NetSet)
                        {
                            sb.Append("Net");
                        }
                        sb.AppendFormat("SetQuestEntryState(\"{0}\", {1}, \"{2}\")",
                                        questName,
                                        item.questEntryIndex + 1,
                                        QuestLog.StateToString(item.questState));
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Variable)
                    {
                        // Variable:
                        string variableName = (0 <= item.variableNamesIndex && item.variableNamesIndex < variableNames.Length) ? variableNames[item.variableNamesIndex] : "Alert";
                        switch (GetWizardVariableType(item.variableNamesIndex))
                        {
                        case FieldType.Boolean:
                            if (item.netSetMode == NetSetMode.NetSet)
                            {
                                sb.AppendFormat("NetSetBool(\"{0}\", {1})",
                                                DialogueLua.StringToTableIndex(variableName),
                                                (item.booleanValue == BooleanType.True) ? "true" : "false");
                            }
                            else
                            {
                                sb.AppendFormat("Variable[\"{0}\"] = {1}",
                                                DialogueLua.StringToTableIndex(variableName),
                                                (item.booleanValue == BooleanType.True) ? "true" : "false");
                            }
                            break;

                        case FieldType.Number:
                            if (item.netSetMode == NetSetMode.NetSet)
                            {
                                switch (item.valueSetMode)
                                {
                                case ValueSetMode.To:
                                    sb.AppendFormat("NetSetNumber(\"{0}\", {1})",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;

                                case ValueSetMode.Add:
                                    sb.AppendFormat("NetSetNumber(\"{0}\", Variable[\"{0}\"] + {1})",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;

                                case ValueSetMode.Subtract:
                                    sb.AppendFormat("NetSetNumber(\"{0}\", Variable[\"{0}\"] - {1})",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;
                                }
                            }
                            else
                            {
                                switch (item.valueSetMode)
                                {
                                case ValueSetMode.To:
                                    sb.AppendFormat("Variable[\"{0}\"] = {1}",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;

                                case ValueSetMode.Add:
                                    sb.AppendFormat("Variable[\"{0}\"] = Variable[\"{0}\"] + {1}",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;

                                case ValueSetMode.Subtract:
                                    sb.AppendFormat("Variable[\"{0}\"] = Variable[\"{0}\"] - {1}",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                    break;
                                }
                            }
                            break;

                        default:
                            if (item.netSetMode == NetSetMode.NetSet)
                            {
                                sb.AppendFormat("NetSetString(\"{0}\", \"{1}\")",
                                                DialogueLua.StringToTableIndex(variableName),
                                                item.stringValue);
                            }
                            else
                            {
                                sb.AppendFormat("Variable[\"{0}\"] = \"{1}\"",
                                                DialogueLua.StringToTableIndex(variableName),
                                                item.stringValue);
                            }
                            break;
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Actor)
                    {
                        // Actor:
                        if (item.actorNamesIndex < actorNames.Length)
                        {
                            item.actorFieldIndex = Mathf.Clamp(item.actorFieldIndex, 0, actorFieldNames.Length - 1);
                            var actorName      = actorNames[item.actorNamesIndex];
                            var actorFieldName = actorFieldNames[item.actorFieldIndex];
                            var fieldType      = GetWizardActorFieldType(item.actorFieldIndex);
                            AppendFormat(sb, "Actor", actorName, actorFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Item)
                    {
                        // Item:
                        if (item.itemNamesIndex < itemNames.Length)
                        {
                            item.itemFieldIndex = Mathf.Clamp(item.itemFieldIndex, 0, itemFieldNames.Length - 1);
                            var itemName      = itemNames[item.itemNamesIndex];
                            var itemFieldName = itemFieldNames[item.itemFieldIndex];
                            var fieldType     = GetWizardItemFieldType(item.itemFieldIndex);
                            AppendFormat(sb, "Item", itemName, itemFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Location)
                    {
                        // Location:
                        if (item.locationNamesIndex < locationNames.Length)
                        {
                            item.locationFieldIndex = Mathf.Clamp(item.locationFieldIndex, 0, locationFieldNames.Length - 1);
                            var locationName      = locationNames[item.locationNamesIndex];
                            var locationFieldName = locationFieldNames[item.locationFieldIndex];
                            var fieldType         = GetWizardLocationFieldType(item.locationFieldIndex);
                            AppendFormat(sb, "Location", locationName, locationFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.SimStatus)
                    {
                        // SimStatus:
                        sb.AppendFormat("Dialog[{0}].SimStatus = \"{1}\"", item.simStatusID, item.simStatusType);
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Alert)
                    {
                        // Custom:
                        sb.Append("ShowAlert(\"" + item.stringValue.Replace("\"", "\\\"") + "\")");
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Custom)
                    {
                        // Custom:
                        if (0 <= item.customLuaFuncIndex && item.customLuaFuncIndex < customLuaFuncs.Length)
                        {
                            var luaFuncRecord = customLuaFuncs[item.customLuaFuncIndex];
                            sb.Append(luaFuncRecord.functionName + "(");
                            for (int p = 0; p < luaFuncRecord.parameters.Length; p++)
                            {
                                if (p > 0)
                                {
                                    sb.Append(", ");
                                }
                                switch (luaFuncRecord.parameters[p])
                                {
                                case CustomLuaParameterType.Bool:
                                    sb.Append(((BooleanType)item.customParamValues[p] == BooleanType.True) ? "true" : "false");
                                    break;

                                case CustomLuaParameterType.Double:
                                    sb.Append((float)item.customParamValues[p]);
                                    break;

                                case CustomLuaParameterType.String:
                                    sb.Append("\"" + (string)item.customParamValues[p] + "\"");
                                    break;

                                case CustomLuaParameterType.Actor:
                                    var actorIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= actorIndex && actorIndex < actorNames.Length) ? ("\"" + actorNames[actorIndex] + "\"") : "\"\"");
                                    break;

                                case CustomLuaParameterType.Quest:
                                    var questIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= questIndex && questIndex < questNames.Length) ? ("\"" + questNames[questIndex] + "\"") : "\"\"");
                                    break;

                                case CustomLuaParameterType.QuestEntry:
                                    sb.Append(((int)item.customParamValues[p] + 1).ToString());
                                    break;

                                case CustomLuaParameterType.Variable:
                                    var variableIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= variableIndex && variableIndex < variableNames.Length) ? ("Variable[\"" + variableNames[variableIndex] + "\"]") : "\"\"");
                                    break;

                                case CustomLuaParameterType.Item:
                                    var itemIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= itemIndex && itemIndex < itemNames.Length) ? ("\"" + itemNames[itemIndex] + "\"") : "\"\"");
                                    break;
                                }
                            }
                            sb.Append(")");
                        }
                    }

                    else if (item.resourceType == ScriptWizardResourceType.ManualEnter)
                    {
                        // Custom:
                        sb.Append(item.stringValue);
                    }

                    if (i < (scriptItems.Count - 1))
                    {
                        sb.AppendFormat(endText);
                    }
                }
                return(sb.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(string.Format("{0}: Internal error building script: {1}", DialogueDebug.Prefix, e.Message));
                return(savedLuaCode);
            }
        }
Exemplo n.º 2
0
        private string ApplyScriptWizard()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                if (append && !string.IsNullOrEmpty(savedLuaCode))
                {
                    sb.AppendFormat("{0};\n", savedLuaCode);
                }
                string endText = (scriptItems.Count > 1) ? ";\n" : string.Empty;
                for (int i = 0; i < scriptItems.Count; i++)
                {
                    var item = scriptItems[i];
                    if (item.resourceType == ScriptWizardResourceType.Quest)
                    {
                        // Quest:
                        string questName = GetWizardQuestName(questNames, item.questNamesIndex);
                        //sb.AppendFormat("Quest[\"{0}\"].State = \"{1}\"",
                        //                DialogueLua.StringToTableIndex(questName),
                        //                QuestLog.StateToString(item.questState));
                        sb.AppendFormat("SetQuestState(\"{0}\", \"{1}\")",
                                        questName,
                                        QuestLog.StateToString(item.questState));
                    }
                    else if (item.resourceType == ScriptWizardResourceType.QuestEntry)
                    {
                        // Quest Entry:
                        string questName = GetWizardQuestName(complexQuestNames, item.questNamesIndex);
                        //sb.AppendFormat("Quest[\"{0}\"].Entry_{1}_State = \"{2}\"",
                        //                DialogueLua.StringToTableIndex(questName),
                        //                item.questEntryIndex + 1,
                        //                QuestLog.StateToString(item.questState));
                        sb.AppendFormat("SetQuestEntryState(\"{0}\", {1}, \"{2}\")",
                                        questName,
                                        item.questEntryIndex + 1,
                                        QuestLog.StateToString(item.questState));
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Variable)
                    {
                        // Variable:
                        string variableName = variableNames[item.variableNamesIndex];
                        switch (GetWizardVariableType(item.variableNamesIndex))
                        {
                        case FieldType.Boolean:
                            sb.AppendFormat("Variable[\"{0}\"] = {1}",
                                            DialogueLua.StringToTableIndex(variableName),
                                            (item.booleanValue == BooleanType.True) ? "true" : "false");
                            break;

                        case FieldType.Number:
                            if (item.valueSetMode == ValueSetMode.To)
                            {
                                sb.AppendFormat("Variable[\"{0}\"] = {1}",
                                                DialogueLua.StringToTableIndex(variableName),
                                                item.floatValue);
                            }
                            else
                            {
                                sb.AppendFormat("Variable[\"{0}\"] = Variable[\"{0}\"] + {1}",
                                                DialogueLua.StringToTableIndex(variableName),
                                                item.floatValue);
                            }
                            break;

                        default:
                            sb.AppendFormat("Variable[\"{0}\"] = \"{1}\"",
                                            DialogueLua.StringToTableIndex(variableName),
                                            item.stringValue);
                            break;
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Actor)
                    {
                        // Actor:
                        if (item.actorNamesIndex < actorNames.Length)
                        {
                            var actorName      = actorNames[item.actorNamesIndex];
                            var actorFieldName = actorFieldNames[item.actorFieldIndex];
                            var fieldType      = GetWizardActorFieldType(item.actorFieldIndex);
                            AppendFormat(sb, "Actor", actorName, actorFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Item)
                    {
                        // Item:
                        if (item.itemNamesIndex < itemNames.Length)
                        {
                            var itemName      = itemNames[item.itemNamesIndex];
                            var itemFieldName = itemFieldNames[item.itemFieldIndex];
                            var fieldType     = GetWizardItemFieldType(item.itemFieldIndex);
                            AppendFormat(sb, "Item", itemName, itemFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Location)
                    {
                        // Location:
                        if (item.locationNamesIndex < locationNames.Length)
                        {
                            var locationName      = locationNames[item.locationNamesIndex];
                            var locationFieldName = locationFieldNames[item.locationFieldIndex];
                            var fieldType         = GetWizardLocationFieldType(item.locationFieldIndex);
                            AppendFormat(sb, "Location", locationName, locationFieldName, fieldType, item);
                        }
                    }
                    else if (item.resourceType == ScriptWizardResourceType.SimStatus)
                    {
                        // SimStatus:
                        sb.AppendFormat("Dialog[{0}].SimStatus = \"{1}\"", item.simStatusID, item.simStatusType);
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Alert)
                    {
                        // Custom:
                        sb.Append("ShowAlert(\"" + item.stringValue.Replace("\"", "\\\"") + "\")");
                    }
                    else if (item.resourceType == ScriptWizardResourceType.Custom)
                    {
                        // Custom:
                        sb.Append(item.stringValue);
                    }

                    if (i < (scriptItems.Count - 1))
                    {
                        sb.AppendFormat(endText);
                    }
                }
                return(sb.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(string.Format("{0}: Internal error building script: {1}", DialogueDebug.Prefix, e.Message));
                return(savedLuaCode);
            }
        }
Exemplo n.º 3
0
        private string ApplyConditionsWizard()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                string        logicalOperator = GetLogicalOperatorText(conditionsLogicalOperator);
                var           needParens      = (conditionItems.Count > 1) || (append && !string.IsNullOrEmpty(savedLuaCode));
                openParen  = needParens ? "(" : string.Empty;
                closeParen = needParens ? ")" : string.Empty;
                if (append && !string.IsNullOrEmpty(savedLuaCode))
                {
                    sb.AppendFormat("{0} {1} ", savedLuaCode, logicalOperator);
                }
                bool first = true;
                foreach (ConditionItem item in conditionItems)
                {
                    if (!first)
                    {
                        sb.AppendFormat(" {0} ", logicalOperator);
                    }
                    first = false;
                    if (item.conditionType == ConditionWizardResourceType.Quest)
                    {
                        // Quest:
                        string questName = GetWizardQuestName(questNames, item.questNamesIndex);
                        //sb.AppendFormat("{0}Quest[\"{1}\"].State {2} \"{3}\"{4}",
                        //                openParen,
                        //                DialogueLua.StringToTableIndex(questName),
                        //                GetWizardEqualityText(item.equalityType),
                        //                QuestLog.StateToString(item.questState),
                        //                closeParen);
                        sb.AppendFormat("{0}CurrentQuestState(\"{1}\") {2} \"{3}\"{4}",
                                        openParen,
                                        questName,
                                        GetWizardEqualityText(item.equalityType),
                                        QuestLog.StateToString(item.questState),
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.QuestEntry)
                    {
                        // Quest Entry:
                        string questName = GetWizardQuestName(complexQuestNames, item.questNamesIndex);
                        //sb.AppendFormat("{0}Quest[\"{1}\"].Entry_{2}_State {3} \"{4}\"{5}",
                        //                openParen,
                        //                DialogueLua.StringToTableIndex(questName),
                        //                item.questEntryIndex + 1,
                        //                GetWizardEqualityText(item.equalityType),
                        //                QuestLog.StateToString(item.questState),
                        //                closeParen);
                        sb.AppendFormat("{0}CurrentQuestEntryState(\"{1}\", {2}) {3} \"{4}\"{5}",
                                        openParen,
                                        questName,
                                        item.questEntryIndex + 1,
                                        GetWizardEqualityText(item.equalityType),
                                        QuestLog.StateToString(item.questState),
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Variable)
                    {
                        // Variable:
                        string variableName = variableNames[item.variableNamesIndex];
                        switch (GetWizardVariableType(item.variableNamesIndex))
                        {
                        case FieldType.Boolean:
                            sb.AppendFormat("{0}Variable[\"{1}\"] {2} {3}{4}",
                                            openParen,
                                            DialogueLua.StringToTableIndex(variableName),
                                            GetWizardEqualityText(item.equalityType),
                                            (item.booleanValue == BooleanType.True) ? "true" : "false",
                                            closeParen);
                            break;

                        case FieldType.Number:
                            if (item.comparisonType == ComparisonType.Between)
                            {
                                sb.AppendFormat("{0}{3} <= Variable[\"{1}\"] and Variable[\"{1}\"] <= {4}{5}",
                                                openParen,
                                                DialogueLua.StringToTableIndex(variableName),
                                                GetWizardComparisonText(item.comparisonType),
                                                item.floatValue,
                                                item.floatValue2,
                                                closeParen);
                            }
                            else
                            {
                                sb.AppendFormat("{0}Variable[\"{1}\"] {2} {3}{4}",
                                                openParen,
                                                DialogueLua.StringToTableIndex(variableName),
                                                GetWizardComparisonText(item.comparisonType),
                                                item.floatValue,
                                                closeParen);
                            }
                            break;

                        default:
                            sb.AppendFormat("{0}Variable[\"{1}\"] {2} \"{3}\"{4}",
                                            openParen,
                                            DialogueLua.StringToTableIndex(variableName),
                                            GetWizardEqualityText(item.equalityType),
                                            item.stringValue,
                                            closeParen);
                            break;
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Actor)
                    {
                        // Actor:
                        if (item.actorNamesIndex < actorNames.Length)
                        {
                            var actorName      = actorNames[item.actorNamesIndex];
                            var actorField     = actorFieldNames[item.actorFieldIndex];
                            var actorFieldType = GetWizardActorFieldType(item.actorFieldIndex);
                            AppendFormat(sb, "Actor", actorName, actorField, actorFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Item)
                    {
                        // Item:
                        if (item.itemNamesIndex < itemNames.Length)
                        {
                            var itemName      = itemNames[item.itemNamesIndex];
                            var itemField     = itemFieldNames[item.itemFieldIndex];
                            var itemFieldType = GetWizardItemFieldType(item.itemFieldIndex);
                            AppendFormat(sb, "Item", itemName, itemField, itemFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Location)
                    {
                        // Location:
                        if (item.locationNamesIndex < locationNames.Length)
                        {
                            var locationName      = locationNames[item.locationNamesIndex];
                            var locationField     = locationFieldNames[item.locationFieldIndex];
                            var locationFieldType = GetWizardLocationFieldType(item.locationFieldIndex);
                            AppendFormat(sb, "Location", locationName, locationField, locationFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.SimStatus)
                    {
                        // SimStatus:
                        string simStatusID = item.simStatusThisID ? "thisID" : item.simStatusID.ToString();
                        sb.AppendFormat("{0}Dialog[{1}].SimStatus {2} \"{3}\"{4}",
                                        openParen,
                                        simStatusID,
                                        GetWizardEqualityText(item.equalityType),
                                        item.simStatusType,
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Custom)
                    {
                        // Custom:
                        sb.AppendFormat("{0}{1}{2}", openParen, item.stringValue, closeParen);
                    }
                }
                return(sb.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(string.Format("{0}: Internal error building condition: {1}", DialogueDebug.Prefix, e.Message));
                return(savedLuaCode);
            }
            //-- Moved to AcceptConditionsWizard: currentConditionsWizardEntry = null;
        }
Exemplo n.º 4
0
        private string ApplyConditionsWizard()
        {
            try
            {
                StringBuilder sb = new StringBuilder();
                string        logicalOperator = GetLogicalOperatorText(conditionsLogicalOperator);
                var           needParens      = (conditionItems.Count > 1) || (append && !string.IsNullOrEmpty(savedLuaCode));
                openParen  = needParens ? "(" : string.Empty;
                closeParen = needParens ? ")" : string.Empty;
                if (append && !string.IsNullOrEmpty(savedLuaCode))
                {
                    sb.AppendFormat("{0} {1} ", savedLuaCode, logicalOperator);
                }
                bool first = true;
                foreach (ConditionItem item in conditionItems)
                {
                    if (!first)
                    {
                        sb.AppendFormat(" {0} ", logicalOperator);
                    }
                    first = false;
                    if (item.conditionType == ConditionWizardResourceType.Quest)
                    {
                        // Quest:
                        string questName = GetWizardQuestName(questNames, item.questNamesIndex);
                        sb.AppendFormat("{0}CurrentQuestState(\"{1}\") {2} \"{3}\"{4}",
                                        openParen,
                                        questName,
                                        GetWizardEqualityText(item.equalityType),
                                        QuestLog.StateToString(item.questState),
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.QuestEntry)
                    {
                        // Quest Entry:
                        string questName = GetWizardQuestName(complexQuestNames, item.questNamesIndex);
                        sb.AppendFormat("{0}CurrentQuestEntryState(\"{1}\", {2}) {3} \"{4}\"{5}",
                                        openParen,
                                        questName,
                                        item.questEntryIndex + 1,
                                        GetWizardEqualityText(item.equalityType),
                                        QuestLog.StateToString(item.questState),
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Variable)
                    {
                        // Variable:
                        string variableName = variableNames[item.variableNamesIndex];
                        switch (GetWizardVariableType(item.variableNamesIndex))
                        {
                        case FieldType.Boolean:
                            sb.AppendFormat("{0}Variable[\"{1}\"] {2} {3}{4}",
                                            openParen,
                                            DialogueLua.StringToTableIndex(variableName),
                                            GetWizardEqualityText(item.equalityType),
                                            (item.booleanValue == BooleanType.True) ? "true" : "false",
                                            closeParen);
                            break;

                        case FieldType.Number:
                            if (item.comparisonType == ComparisonType.Between)
                            {
                                sb.AppendFormat("{0}{3} <= Variable[\"{1}\"] and Variable[\"{1}\"] <= {4}{5}",
                                                openParen,
                                                DialogueLua.StringToTableIndex(variableName),
                                                GetWizardComparisonText(item.comparisonType),
                                                item.floatValue,
                                                item.floatValue2,
                                                closeParen);
                            }
                            else
                            {
                                sb.AppendFormat("{0}Variable[\"{1}\"] {2} {3}{4}",
                                                openParen,
                                                DialogueLua.StringToTableIndex(variableName),
                                                GetWizardComparisonText(item.comparisonType),
                                                item.floatValue,
                                                closeParen);
                            }
                            break;

                        default:
                            sb.AppendFormat("{0}Variable[\"{1}\"] {2} \"{3}\"{4}",
                                            openParen,
                                            DialogueLua.StringToTableIndex(variableName),
                                            GetWizardEqualityText(item.equalityType),
                                            item.stringValue,
                                            closeParen);
                            break;
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Actor)
                    {
                        // Actor:
                        if (item.actorNamesIndex < actorNames.Length)
                        {
                            var actorName      = actorNames[item.actorNamesIndex];
                            var actorField     = actorFieldNames[item.actorFieldIndex];
                            var actorFieldType = GetWizardActorFieldType(item.actorFieldIndex);
                            AppendFormat(sb, "Actor", actorName, actorField, actorFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Item)
                    {
                        // Item:
                        if (item.itemNamesIndex < itemNames.Length)
                        {
                            var itemName      = itemNames[item.itemNamesIndex];
                            var itemField     = itemFieldNames[item.itemFieldIndex];
                            var itemFieldType = GetWizardItemFieldType(item.itemFieldIndex);
                            AppendFormat(sb, "Item", itemName, itemField, itemFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Location)
                    {
                        // Location:
                        if (item.locationNamesIndex < locationNames.Length)
                        {
                            var locationName      = locationNames[item.locationNamesIndex];
                            var locationField     = locationFieldNames[item.locationFieldIndex];
                            var locationFieldType = GetWizardLocationFieldType(item.locationFieldIndex);
                            AppendFormat(sb, "Location", locationName, locationField, locationFieldType, item);
                        }
                        else
                        {
                            sb.Append("(true)");
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.SimStatus)
                    {
                        // SimStatus:
                        string simStatusID = item.simStatusThisID ? "thisID" : item.simStatusID.ToString();
                        sb.AppendFormat("{0}Dialog[{1}].SimStatus {2} \"{3}\"{4}",
                                        openParen,
                                        simStatusID,
                                        GetWizardEqualityText(item.equalityType),
                                        item.simStatusType,
                                        closeParen);
                    }
                    else if (item.conditionType == ConditionWizardResourceType.Custom)
                    {
                        // Custom:
                        if (0 <= item.customLuaFuncIndex && item.customLuaFuncIndex < customLuaFuncs.Length)
                        {
                            sb.Append(openParen);
                            var luaFuncRecord = customLuaFuncs[item.customLuaFuncIndex];
                            sb.Append(luaFuncRecord.functionName + "(");
                            if (item.customParamValues == null)
                            {
                                InitCustomParamValues(luaFuncRecord, out item.customParamValues);
                            }
                            for (int p = 0; p < luaFuncRecord.parameters.Length; p++)
                            {
                                if (p > 0)
                                {
                                    sb.Append(", ");
                                }
                                switch (luaFuncRecord.parameters[p])
                                {
                                case CustomLuaParameterType.Bool:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = BooleanType.True;
                                    }
                                    sb.Append(((BooleanType)item.customParamValues[p] == BooleanType.True) ? "true" : "false");
                                    break;

                                case CustomLuaParameterType.Double:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = (float)0;
                                    }
                                    sb.Append((float)item.customParamValues[p]);
                                    break;

                                case CustomLuaParameterType.String:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = string.Empty;
                                    }
                                    sb.Append("\"" + (string)item.customParamValues[p] + "\"");
                                    break;

                                case CustomLuaParameterType.Actor:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = (int)0;
                                    }
                                    var actorIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= actorIndex && actorIndex < actorNames.Length) ? ("\"" + actorNames[actorIndex] + "\"") : "\"\"");
                                    break;

                                case CustomLuaParameterType.Quest:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = (int)0;
                                    }
                                    var questIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= questIndex && questIndex < questNames.Length) ? ("\"" + questNames[questIndex] + "\"") : "\"\"");
                                    break;

                                case CustomLuaParameterType.QuestEntry:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = (int)0;
                                    }
                                    sb.Append(((int)item.customParamValues[p] + 1).ToString());
                                    break;

                                case CustomLuaParameterType.Variable:
                                    if (item.customParamValues[p] == null)
                                    {
                                        item.customParamValues[p] = (int)0;
                                    }
                                    var variableIndex = (int)item.customParamValues[p];
                                    sb.Append((0 <= variableIndex && variableIndex < variableNames.Length) ? ("Variable[\"" + variableNames[variableIndex] + "\"]") : "\"\"");
                                    break;
                                }
                            }
                            sb.Append(") ");
                            switch (luaFuncRecord.returnValue)
                            {
                            case CustomLuaReturnType.Bool:
                                sb.Append(((item.equalityType == EqualityType.Is) ? " == " : " ~= ") +
                                          ((item.booleanValue == BooleanType.True) ? "true" : "false"));
                                break;

                            case CustomLuaReturnType.Double:
                                sb.Append(GetWizardComparisonText(item.comparisonType) + " " + item.floatValue);
                                break;

                            case CustomLuaReturnType.String:
                                sb.Append(((item.equalityType == EqualityType.Is) ? " == " : " ~= ") +
                                          "\"" + item.stringValue + "\"");
                                break;
                            }
                            sb.Append(closeParen);
                        }
                    }
                    else if (item.conditionType == ConditionWizardResourceType.ManualEnter)
                    {
                        // Manual Enter:
                        sb.AppendFormat("{0}{1}{2}", openParen, item.stringValue, closeParen);
                    }
                }
                return(sb.ToString());
            }
            catch (Exception e)
            {
                Debug.LogError(string.Format("{0}: Internal error building condition: {1}", DialogueDebug.Prefix, e.Message));
                return(savedLuaCode);
            }
            //-- Moved to AcceptConditionsWizard: currentConditionsWizardEntry = null;
        }
        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();
        }