/// <summary> /// Clicks through a specified number of text screens with the space bar. /// </summary> /// <param name="screenCount">number of text screens to click through</param> /// <param name="timeout">max time allowed to wait for each text screen</param> /// <returns></returns> public bool ClickThroughTextScreens(int screenCount, int timeout) { Stopwatch watch = new Stopwatch(); int screensClicked = 0; double textHash = 0, priorText = 0; watch.Start(); while (screensClicked < screenCount && watch.ElapsedMilliseconds < timeout && !BotProgram.StopFlag) { textHash = DialogBodyText(); if (textHash != priorText) { priorText = textHash; Keyboard.Space(); screensClicked++; BotProgram.SafeWaitPlus(500, 100); watch.Restart(); } else { BotProgram.SafeWait(100); } } return(screensClicked == screenCount); }
/// <summary> /// Drops all of the items in the inventory /// </summary> /// <param name="safeTab"></param> public void DropInventory(bool safeTab = true, bool onlyDropPreviouslyEmptySlots = true) { Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow()); OpenInventory(safeTab); int effectiveY; Keyboard.ShiftDown(); for (int x = 0; x < INVENTORY_COLUMNS; x++) { for (int y = 0; y < INVENTORY_ROWS; y++) { effectiveY = (x % 2 == 0) ? y : INVENTORY_ROW_MAX - y; if ((!onlyDropPreviouslyEmptySlots || EmptySlots[x, effectiveY]) && !SlotIsEmpty(x, effectiveY, false, false)) { if (BotProgram.StopFlag) { Keyboard.ShiftUp(); return; } ClickInventory(x, effectiveY, false); BotProgram.SafeWaitPlus(50, 25); } } } Keyboard.ShiftUp(); }
/// <summary> /// Clicks on a stationary object /// </summary> /// <param name="stationaryObject">color filter for the stationary object</param> /// <param name="tolerance">maximum allowable distance between two subsequent checks to consider both objects the same object</param> /// <param name="afterClickWait">time to wait after clicking on the stationary object</param> /// <param name="maxWaitTime">maximum time to wait before giving up</param> /// <returns></returns> internal bool ClickStationaryObject(ColorFilter stationaryObject, double tolerance, int afterClickWait, int maxWaitTime, int minimumSize) { Blob foundObject; if (Vision.LocateStationaryObject(stationaryObject, out foundObject, tolerance, maxWaitTime, minimumSize)) { Mouse.LeftClick(foundObject.Center.X, foundObject.Center.Y); BotProgram.SafeWaitPlus(afterClickWait, 0.2 * afterClickWait); return(true); } return(false); }
/// <summary> /// Casts a spell on an item in the inventory. Assumes that casting the spell reopens the spellbook. /// </summary> /// <param name="spellBookX"></param> /// <param name="spellBookY"></param> /// <param name="castTime">cooldown time of the spell</param> /// <param name="x">x inventory or screen coordinate within the inventory</param> /// <param name="y">y inventory or screen coordinate within the inventory</param> /// <param name="safeTab"></param> /// <returns>true if the spell is cast successfully</returns> private bool CastInventorySpell(int spellBookX, int spellBookY, int castTime, int x, int y, bool safeTab = true, bool autoWait = true) { if (ScreenToInventory(ref x, ref y)) { OpenSpellbook(safeTab); ClickSpellbookStandard(spellBookX, spellBookY, safeTab); SelectedTab = TabSelect.Inventory; ClickInventory(x, y, false); SelectedTab = TabSelect.Spellbook; if (autoWait) { BotProgram.SafeWaitPlus(castTime, 100); } return(true); } return(false); }
/// <summary> /// Uses an item in the inventory on another item in the inventory /// </summary> /// <param name="subjectItem">the item to use on another item</param> /// <param name="objectItem">the item to be used on</param> /// <returns>true if the operation seems to succeed</returns> public void UseItemOnItem(Point subjectItem, Point objectItem, bool safeTab = false) { ClickInventory(subjectItem.X, subjectItem.Y, safeTab); BotProgram.SafeWaitPlus(200, 30); ClickInventory(objectItem.X, objectItem.Y, false); }