123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273 |
- using CommonFroms.G2D.DataGrid;
- using CommonLang;
- using CommonLang.Xml;
- using pomelo.area;
- using pomelo.item;
- using Pomelo.DotNetClient;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Globalization;
- using System.IO;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using XmdsBattleClientBot;
- using XmdsBattleClientBot.Bot;
- using XmdsBattleClientWin32.WinForm;
- namespace XmdsBattleClientWin32.Func
- {
- public partial class FormTC : Form
- {
- private readonly BotClient bot;
- private readonly PushHandler listener;
- private string save_file = Application.StartupPath + "/bot_FormTC.cfg";
- private HashSet<string> save_codes = new HashSet<string>();
- private List<SimulateDataPush> execute_list = new List<SimulateDataPush>();
- private HashMap<string, ItemInfo> execute_map = new HashMap<string, ItemInfo>();
- public FormTC(BotClient bot)
- {
- this.bot = bot;
- InitializeComponent();
- this.txt_Server.Text = bot.ServerName;
- this.listener = this.bot.Client.GameSocket.listen<SimulateDataPush>(on_data_push);
- this.load_tc_code();
- }
- protected override void OnFormClosing(FormClosingEventArgs e)
- {
- this.save_tc_code();
- this.listener.Clear();
- base.OnFormClosing(e);
- }
- private void load_tc_code()
- {
- try
- {
- if (File.Exists(save_file))
- {
- var lines = File.ReadAllLines(save_file, CUtils.UTF8);
- foreach(var code in lines)
- {
- if (save_codes.Add(code))
- {
- txt_Code.Items.Add(code);
- }
- }
- }
- }
- catch(Exception err) { MessageBox.Show(err.Message); }
- }
- private void save_tc_code()
- {
- File.WriteAllLines(save_file, save_codes.ToArray(), CUtils.UTF8);
- }
- private string ToResultText()
- {
- StringBuilder sb = new StringBuilder();
- foreach (ListViewItem line in list_Result.Items)
- {
- foreach (ListViewItem.ListViewSubItem sub in line.SubItems)
- {
- sb.Append(sub.Text + "\t,");
- }
- sb.AppendLine();
- }
- return sb.ToString();
- }
- private ListViewItem print_line(string msg = "")
- {
- var line = list_Result.Items.Add(msg);
- return line;
- }
- private void on_data_push(SimulateDataPush push)
- {
- execute_list.Add(push);
- print_line(string.Format("第{0}次", execute_list.Count)).BackColor = Color.FromArgb(0xFF, 0x20, 0x20, 0x20);
- foreach (var item in push.s2c_items)
- {
- if (execute_map.ContainsKey(item.code))
- execute_map[item.code].Combine(item);
- else
- execute_map[item.code] = new ItemInfo(item);
- var info = new ItemInfo(item);
- var argb = info.color;
- //print_result(string.Format("掉落了:\t{0}\t数量:{1}\tCode:{2}\tStar:{3}", item.name, item.groupCount, item.code, item.star));
- var line = list_Result.Items.Add("掉落了:");
- line.UseItemStyleForSubItems = false;
- line.SubItems.Add(item.name).ForeColor = Color.FromArgb(argb);
- line.SubItems.Add(item.groupCount + "");
- line.SubItems.Add(item.code + "").ForeColor = Color.FromArgb(argb);
- line.SubItems.Add(item.star + "");
- line.Tag = info;
- }
- }
- public class ItemInfo : IComparable<ItemInfo>
- {
- public string name { get; private set; }
- public string code { get; private set; }
- public int color { get; private set; }
- public Dictionary<string, object> template { get; private set; }
- public Dictionary<string, object> item_quality { get; private set; }
- public int count { get; private set; }
- public ItemInfo(MiniItem i)
- {
- this.name = i.name;
- this.code = i.code;
- this.color = i.qColor;
- this.template = BotClientManager.GetItemTemplate(code);
- if (template != null)
- {
- object qc;
- int qid;
- if (template.TryGetValue("Qcolor", out qc) && int.TryParse(qc.ToString(), out qid))
- {
- item_quality = BotClientManager.GetItemQuality(qid);
- if (item_quality != null && item_quality.TryGetValue("Argb", out qc))
- {
- try
- {
- color = int.Parse(qc.ToString(), NumberStyles.HexNumber);
- }
- catch (Exception err) { err.ToString(); }
- }
- }
- }
- this.count = i.groupCount;
- }
- public void Combine(MiniItem item)
- {
- this.count += item.groupCount;
- }
- public int CompareTo(ItemInfo other)
- {
- return this.name.CompareTo(other.name);
- }
- }
- public ItemInfo SelectedItemInfo
- {
- get
- {
- if (list_Result.SelectedItems.Count > 0) { return list_Result.SelectedItems[0].Tag as ItemInfo; }
- return null;
- }
- }
- private void btn_Execute_Click(object sender, EventArgs e)
- {
- try
- {
- int count = (int)num_Count.Value;
- if (count <= 0)
- {
- throw new Exception("次数至少为1");
- }
- var level = int.Parse(txt_Level.Text);
- var code = txt_Code.Text;
- execute_list.Clear();
- execute_map.Clear();
- print_line("执行开始").BackColor = Color.FromArgb(0xFF, 0x40, 0x40, 0x40);
- bot.Client.GameSocket.playerHandler.getSimulateDropByTcRequest(code, count, level, (err, rsp) =>
- {
- if (err != null)
- {
- FormBot.on_error(err);
- }
- else
- {
- if (save_codes.Add(code))
- {
- txt_Code.Items.Add(code);
- }
- print_line("结果").BackColor = Color.FromArgb(0xFF, 0x40, 0x40, 0x40);
- var list = new List<ItemInfo>(execute_map.Values);
- list.Sort();
- foreach (var k in list)
- {
- var line = print_line(k.name + " x" + k.count);
- line.ForeColor = Color.FromArgb(k.color);
- line.Tag = k;
- }
- print_line("").EnsureVisible();
- }
- });
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- private void btn_Output_Click(object sender, EventArgs e)
- {
- try
- {
- var file = Application.StartupPath + @"\TC_" + CUtils.FormatTime(DateTime.Now) + ".txt";
- File.WriteAllText(file, ToResultText(), CUtils.UTF8_BOM);
- MessageBox.Show("本次结果已保存在:\n" + file);
- }
- catch (Exception err)
- {
- MessageBox.Show(err.Message);
- }
- }
- private void btn_Clear_Click(object sender, EventArgs e)
- {
- list_Result.Items.Clear();
- txt_Code.Items.Clear();
- save_codes.Clear();
- save_tc_code();
- }
- private void btn_Copy_Click(object sender, EventArgs e)
- {
- Clipboard.SetText(ToResultText());
- }
- private void list_Result_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
- {
- var item = SelectedItemInfo;
- if (item == null)
- {
- prop_ItemInfo.SelectedObject = null;
- }
- else
- {
- prop_ItemInfo.SelectedObject = new G2DPropertyDescriptor(item.template);
- }
- }
- private void list_Result_MouseMove(object sender, MouseEventArgs e)
- {
- // var info = list_Result.HitTest(e.Location);
- // if (info.Item != null && info.Item.Tag is ItemInfo)
- // {
- // list_Result.Cursor = Cursors.Hand;
- // }
- // else
- // {
- // list_Result.Cursor = Cursors.Default;
- // }
- }
- private void list_Result_MouseHover(object sender, EventArgs e)
- {
- }
- private void list_Result_MouseCaptureChanged(object sender, EventArgs e)
- {
- }
- }
- }
|