Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.99 KB | None | 0 0
  1. using System;
  2. using Decal.Adapter;
  3. using MyClasses.MetaViewWrappers;
  4. using System.Text.RegularExpressions;
  5. using System.Collections.Generic;
  6. using VirindiViewService.Controls;
  7. using System.Data;
  8.  
  9. namespace UtilityBelt.Tools
  10. {
  11. class QuestTracker : IDisposable
  12. {
  13.  
  14. private bool disposed = false;
  15. private bool shouldEatQuests = false;
  16. private bool buttonClicked = false;
  17.  
  18. HudList UIMyQuestList { get; set; }
  19. //HudStaticText UIQuest { get; set; }
  20. //HudStaticText UIrepeatTimeTest { get; set; }
  21. //HudStaticText UISsolveCountTest { get; set; }
  22. HudButton UIPopulateQuestList { get; set; }
  23. HudList UIMyKillTaskList { get; set; }
  24. HudStaticText UIQuestName { get; set; }
  25. HudStaticText UIMaxCompletionsTest { get; set; }
  26. HudButton PopulateKillTaskList { get; set; }
  27. HudList UIMyOneTimeList { get; set; }
  28. HudStaticText PopulateOneTimeList { get; set; }
  29.  
  30. public QuestTracker()
  31. {
  32. //CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(Current_ChatBoxMessage);
  33. Globals.Core.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(Current_ChatBoxMessage);
  34.  
  35. UIPopulateQuestList = Globals.View.view != null ? (HudButton)Globals.View.view["AutoSalvageStart"] : new HudButton();
  36. UIPopulateQuestList.Hit += PopulateQuestList_Click;
  37.  
  38. }
  39. public string GetFriendlyTimeDifference(TimeSpan difference)
  40. {
  41. string output = "";
  42.  
  43. if (difference.TotalDays > 0) output += difference.Days.ToString() + "d ";
  44. if (difference.TotalHours > 0) output += difference.Hours.ToString() + "h ";
  45. if (difference.TotalMinutes > 0) output += difference.Minutes.ToString() + "m ";
  46. if (difference.TotalSeconds > 0) output += difference.Seconds.ToString() + "s ";
  47.  
  48. return output;
  49. }
  50.  
  51. public string GetFriendlyTimeDifference(long difference)
  52. {
  53. return GetFriendlyTimeDifference(TimeSpan.FromSeconds(difference));
  54. }
  55.  
  56.  
  57.  
  58.  
  59. public void CreateDataTable()
  60. {
  61. questDataTable.Columns.Add("questKeyTest");
  62. questDataTable.Columns.Add("solveCountTest");
  63. //questDataTable.Columns.Add("completedOnTest");
  64. questDataTable.Columns.Add("questDescriptionTest");
  65. questDataTable.Columns.Add("maxCompletionsTest");
  66. questDataTable.Columns.Add("repeatTimeTest");
  67. questDataTable.Columns.Add("questType");
  68. }
  69.  
  70. //DataTable questDataTable = new DataTable();
  71. private Dictionary<string, string> questList = new Dictionary<string, string>();
  72. private Dictionary<string, string> killTaskList = new Dictionary<string, string>();
  73. private static readonly Regex myQuestRegex = new Regex(@"(?<questKey>\S+) \- (?<solveCount>\d+) solves \((?<completedOn>\d{0,11})\)""?((?<questDescription>.*)"" (?<maxCompletions>.*) (?<repeatTime>\d{0,6}))?.*$");
  74. //private static readonly Regex myQuestRegex = new Regex(@"(?<questKey>\S+) \- (?<solveCount>\d+) solves? \((?<completedOn>\d{0,11})\)((?<questDescription>.*) -?\d+ (?<repeatTime>\d+))?.*$");
  75. private static readonly Regex killTaskRegex = new Regex(@"killtask|killcount|slayerquest|totalgolem.*dead");
  76. DataTable questDataTable = new DataTable();
  77.  
  78. public void Current_ChatBoxMessage(object sender, ChatTextInterceptEventArgs e)
  79. {
  80. try
  81. {
  82. Match match = myQuestRegex.Match(e.Text);
  83.  
  84. if (match.Success)
  85. {
  86.  
  87. if (questDataTable.Rows.Count == 0)
  88. {
  89. //Util.WriteToChat("does not exit");
  90. CreateDataTable();
  91. }
  92. else
  93. {
  94. //Util.WriteToChat("exists");
  95. }
  96.  
  97. string questKey = match.Groups["questKey"].Value;
  98. string solveCount = match.Groups["solveCount"].Value;
  99. //string completedOn = match.Groups["completedOn"].Value;
  100. string questDescription = match.Groups["questDescription"].Value;
  101. string maxCompletions = match.Groups["maxCompletions"].Value;
  102. //string repeatTime = match.Groups["repeatTime"].Value;
  103. long availableOnEpoch = 0;
  104. string questTimerstr = "";
  105. string questType = "";
  106. long todayEpoch = (long)((DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds);
  107. bool dupe = false;
  108. if (Int32.TryParse(match.Groups["completedOn"].Value, out int completedOn))
  109. {
  110. availableOnEpoch = completedOn;
  111. }
  112. if (Int32.TryParse(match.Groups["repeatTime"].Value, out int repeatTime))
  113. {
  114. availableOnEpoch += repeatTime;
  115. }
  116.  
  117. if (todayEpoch > availableOnEpoch)
  118. {
  119. questTimerstr = "Ready";
  120. }
  121. else
  122. {
  123. questTimerstr = GetFriendlyTimeDifference(availableOnEpoch - todayEpoch);
  124. }
  125.  
  126.  
  127. Match matchKillTask = killTaskRegex.Match(questKey);
  128.  
  129. if (matchKillTask.Success)
  130. {
  131. //Util.WriteToChat("test");
  132. questType = "killTask";
  133. }
  134. if (maxCompletions == "1")
  135. {
  136. questType = "oneTimeQuest";
  137. }
  138.  
  139.  
  140. DataRow newDTRow = questDataTable.NewRow();
  141. foreach (DataRow row in questDataTable.Rows)
  142. {
  143. if (row["questKeyTest"].ToString() == questKey)
  144. {
  145. // Util.WriteToChat(questKey + " already exists");
  146. dupe = true;
  147. // Util.WriteToChat(questKey + ": duplicate");
  148. row["solveCountTest"] = solveCount;
  149. //newDTRow["completedOnTest"] = completedOn;
  150. if (questDescription == "")
  151. {
  152. row["questDescriptionTest"] = questKey;
  153. }
  154. else
  155. {
  156. row["questDescriptionTest"] = questDescription;
  157. }
  158.  
  159. row["maxCompletionsTest"] = maxCompletions;
  160. row["repeatTimeTest"] = questTimerstr;
  161. row["questType"] = questType;
  162. }
  163. }
  164.  
  165.  
  166. if (dupe == true)
  167. {
  168. //Util.WriteToChat(questKey + ": duplicate");
  169. //newDTRow["solveCountTest"] = solveCount;
  170. ////newDTRow["completedOnTest"] = completedOn;
  171. //newDTRow["questDescriptionTest"] = questDescription;
  172. //newDTRow["maxCompletionsTest"] = maxCompletions;
  173. //newDTRow["repeatTimeTest"] = questTimerstr;
  174. //newDTRow["questType"] = questType;
  175. }
  176. else
  177. {
  178.  
  179. //if(row["questKeyTest"])
  180. newDTRow["questKeyTest"] = questKey;
  181. newDTRow["solveCountTest"] = solveCount;
  182. //newDTRow["completedOnTest"] = completedOn;
  183. if (questDescription == "")
  184. {
  185. newDTRow["questDescriptionTest"] = questKey;
  186. }
  187. else
  188. {
  189. newDTRow["questDescriptionTest"] = questDescription;
  190. }
  191. newDTRow["maxCompletionsTest"] = maxCompletions;
  192. newDTRow["repeatTimeTest"] = questTimerstr;
  193. newDTRow["questType"] = questType;
  194. questDataTable.Rows.Add(newDTRow);
  195. }
  196.  
  197. if (shouldEatQuests)
  198. {
  199. e.Eat = true;
  200. }
  201. }
  202. }
  203. catch (Exception ex) { Util.LogException(ex); }
  204. }
  205.  
  206.  
  207. public void PopulateQuests()
  208. {
  209. try
  210. {
  211. buttonClicked = true;
  212. shouldEatQuests = true;
  213.  
  214. Globals.Core.Actions.InvokeChatParser("/myquests");
  215.  
  216. HudList.HudListRowAccessor newQLRow = UIMyQuestList.AddRow();
  217. ((HudStaticText)newQLRow[0]).Text = "QuestName";
  218. ((HudStaticText)newQLRow[1]).Text = "solveCount";
  219. ((HudStaticText)newQLRow[2]).Text = "maxCompletions";
  220.  
  221. HudList.HudListRowAccessor newKTRow = UIMyKillTaskList.AddRow();
  222. ((HudStaticText)newKTRow[0]).Text = "QuestName";
  223.  
  224. HudList.HudListRowAccessor newOTRow = UIMyOneTimeList.AddRow();
  225. ((HudStaticText)newQLRow[0]).Text = "QuestName";
  226. ((HudStaticText)newQLRow[1]).Text = "repeatTime";
  227. ((HudStaticText)newQLRow[2]).Text = "solveCount";
  228.  
  229.  
  230. System.Threading.Timer timer = null;
  231. timer = new System.Threading.Timer((obj) =>
  232. {
  233. try
  234. {
  235. shouldEatQuests = false;
  236.  
  237. if (questDataTable.Rows.Count >= 1)
  238. {
  239. DataView dv = questDataTable.DefaultView;
  240. dv.Sort = "repeatTimeTest ASC";
  241. DataTable sortedQuestDataTable = dv.ToTable();
  242.  
  243.  
  244. foreach (DataRow row in sortedQuestDataTable.Rows)
  245. {
  246.  
  247. string QuestName = row["questDescriptionTest"].ToString();
  248.  
  249. if (row["questType"].ToString() == "killTask")
  250. {
  251. ((HudStaticText)newQLRow[0]).Text = QuestName;
  252. ((HudStaticText)newQLRow[1]).Text = row["solveCountTest"].ToString();
  253. ((HudStaticText)newQLRow[2]).Text = row["maxCompletionsTest"].ToString();
  254. }
  255. else if (row["questType"].ToString() == "oneTimeQuest")
  256. {
  257. ((HudStaticText)newKTRow[0]).Text = QuestName;
  258. }
  259. else
  260. {
  261. ((HudStaticText)newQLRow[0]).Text = QuestName;
  262. ((HudStaticText)newQLRow[1]).Text = row["repeatTimeTest"].ToString();
  263. ((HudStaticText)newQLRow[2]).Text = row["solveCountTest"].ToString();
  264. }
  265. }
  266. }
  267. buttonClicked = false;
  268. timer.Dispose();
  269. }
  270. catch (Exception ex) { Util.LogException(ex); }
  271.  
  272. },
  273. null, 500, System.Threading.Timeout.Infinite);
  274. }
  275. catch (Exception ex) { Util.LogException(ex); }
  276. }
  277.  
  278. private void PopulateQuestList_Click(object sender, EventArgs e)
  279. {
  280. if (buttonClicked == false)
  281. {
  282. PopulateQuests();
  283. }
  284. }
  285. private void PopulateKillTaskList_Click(object sender, EventArgs e)
  286. {
  287. if (buttonClicked == false)
  288. {
  289. PopulateQuests();
  290. }
  291. }
  292. private void PopulateOneTimeList_Click(object sender, EventArgs e)
  293. {
  294. if (buttonClicked == false)
  295. {
  296. PopulateQuests();
  297. }
  298. }
  299.  
  300.  
  301. public void Dispose()
  302. {
  303. Dispose(true);
  304. GC.SuppressFinalize(this);
  305. }
  306.  
  307. protected virtual void Dispose(bool disposing)
  308. {
  309. if (!disposed)
  310. {
  311. if (disposing)
  312. {
  313. Globals.Core.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(Current_ChatBoxMessage);
  314. }
  315. disposed = true;
  316. }
  317. }
  318. }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement