asmrobot
2019-11-13 576b92fd82f568572bc4beb125fa0ba0191a602f
src/RichCreator.Utility/CV/LindongCVHelper.cs
@@ -20,129 +20,6 @@
    public class LindongCVHelper
    {
        /// <summary>
        /// 小地图怪物颜色
        /// </summary>
        private static ZTHsvFloatColor minMinimapMainMonsterColor = new ZTHsvFloatColor(0.054f, 0.098f, 0.896f);
        private static ZTHsvFloatColor maxMinimapMainMonsterColor = new ZTHsvFloatColor(0.068f,   1.0f,   1.0f);
        /// <summary>
        /// 小地图主角颜色
        /// </summary>
        private static ZTHsvFloatColor minMinimapRoleColor = new ZTHsvFloatColor(0.508f, 0.860f, 0.731f);
        private static ZTHsvFloatColor maxMinimapRoleColor = new ZTHsvFloatColor(0.609f, 1f    ,     1f);
        /// <summary>
        /// 小方格主角偏移
        /// </summary>
        private static Structs.ZTPoint[] houseRoleBlockOffset = new Structs.ZTPoint[] {
            new Structs.ZTPoint(0,0),
            new Structs.ZTPoint(1,0),
            new Structs.ZTPoint(0,1),
            new Structs.ZTPoint(1,1)
        };
        /// <summary>
        /// 得到当前角色所在房间
        /// </summary>
        /// <param name="image"></param>
        /// <param name="minMapStart"></param>
        /// <param name="offset"></param>
        /// <returns></returns>
        public static bool GetCurrentHouseIndex(out Int32 houseIndex, Image<Rgb, byte> image, Structs.ZTPoint minMapStart)
        {
            houseIndex = -1;
            Int32 mainMonsterHouseIndex = -1;
            for (int i = 0; i < 20; i++)
            {
                Int32 row = i / 4;
                Int32 col = i % 4;
                //目标块第一块坐标
                Int32 x = minMapStart.X + col * 18;
                Int32 y = minMapStart.Y + row * 18;
                Structs.ZTPoint position = Structs.ZTPoint.Empty;
                ZTRectangle limit = new ZTRectangle(x, y, x + 17, y + 17);
                if (CVHelper.FindColorBlock(out position, image, limit, minMinimapRoleColor, maxMinimapRoleColor, houseRoleBlockOffset))
                {
                    houseIndex = i;
                    return true;
                }
                if (i == 15 )
                {
                    //查看,14格是否青色
                    if (CVHelper.InRange(image.Data, x-18, y, minMinimapCurrentColor, maxMinimapCurrentColor, houseColorBlockOffset))
                    {
                        //是否怪物图像
                        if (CVHelper.FindColorBlock(out position, image, limit, minMinimapMainMonsterColor, maxMinimapMainMonsterColor, houseRoleBlockOffset))
                        {
                            mainMonsterHouseIndex = 15;
                            break;
                        }
                        return true;
                    }
                }
            }
            if (mainMonsterHouseIndex > -1)
            {
                houseIndex = mainMonsterHouseIndex;
                return true;
            }
            return false;
        }
        /// <summary>
        /// 小地图已经走过的房间颜色(青色)
        /// </summary>
        private static ZTHsvFloatColor minMinimapCurrentColor = new ZTHsvFloatColor(0.498, 0.998, 0.998);
        private static ZTHsvFloatColor maxMinimapCurrentColor = new ZTHsvFloatColor(0.502, 1, 1);
        /// <summary>
        /// 小地图下一个房间的颜色(绿色)
        /// </summary>
        private static ZTHsvFloatColor minMinimapNextColor = new ZTHsvFloatColor(0.298, 0.998, 0.998);
        private static ZTHsvFloatColor maxMinimapNextColor = new ZTHsvFloatColor(0.302, 1, 1);
        /// <summary>
        /// 小方格色块偏移
        /// </summary>
        private static Structs.ZTPoint[] houseColorBlockOffset = new Structs.ZTPoint[] {
            new Structs.ZTPoint(2,2),
            new Structs.ZTPoint(2,3),
            new Structs.ZTPoint(15,14),
            new Structs.ZTPoint(15,15),
        };
        /// <summary>
        /// 房间是否开放
        /// </summary>
        /// <param name="houseIndex"></param>
        /// <returns></returns>
        public static bool HouseIsOpen(Image<Rgb, byte> image, Structs.ZTPoint minMapStart, Int32 houseIndex)
        {
            //第一块距上边15px,距左边1px
            Int32 row = houseIndex / 4;
            Int32 col = houseIndex % 4;
            //目标块第一块坐标
            Int32 x = minMapStart.X + col * 18;
            Int32 y = minMapStart.Y + row * 18;
            byte[,,] data = image.Data;
            if (CVHelper.InRange(data, x, y, minMinimapNextColor, maxMinimapNextColor, houseColorBlockOffset))
            {
                return true;
            }
            if (CVHelper.InRange(data, x, y, minMinimapCurrentColor, maxMinimapCurrentColor, houseColorBlockOffset))
            {
                return true;
            }
            return false;
        }