Advertisement
Guest User

Untitled

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