Пример #1
0
        HtmlPage[] ExtractFollowingPages(HtmlPage page, int pageIndex, HtmlPage[] allPages)
        {
            if (pageIndex < 0)
                throw new ArgumentException("pageIndex");

            List<HtmlPage> followingPages = new List<HtmlPage>(0);
            if (page.Selects == null || pageIndex >= allPages.Length - 1)
                return followingPages.ToArray();

            foreach (SelectsAct action in page.Selects) {
                if (String.IsNullOrEmpty(action.href))
                    continue;

                string nextPageName = action.ActionName;
                if (nextPageName == null)
                    continue;
                HtmlPage nextPage = allPages.Where(p => p != null && p.name == nextPageName)
                                            .FirstOrDefault();
                if (nextPage == null) {
                    // doesn't match
                    nextPage = allPages.Where(p => p != null && p.name.StartsWith(nextPageName))
                                       .FirstOrDefault();
                }

                if (nextPage != null) {
                    int nextPageIdx = Array.IndexOf(allPages, nextPage);
                    if (nextPageIdx == pageIndex + 2) {
                        // theres's a page between, check if it has only a "finish_dialog" action
                        HtmlPage skippedPage = allPages[pageIndex + 1];
                        if (skippedPage != null && skippedPage.Selects != null) {
                            string name = skippedPage.Selects[0].ActionName;
                            if (name == "finish_dialog") {
                                // add the skipped page before
                                // TODO: check for being non-referenced by other pages?
                                followingPages.Add(skippedPage);
                                allPages[pageIndex + 1] = null;
                            }
                        }
                    }
                    followingPages.Add(nextPage);
                    // remove, so if other pages back-referencing it, the page won't be picked up again
                    allPages[nextPageIdx] = null;
                    followingPages.AddRange(ExtractFollowingPages(nextPage, nextPageIdx, allPages));
                } else if (nextPageName == "check_user_has_quest_item") {
                    // add the next page which is displayed when the check fails
                    // make sure it has "finish_dialog" button
                    // Add to select3 --> select3_1 etc. instead ??
                    // it also can contain "setpro" button !!!
                    int addedCount = 0;
                    string lastAddedPageName = String.Empty;
                    for (int i = pageIndex + 1; i < allPages.Length; i++) {
                        HtmlPage pageAfter = allPages[i];
                        if (pageAfter == null)
                            continue;
                        bool canClose = pageAfter.Selects == null ||
                                        pageAfter.name == "user_item_ok" ||
                                        pageAfter.name == "user_item_fail";
                        if (!canClose && pageAfter.Selects.Length == 1) {
                            string pgAct = pageAfter.Selects[0].ActionName;
                            canClose = pgAct == "finish_dialog" || pgAct.StartsWith("setpro");
                        }
                        if (canClose || pageAfter.name.StartsWith(page.name) ||
                            addedCount > 0 && pageAfter.name.StartsWith(lastAddedPageName)) {
                            followingPages.Add(pageAfter);
                            allPages[i] = null;
                            addedCount++;
                            lastAddedPageName = pageAfter.name;
                            if (!canClose || pageAfter.name == "user_item_ok" ||
                                pageAfter.name == "user_item_fail") {
                                followingPages.AddRange(ExtractFollowingPages(pageAfter, i + 1, allPages));
                            }
                            if (addedCount == 2) // added Accept and Deny pages
                                break;
                        }
                    }
                }
            }
            return followingPages.ToArray();
        }
Пример #2
0
        HtmlPage[][] GetSortedQuestPages(int totalSteps)
        {
            var pages = _quest.HtmlPages.Where(p => p.name != "quest_summary" &&
                                                    p.name != "select_acqusitive_quest_desc" &&
                                                    p.name != "select_progressive_quest_desc" &&
                                                    p.name != "quest_complete" || p.ForceInclude).ToArray();
            var pagesWithReward = pages.Where(p => p != null && p.name.StartsWith("select_quest_reward"))
                                       .ToList();

            HtmlPage[][] result = new HtmlPage[totalSteps][];
            if (totalSteps == 1) { // add all pages
                result[0] = pages;
                return result;
            }

            int stepToAdd = 0;

            for (int i = 0; i < pages.Length; i++) {
                HtmlPage currentPage = pages[i];
                HtmlPage prePage = null;

                if (currentPage == null) // removed page, allready extracted
                    continue;
                bool isPrepage = currentPage.name.StartsWith("select_none") ||
                                 currentPage.name.StartsWith("ask_quest_accept") && i == 0;

                int oldStep = stepToAdd;
                bool usePrepageProcessing;
                FixQuestStep(ref stepToAdd, out usePrepageProcessing);

                if (isPrepage && usePrepageProcessing) {
                    // item touch quest if the button is also "ask_quest_accept"
                    if (currentPage.Selects != null) {
                        string actionName = currentPage.Selects[0].ActionName;
                        if (actionName != null &&
                            (actionName.StartsWith("ask_quest_accept") ||
                             actionName.StartsWith("finish_dialog"))) {
                            prePage = currentPage;
                            pages[i] = null;
                            if (pages.Length > i + 1) { // add the first select pages too
                                currentPage = pages[i + 1];
                                pages[i + 1] = null; // don't add the same
                                i++;
                            }
                        }
                    }
                }

                if (stepToAdd != 0 && _allSteps.Length > stepToAdd) {
                    // check if that (x/x) kill or gather quest;
                    // if so, no pages for it, if the previous step wasn't a collect items quest
                    // in the latter case the dialogs have to be added
                    HtmlPage[] prevStepPages = result[stepToAdd - 1];
                    if (prevStepPages != null) {
                        bool prevHasNumbers = _allSteps[stepToAdd - 1].IsCollection ||
                                              _allSteps[stepToAdd - 1].HasCount;
                        //bool thisHasNumbers = _allSteps[stepToAdd].IsCollection ||
                        //                      _allSteps[stepToAdd].HasCount;
                        if (!prevHasNumbers && _allSteps[stepToAdd].HasCount) {
                            stepToAdd++;
                            i--; // add the same page
                            continue;
                        }
                    }
                }

                HtmlPage[] following = ExtractFollowingPages(currentPage, i, pages);
                if (following != null) {
                    if (stepToAdd > _allSteps.Length - 1) {
                        // add to the last step
                        stepToAdd = _allSteps.Length - 1;
                        int startIdx = 1;
                        if (result[stepToAdd] == null) {
                            result[stepToAdd] = new HtmlPage[following.Length + 1];
                        } else {
                            startIdx += result[stepToAdd].Length;
                            Array.Resize(ref result[stepToAdd],
                                         result[stepToAdd].Length + following.Length + 1);
                        }
                        result[stepToAdd][startIdx - 1] = currentPage;
                        Array.Copy(following, 0, result[stepToAdd], startIdx, following.Length);
                        pages[i] = null;
                        stepToAdd++; // make sure the array is always resized after
                        continue;
                    }
                    // check collection steps
                    if (_allSteps[stepToAdd].IsCollection) {
                        if (_step.Number - 1 == stepToAdd) {
                            if (result[_step.Number - 1] != null) {
                            }
                            // TODO: populate _collectItems
                        }
                    }

                    bool rewardFollows = following.Where(p => p.name.StartsWith("select_quest_reward")).Any();
                    if (rewardFollows && pagesWithReward.Count == 1 &&
                        stepToAdd < totalSteps - 1 && !_allSteps[stepToAdd].IsCollection &&
                        stepToAdd == oldStep) {
                        // only one reward and we are not on the last step,
                        // then move it forth
                        stepToAdd = totalSteps - 1;
                    }

                    int plus = prePage == null ? 0 : 1;
                    if (result[stepToAdd] == null) {
                        result[stepToAdd] = new HtmlPage[following.Length + plus + 1];
                    } else {
                        int len = result[stepToAdd].Length;
                        Array.Resize(ref result[stepToAdd], len + following.Length + plus + 1);
                        plus += len;
                    }
                    if (prePage != null)
                        result[stepToAdd][plus - 1] = prePage;
                    result[stepToAdd][plus] = currentPage;
                    Array.Copy(following, 0, result[stepToAdd], 1 + plus, following.Length);

                    if (oldStep != stepToAdd)
                        stepToAdd = oldStep; // continue if the reward was moved
                    pages[i] = null;
                }
                stepToAdd++;
            }

            Debug.Print("======STEPS: {0}========", --stepToAdd);

            return result;
        }
Пример #3
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);
            });
        }
Пример #4
0
        void AddTabPage(HtmlPage page, bool create, int rewardNo)
        {
            this.tabPages.SuspendLayout();

            TabPage tab = null;
            TableLayoutPanel wholeTable = null;
            TableLayoutPanel buttonTable = null;
            TransparentRichTextBox textBox = null;

            if (create) {
                wholeTable = new TableLayoutPanel();
                buttonTable = new TableLayoutPanel();
                textBox = new TransparentRichTextBox();
                tabPages.TabPages.Add(page.HtmlPageId.ToString());
                tab = tabPages.TabPages[tabPages.TabPages.Count - 1];
                tab.BackColor = SystemColors.ControlDarkDark;
                tab.BackgroundImage = Properties.Resources.dialogBackground;
                tab.Controls.Add(wholeTable);
                tab.ForeColor = SystemColors.Info;
                tab.Location = new Point(4, 27);
                tab.Margin = new Padding(0);
                tab.Size = new Size(401, 449);
            } else {
                tab = tabPages.TabPages[0];
                wholeTable = tableLayoutPanel1;
                buttonTable = tableLayoutPanel2;
                textBox = transparentRichTextBox1;
            }

            tab.Text = page.HtmlPageId.ToString();
            tab.Tag = tab.ToolTipText = page.name;

            tab.SuspendLayout();
            wholeTable.SuspendLayout();
            buttonTable.SuspendLayout();
            textBox.SuspendLayout();
            this.SuspendLayout();

            if (create) {
                int scrollWidth = SystemInformation.VerticalScrollBarWidth;
                const int rewardsMaxHeight = 230;
                const int totalHeight = 401;

                wholeTable.BackColor = System.Drawing.Color.Transparent;
                wholeTable.ColumnCount = 1;
                wholeTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                wholeTable.Controls.Add(buttonTable, 0, 1);
                wholeTable.Controls.Add(textBox, 0, 0);
                wholeTable.Location = new Point(31, 23);
                wholeTable.RowCount = 2;
                wholeTable.Size = new Size(339, totalHeight);

                bool isReward = page.name.StartsWith("select_quest_reward");
                RewardList rw = null;

                buttonTable.ColumnCount = 1;
                buttonTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                buttonTable.Dock = DockStyle.Fill;

                int topHeight = 305;

                if (isReward) {
                    int repeat;
                    rw = new RewardList(_quest.GetReward(rewardNo, out repeat))
                    {
                        BackColor = Color.Transparent,
                        Width = 339 - 2 * scrollWidth,
                    };
                    int height = rw.RecommendedHeight;
                    if (height > rewardsMaxHeight)
                        height = rewardsMaxHeight;
                    rw.Height = height;

                    float topPerc = (float)(totalHeight - height) / totalHeight;
                    topHeight = (int)Math.Ceiling(totalHeight * topPerc);
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, topPerc * 100));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f * (1 - topPerc)));

                    buttonTable.Location = new Point(0, topHeight);
                    buttonTable.Margin = new Padding(scrollWidth, 0, 0, 0);
                    buttonTable.RowCount = 1;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
                    buttonTable.Size = new Size(339 - 2 * scrollWidth, totalHeight - topHeight);
                    rw.RewardSelected += new RewardList.RewardSelectedEventHandler(OnRewardSelected);
                    buttonTable.Controls.Add(rw, 0, 0);
                } else {
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 76.05985F));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 23.94015F));

                    buttonTable.Margin = new Padding(0);
                    buttonTable.Location = new Point(0, 305);
                    buttonTable.RowCount = 4;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.Size = new Size(339, 96);
                }

                textBox.BorderStyle = BorderStyle.None;
                textBox.Dock = DockStyle.Fill;
                textBox.Font = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
                textBox.Location = new Point(0, 0);
                textBox.Margin = new Padding(0);
                textBox.ReadOnly = true;
                textBox.ScrollBars = RichTextBoxScrollBars.None;
                textBox.Size = new Size(339, topHeight);
            }

            buttonPanels.Add(buttonTable);

            StringBuilder text = new StringBuilder();
            if (page.Content != null) {
                if (page.Content.html != null && page.Content.html.body != null &&
                    page.Content.html.body.p != null) {
                    foreach (Paragraph para in page.Content.html.body.p) {
                        if (!String.IsNullOrEmpty(para.visible))
                            continue;
                        string line = para.Value;
                        if (!String.IsNullOrEmpty(line))
                            text.Append(Utility.GetParsedString(line, true));
                        text.Append('\n');
                    }
                }
                if (page.Selects != null) {
                    int i = 0;
                    foreach (SelectsAct action in page.Selects) {
                        if (String.IsNullOrEmpty(action.Value))
                            continue;
                        Button button = new Button();
                        button.BackColor = Color.DarkKhaki;
                        button.ForeColor = SystemColors.ControlText;
                        button.Text = action.Value.Trim('"', ' ', '“', '”');
                        button.Margin = new Padding(1, 1, 1, 1);
                        button.Dock = DockStyle.Fill;
                        ToolTip toolTip = new ToolTip();

                        string actionName = action.ActionName;
                        string emotionName = action.EmotionName;
                        string fixedPage = String.Empty;

                        // check if that page exists
                        HtmlPage matchedPage = _pages.Where(p => p.name == actionName)
                                                     .FirstOrDefault();
                        if (matchedPage == null) {
                            matchedPage = _pages.Where(p => p.name.StartsWith(actionName) &&
                                                            _pages.IndexOf(p) > _pages.IndexOf(page))
                                                .FirstOrDefault();
                            if (matchedPage == null && actionName == "ask_quest_accept") {
                                matchedPage = _pages.Where(p => p.name.StartsWith("quest_accept") &&
                                                            _pages.IndexOf(p) > _pages.IndexOf(page))
                                                    .FirstOrDefault();
                                fixedPage = String.Format("(wrong!!! Id = {0}, Name = ask_quest_accept)",
                                                          HtmlPage.Index["ask_quest_accept"]);
                            }
                        }

                        string tip = String.Empty;
                        if (matchedPage != null) {
                            // create click handler
                            button.Click += new EventHandler(delegate(object sender, EventArgs args)
                            {
                                var allPages = tabPages.TabPages.Cast<TabPage>();
                                var showPage = allPages.Where(t => ((string)t.Tag) == matchedPage.name &&
                                                                   !t.Equals(tab))
                                                       .FirstOrDefault();
                                if (showPage != null) {
                                    tabPages.SelectedTab = showPage;
                                }
                            });
                            tip = String.Format("Action Id = {0}, Page Id = {1}",
                                                action.Id, matchedPage.HtmlPageId);
                        } else {
                            tip = String.Format("Action Id = {0}, Name = {1}", action.Id, actionName);
                        }

                        if (!string.IsNullOrEmpty(fixedPage))
                            tip += fixedPage;

                        if (!String.IsNullOrEmpty(emotionName))
                            tip += String.Format(", Emotion = {0}", emotionName);

                        toolTip.SetToolTip(button, tip);

                        if (i > 3)
                            continue;
                        buttonTable.Controls.Add(button, 0, i++);
                    }
                }
            }

            textBox.Text = text.ToString();
            textBoxes.Add(textBox);

            tabPages.ResumeLayout(true);
            tab.ResumeLayout(true);
            wholeTable.ResumeLayout(true);
            buttonTable.ResumeLayout(true);
            textBox.ResumeLayout(true);
            this.ResumeLayout(false);
        }
Пример #5
0
        private void OnSelected(object sender, TreeViewEventArgs args)
        {
            using (var freezer = new FormFreezer(this, true)) {
                string         name   = args.Node.Name;
                TreeViewAction action = args.Action;

                if (table.Controls.Count == 3)
                {
                    var control = table.Controls[2];
                    table.Controls.RemoveAt(2);
                    control.Dispose();
                    GC.Collect();
                }

                if (name == "pc_light")
                {
                    lblTitle.Text       = Program.IniReader["elyosQuests"];
                    txtDescription.Text = String.Empty;
                }
                else if (name == "pc_dark")
                {
                    lblTitle.Text       = Program.IniReader["asmodiansQuests"];
                    txtDescription.Text = String.Empty;
                }
                else if (name.StartsWith("Q"))
                {
                    Quest    quest   = (Quest)args.Node.Tag;
                    HtmlPage summary = quest.HtmlPages.Where(p => p.name == "quest_summary")
                                       .FirstOrDefault();
                    if (summary == null)
                    {
                        lblTitle.Text       = args.Node.Text;
                        txtDescription.Text = String.Empty;
                    }
                    else
                    {
                        lblTitle.Text       = summary.QuestTitle;
                        txtDescription.Text = summary.QuestDescription;
                        var page = new QuestPage(args.Node);
                        page.Width            = table.Width - page.Margin.Horizontal;
                        page.QuestId          = quest.id;
                        page.IsMission        = quest.category1 == "mission";
                        page.Zone             = Utility.StringIndex.GetString(quest.category2);
                        page.RepeatCount      = quest.max_repeat_count;
                        page.CanAbandon       = !quest.cannot_giveup;
                        page.CanShare         = !quest.cannot_share;
                        page.ClientLevel      = quest.client_level;
                        page.ExtendsInventory = quest.reward_extend_inventory1 > 0;
                        page.ExtendsStigma    = quest.reward_extend_stigma1;
                        if (!String.IsNullOrEmpty(quest.gender_permitted))
                        {
                            page.Genders = quest.gender_permitted.Split(' ', ',');
                        }
                        if (!String.IsNullOrEmpty(quest.race_permitted))
                        {
                            page.Races = quest.race_permitted.Split(' ', ',');
                        }
                        if (!String.IsNullOrEmpty(quest.class_permitted))
                        {
                            page.Classes = quest.class_permitted.Split(' ', ',');
                        }

                        List <string> finished = new List <string>();
                        if (!String.IsNullOrEmpty(quest.finished_quest_cond1))
                        {
                            finished.AddRange(quest.finished_quest_cond1.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.finished_quest_cond2))
                        {
                            finished.AddRange(quest.finished_quest_cond2.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.finished_quest_cond3))
                        {
                            finished.AddRange(quest.finished_quest_cond3.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.finished_quest_cond4))
                        {
                            finished.AddRange(quest.finished_quest_cond4.Split(' ', ','));
                        }
                        if (finished.Count > 0)
                        {
                            page.Finished = finished.ToArray();
                        }

                        List <string> unfinished = new List <string>();
                        if (!String.IsNullOrEmpty(quest.unfinished_quest_cond1))
                        {
                            unfinished.AddRange(quest.unfinished_quest_cond1.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.unfinished_quest_cond2))
                        {
                            unfinished.AddRange(quest.unfinished_quest_cond2.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.unfinished_quest_cond3))
                        {
                            unfinished.AddRange(quest.unfinished_quest_cond3.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.unfinished_quest_cond4))
                        {
                            unfinished.AddRange(quest.unfinished_quest_cond4.Split(' ', ','));
                        }
                        if (!String.IsNullOrEmpty(quest.unfinished_quest_cond5))
                        {
                            unfinished.AddRange(quest.unfinished_quest_cond5.Split(' ', ','));
                        }
                        if (unfinished.Count > 0)
                        {
                            page.Unfinished = unfinished.ToArray();
                        }

                        table.Controls.Add(page, 0, 2);
                    }
                }
                else if (name.StartsWith("S"))
                {
                    var      questNode = args.Node.Parent;
                    Quest    quest     = (Quest)questNode.Tag;
                    HtmlPage summary   = quest.HtmlPages.Where(p => p.name == "quest_summary")
                                         .FirstOrDefault();
                    Step step = (Step)args.Node.Tag;
                    lblTitle.Text       = summary.QuestTitle;
                    txtDescription.Text = step.Description;
                    Step[] allSteps = questNode.Nodes.Cast <TreeNode>().Select(n => (Step)n.Tag).ToArray();
                    var    page     = new StepPage(quest, allSteps, step.Number);
                    page.Width = table.Width - page.Margin.Horizontal;
                    table.Controls.Add(page, 0, 2);
                }
                else
                {
                    lblTitle.Text       = args.Node.Text;
                    txtDescription.Text = String.Empty;
                    //var page = new StepPage(args.Node);
                    //page.Width = table.Width - page.Margin.Horizontal;
                    //table.Controls.Add(page, 0, 2);
                }

                // fix row 2 height
                OnTableSizeChanged(null, null);
            }
        }
Пример #6
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);
            });
        }
Пример #7
0
        void AddTabPage(HtmlPage page, bool create, int rewardNo)
        {
            this.tabPages.SuspendLayout();

            TabPage                tab         = null;
            TableLayoutPanel       wholeTable  = null;
            TableLayoutPanel       buttonTable = null;
            TransparentRichTextBox textBox     = null;

            if (create)
            {
                wholeTable  = new TableLayoutPanel();
                buttonTable = new TableLayoutPanel();
                textBox     = new TransparentRichTextBox();
                tabPages.TabPages.Add(page.HtmlPageId.ToString());
                tab                 = tabPages.TabPages[tabPages.TabPages.Count - 1];
                tab.BackColor       = SystemColors.ControlDarkDark;
                tab.BackgroundImage = Properties.Resources.dialogBackground;
                tab.Controls.Add(wholeTable);
                tab.ForeColor = SystemColors.Info;
                tab.Location  = new Point(4, 27);
                tab.Margin    = new Padding(0);
                tab.Size      = new Size(401, 449);
            }
            else
            {
                tab         = tabPages.TabPages[0];
                wholeTable  = tableLayoutPanel1;
                buttonTable = tableLayoutPanel2;
                textBox     = transparentRichTextBox1;
            }

            tab.Text = page.HtmlPageId.ToString();
            tab.Tag  = tab.ToolTipText = page.name;

            tab.SuspendLayout();
            wholeTable.SuspendLayout();
            buttonTable.SuspendLayout();
            textBox.SuspendLayout();
            this.SuspendLayout();

            if (create)
            {
                int       scrollWidth      = SystemInformation.VerticalScrollBarWidth;
                const int rewardsMaxHeight = 230;
                const int totalHeight      = 401;

                wholeTable.BackColor   = System.Drawing.Color.Transparent;
                wholeTable.ColumnCount = 1;
                wholeTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                wholeTable.Controls.Add(buttonTable, 0, 1);
                wholeTable.Controls.Add(textBox, 0, 0);
                wholeTable.Location = new Point(31, 23);
                wholeTable.RowCount = 2;
                wholeTable.Size     = new Size(339, totalHeight);

                bool       isReward = page.name.StartsWith("select_quest_reward");
                RewardList rw       = null;

                buttonTable.ColumnCount = 1;
                buttonTable.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
                buttonTable.Dock = DockStyle.Fill;

                int topHeight = 305;

                if (isReward)
                {
                    int repeat;
                    rw = new RewardList(_quest.GetReward(rewardNo, out repeat))
                    {
                        BackColor = Color.Transparent,
                        Width     = 339 - 2 * scrollWidth,
                    };
                    int height = rw.RecommendedHeight;
                    if (height > rewardsMaxHeight)
                    {
                        height = rewardsMaxHeight;
                    }
                    rw.Height = height;

                    float topPerc = (float)(totalHeight - height) / totalHeight;
                    topHeight = (int)Math.Ceiling(totalHeight * topPerc);
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, topPerc * 100));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100f * (1 - topPerc)));

                    buttonTable.Location = new Point(0, topHeight);
                    buttonTable.Margin   = new Padding(scrollWidth, 0, 0, 0);
                    buttonTable.RowCount = 1;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 100F));
                    buttonTable.Size   = new Size(339 - 2 * scrollWidth, totalHeight - topHeight);
                    rw.RewardSelected += new RewardList.RewardSelectedEventHandler(OnRewardSelected);
                    buttonTable.Controls.Add(rw, 0, 0);
                }
                else
                {
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 76.05985F));
                    wholeTable.RowStyles.Add(new RowStyle(SizeType.Percent, 23.94015F));

                    buttonTable.Margin   = new Padding(0);
                    buttonTable.Location = new Point(0, 305);
                    buttonTable.RowCount = 4;
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.RowStyles.Add(new RowStyle(SizeType.Percent, 25F));
                    buttonTable.Size = new Size(339, 96);
                }

                textBox.BorderStyle = BorderStyle.None;
                textBox.Dock        = DockStyle.Fill;
                textBox.Font        = new Font("Microsoft Sans Serif", 9.75F, FontStyle.Regular, GraphicsUnit.Point);
                textBox.Location    = new Point(0, 0);
                textBox.Margin      = new Padding(0);
                textBox.ReadOnly    = true;
                textBox.ScrollBars  = RichTextBoxScrollBars.None;
                textBox.Size        = new Size(339, topHeight);
            }

            buttonPanels.Add(buttonTable);

            StringBuilder text = new StringBuilder();

            if (page.Content != null)
            {
                if (page.Content.html != null && page.Content.html.body != null &&
                    page.Content.html.body.p != null)
                {
                    foreach (Paragraph para in page.Content.html.body.p)
                    {
                        if (!String.IsNullOrEmpty(para.visible))
                        {
                            continue;
                        }
                        string line = para.Value;
                        if (!String.IsNullOrEmpty(line))
                        {
                            text.Append(Utility.GetParsedString(line, true));
                        }
                        text.Append('\n');
                    }
                }
                if (page.Selects != null)
                {
                    int i = 0;
                    foreach (SelectsAct action in page.Selects)
                    {
                        if (String.IsNullOrEmpty(action.Value))
                        {
                            continue;
                        }
                        Button button = new Button();
                        button.BackColor = Color.DarkKhaki;
                        button.ForeColor = SystemColors.ControlText;
                        button.Text      = action.Value.Trim('"', ' ', '“', '”');
                        button.Margin    = new Padding(1, 1, 1, 1);
                        button.Dock      = DockStyle.Fill;
                        ToolTip toolTip = new ToolTip();

                        string actionName  = action.ActionName;
                        string emotionName = action.EmotionName;
                        string fixedPage   = String.Empty;

                        // check if that page exists
                        HtmlPage matchedPage = _pages.Where(p => p.name == actionName)
                                               .FirstOrDefault();
                        if (matchedPage == null)
                        {
                            matchedPage = _pages.Where(p => p.name.StartsWith(actionName) &&
                                                       _pages.IndexOf(p) > _pages.IndexOf(page))
                                          .FirstOrDefault();
                            if (matchedPage == null && actionName == "ask_quest_accept")
                            {
                                matchedPage = _pages.Where(p => p.name.StartsWith("quest_accept") &&
                                                           _pages.IndexOf(p) > _pages.IndexOf(page))
                                              .FirstOrDefault();
                                fixedPage = String.Format("(wrong!!! Id = {0}, Name = ask_quest_accept)",
                                                          HtmlPage.Index["ask_quest_accept"]);
                            }
                        }

                        string tip = String.Empty;
                        if (matchedPage != null)
                        {
                            // create click handler
                            button.Click += new EventHandler(delegate(object sender, EventArgs args)
                            {
                                var allPages = tabPages.TabPages.Cast <TabPage>();
                                var showPage = allPages.Where(t => ((string)t.Tag) == matchedPage.name &&
                                                              !t.Equals(tab))
                                               .FirstOrDefault();
                                if (showPage != null)
                                {
                                    tabPages.SelectedTab = showPage;
                                }
                            });
                            tip = String.Format("Action Id = {0}, Page Id = {1}",
                                                action.Id, matchedPage.HtmlPageId);
                        }
                        else
                        {
                            tip = String.Format("Action Id = {0}, Name = {1}", action.Id, actionName);
                        }

                        if (!string.IsNullOrEmpty(fixedPage))
                        {
                            tip += fixedPage;
                        }

                        if (!String.IsNullOrEmpty(emotionName))
                        {
                            tip += String.Format(", Emotion = {0}", emotionName);
                        }

                        toolTip.SetToolTip(button, tip);

                        if (i > 3)
                        {
                            continue;
                        }
                        buttonTable.Controls.Add(button, 0, i++);
                    }
                }
            }

            textBox.Text = text.ToString();
            textBoxes.Add(textBox);

            tabPages.ResumeLayout(true);
            tab.ResumeLayout(true);
            wholeTable.ResumeLayout(true);
            buttonTable.ResumeLayout(true);
            textBox.ResumeLayout(true);
            this.ResumeLayout(false);
        }
Пример #8
0
        HtmlPage[] ExtractFollowingPages(HtmlPage page, int pageIndex, HtmlPage[] allPages)
        {
            if (pageIndex < 0)
            {
                throw new ArgumentException("pageIndex");
            }

            List <HtmlPage> followingPages = new List <HtmlPage>(0);

            if (page.Selects == null || pageIndex >= allPages.Length - 1)
            {
                return(followingPages.ToArray());
            }

            foreach (SelectsAct action in page.Selects)
            {
                if (String.IsNullOrEmpty(action.href))
                {
                    continue;
                }

                string nextPageName = action.ActionName;
                if (nextPageName == null)
                {
                    continue;
                }
                HtmlPage nextPage = allPages.Where(p => p != null && p.name == nextPageName)
                                    .FirstOrDefault();
                if (nextPage == null)
                {
                    // doesn't match
                    nextPage = allPages.Where(p => p != null && p.name.StartsWith(nextPageName))
                               .FirstOrDefault();
                }

                if (nextPage != null)
                {
                    int nextPageIdx = Array.IndexOf(allPages, nextPage);
                    if (nextPageIdx == pageIndex + 2)
                    {
                        // theres's a page between, check if it has only a "finish_dialog" action
                        HtmlPage skippedPage = allPages[pageIndex + 1];
                        if (skippedPage != null && skippedPage.Selects != null)
                        {
                            string name = skippedPage.Selects[0].ActionName;
                            if (name == "finish_dialog")
                            {
                                // add the skipped page before
                                // TODO: check for being non-referenced by other pages?
                                followingPages.Add(skippedPage);
                                allPages[pageIndex + 1] = null;
                            }
                        }
                    }
                    followingPages.Add(nextPage);
                    // remove, so if other pages back-referencing it, the page won't be picked up again
                    allPages[nextPageIdx] = null;
                    followingPages.AddRange(ExtractFollowingPages(nextPage, nextPageIdx, allPages));
                }
                else if (nextPageName == "check_user_has_quest_item")
                {
                    // add the next page which is displayed when the check fails
                    // make sure it has "finish_dialog" button
                    // Add to select3 --> select3_1 etc. instead ??
                    // it also can contain "setpro" button !!!
                    int    addedCount        = 0;
                    string lastAddedPageName = String.Empty;
                    for (int i = pageIndex + 1; i < allPages.Length; i++)
                    {
                        HtmlPage pageAfter = allPages[i];
                        if (pageAfter == null)
                        {
                            continue;
                        }
                        bool canClose = pageAfter.Selects == null ||
                                        pageAfter.name == "user_item_ok" ||
                                        pageAfter.name == "user_item_fail";
                        if (!canClose && pageAfter.Selects.Length == 1)
                        {
                            string pgAct = pageAfter.Selects[0].ActionName;
                            canClose = pgAct == "finish_dialog" || pgAct.StartsWith("setpro");
                        }
                        if (canClose || pageAfter.name.StartsWith(page.name) ||
                            addedCount > 0 && pageAfter.name.StartsWith(lastAddedPageName))
                        {
                            followingPages.Add(pageAfter);
                            allPages[i] = null;
                            addedCount++;
                            lastAddedPageName = pageAfter.name;
                            if (!canClose || pageAfter.name == "user_item_ok" ||
                                pageAfter.name == "user_item_fail")
                            {
                                followingPages.AddRange(ExtractFollowingPages(pageAfter, i + 1, allPages));
                            }
                            if (addedCount == 2) // added Accept and Deny pages
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(followingPages.ToArray());
        }
Пример #9
0
        HtmlPage[][] GetSortedQuestPages(int totalSteps)
        {
            var pages = _quest.HtmlPages.Where(p => p.name != "quest_summary" &&
                                               p.name != "select_acqusitive_quest_desc" &&
                                               p.name != "select_progressive_quest_desc" &&
                                               p.name != "quest_complete" || p.ForceInclude).ToArray();
            var pagesWithReward = pages.Where(p => p != null && p.name.StartsWith("select_quest_reward"))
                                  .ToList();

            HtmlPage[][] result = new HtmlPage[totalSteps][];
            if (totalSteps == 1)   // add all pages
            {
                result[0] = pages;
                return(result);
            }

            int stepToAdd = 0;

            for (int i = 0; i < pages.Length; i++)
            {
                HtmlPage currentPage = pages[i];
                HtmlPage prePage     = null;

                if (currentPage == null) // removed page, allready extracted
                {
                    continue;
                }
                bool isPrepage = currentPage.name.StartsWith("select_none") ||
                                 currentPage.name.StartsWith("ask_quest_accept") && i == 0;

                int  oldStep = stepToAdd;
                bool usePrepageProcessing;
                FixQuestStep(ref stepToAdd, out usePrepageProcessing);

                if (isPrepage && usePrepageProcessing)
                {
                    // item touch quest if the button is also "ask_quest_accept"
                    if (currentPage.Selects != null)
                    {
                        string actionName = currentPage.Selects[0].ActionName;
                        if (actionName != null &&
                            (actionName.StartsWith("ask_quest_accept") ||
                             actionName.StartsWith("finish_dialog")))
                        {
                            prePage  = currentPage;
                            pages[i] = null;
                            if (pages.Length > i + 1)   // add the first select pages too
                            {
                                currentPage  = pages[i + 1];
                                pages[i + 1] = null; // don't add the same
                                i++;
                            }
                        }
                    }
                }

                if (stepToAdd != 0 && _allSteps.Length > stepToAdd)
                {
                    // check if that (x/x) kill or gather quest;
                    // if so, no pages for it, if the previous step wasn't a collect items quest
                    // in the latter case the dialogs have to be added
                    HtmlPage[] prevStepPages = result[stepToAdd - 1];
                    if (prevStepPages != null)
                    {
                        bool prevHasNumbers = _allSteps[stepToAdd - 1].IsCollection ||
                                              _allSteps[stepToAdd - 1].HasCount;
                        //bool thisHasNumbers = _allSteps[stepToAdd].IsCollection ||
                        //                      _allSteps[stepToAdd].HasCount;
                        if (!prevHasNumbers && _allSteps[stepToAdd].HasCount)
                        {
                            stepToAdd++;
                            i--; // add the same page
                            continue;
                        }
                    }
                }

                HtmlPage[] following = ExtractFollowingPages(currentPage, i, pages);
                if (following != null)
                {
                    if (stepToAdd > _allSteps.Length - 1)
                    {
                        // add to the last step
                        stepToAdd = _allSteps.Length - 1;
                        int startIdx = 1;
                        if (result[stepToAdd] == null)
                        {
                            result[stepToAdd] = new HtmlPage[following.Length + 1];
                        }
                        else
                        {
                            startIdx += result[stepToAdd].Length;
                            Array.Resize(ref result[stepToAdd],
                                         result[stepToAdd].Length + following.Length + 1);
                        }
                        result[stepToAdd][startIdx - 1] = currentPage;
                        Array.Copy(following, 0, result[stepToAdd], startIdx, following.Length);
                        pages[i] = null;
                        stepToAdd++; // make sure the array is always resized after
                        continue;
                    }
                    // check collection steps
                    if (_allSteps[stepToAdd].IsCollection)
                    {
                        if (_step.Number - 1 == stepToAdd)
                        {
                            if (result[_step.Number - 1] != null)
                            {
                            }
                            // TODO: populate _collectItems
                        }
                    }

                    bool rewardFollows = following.Where(p => p.name.StartsWith("select_quest_reward")).Any();
                    if (rewardFollows && pagesWithReward.Count == 1 &&
                        stepToAdd < totalSteps - 1 && !_allSteps[stepToAdd].IsCollection &&
                        stepToAdd == oldStep)
                    {
                        // only one reward and we are not on the last step,
                        // then move it forth
                        stepToAdd = totalSteps - 1;
                    }

                    int plus = prePage == null ? 0 : 1;
                    if (result[stepToAdd] == null)
                    {
                        result[stepToAdd] = new HtmlPage[following.Length + plus + 1];
                    }
                    else
                    {
                        int len = result[stepToAdd].Length;
                        Array.Resize(ref result[stepToAdd], len + following.Length + plus + 1);
                        plus += len;
                    }
                    if (prePage != null)
                    {
                        result[stepToAdd][plus - 1] = prePage;
                    }
                    result[stepToAdd][plus] = currentPage;
                    Array.Copy(following, 0, result[stepToAdd], 1 + plus, following.Length);

                    if (oldStep != stepToAdd)
                    {
                        stepToAdd = oldStep; // continue if the reward was moved
                    }
                    pages[i] = null;
                }
                stepToAdd++;
            }

            Debug.Print("======STEPS: {0}========", --stepToAdd);

            return(result);
        }