Ejemplo n.º 1
0
        public static void Process()
        {
            PointGroup pg = new PointGroup(
                new Point(6, 10),
                new Point(35, 33),
                new Point(12, 37)
                );

            Color      emptyInvColor         = ColorUtils.GetColorAt(6, 745);
            int        minDiffBeforeNotEmpty = 40;
            LockBitmap lockb = ImgUtils.GetLockBitmap(screenshotRect);

            lockb.LockBits();
            IsFull = true;
            for (int x = 0; x < inventorySlots.GetLength(0); x++)
            {
                int y = 0;
                for (y = 0; y < inventorySlots.GetLength(1); y++)
                {
                    if (inventorySlots[x, y])
                    {
                        continue;
                    }

                    bool empty = IsSlotEmpty(x, y, lockb, emptyInvColor, minDiffBeforeNotEmpty);
                    IsFull &= !empty;
                    if (!empty)
                    {
                        Debug.Log($"{x},{y} not empty");
                    }
                    inventorySlots[x, y] = !empty;
                    pg.OffsetY(SLOT_SIZE);
                }
                pg.Offset(SLOT_SIZE, -y * SLOT_SIZE);
            }
            lockb.UnlockBits();
            Debug.Log("inv full:" + IsFull);
        }
Ejemplo n.º 2
0
        public List <Point> ProcessImage(int maxEncounters = 1)
        {
            List <Point> points     = new List <Point>();
            int          encounters = 0;
            PointGroup   pointGroup = group.OffsetCopy(0, 0);
            LockBitmap   lockB      = ImgUtils.GetLockBitmap(rect);

            lockB.LockBits();
            Point fartherDownRight = GetFartherPoint();
            int   x = 0;


            while (encounters < maxEncounters && (fartherDownRight.X + x) < lockB.Width)
            {
                int y = 0;
                while (encounters < maxEncounters && (fartherDownRight.Y + y) < lockB.Height)
                {
                    bool valid = true;
                    foreach (var pointDiff in pointDiffs)
                    {
                        Point p1   = GetCorrespondingPoint(pointGroup, pointDiff.Key.Item1, x, y);
                        Point p2   = GetCorrespondingPoint(pointGroup, pointDiff.Key.Item2, x, y);
                        Color c1   = lockB.GetPixel(p1.X, p1.Y);
                        Color c2   = lockB.GetPixel(p2.X, p2.Y);
                        int   diff = ColorUtils.ColorDiff(c1, c2);
                        if (diff != pointDiff.Value)
                        {
                            valid = false;
                            break;
                        }
                    }

                    if (valid) // Check color diffs
                    {
                        foreach (var colorDiff in colorDiffs)
                        {
                            foreach (var point in pointGroup.Points)
                            {
                                Point relative = new Point(point.X - x, point.Y - y);
                                if (relative == colorDiff.Key.Item1)
                                {
                                    int diff = ColorUtils.ColorDiff(lockB.GetPixel(point.X, point.Y), colorDiff.Key.Item2);
                                    if (diff != colorDiff.Value)
                                    {
                                        valid = false;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    if (valid)
                    {
                        encounters++;
                        points.Add(new Point(rect.X + x, rect.Y + y));
                    }

                    pointGroup.OffsetY(1);
                    ++y;
                }
                pointGroup.Offset(1, -y);
                ++x;
            }
            lockB.UnlockBits();


            return(points);
        }