FormTC.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. using CommonFroms.G2D.DataGrid;
  2. using CommonLang;
  3. using CommonLang.Xml;
  4. using pomelo.area;
  5. using pomelo.item;
  6. using Pomelo.DotNetClient;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.ComponentModel;
  10. using System.Data;
  11. using System.Drawing;
  12. using System.Globalization;
  13. using System.IO;
  14. using System.Linq;
  15. using System.Text;
  16. using System.Windows.Forms;
  17. using XmdsBattleClientBot;
  18. using XmdsBattleClientBot.Bot;
  19. using XmdsBattleClientWin32.WinForm;
  20. namespace XmdsBattleClientWin32.Func
  21. {
  22. public partial class FormTC : Form
  23. {
  24. private readonly BotClient bot;
  25. private readonly PushHandler listener;
  26. private string save_file = Application.StartupPath + "/bot_FormTC.cfg";
  27. private HashSet<string> save_codes = new HashSet<string>();
  28. private List<SimulateDataPush> execute_list = new List<SimulateDataPush>();
  29. private HashMap<string, ItemInfo> execute_map = new HashMap<string, ItemInfo>();
  30. public FormTC(BotClient bot)
  31. {
  32. this.bot = bot;
  33. InitializeComponent();
  34. this.txt_Server.Text = bot.ServerName;
  35. this.listener = this.bot.Client.GameSocket.listen<SimulateDataPush>(on_data_push);
  36. this.load_tc_code();
  37. }
  38. protected override void OnFormClosing(FormClosingEventArgs e)
  39. {
  40. this.save_tc_code();
  41. this.listener.Clear();
  42. base.OnFormClosing(e);
  43. }
  44. private void load_tc_code()
  45. {
  46. try
  47. {
  48. if (File.Exists(save_file))
  49. {
  50. var lines = File.ReadAllLines(save_file, CUtils.UTF8);
  51. foreach(var code in lines)
  52. {
  53. if (save_codes.Add(code))
  54. {
  55. txt_Code.Items.Add(code);
  56. }
  57. }
  58. }
  59. }
  60. catch(Exception err) { MessageBox.Show(err.Message); }
  61. }
  62. private void save_tc_code()
  63. {
  64. File.WriteAllLines(save_file, save_codes.ToArray(), CUtils.UTF8);
  65. }
  66. private string ToResultText()
  67. {
  68. StringBuilder sb = new StringBuilder();
  69. foreach (ListViewItem line in list_Result.Items)
  70. {
  71. foreach (ListViewItem.ListViewSubItem sub in line.SubItems)
  72. {
  73. sb.Append(sub.Text + "\t,");
  74. }
  75. sb.AppendLine();
  76. }
  77. return sb.ToString();
  78. }
  79. private ListViewItem print_line(string msg = "")
  80. {
  81. var line = list_Result.Items.Add(msg);
  82. return line;
  83. }
  84. private void on_data_push(SimulateDataPush push)
  85. {
  86. execute_list.Add(push);
  87. print_line(string.Format("第{0}次", execute_list.Count)).BackColor = Color.FromArgb(0xFF, 0x20, 0x20, 0x20);
  88. foreach (var item in push.s2c_items)
  89. {
  90. if (execute_map.ContainsKey(item.code))
  91. execute_map[item.code].Combine(item);
  92. else
  93. execute_map[item.code] = new ItemInfo(item);
  94. var info = new ItemInfo(item);
  95. var argb = info.color;
  96. //print_result(string.Format("掉落了:\t{0}\t数量:{1}\tCode:{2}\tStar:{3}", item.name, item.groupCount, item.code, item.star));
  97. var line = list_Result.Items.Add("掉落了:");
  98. line.UseItemStyleForSubItems = false;
  99. line.SubItems.Add(item.name).ForeColor = Color.FromArgb(argb);
  100. line.SubItems.Add(item.groupCount + "");
  101. line.SubItems.Add(item.code + "").ForeColor = Color.FromArgb(argb);
  102. line.SubItems.Add(item.star + "");
  103. line.Tag = info;
  104. }
  105. }
  106. public class ItemInfo : IComparable<ItemInfo>
  107. {
  108. public string name { get; private set; }
  109. public string code { get; private set; }
  110. public int color { get; private set; }
  111. public Dictionary<string, object> template { get; private set; }
  112. public Dictionary<string, object> item_quality { get; private set; }
  113. public int count { get; private set; }
  114. public ItemInfo(MiniItem i)
  115. {
  116. this.name = i.name;
  117. this.code = i.code;
  118. this.color = i.qColor;
  119. this.template = BotClientManager.GetItemTemplate(code);
  120. if (template != null)
  121. {
  122. object qc;
  123. int qid;
  124. if (template.TryGetValue("Qcolor", out qc) && int.TryParse(qc.ToString(), out qid))
  125. {
  126. item_quality = BotClientManager.GetItemQuality(qid);
  127. if (item_quality != null && item_quality.TryGetValue("Argb", out qc))
  128. {
  129. try
  130. {
  131. color = int.Parse(qc.ToString(), NumberStyles.HexNumber);
  132. }
  133. catch (Exception err) { err.ToString(); }
  134. }
  135. }
  136. }
  137. this.count = i.groupCount;
  138. }
  139. public void Combine(MiniItem item)
  140. {
  141. this.count += item.groupCount;
  142. }
  143. public int CompareTo(ItemInfo other)
  144. {
  145. return this.name.CompareTo(other.name);
  146. }
  147. }
  148. public ItemInfo SelectedItemInfo
  149. {
  150. get
  151. {
  152. if (list_Result.SelectedItems.Count > 0) { return list_Result.SelectedItems[0].Tag as ItemInfo; }
  153. return null;
  154. }
  155. }
  156. private void btn_Execute_Click(object sender, EventArgs e)
  157. {
  158. try
  159. {
  160. int count = (int)num_Count.Value;
  161. if (count <= 0)
  162. {
  163. throw new Exception("次数至少为1");
  164. }
  165. var level = int.Parse(txt_Level.Text);
  166. var code = txt_Code.Text;
  167. execute_list.Clear();
  168. execute_map.Clear();
  169. print_line("执行开始").BackColor = Color.FromArgb(0xFF, 0x40, 0x40, 0x40);
  170. bot.Client.GameSocket.playerHandler.getSimulateDropByTcRequest(code, count, level, (err, rsp) =>
  171. {
  172. if (err != null)
  173. {
  174. FormBot.on_error(err);
  175. }
  176. else
  177. {
  178. if (save_codes.Add(code))
  179. {
  180. txt_Code.Items.Add(code);
  181. }
  182. print_line("结果").BackColor = Color.FromArgb(0xFF, 0x40, 0x40, 0x40);
  183. var list = new List<ItemInfo>(execute_map.Values);
  184. list.Sort();
  185. foreach (var k in list)
  186. {
  187. var line = print_line(k.name + " x" + k.count);
  188. line.ForeColor = Color.FromArgb(k.color);
  189. line.Tag = k;
  190. }
  191. print_line("").EnsureVisible();
  192. }
  193. });
  194. }
  195. catch (Exception err)
  196. {
  197. MessageBox.Show(err.Message);
  198. }
  199. }
  200. private void btn_Output_Click(object sender, EventArgs e)
  201. {
  202. try
  203. {
  204. var file = Application.StartupPath + @"\TC_" + CUtils.FormatTime(DateTime.Now) + ".txt";
  205. File.WriteAllText(file, ToResultText(), CUtils.UTF8_BOM);
  206. MessageBox.Show("本次结果已保存在:\n" + file);
  207. }
  208. catch (Exception err)
  209. {
  210. MessageBox.Show(err.Message);
  211. }
  212. }
  213. private void btn_Clear_Click(object sender, EventArgs e)
  214. {
  215. list_Result.Items.Clear();
  216. txt_Code.Items.Clear();
  217. save_codes.Clear();
  218. save_tc_code();
  219. }
  220. private void btn_Copy_Click(object sender, EventArgs e)
  221. {
  222. Clipboard.SetText(ToResultText());
  223. }
  224. private void list_Result_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
  225. {
  226. var item = SelectedItemInfo;
  227. if (item == null)
  228. {
  229. prop_ItemInfo.SelectedObject = null;
  230. }
  231. else
  232. {
  233. prop_ItemInfo.SelectedObject = new G2DPropertyDescriptor(item.template);
  234. }
  235. }
  236. private void list_Result_MouseMove(object sender, MouseEventArgs e)
  237. {
  238. // var info = list_Result.HitTest(e.Location);
  239. // if (info.Item != null && info.Item.Tag is ItemInfo)
  240. // {
  241. // list_Result.Cursor = Cursors.Hand;
  242. // }
  243. // else
  244. // {
  245. // list_Result.Cursor = Cursors.Default;
  246. // }
  247. }
  248. private void list_Result_MouseHover(object sender, EventArgs e)
  249. {
  250. }
  251. private void list_Result_MouseCaptureChanged(object sender, EventArgs e)
  252. {
  253. }
  254. }
  255. }