// 4. Override "GetNewTaskData" // Create a 'blank state' on the given goose. Called just before the Task begins running. public override GooseTaskData GetNewTaskData(GooseEntity goose) { GrabbingOctocatTaskData taskData = new GrabbingOctocatTaskData(); IntPtr activeWindow = GetForegroundWindow(); Rect lpRect = new Rect(); bool success = GetWindowRect(activeWindow, out lpRect); if (!success) { taskData.activeWindowTopRightCorner = new Vector2((int)500, (int)500); } else { if (Double.IsNaN(lpRect.Right) || lpRect.Right < 1) { lpRect.X = 0; lpRect.Width = (SystemParameters.WorkArea.Width - 75); Console.WriteLine("NaN right detected, attempting to update rect"); } taskData.activeWindowTopRightCorner = new Vector2((int)lpRect.Right, (int)lpRect.Top); } string output = "Top: " + lpRect.Top + " Right: " + lpRect.Right; Console.WriteLine(output); // TODO: Remove me // taskData.activeWindowTopRightCorner = new Vector2((float)500, (float)500); return(taskData); }
// 4. Override "RunTask" // Run a frame of this Task on the given goose. public override void RunTask(GooseEntity goose) { // This function is only called when we're the currently running task. // The goose's taskData will be of this task's type. GrabbingOctocatTaskData data = (GrabbingOctocatTaskData)goose.currentTaskData; goose.targetPos = data.activeWindowTopRightCorner; /* ----------- Grabbing -------------- */ Cursor cursor = new Cursor(Cursor.Current.Handle); Cursor.Position = new System.Drawing.Point((int)goose.position.x, (int)goose.position.y); if (Vector2.Distance(goose.targetPos, goose.position) < 50) { API.Goose.setCurrentTaskByID(goose, "HappyOctocat"); } //TODO, detect if near top right, if near top right, sleep for a bit :/ /*goose.currentTaskData.activeWindow = GetActiveWindow();*/ }