Beispiel #1
0
        public void CreateTest()
        {
            string text   = @"switch (""1"") {
            case (1) {
                msg (""!"")
            }
            }";
            var    script = m_constructor.Create(text, scriptContext);
            QuestDictionary <IScript> actualCases = (QuestDictionary <IScript>)script.GetParameter(1);

            Assert.AreEqual(1, actualCases.Count);
            Assert.IsTrue(actualCases.Contains("1"));

            text        = @"switch (""1"") {
            case (StringListItem(myStringList, 0), 1) {
                msg (""!"")
            }
            }";
            script      = m_constructor.Create(text, scriptContext);
            actualCases = (QuestDictionary <IScript>)script.GetParameter(1);

            Assert.AreEqual(2, actualCases.Count);
            Assert.ReferenceEquals(actualCases["StringListItem(myStringList, 0)"],
                                   actualCases["1"]);
        }
    static string state = "";                //Store the Data to PlayerPrefs at some point
    public string StatusUpdate()             //Gets called any time the game wants to know what the status of the quest is, also when the quest is first started
    {
        InventoryData.OnChange += InvUpdate; //start listening to inventory updates
        if (state.Equals(""))
        {
            state = PlayerPrefs.GetString("SampleQuest", "blanke");                      //if the file is just initialized, read the data from disk, default to "blank" if it's the first time
        }
        PlayerPrefs.SetString("SampleQuest", state);                                     //Store the data again in case it changes
        switch (state)                                                                   //switch between the set states
        {
        case "blank":                                                                    //blank state can be used as a startup function
            NotificationManager.AddNotification("Quest Started", "Started SampleQuest"); //Adding notification that the quest started
            state = "Pick up Diary (0/1)";
            QuestDictionary.SetCurrent("SampleQuest");
            break;

        case "Pick up Diary (0/1)":
            break;

        case "Pick up Diary (1/1)":
            state = "Finished";
            NotificationManager.AddNotification("Quest Complete", "Finished SampleQuest"); //adding notification that the quest is finished
            //InventoryData.OnChange -= InvUpdate;  //stop listening to inventory updates
            PlayerPrefs.Save();                                                            //Writes all data changes to disk just in case
            break;
        }
        return(state);          //Return a string stating the status of the quest
    }
Beispiel #3
0
 public string ShowMenu(string caption, QuestDictionary <string> options, bool allowCancel)
 {
     if (m_worldModel.Version >= WorldModelVersion.v540)
     {
         throw new Exception("The 'ShowMenu' function is not supported for games written for Quest 5.4 or later. Use the 'show menu' script command instead.");
     }
     return(m_worldModel.DisplayMenu(caption, options, allowCancel, false));
 }
Beispiel #4
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            var list = new QuestList<object> {"string1"};
            var dictionary = new QuestDictionary<object> {{"key1", "nested string"}};
            list.Add(dictionary);
            m_object.Fields.Set("list", list);
            m_object.Fields.Resolve(null);
        }
Beispiel #5
0
        static public Dictionary <string, T> ConvertToObjectTypeDictionary <T>(QuestDictionary <string> dictionary, WorldModel worldModel, Func <Element, T> factory) where T : ObjectTypeBase
        {
            var dict = new Dictionary <string, T>();

            foreach (var kvp in dictionary)
            {
                T newObj = factory(worldModel.Elements.Get(kvp.Key));
                dict.Add(kvp.Key, newObj);
            }
            return(dict);
        }
Beispiel #6
0
        public void Setup()
        {
            m_worldModel = new WorldModel();

            m_object = m_worldModel.GetElementFactory(ElementType.Object).Create("object");
            var list = new QuestList <object> {
                "string1"
            };
            var dictionary = new QuestDictionary <object> {
                { "key1", "nested string" }
            };

            list.Add(dictionary);
            m_object.Fields.Set("list", list);
            m_object.Fields.Resolve(null);
        }
Beispiel #7
0
    public string StatusUpdate()
    {
        if (state.Equals(""))
        {
            if (JsonFile.save.Quests.QuestData.ContainsKey("Beavers"))
            {
                state = (string)JsonFile.save.Quests.QuestData["Beavers"][0];
            }
            else
            {
                state = "blank";
                JsonFile.save.Quests.QuestData.Add("Beavers", new object[] { state });
            }
        }
        switch (state)
        {
        case "blank":
            break;

        case "blank2":
            break;

        case "bridge":
            break;

        case "stoiyt":
            NotificationManager.AddNotification("Quest Started", "A mystery with wooden proportions");
            QuestDictionary.SetCurrent("Beavers");
            state = "Go to the scene of the crime";
            break;

        case "Go to the scene of the crime":
            break;

        //stuff happens here... WIP

        case "Return to Desislav":
            break;

        case "Finished":
            break;
        }
        return(state);
    }
 static void InvUpdate()         //Function for inventory updates, setup above
 {
     if (!state.Equals("Finished"))
     {
         //Check for the wood, tools, and cider in the inventory, set the boolean values
         if (InventoryData.HasItem(ItemDictionary.itemDict.GetItem("Planks")))
         {
             items[0] = true;
         }
         if (InventoryData.HasItem(ItemDictionary.itemDict.GetItem("Cider")))
         {
             items[1] = true;
         }
         if (InventoryData.HasItem(ItemDictionary.itemDict.GetItem("Tools")))
         {
             items[2] = true;
         }
         QuestDictionary.GetUpdate("Rebuild Town Bridge");                   //Update the status after new items
     }
 }
Beispiel #9
0
 public bool CheckData(int node)
 {
     for (int i = 0; i < Quests.Length; i++)
     {
         if (QuestDictionary.Quests.ContainsKey(questNames[i]))
         {
             if (node < Quests[i].states.Length)             //if the node checked has a qualifier, true if not
             {
                 if ((Quests[i].states[node]).Contains("!")) //Return the result if the state is not such
                 {
                     string newState = Quests[i].states[node].Replace("!", "");
                     if (Quests[i].states[node] != null && !newState.Equals(QuestDictionary.GetUpdate(questNames[i])) || Quests[i].states[node].Equals("true"))
                     {
                         return(true);
                     }
                 }
                 else if ((Quests[i].states[node]).Contains("..."))
                 {
                     string newState = Quests[i].states[node].Replace("...", "");
                     if (Quests[i].states[node] != null && (QuestDictionary.GetUpdate(questNames[i])).Contains(newState) || Quests[i].states[node].Equals("true"))
                     {
                         return(true);
                     }
                 }
                 else                            //Return the result if the state is such
                 {
                     if (Quests[i].states[node] != null && Quests[i].states[node].Equals(QuestDictionary.GetUpdate(questNames[i])) || Quests[i].states[node].Equals("true"))
                     {
                         return(true);
                     }
                 }
             }
             else
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #10
0
    void Awake()
    {
        if (instance == null)
        {
            instance = this;
        }
        else if (instance != this)
        {
            Destroy(gameObject);
        }

        DontDestroyOnLoad(gameObject);

        if (dictObjectives == null)
        {
            dictObjectives = new Dictionary <QuestName, Objective>();
            foreach (ObjectiveDictionary item in objectives)
            {
                dictObjectives.Add(item.key, item.objective);
            }
            objectives.Clear();
        }
    }
Beispiel #11
0
 public void DrawInv()
 {
     if (names != null)
     {
         foreach (object entry in InventoryData.items)
         {
             Text newItem = Instantiate(item);
             newItem.transform.SetParent(names.transform, false);
             newItem.text = " " + ((InventoryData.itemCount[entry] > 1) ? ("" + InventoryData.itemCount[entry] + "x ") : ("")) + entry.ToString() + ((InventoryData.compareItems(InventoryData.getEquipped(), entry)) ? (" \u25cf") : (""));
             newItem.name = entry.ToString() + "1";
             newItem.GetComponent <ItemExecution>().item = entry;
         }
         questStatus.text = JsonFile.save.PlayerData.currentQuest + ((!JsonFile.save.PlayerData.currentQuest.Equals("")) ? (": \n\n") : ("")) + QuestDictionary.GetUpdate(JsonFile.save.PlayerData.currentQuest);
         gold.text        = "Gold: " + InventoryData.gold;
     }
 }
Beispiel #12
0
        public static QuestDictionary<string> Populate(string regexPattern, string input)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexPattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (!regex.IsMatch(input)) throw new Exception(string.Format("String '{0}' is not a match for Regex '{1}'", input, regexPattern));

            QuestDictionary<string> result = new QuestDictionary<string>();

            foreach (string groupName in regex.GetGroupNames())
            {
                if (!TextAdventures.Utility.Strings.IsNumeric(groupName))
                {
                    string groupMatch = regex.Match(input).Groups[groupName].Value;
                    result.Add(groupName, groupMatch);
                }
            }

            return result;
        }
Beispiel #13
0
 public string ShowMenu(string caption, QuestDictionary<string> options, bool allowCancel)
 {
     return m_worldModel.DisplayMenu(caption, options, allowCancel);
 }
Beispiel #14
0
        public IEditableDictionary<string> CreateNewEditableStringDictionary(string parent, string attribute, string key, string item, bool useTransaction)
        {
            if (useTransaction)
            {
                WorldModel.UndoLogger.StartTransaction(string.Format("Set '{0}' {1} to '{2}'", parent, attribute, item));
            }
            Element element = (parent == null) ? null : m_worldModel.Elements.Get(parent);

            QuestDictionary<string> newDictionary = new QuestDictionary<string>();

            if (key != null)
            {
                newDictionary.Add(key, item);
            }

            if (element != null)
            {
                element.Fields.Set(attribute, newDictionary);

                // setting an element field will clone the value, so we want to return the new dictionary
                newDictionary = element.Fields.GetAsType<QuestDictionary<string>>(attribute);
            }

            EditableDictionary<string> newValue = new EditableDictionary<string>(this, newDictionary);

            if (useTransaction)
            {
                WorldModel.UndoLogger.EndTransaction();
            }

            return newValue;
        }
    public string StatusUpdate()        //Gets called any time the game wants to know what the status of the quest is, also when the quest is first started
    {
        if (state.Equals(""))
        {
            if (JsonFile.save.Quests.QuestData.ContainsKey("RebuildBridge"))                    //If the quest data entry exists in the data read from file
            {
                state    = (string)JsonFile.save.Quests.QuestData["RebuildBridge"][0];
                items[0] = (bool)JsonFile.save.Quests.QuestData["RebuildBridge"][1];                    //Retrieve data from object array at the index of the quest string
                items[1] = (bool)JsonFile.save.Quests.QuestData["RebuildBridge"][2];
                items[2] = (bool)JsonFile.save.Quests.QuestData["RebuildBridge"][3];
            }
            else
            {
                state = "blank";
                JsonFile.save.Quests.QuestData.Add("RebuildBridge", new object[] { state, false, false, false }); //New blanket array if one does not exist yet with default valuess
                SaveData.queueSave = true;                                                                        //Force a data write
            }
        }
        switch (state)                  //switch between the set states
        {
        case "blank":
            break;

        case "blank2":
            break;

        case "Styoit":
            state = "Collected: ";
            NotificationManager.AddNotification("Quest Started", "Rebuild Town Bridge");                 //Adding notification that the quest started
            QuestDictionary.SetCurrent("Rebuild Town Bridge");
            break;

        case "Collected: ":
            break;

        case "Solve the mystery of foresters wood":
            // Place for second quest that has to do with beavers
            break;

        case "wait until midnight for bridge to be built":
            break;

        case "quest finished":
            state = "Finished";
            NotificationManager.AddNotification("Quest Complete", "Rebuild Town Bridge");                   //adding notification that the quest is finished
            break;
        }
        if (state.Equals("Collected: "))                //Create dynamic list of items
        {
            state += ("\nWood: " + items[0] + "\nTools: " + items[1] + "\nCider: " + items[2]);
        }
        bool changed = false;

        if (!state.Equals((string)JsonFile.save.Quests.QuestData["RebuildBridge"][0]))
        {
            JsonFile.save.Quests.QuestData["RebuildBridge"][0] = state;
            changed = true;
        }
        if (items[0] != ((bool)JsonFile.save.Quests.QuestData["RebuildBridge"][1]))
        {
            JsonFile.save.Quests.QuestData["RebuildBridge"][1] = items[0];
            changed = true;
        }
        if (items[1] != ((bool)JsonFile.save.Quests.QuestData["RebuildBridge"][2]))
        {
            JsonFile.save.Quests.QuestData["RebuildBridge"][1] = items[1];
            changed = true;
        }
        if (items[2] != ((bool)JsonFile.save.Quests.QuestData["RebuildBridge"][3]))
        {
            JsonFile.save.Quests.QuestData["RebuildBridge"][1] = items[2];
            changed = true;
        }
        if (changed)
        {
            SaveData.queueSave = true; //Writes all data changes to disk just in case
        }
        return(state);                 //Return a string stating the status of the quest
    }
Beispiel #16
0
        public IEditableDictionary<IEditableScripts> CreateNewEditableScriptDictionary(string parent, string attribute, string key, IEditableScripts script, bool useTransaction)
        {
            if (useTransaction)
            {
                WorldModel.UndoLogger.StartTransaction(string.Format("Set '{0}' {1} to '{2}'", parent, attribute, script.DisplayString()));
            }

            Element element = (parent == null) ? null : m_worldModel.Elements.Get(parent);

            QuestDictionary<IScript> newDictionary = new QuestDictionary<IScript>();

            if (key != null)
            {
                newDictionary.Add(key, (IScript)script.GetUnderlyingValue());
            }

            if (element != null)
            {
                element.Fields.Set(attribute, newDictionary);

                // setting an element field will clone the value, so we want to return the new dictionary
                newDictionary = element.Fields.GetAsType<QuestDictionary<IScript>>(attribute);
            }

            IEditableDictionary<IEditableScripts> newValue = (IEditableDictionary<IEditableScripts>)WrapValue(newDictionary);

            if (useTransaction)
            {
                WorldModel.UndoLogger.EndTransaction();
            }

            return newValue;
        }
Beispiel #17
0
            public override void Load(Element element, string attribute, string value)
            {
                QuestDictionary<string> result = new QuestDictionary<string>();

                string[] values = Utility.ListSplit(value);
                foreach (string pair in values)
                {
                    if (pair.Length > 0)
                    {
                        string trimmedPair = pair.Trim();
                        int splitPos = trimmedPair.IndexOf('=');
                        if (splitPos == -1)
                        {
                            GameLoader.AddError(string.Format("Missing '=' in dictionary element '{0}' in '{1}.{2}'", trimmedPair, element.Name, attribute));
                            return;
                        }
                        string key = trimmedPair.Substring(0, splitPos).Trim();
                        string dictValue = trimmedPair.Substring(splitPos + 1).Trim();
                        result.Add(key, dictValue);
                    }
                }

                element.Fields.Set(attribute, result);
            }
Beispiel #18
0
        void LoadFiles(object filePaths)
        {
            List<string> files = (List<string>)filePaths;

            InvokeIfRequired(() =>
            {
                this.Cursor = Cursors.WaitCursor;
                statusProgressBar.Maximum = files.Count;
                ToggleProgressBar(true);
            });

            // Load HTML files

            // Step 0
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " Html's...");

            if (File.Exists(Path.Combine(root, @".\dialogs\quests.dat"))) {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Open)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        questFiles = (QuestDictionary)bf.Deserialize(fs);
                    }
                } catch { }
            }
            if (questFiles == null)
                questFiles = new QuestDictionary();

            bool addedNew = false;

            ResetProgress(questFiles.Count, String.Empty);

            for (int i = 0; i < files.Count; i++) {
                string name = Path.GetFileName(files[i]);
                if (!name.StartsWith("quest_"))
                    continue;
                string qId = Path.GetFileNameWithoutExtension(Path.GetFileName(files[i]))
                                 .Remove(0, 7).Trim();
                int id;
                if (!Int32.TryParse(qId, out id))
                    continue;
                if (_raceToView == "elyo" && id >= 2000 && id < 3000)
                    continue;
                if (_raceToView == "asmodian" && id < 2000)
                    continue;
                string msg = String.Format(Program.IniReader["loading"] + " {0}...", Path.GetFileName(files[i]));
                InvokeIfRequired(() => { statusLabel.Text = msg; });
                if (!questFiles.ContainsKey(id)) {
                    addedNew = true;
                    QuestFile questFile;
                    if (Utility.TryLoadQuestHtml(files[i], out questFile))
                        questFiles.Add(id, questFile);
                }
                InvokeIfRequired(() => { statusProgressBar.Value = i + 1; });
                Thread.Sleep(1);
            }

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HtmlPages.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(HtmlPageIndex));
                    HtmlPage.Index = (HtmlPageIndex)ser.Deserialize(reader);
                    HtmlPage.Index.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 1
            ResetProgress(LOAD_STEPS, Program.IniReader["loading"] + " HyperLinks.xml...");

            try {
                using (var fs = new FileStream(Path.Combine(root, @".\dialogs\HyperLinks.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(HyperLinkIndex));
                    SelectsAct.Index = (HyperLinkIndex)ser.Deserialize(reader);
                    SelectsAct.Index.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 2
            ShowProgress(Program.IniReader["loadingStrings"] + "...");
            Utility.LoadStrings(root);

            // Step 3
            ShowProgress(Program.IniReader["loadingNpc"] + "...");
            Utility.LoadNpcs(root);

            // Step 4
            ShowProgress(Program.IniReader["loadingQuestData"] + "...");
            try {
                using (var fs = new FileStream(Path.Combine(root, @".\quest\quest.xml"),
                                               FileMode.Open, FileAccess.Read))
                using (var reader = XmlReader.Create(fs)) {
                    XmlSerializer ser = new XmlSerializer(typeof(QuestsFile));
                    questData = (QuestsFile)ser.Deserialize(reader);
                    questData.CreateIndex();
                }
            } catch (Exception ex) {
                Debug.Print(ex.ToString());
            }

            // Step 5
            ShowProgress(Program.IniReader["loadingItemData"] + "...");
            Utility.LoadItems(root);

            /*
            InvBonuses bonuses = new InvBonuses();
            bonuses.BonusItems = new List<BonusItem>();
            foreach (var q in questData.QuestList) {
                WrapItem wi = null;
                if (q.reward_item_ext_1 != null && q.reward_item_ext_1.StartsWith("wrap_")) {
                    wi = new WrapItem();
                    string[] itemData = q.reward_item_ext_1.Split(' ');
                    Item item = Utility.ItemIndex.GetItem(itemData[0]);
                    if (item == null)
                        wi.itemId = 0;
                    else
                        wi.itemId = item.id;
                    if (itemData[0].Contains("_enchant_"))
                        wi.type = BonusType.ENCHANT;
                    else
                        wi.type = BonusType.MANASTONE;
                    string lvl = itemData[0].Substring(itemData[0].Length - 3, 2);
                    wi.level = Int32.Parse(lvl);
                }
                if (q.HasRandomRaward()) {
                    BonusItem bi = new BonusItem();
                    bi.questId = q.id;
                    bi.BonusInfos = new List<BonusInfo>();
                    if (q.reward_item1_1 != null && q.reward_item1_1.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_1 != null) {
                            string[] itemData = q.check_item1_1.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_1;
                        bi.BonusInfos.Add(bii);
                    }
                    if (q.reward_item1_2 != null && q.reward_item1_2.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_2 != null) {
                            string[] itemData = q.check_item1_2.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_2;
                        bi.BonusInfos.Add(bii);
                    }
                    if (q.reward_item1_3 != null && q.reward_item1_3.StartsWith("%Quest_")) {
                        BonusInfo bii = new BonusInfo();
                        if (q.check_item1_3 != null) {
                            string[] itemData = q.check_item1_3.Split(' ');
                            bii.checkItem = Utility.ItemIndex.GetItem(itemData[0]).id;
                            bii.checkItemSpecified = true;
                            bii.count = Int32.Parse(itemData[1]);
                            bii.countSpecified = true;
                        }
                        bii.Value = q.reward_item1_3;
                        bi.BonusInfos.Add(bii);
                    }
                    if (wi != null) {
                        bi.wrap = wi;
                        bi.wrapSpecified = true;
                    }
                    bonuses.BonusItems.Add(bi);
                } else if (wi != null) {
                    BonusItem bi = new BonusItem();
                    bi.questId = q.id;
                    bi.wrap = wi;
                    bi.wrapSpecified = true;
                    bonuses.BonusItems.Add(bi);
                }
            }

            XmlWriterSettings set = new XmlWriterSettings()
            {
                CloseOutput = false,
                Encoding = Encoding.UTF8,
                Indent = true,
                IndentChars = "\t",
            };
            using (FileStream stream = new FileStream("bonuses.xml", FileMode.Create, FileAccess.Write)) {
                using (XmlWriter wr = XmlWriter.Create(stream, set)) {
                    XmlSerializer ser = new XmlSerializer(typeof(InvBonuses));
                    ser.Serialize(wr, bonuses);
                }
            }
            */

            // Step 6
            ResetProgress(questFiles.Count, String.Empty);

            InvokeIfRequired(() =>
            {
                try {
                    this.Cursor = Cursors.Default;

                    foreach (int level in questData.Levels) {
                        var lvlNode = rootNode.Nodes.Add(level.ToString(),
                                        String.Format(Program.IniReader["level"] + " {0}", level));
                        TreeNode raceNode = null;
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "elyo")
                            raceNode = lvlNode.Nodes.Add("pc_light", Program.IniReader["elyo"]);
                        if (String.IsNullOrEmpty(_raceToView) || _raceToView == "asmodian")
                            raceNode = lvlNode.Nodes.Add("pc_dark", Program.IniReader["asmodian"]);
                        Application.DoEvents();
                    }

                    rootNode.Nodes.Add("0", Program.IniReader["misc"]);
                    rootNode.Expand();
                } catch { }
            });

            var writer = new StreamWriter("quests.txt");

            foreach (KeyValuePair<int, QuestFile> quest in questFiles) {
                HtmlPage summary = quest.Value.HtmlPages.Where(p => p.name == "quest_summary")
                                                        .FirstOrDefault();
                Quest questInfo = null;
                string qName = "Q" + quest.Key.ToString();

                ShowProgress(String.Format(Program.IniReader["parsing"] + " {0}", quest.Value.fileName));

                var title = Utility.StringIndex.GetStringDescription("STR_QUEST_NAME_" + qName);

                questInfo = questData["Q" + quest.Key];
                if (questInfo == null) {
                    Debug.Print("Missing data for: {0}", quest.Value.fileName);
                    questInfo = new Quest();
                }

                //if (!questInfo.HasRandomRaward())
                //    continue;

                questInfo.HtmlPages = quest.Value.HtmlPages;
                bool reconstructed = false;

                if (summary == null) {
                    Debug.Print("Quest: {0} doesn't contain summary", quest.Value.fileName);
                    if (title == null) {
                        continue;
                    }
                    Debug.Print("Quest Title: {0}", title.body);
                    summary = new HtmlPage() { name = "quest_summary" };
                    summary.Content = new Contents()
                    {
                        html = new ContentsHtml()
                        {
                            body = new Body()
                            {
                                steps = new Step[] { new Step() },
                                p = new Paragraph[] { new Paragraph() }
                            }
                        }
                    };
                    Paragraph para = summary.Content.html.body.p[0];
                    para.font = new pFont()
                    {
                        font_xml = "quest_summary",
                        Value = String.Empty
                    };

                    if (String.IsNullOrEmpty(questInfo.extra_category)) {
                        questInfo.extra_category = "devanion_quest";
                        Debug.Print("Quest: {0} extra_category is null", quest.Value.fileName);
                    }

                    CultureInfo ci = new CultureInfo(String.Empty);
                    string tit = ci.TextInfo.ToTitleCase(questInfo.extra_category.Replace('_', ' '));
                    para.font.Value = tit;

                    Step singleStep = summary.Content.html.body.steps[0];
                    singleStep.p = new Paragraph()
                    {
                        font = new pFont() { Value = Program.IniReader["step"] + " 1" }
                    };

                    // Include Quest Complete page too
                    var qc = quest.Value.HtmlPages.Where(p => p.name == "quest_complete").FirstOrDefault();
                    if (qc != null)
                        qc.ForceInclude = true;

                    quest.Value.HtmlPages.Add(summary);
                    reconstructed = true;
                }
                if (!reconstructed) {
                    if (summary.Content == null) {
                        Debug.Print("Quest: {0} summary doesn't contain content", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html == null) {
                        Debug.Print("Quest: {0} summary doesn't contain html", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body == null) {
                        Debug.Print("Quest: {0} summary doesn't contain body", quest.Value.fileName);
                        continue;
                    }
                    if (summary.Content.html.body.steps == null) {
                        Debug.Print("Quest: {0} summary doesn't contain steps", quest.Value.fileName);
                        continue;
                    }
                }

                if (title == null) {
                    Debug.Print("Quest: {0} has no title", quest.Value.fileName);
                    summary.QuestTitle = qName;
                } else {
                    summary.QuestTitle = title.body;
                }

                TreeNode questNode = new TreeNode(summary.QuestTitle);
                questNode.Name = qName;
                questNode.Tag = questInfo;

                writer.WriteLine(String.Format("{0}\t{1}", qName.Remove(0, 1), summary.QuestTitle));
                writer.Flush();

                int i = 0;
                foreach (Step step in summary.Content.html.body.steps) {
                    // [%collectitem]
                    // step.Value
                    i++;
                    if (String.IsNullOrEmpty(step.Value)) {
                        // ok
                    } else if (step.Value == "[%collectitem]") {
                    }

                    if (String.IsNullOrEmpty(step.p.font.Value)) {
                        Debug.Print("Empty step {0}", i);
                        continue;
                    }

                    step.Number = i;
                    var stepNode = questNode.Nodes.Add("S" + i.ToString(),
                                          String.Format(Program.IniReader["step"] + " {0}", i));
                    stepNode.Tag = step;
                    Thread.Sleep(1);
                }

                TreeNode nodeToAdd = null;

                InvokeIfRequired(() =>
                {
                    if (questInfo.minlevel_permitted == 0) {
                        nodeToAdd = rootNode.Nodes["0"];
                        nodeToAdd.Nodes.Add(questNode);
                        Application.DoEvents();
                    } else {
                        nodeToAdd = rootNode.Nodes[questInfo.minlevel_permitted.ToString()];
                        if (questInfo.race_permitted == "pc_light" &&
                            (_raceToView == null || _raceToView == "elyo")) {
                            nodeToAdd = nodeToAdd.Nodes["pc_light"];
                            AddQuestToRace(nodeToAdd, questNode);
                        } else if (questInfo.race_permitted == "pc_dark" &&
                                   (_raceToView == null || _raceToView == "asmodian")) {
                            nodeToAdd = nodeToAdd.Nodes["pc_dark"];
                            AddQuestToRace(nodeToAdd, questNode);
                        } else {
                            TreeNode node = null;
                            if (_raceToView == null || _raceToView == "elyo") {
                                node = nodeToAdd.Nodes["pc_light"];
                                AddQuestToRace(node, questNode);
                            }
                            if (_raceToView == null || _raceToView == "asmodian") {
                                node = nodeToAdd.Nodes["pc_dark"];
                                AddQuestToRace(node, questNode);
                            }
                        }
                    }
                });
                Thread.Sleep(1);
            }

            writer.Close();

            if (addedNew) {
                try {
                    using (FileStream fs = new FileStream(Path.Combine(root, @".\dialogs\quests.dat"), FileMode.Create)) {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.Serialize(fs, questFiles);
                    }
                } catch (Exception e) {
                }
            }

            // Done
            InvokeIfRequired(() =>
            {
                statusProgressBar.Value = statusProgressBar.Maximum;
                statusLabel.Text = String.Empty;
                ToggleProgressBar(false);
            });
        }
Beispiel #19
0
 public static void ResetQuestData()
 {
     QuestDictionary.Reset();
     JsonFile.WriteData();
 }
Beispiel #20
0
        private static QuestDictionary<string> PopulateInternal(Regex regex, string input)
        {
            if (!regex.IsMatch(input)) throw new Exception(string.Format("String '{0}' is not a match for Regex '{1}'", input, regex.ToString()));

            QuestDictionary<string> result = new QuestDictionary<string>();

            foreach (string groupName in regex.GetGroupNames())
            {
                if (!TextAdventures.Utility.Strings.IsNumeric(groupName))
                {
                    string groupMatch = regex.Match(input).Groups[groupName].Value;
                    result.Add(groupName, groupMatch);
                }
            }

            return result;
        }