public void UpdateTasks()
 {
     lock (tasks)
     {
         tasks.Clear();
         if (!dataExchange.BotEnabled)
         {
             return;
         }
         if (!dataExchange.GUITasks.ContainsKey(CanvasId))
         {
             tasks.Clear();
             return;
         }
         foreach (GUITask task in dataExchange.GUITasks[CanvasId])
         {
             if (!task.Enabled)
             {
                 continue;
             }
             UsefulTask newTask = new UsefulTask(task.InternalId, task.Dithering ? task.DitheredConvertedBitmap.Clone() as Bitmap : task.ConvertedBitmap.Clone() as Bitmap, task.X, task.Y, task.KeepRepairing);
             tasks.Add(newTask);
         }
     }
 }
        private List <IdPixel> GenerateTaskQueue(UsefulTask task)
        {
            List <IdPixel> queue = new List <IdPixel>();

            for (int j = 0; j < task.Image.Height; j++)
            {
                for (int i = 0; i < task.Image.Width; i++)
                {
                    Color canvasPixel;
                    Color bordersPixel;

                    int canvasX = task.X + i;
                    int canvasY = task.Y + j;
                    if (canvasX < 0 || canvasY < 0 || canvasX >= canvas.Width || canvasY >= canvas.Height)
                    {
                        continue;
                    }
                    canvasPixel  = canvas.GetPixel(canvasX, canvasY);
                    bordersPixel = borders.GetPixel(canvasX, canvasY);

                    if (bordersPixel.R == 204 && bordersPixel.G == 204 && bordersPixel.B == 204)
                    {
                        continue;
                    }
                    var taskPixel = task.Image.GetPixel(i, j);
                    if (taskPixel.A == 0)
                    {
                        continue;
                    }
                    var reqPixel = GetAntidotColor(canvasX, canvasY);
                    if (canvasPixel == reqPixel)
                    {
                        continue;
                    }
                    if (!curCanvasInvPalette.ContainsKey(reqPixel))
                    {
                        continue;
                    }
                    IdPixel pixel = new IdPixel(curCanvasInvPalette[reqPixel], task.X + i, task.Y + j);
                    queue.Add(pixel);
                }
            }
            return(queue);
        }
        private void AddTasks(List <IdPixel> queue, int userNumber, int totalUsers, List <UsefulTask> completedTasksToFill)
        {
            ShuffleQueues();

            int  queueColor       = -1;
            bool queueColorChosen = false;

            foreach (KeyValuePair <Guid, List <IdPixel> > pair in taskQueues)
            {
                for (int i = pair.Value.Count - 1; i >= 0; i--)
                {
                    if (queue.Count >= maxQueueSize)
                    {
                        return;
                    }
                    var reqPixel = pair.Value[i];
                    if (!queueColorChosen)
                    {
                        queueColor       = reqPixel.Color;
                        queueColorChosen = true;
                    }
                    if (reqPixel.Color != queueColor)
                    {
                        continue;
                    }
                    queue.Add(reqPixel);
                    pair.Value.RemoveAt(i);
                }

                if (pair.Value.Count == 0)
                {
                    UsefulTask done = guiData.Tasks.Where((a) => a.Id == pair.Key).FirstOrDefault();
                    if (done != null && !done.KeepRepairing)
                    {
                        completedTasksToFill.Add(done);
                    }
                }
            }
        }
Exemplo n.º 4
0
 private void EnqueueTask(UsefulTask task)
 {
 }