Beispiel #1
0
        private static void AddNpcQuestStart(NPC npc, string[] opts, string lfs)
        {
            Quest q = null;

            // Check parsing result
            for (int i = 1; i < 4; i++)
            {
                string s = opts[i];

                if (string.IsNullOrEmpty(opts[i]))
                {
                    Output.Instance.LogError(lfs, i +
                                             " parameter from quest info result is empty");
                    return;
                }

                // Check each value against pattern
                Regex rx = DataManager.CurWoWVersion.QuestConfig.Patterns[i - 1];
                if (!rx.IsMatch(s))
                {
                    Output.Instance.LogError(lfs, i +
                                             " parameter '" + s + "' from quest scan" +
                                             " doesn't match template '" + rx.ToString() + "'");
                    return;
                }
            }

            // Read header
            string[] headers = opts[1].Split(new string[] { "::" }, StringSplitOptions.None);
            string   qtitle  = headers[0];

            // At this point we staying in front of NPC and quest opened
            // Accepting quest and reading it info from toon's quest log
            try
            {
                QuestHelper.DoAction(QuestHelper.MakeAcceptQuestReq(), lfs);

                // Look on quest log for all details
                string[] ret = ProcessManager.Injector.
                               Lua_ExecByName("GetLogQuestInfo", new string[] { qtitle });


                // Parse result
                string[] info    = opts[2].Split(',');
                string[] details = opts[3].Split(new string[] { "||" }, StringSplitOptions.None);


                Output.Instance.Log("Assign current NPC as start for quest '" + qtitle + "'");

                q = new Quest(Convert.ToInt32(ret[1]), qtitle,
                              headers[1], headers[2], Convert.ToInt32(ret[2]),
                              new int[] { Convert.ToInt32(info[3]), Convert.ToInt32(info[4]),
                                          Convert.ToInt32(info[5]) }, details, ret[4], info[0], ret[3]);
            }
            catch (Exception e)
            {
                Output.Instance.LogError(lfs, "Error creating quest with parameters " +
                                         "Header: " + headers[1] + "; Text: " + headers[2] +
                                         "; Level: " + headers[3], e);
                throw new QuestProcessingException("Failed add quest" + e.Message);
            }
            finally
            {
                // Whatever happened need abandon quest
                QuestHelper.AbandonQuest(qtitle, lfs);
            }

            if (q != null)
            {
                // Screen in npcdata how many quests with same title exists
                Quest mq = DataManager.CurWoWVersion.GameObjData.FindMaxQuestByTitle(q.Title);
                if (mq != null)
                {
                    q.QNum = mq.QNum + 1;
                    // Probably I need link to high lvl quest with same title
                    q.Relations.Add(q.Id);
                }
                npc.AddQuest(q);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Check if current quest avail
        /// If it on NPC gossip frame than select it
        /// If it already open than we fine
        /// </summary>
        /// <param name="q">Quest</param>
        /// <returns>true if NPC has quest</returns>
        private static bool CheckQuest(Quest q,
                                       string[] dinfo, QuestReq req, string lfs)
        {
            string cur_service = null;

            if (dinfo == null)
            {
                dinfo       = NpcHelper.GetTargetNpcDialogInfo(q.Src.Name, false, lfs);
                cur_service = dinfo[0];
            }
            else
            {
                cur_service = dinfo[0];
            }

            if (cur_service.Equals("gossip"))
            {
                Output.Instance.Debug(lfs, "GossipFrame opened.");

                Output.Instance.Debug(lfs, "Looking for quest ...");

                int idx = QuestHelper.FindGossipQuestIdByTitle(q.Title, req.ProcName);
                if (idx < 0)
                {
                    return(false);
                }

                // Selecting quest
                Output.Instance.Debug(lfs, "Selecting quest by Id: " + idx);
                LuaHelper.Exec("SelectGossip" + req.ProcName + "Quest", idx);

                // Wait for quest frame pop up
                try
                {
                    NpcHelper.WaitDialogOpen("Quest", lfs);
                }
                catch (NpcInteractException ne)
                {
                    throw new QuestProcessingException(ne.Message);
                }
                catch (Exception e)
                {
                    throw new QuestProcessingException(
                              "NPC doesn't show QuestFrame. " + e.Message);
                }

                // Call itself again to parse the quest
                return(CheckQuest(q, null, req, lfs));
            }
            else if (cur_service.Equals("quest_start"))
            {
                Output.Instance.Debug("Parsing quest info line '" + dinfo[1] + "'");
                string[] headers = dinfo[1].Split(new string[] {
                    "::"
                }, StringSplitOptions.None);

                string title = headers[0];
                return(!string.IsNullOrEmpty(title) && title.Equals(q.Title));
            }
            else if (cur_service.Equals("quest_progress"))
            {
                // Quest progress
                // Click continue and check next screen
                LuaHelper.Exec("CompleteQuest");
                // Wait to change quest frame
                Thread.Sleep(2000);
                return(CheckQuest(q, null, req, lfs));
            }
            else if (cur_service.Equals("quest_end"))
            {
                return(true);
            }
            else
            {
                // Quest not found nor on gossip frame nor on active frame
                throw new QuestProcessingException(
                          "Quest not found nor on GossipFrame nor on ActiveFrame");
            }
        }