Пример #1
0
        //! @todo исправлять это говнище!!!
        public void createResults()
        {
            NPCDicts results = new NPCDicts();

            foreach (var npc_name in this.locales[parent.settings.getCurrentLocale()].Keys)
            {
                foreach (var locale_dialog in this.locales[parent.settings.getCurrentLocale()][npc_name].Values)
                {
                    var dialog = parent.getDialogOnDialogID(npc_name, locale_dialog.DialogID);
                    if (dialog != null && dialog.version == locale_dialog.version)
                    {
                        if (!results.Keys.Contains(npc_name))
                        {
                            results.Add(npc_name, new Dictionary <int, CDialog>());
                        }
                        results[npc_name].Add(dialog.DialogID, new CDialog(dialog.Holder, locale_dialog.Title, locale_dialog.Text, dialog.QuestDialog, dialog.Precondition, dialog.Actions, dialog.Nodes, dialog.DialogID, dialog.version));
                    }
                }
            }
            this.save(parent.settings.dialogXML, results);
        }
Пример #2
0
        //! Парсер xml - файла диалогов, записывает результат в target
        private void parseDialogsFile(String DialogsXMLFile, NPCDicts target)
        {
            if (!File.Exists(DialogsXMLFile))
            {
                return;
            }

            doc = XDocument.Load(DialogsXMLFile);
            foreach (XElement item in doc.Root.Elements())
            {
                int DialogID = int.Parse(item.Element("DialogID").Value);

                string              Title        = item.Element("Title").Value.Trim();
                string              Text         = item.Element("Text").Value.Trim();
                List <string>       Holder       = new List <string>();
                int                 QuestDialog  = new int();
                List <int>          Nodes        = new List <int>();
                Actions             Actions      = new Actions();
                CDialogPrecondition Precondition = new CDialogPrecondition();

                if (item.Element("QuestDialog").Element("toCompleteQuest").Value != "")
                {
                    QuestDialog = int.Parse(item.Element("QuestDialog").Element("toCompleteQuest").Value);
                }

                foreach (string holder in item.Element("Holder").Value.Split(','))
                {
                    Holder.Add(holder.Trim());
                }

                if (item.Element("Nodes").Value != "")
                {
                    foreach (string node in item.Element("Nodes").Value.Split(','))
                    {
                        if (node != "")
                        {
                            Nodes.Add(int.Parse(node));
                        }
                    }
                }

                if (item.Element("Actions").Element("Exit").Value == "1")
                {
                    Actions.Exit = true;
                }
                else
                {
                    Actions.Exit = false;
                }

                if (item.Element("Actions").Element("ToDialog").Value != "")
                {
                    Actions.ToDialog = int.Parse(item.Element("Actions").Element("ToDialog").Value);
                }

                if (!item.Element("Actions").Element("Event").Value.Equals(""))
                {
                    Actions.Event = int.Parse(item.Element("Actions").Element("Event").Value);
                }
                else
                {
                    Actions.Event = 0;
                }

                Actions.Data = item.Element("Actions").Element("Data").Value;

                if (item.Element("Actions").Element("GetQuest").Value != "")
                {
                    foreach (string quest in item.Element("Actions").Element("GetQuest").Value.Split(','))
                    {
                        Actions.GetQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Actions").Element("CompleteQuest").Value != "")
                {
                    foreach (string quest in item.Element("Actions").Element("CompleteQuest").Value.Split(','))
                    {
                        Actions.CompleteQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfCompletedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfCompletedQuests").Value.Split(','))
                    {
                        Precondition.ListOfNecessaryQuests.ListOfCompletedQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfOpenedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfOpenedQuests").Value.Split(','))
                    {
                        Precondition.ListOfNecessaryQuests.ListOfOpenedQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfOnTestQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfOnTestQuests").Value.Split(','))
                    {
                        Precondition.ListOfNecessaryQuests.ListOfOnTestQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfCompletedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfCompletedQuests").Value.Split(','))
                    {
                        Precondition.ListOfMustNoQuests.ListOfCompletedQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfOpenedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfOpenedQuests").Value.Split(','))
                    {
                        Precondition.ListOfMustNoQuests.ListOfOpenedQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfOnTestQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfOnTestQuests").Value.Split(','))
                    {
                        Precondition.ListOfMustNoQuests.ListOfOnTestQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfFailedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfMustNoQuests").Element("listOfFailedQuests").Value.Split(','))
                    {
                        Precondition.ListOfMustNoQuests.ListOfFailedQuests.Add(int.Parse(quest));
                    }
                }

                if (item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfFailedQuests").Value != "")
                {
                    foreach (string quest in item.Element("Precondition").Element("ListOfNecessaryQuests").Element("listOfFailedQuests").Value.Split(','))
                    {
                        Precondition.ListOfNecessaryQuests.ListOfOnTestQuests.Add(int.Parse(quest));
                    }
                }

                //if (item.Element("Precondition").Element("CheckClan").Value == "1")
                //    Precondition.tests.Add(0);
                //if (item.Element("Precondition").Element("CheckClanID").Value == "1")
                //    Precondition.tests.Add(1);

                Precondition.KarmaPK = new List <int>();
                if (item.Element("Precondition").Element("KarmaPK").Value != "")
                {
                    foreach (string karme_el in item.Element("Precondition").Element("KarmaPK").Value.Split(','))
                    {
                        Precondition.KarmaPK.Add(int.Parse(karme_el));
                    }
                }

                if (item.Element("Precondition").Element("tests").Value != "")
                {
                    foreach (string test in item.Element("Precondition").Element("tests").Value.Split(','))
                    {
                        Precondition.tests.Add(int.Parse(test));
                    }
                }

                int Version = 0;
                if (!item.Element("Version").Value.Equals(""))
                {
                    Version = int.Parse(item.Element("Version").Value);
                }

                foreach (string el in item.Element("Precondition").Element("Reputation").Value.Split(';'))
                {
                    string[] fr = el.Split(':');
                    if (fr.Count() > 1)
                    {
                        Precondition.Reputation.Add(int.Parse(fr[0]), new List <double>());
                        int type = int.Parse(fr[1]);
                        Precondition.Reputation[int.Parse(fr[0])].Add(type);
                        double a = 0;
                        if (fr[2] != "")
                        {
                            a = double.Parse(fr[2]);
                        }
                        Precondition.Reputation[int.Parse(fr[0])].Add(a);
                        double b = 0;
                        if (fr[3] != "")
                        {
                            b = double.Parse(fr[3]);
                        }
                        Precondition.Reputation[int.Parse(fr[0])].Add(b);
                    }
                }

                foreach (string holder in Holder)
                {
                    if (target.Keys.Contains(holder))
                    {
                        if (!target[holder].Keys.Contains(DialogID))
                        {
                            target[holder].Add(DialogID, new CDialog(holder, Title, Text, QuestDialog, Precondition, Actions, Nodes, DialogID, Version));
                        }
                    }
                    else
                    {
                        target.Add(holder, new Dictionary <int, CDialog>());
                        target[holder].Add(DialogID, new CDialog(holder, Title, Text, QuestDialog, Precondition, Actions, Nodes, DialogID, Version));
                    }
                }
            }
        }
Пример #3
0
        /*
         * //! Трэшак со StartQuests
         * bool isDialogRoot(int dialogID, string holder)
         * {
         *  NPCDialogDict npc_dialogs = this.dialogs[holder];
         *  foreach (CDialog dialog in npc_dialogs.Values)
         *  {
         *      //System.Console.WriteLine(dialog.QuestDialog.ToString() + " vs " + currentQuestDialog.ToString());
         *      if ((parent.isStartQuest(dialog.QuestDialog)) && (dialog.DialogID == dialogID))
         *          return true;
         *      else
         *          return false;
         *  }
         *  return false;
         * }
         */


        //! Сохранение всех диалогов в xml файл
        private void save(string fileName, NPCDicts target)
        {
            string newOldName = (fileName.Replace(".xml", "") + "_" + DateTime.UtcNow.ToString() + ".xml").Replace(':', '_');

            replaceOldDialogsFile(0, newOldName, fileName);

            XDocument resultDoc = new XDocument(new XElement("root"));
            XElement  element;

            int toCompleteQuest;

            foreach (NPCDialogDict Dictdialog in target.Values)
            {
                foreach (CDialog dialog in Dictdialog.Values)
                {
                    toCompleteQuest = dialog.QuestDialog;

                    element = new XElement("dialog",
                                           new XElement("DialogID", dialog.DialogID.ToString()),
                                           new XElement("Version", dialog.version.ToString()),
                                           new XElement("Holder", dialog.Holder.ToString()),
                                           new XElement("Title", dialog.Title.ToString()),
                                           new XElement("QuestDialog",
                                                        //new XElement("toCompleteQuest", isDialogRoot(dialog.DialogID, dialog.Holder)? getIntAsString(toCompleteQuest) : "")),
                                                        new XElement("toCompleteQuest", dialog.QuestDialog.ToString())),
                                           new XElement("Precondition",
                                                        new XElement("ListOfNecessaryQuests",
                                                                     new XElement("listOfCompletedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfNecessaryQuests.ListOfCompletedQuests)),
                                                                     new XElement("listOfOpenedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfNecessaryQuests.ListOfOpenedQuests)),
                                                                     new XElement("listOfOnTestQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfNecessaryQuests.ListOfOnTestQuests)),
                                                                     new XElement("listOfFailedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfNecessaryQuests.ListOfFailedQuests))),
                                                        new XElement("ListOfMustNoQuests",
                                                                     new XElement("listOfCompletedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfMustNoQuests.ListOfCompletedQuests)),
                                                                     new XElement("listOfOpenedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfMustNoQuests.ListOfOpenedQuests)),
                                                                     new XElement("listOfOnTestQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfMustNoQuests.ListOfOnTestQuests)),
                                                                     new XElement("listOfFailedQuests",
                                                                                  getListAsString(dialog.Precondition.ListOfMustNoQuests.ListOfFailedQuests))),
                                                        new XElement("tests", getListAsString(dialog.Precondition.tests)),
                                                        new XElement("Reputation", dialog.Precondition.getReputation()),
                                                        new XElement("KarmaPK", getListAsString(dialog.Precondition.KarmaPK))
                                                        ),
                                           new XElement("Text", dialog.Text),
                                           new XElement("Actions",
                                                        new XElement("Exit", getBoolAsString(dialog.Actions.Exit)),
                                                        new XElement("ToDialog", getIntAsString(dialog.Actions.ToDialog)),
                                                        new XElement("Data", dialog.Actions.Data),
                                                        new XElement("Event", dialog.Actions.Event.ToString()),
                                                        new XElement("GetQuest", getListAsString(dialog.Actions.GetQuests)),
                                                        new XElement("CompleteQuest", getListAsString(dialog.Actions.CompleteQuests))),
                                           new XElement("Nodes", getListAsString(dialog.Nodes))
                                           );
                    resultDoc.Root.Add(element);
                }
            }

            System.Xml.XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
            settings.Encoding            = new UTF8Encoding(false);
            settings.Indent              = true;
            settings.OmitXmlDeclaration  = true;
            settings.NewLineOnAttributes = true;
            using (System.Xml.XmlWriter w = System.Xml.XmlWriter.Create(fileName, settings))
            {
                resultDoc.Save(w);
            }
        }