Beispiel #1
0
        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:
            if (!string.IsNullOrEmpty(questName))
            {
                QuestLog.SetQuestState(questName, questState);
            }

            // 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);
                }
            }

            // Once?
            DestroyIfOnce();
        }
 void RpcSetQuestState(string questName, string state)
 {
     QuestLog.SetQuestState(questName, state);
 }
 void RpcSetQuestEntryState(string questName, int entryNumber, string state)
 {
     QuestLog.SetQuestEntryState(questName, entryNumber, state);
 }
        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 = variableNames[item.variableNamesIndex];
                        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)
                            {
                                if (item.valueSetMode == ValueSetMode.To)
                                {
                                    sb.AppendFormat("NetSetNumber(\"{0}\", {1})",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                }
                                else
                                {
                                    sb.AppendFormat("NetSetNumber(\"{0}\", Variable[\"{0}\"] + {1})",
                                                    DialogueLua.StringToTableIndex(variableName),
                                                    item.floatValue);
                                }
                            }
                            else
                            {
                                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:
                            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)
                        {
                            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);
            }
        }