示例#1
0
        public QuestPage(TreeNode questNode)
            : this()
        {
            rootNode = questNode;
            _quest = (Quest)rootNode.Tag;

            // temp disable
            _quest.StepPages = null;

            lblSteps.Text = String.Format(Program.IniReader["steps"] +
                                          " ({0} " + Program.IniReader["pages"] + "):",
                                          _quest.ValidHtmlPages.Count);

            if (questNode.Nodes.Count > 0) {
                int row = 0;
                var nInfo = questNode.Nodes.OfType<TreeNode>().Select(n =>
                                                        new { Node = n, Step = n.Tag as Step } )
                                           .Where(n => n.Step != null);
                tableSteps.AutoSize = true;
                tableSteps.RowCount = nInfo.Count();
                foreach (var info in nInfo) {
                    var link = new LinkLabel();
                    link.AutoSize = true;
                    link.LinkColor = Color.FromArgb(255, 255, 192);
                    link.VisitedLinkColor = Color.FromArgb(230, 230, 0);
                    link.ActiveLinkColor = Color.Yellow;
                    link.DisabledLinkColor = Color.FromArgb(224, 224, 224);
                    link.Text = info.Step.p.font.Text;
                    var vars = Utility.GetNpcIdsFromDescription(info.Step.p.font.Value);
                    if (vars.Any()) {
                        link.Text += " (NPC Id: ";
                        foreach (var id in vars)
                            link.Text += id + ", ";
                        link.Text = link.Text.TrimEnd(',', ' ');
                        link.Text += ")";
                    }
                    link.Links[0].LinkData = info.Node;
                    link.Margin = new Padding(30, 1, 3, 1);
                    link.LinkClicked += new LinkLabelLinkClickedEventHandler(OnLinkClicked);
                    tableSteps.Controls.Add(link, 0, row++);
                }
            }
        }
示例#2
0
        public StepPage(Quest quest, Step[] steps, int stepToGet)
            : this()
        {
            if (quest == null)
                throw new ArgumentNullException("quest");
            if (steps == null)
                throw new ArgumentNullException("steps");
            _allSteps = steps;
            _quest = quest;
            if (stepToGet < 1 || stepToGet > steps.Length)
                throw new ArgumentOutOfRangeException("stepToGet");
            _step = steps[stepToGet - 1];

            HtmlPage[][] sortedPages = quest.StepPages;
            if (sortedPages == null) {
                try {
                    sortedPages = quest.StepPages = GetSortedQuestPages(steps.Length);
                } catch (Exception ex) {
                    Debug.Print(ex.ToString());
                    return;
                }
            }

            if (sortedPages[stepToGet - 1] != null)
                _pages = sortedPages[stepToGet - 1].ToList();

            int row = 0;
            if (_step != null) {
                if (_step.IsCollection) {
                    if (!String.IsNullOrEmpty(_quest.collect_item1))
                        _collectItems.Add(_quest.collect_item1);
                    if (!String.IsNullOrEmpty(_quest.collect_item2))
                        _collectItems.Add(_quest.collect_item2);
                    if (!String.IsNullOrEmpty(_quest.collect_item3))
                        _collectItems.Add(_quest.collect_item3);
                    if (!String.IsNullOrEmpty(_quest.collect_item4))
                        _collectItems.Add(_quest.collect_item4);
                    foreach (string item in _collectItems) {
                        var itemLabel = new LinkLabel();
                        itemLabel.AutoSize = true;
                        itemLabel.LinkColor = Color.FromArgb(255, 255, 192);
                        itemLabel.VisitedLinkColor = Color.FromArgb(230, 230, 0);
                        itemLabel.ActiveLinkColor = Color.Yellow;
                        itemLabel.DisabledLinkColor = Color.FromArgb(224, 224, 224);
                        itemLabel.Margin = new Padding(30, 1, 3, 1);

                        string[] itemPlusCount = item.Split(' ');
                        if (itemPlusCount.Length != 2) {
                            continue;
                        }
                        itemLabel.Text = String.Format("{0} (×{1})",
                                                       Utility.ItemIndex[itemPlusCount[0]], itemPlusCount[1]);
                        tableItems.Controls.Add(itemLabel, 0, row++);
                        if (row > 1) {
                            tableItems.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                        }
                        itemLabel.Links[0].LinkData = Utility.ItemIndex.GetItem(itemPlusCount[0]);
                        itemLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(OnItemLinkClicked);
                        // itemLabel.Click += new EventHandler(OnLinkLabelClicked);
                    }
                    if (row != 0) {
                        lblTask.Text = Program.IniReader["collectItems"] + ':';
                        tableItems.RowCount = row;
                        tableItems.AutoSize = true;
                    } else {
                        lblTask.Text = String.Empty;
                    }
                } else {
                    lblTask.Text = String.Empty;
                }
            }

            int pageCount = 0;
            int rewardNo = 0;
            foreach (HtmlPage page in _pages) {
                pageCount++;
                if (page.name.StartsWith("select_quest_reward"))
                    rewardNo = page.HtmlPageId - 4;
                AddTabPage(page, true, rewardNo);
                //break;
            }

            tabPages.TabPages.RemoveAt(0);
        }
示例#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);
            });
        }