private Rect getSqmRect(int xDif, int yDif, Rect gameMapRect) { int numCols = 11; int numRows = 15; int sqmWidth = ClientGuiHelper.calculateSqmWidth(gameMapRect, numCols, numRows); //Console.WriteLine("SQM width: " + sqmWidth); Rect[,] map = new Rect[numRows, numCols]; for (int i = 0; i < numRows; i++) { for (int j = 0; j < numCols; j++) { Rect r = new Rect(); r.Left = i * sqmWidth; r.Top = j * sqmWidth; r.Right = r.Left + sqmWidth; r.Bottom = r.Top + sqmWidth; map[i, j] = r; } } int posX = xCenter + xDif; int posY = yCenter + yDif; Rect sqm = map[posX - 1, posY - 1]; return(sqm); }
public Point InventoryPosition(int slotId) { string slotID = "slot" + slotId; List <UIWidget> slots = guiReader.GetInventorySlotsUIWidgets(); foreach (UIWidget slot in slots) { if (slot.Id.Equals(slotID)) { return(ClientGuiHelper.GetRandomCenterPos(slot.Rect)); } } return(new Point(-1, -1)); }
public Point GetGroundPosition(Location location) { Rect gameMapRect = guiReader.GetGameMapRect(); Location center = player.Location(); int xDif = location.X - center.X; int yDif = location.Y - center.Y; if (isOutOFRange(xDif, yDif, location.Z, center.Z)) { return(new Point(-1, -1)); } Rect sqm = getSqmRect(xDif, yDif, gameMapRect); Rect sqmClient = convertRelativeToClient(sqm, gameMapRect); return(ClientGuiHelper.GetRandomCenterPos(sqmClient)); }
public Point GetInventoryPosition(int slot, int containerIndex) { //try scroll 10 times for (int i = 0; i < 10; i++) { //Console.WriteLine("Tries: " + (i + 1)); string containerId = "container" + containerIndex; UIWidget container = getContainerByID(containerId, guiReader.GetContainerUIWidgets()); if (container == null) { Console.WriteLine("Container with id: " + containerId + " not found"); return(new Point(-1, -1)); } List <UIWidget> slots = container.Childrens; UIWidget item = slots[slot]; int isVisible = slotIsVisible(item.Rect, container.Rect); Rect containerRect = container.Rect; //remove toolbar height for wheel containerRect.Top = containerRect.Top + 22; Point wheelPos = ClientGuiHelper.GetRandomCenterPos(container.Rect); if (isVisible == -1) { inputSender.SendScrollUp(wheelPos); Thread.Sleep(20); } else if (isVisible == 0) { return(ClientGuiHelper.GetRandomCenterPos(item.Rect)); } else if (isVisible == 1) { inputSender.SendScrollDown(wheelPos); Thread.Sleep(20); } } Console.WriteLine("Could not get the item slot"); return(new Point(-1, -1)); }
private int slotIsVisible(Rect inner, Rect outRect) { //remove 21 pixels to toolbarheight outRect.Top = outRect.Top + 21; //not random Point p = ClientGuiHelper.getCenterPos(inner); Point upper = new Point(p.X - 5, p.Y - 5); Point lower = new Point(p.X + 5, p.Y + 5); int isInside = 0; //check upper point isInside = outRect.ContainsPoint(upper); if (isInside == -1 || isInside == 1) { return(isInside); } //check lower point isInside = outRect.ContainsPoint(lower); return(isInside); }