//! @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); }
//! Парсер 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)); } } } }