public static void AbandonQuest(string qtitle, string lfs) { // Find quest id in toon log Output.Instance.Log(lfs, "Abandoning Quest '" + qtitle + "' ... "); int idx = FindLogQuest(qtitle, lfs); if (idx == 0) { Output.Instance.Log(lfs, "Not found in toon's quest log"); return; } // Open QuestLogFrame LuaHelper.Exec("ToggleFrame", "QuestLog"); NpcHelper.WaitDialogOpen("QuestLog", lfs); string[] ret = LuaHelper.Exec("SelectAbandonQuest", idx); string aq_name = ret[0]; if (string.IsNullOrEmpty(aq_name)) { throw new QuestProcessingException( "Abandoning preparation procedure didn't return quest name"); } else if (!aq_name.Equals(qtitle)) { throw new QuestProcessingException("Abandoned quest '" + aq_name + "' is different from expected '" + qtitle + "'."); } else { // Wait to get selection activated Thread.Sleep(2000); LuaHelper.Exec("AbandonQuest"); // Wait to get abandon action activated Thread.Sleep(2000); if (FindLogQuest(qtitle, lfs) == 0) { Output.Instance.Log(lfs, "Quest '" + qtitle + "' removed from toon logs"); } else { throw new QuestProcessingException("Abandoned quest '" + qtitle + "' is still in toon quest log after abandon action."); } } }
/// <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"); } }