private void ClickItem(IntPtr hwnd, int x, int y) { MouseTools.SetCursorPosition(x, y); Thread.Sleep(Config.Delay2); SimulateMouseLeft(poeHwnd, x, y); Thread.Sleep(Config.Delay1); }
private void button_StartSort_Click(object sender, EventArgs e) { Stop = false; if (!Loaded) { MessageBox.Show("還未載入完全\r\nNot loaded."); return; } poeHwnd = ApplicationHelper.OpenPathOfExile(); if (poeHwnd == IntPtr.Zero) { MessageBox.Show("未偵測到Path Of Exile\r\nCould not find Path Of Exile"); return; } GetStashDimentions(); MouseTools.SetCursorPosition(startPos1.X, startPos1.Y - (int)cellHeight1 * 3); MouseTools.MouseClickEvent(70); MouseTools.MouseClickEvent(70); Task.Delay(500); if (radioButton1.Checked) { StartSorting((radioButton4.Checked ? 12 : 24)); } else { Round40Q((radioButton4.Checked ? 12 : 24), radioButton2.Checked ? 0 : 1); resoult = Sort(Items, used, (radioButton4.Checked ? 12 : 24)); DrawBoxRegion(Items, (radioButton4.Checked ? 12 : 24), 1); DrawBoxRegion(resoult, (radioButton4.Checked ? 12 : 24), 2); } }
private void GetItem(IntPtr hwnd, int x, int y) { MouseTools.SetCursorPosition(x, y); Thread.Sleep(Config.Delay2); KeyBoardTool.KeyDown(Keys.ControlKey); Thread.Sleep(100); SimulateMouseLeft(poeHwnd, x, y); Thread.Sleep(100); KeyBoardTool.KeyUp(Keys.ControlKey); Thread.Sleep(Config.Delay1); }
/// <summary> /// 移動滑鼠到x,y上(桌面座標),並複製 /// </summary> /// <param name="x"></param> /// <param name="y"></param> void POE_GetItemInfo(int x, int y) { MouseTools.SetCursorPosition(x, y); Thread.Sleep(Config.Delay_Scan); KeyBoardTool.KeyDown(Keys.ControlKey); KeyBoardTool.KeyDown(Keys.C); Thread.Sleep(Config.Delay_Scan); KeyBoardTool.KeyUp(Keys.C); KeyBoardTool.KeyUp(Keys.ControlKey); Thread.Sleep(Config.Delay_Scan); Application.DoEvents(); }
private void button_StartSort_Click(object sender, EventArgs e) { Stop = false; if (!Loaded) { MessageBox.Show("還未載入完全\r\nDoes not loaded."); return; } poeHwnd = ApplicationHelper.OpenPathOfExile(); if (poeHwnd == IntPtr.Zero) { MessageBox.Show("未偵測到Path Of Exile\r\nDid't find Path Of Exile"); return; } GetStashDimentions(); MouseTools.SetCursorPosition(startPos1.X, startPos1.Y - (int)cellHeight1 * 3); MouseTools.MouseClickEvent(70); MouseTools.MouseClickEvent(70); Task.Delay(500); StartSorting((radioButton4.Checked ? 12 : 24)); }
public async void StartSorting(int length) { await Task.Delay(0); if (resoult.Count > 0) { //由於ClipBoard的緣故,需要在STAThread執行 RunAsSTAThread( () => { List <Item> _Items = new List <Item>(); Items.ForEach(x => _Items.Add((Item)x.Clone())); if (radioButton6.Checked) { //從結果找到一個跟目前同個ID但不同位置的物品 var diff = resoult.Where(x => !x.point.Equals(_Items.Where(y => y.id == x.id).FirstOrDefault().point)).Select(t => t).FirstOrDefault(); Item onHand = null; while (diff != null) { if (Stop) { return; } Item p0 = _Items.Where(x => x.id == diff.id).Select(t => t).FirstOrDefault(); ClickItem(poeHwnd, (int)(((float)p0.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)p0.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); ClickItem(poeHwnd, (int)(((float)diff.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)diff.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); p0.point = new POINT(diff.point); onHand = _Items.Where(x => x.id != diff.id && x.point.Equals(diff.point)).Select(t => t).FirstOrDefault(); while (onHand != null) { if (Stop) { return; } Item p3 = resoult.Where(x => x.id == onHand.id).FirstOrDefault(); ClickItem(poeHwnd, (int)(((float)p3.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)p3.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); onHand.point = new POINT(p3.point); onHand = _Items.Where(x => x.id != onHand.id && x.point.Equals(onHand.point)).Select(t => t).FirstOrDefault(); } diff = resoult.Where(x => !x.point.Equals(_Items.Where(y => y.id == x.id).FirstOrDefault().point)).Select(t => t).FirstOrDefault(); } } else { //檢查背包第一二格是否清空 MouseTools.SetCursorPosition((startPos1.X), startPos1.Y - (int)cellHeight1 * 3); MouseTools.MouseClickEvent(70); MouseTools.MouseClickEvent(70); Task.Delay(500); Clipboard.Clear(); POE_GetItemInfo(bagstartPos.X, bagstartPos.Y); string clip = Clipboard.GetText(TextDataFormat.UnicodeText); if (clip == "") { clip = Clipboard.GetText(TextDataFormat.UnicodeText); } if (clip == "") { Clipboard.Clear(); POE_GetItemInfo(bagstartPos.X, bagstartPos.Y + (int)cellHeight1); clip = Clipboard.GetText(TextDataFormat.UnicodeText); if (clip == "") { clip = Clipboard.GetText(TextDataFormat.UnicodeText); } if (clip != "") { MessageBox.Show(String.Format("請清空背包第二格\n物品資訊為:\n\n{0}", clip)); return; } } else { MessageBox.Show(String.Format("請清空背包第二格\n物品資訊為:\n\n{0}", clip)); return; } //依照結果清單和目前清單,建立可用暫存空間的清單 List <Item> swap = new List <Item>(); swap.Add(new Item() { point = new POINT(0, 0) }); swap.Add(new Item() { point = new POINT(0, 1) }); //從結果找到一個跟目前同個ID但不同位置的物品 var diff = resoult.Where(x => !x.point.Equals(_Items.Where(y => y.id == x.id && y.point.X >= 0).FirstOrDefault().point)).Select(t => t).FirstOrDefault(); while (diff != null) { if (Stop) { return; } Item k0 = _Items.Where(x => x.point.Equals(diff.point)).FirstOrDefault(); if (k0 != null) { //原本的位置有東西占用,先移到swap ClickItem(poeHwnd, (int)(((float)diff.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)diff.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); var k1 = swap.Where(x => x.id == 0).FirstOrDefault(); if (k1 != null) { ClickItem(poeHwnd, (int)(((float)k1.point.X * cellWidth1) + bagstartPos.X), (int)(((float)k1.point.Y * cellHeight1) + bagstartPos.Y)); k1.id = k0.id; k0.point = new POINT(-1 - k1.point.X, -1 - k1.point.Y); } else { } } Item p0 = _Items.Where(x => x.id == diff.id).Select(t => t).FirstOrDefault(); ClickItem(poeHwnd, (int)(((float)p0.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)p0.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); ClickItem(poeHwnd, (int)(((float)diff.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)diff.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); p0.point = new POINT(diff.point); while (swap.Any(x => x.id != 0)) { if (Stop) { return; } var FirstItemInSwap = swap.Where(x => x.id != 0).FirstOrDefault(); var FirstItemInResoult_IdIsFirstItemInSwap = resoult.Where(x => x.id.Equals(FirstItemInSwap.id)).FirstOrDefault(); var ItemNow = _Items.Where(x => x.point.Equals(FirstItemInResoult_IdIsFirstItemInSwap.point)).FirstOrDefault(); if (ItemNow != null) { ClickItem(poeHwnd, (int)(((float)FirstItemInResoult_IdIsFirstItemInSwap.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)FirstItemInResoult_IdIsFirstItemInSwap.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); var FirstFreeSapceInSwap = swap.Where(x => x.id == 0).FirstOrDefault(); if (FirstFreeSapceInSwap != null) { ClickItem(poeHwnd, (int)(((float)FirstFreeSapceInSwap.point.X * cellWidth1) + bagstartPos.X), (int)(((float)FirstFreeSapceInSwap.point.Y * cellHeight1) + bagstartPos.Y)); FirstFreeSapceInSwap.id = ItemNow.id; _Items.Where(x => x.id == FirstItemInResoult_IdIsFirstItemInSwap.id).FirstOrDefault().point = new POINT(-1 - FirstFreeSapceInSwap.point.X, -1 - FirstFreeSapceInSwap.point.Y * -1); } else { } } ClickItem(poeHwnd, (int)(((float)FirstItemInSwap.point.X * cellWidth1) + bagstartPos.X), (int)(((float)FirstItemInSwap.point.Y * cellHeight1) + bagstartPos.Y)); ClickItem(poeHwnd, (int)(((float)FirstItemInResoult_IdIsFirstItemInSwap.point.X * (length == 12 ? cellWidth1 : cellWidth4)) + (length == 12 ? startPos1.X : startPos4.X)), (int)(((float)FirstItemInResoult_IdIsFirstItemInSwap.point.Y * (length == 12 ? cellHeight1 : cellHeight4)) + (length == 12 ? startPos1.Y : startPos4.Y))); _Items.Where(x => x.id == FirstItemInSwap.id).FirstOrDefault().point = new POINT(FirstItemInResoult_IdIsFirstItemInSwap.point); FirstItemInSwap.id = 0; } diff = resoult.Where(x => !x.point.Equals(_Items.Where(y => y.id == x.id && y.point.X >= 0).FirstOrDefault().point)).Select(t => t).FirstOrDefault(); } } }); } Stop = true; }