using RichCreator.Utility.CV;
using RichCreator.Utility.Structs;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Emgu.CV;
using Emgu.CV.Structure;
using System.Threading;
using RichCreator.Utility.Captures;
using ZTImage.Configuration;
using RichCreator.Utility.Utilitys;
namespace RichCreator.Utility.CV
{
///
/// 凛冬识别
///
public class LindongCVHelper
{
///
/// 小地图怪物颜色
///
private static ZTHsvFloatColor minMinimapMainMonsterColor = new ZTHsvFloatColor(0.054f, 0.098f, 0.896f);
private static ZTHsvFloatColor maxMinimapMainMonsterColor = new ZTHsvFloatColor(0.068f, 1.0f, 1.0f);
///
/// 小地图主角颜色
///
private static ZTHsvFloatColor minMinimapRoleColor = new ZTHsvFloatColor(0.508f, 0.860f, 0.731f);
private static ZTHsvFloatColor maxMinimapRoleColor = new ZTHsvFloatColor(0.609f, 1f , 1f);
///
/// 小方格主角偏移
///
private static ZTPoint[] houseRoleBlockOffset = new ZTPoint[] {
new ZTPoint(0,0),
new ZTPoint(1,0),
new ZTPoint(0,1),
new ZTPoint(1,1)
};
///
/// 得到当前角色所在房间
///
///
///
///
///
public static bool GetCurrentHouseIndex(out Int32 houseIndex, Image image, 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;
ZTPoint position = 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;
}
///
/// 小地图已经走过的房间颜色(青色)
///
private static ZTHsvFloatColor minMinimapCurrentColor = new ZTHsvFloatColor(0.498, 0.998, 0.998);
private static ZTHsvFloatColor maxMinimapCurrentColor = new ZTHsvFloatColor(0.502, 1, 1);
///
/// 小地图下一个房间的颜色(绿色)
///
private static ZTHsvFloatColor minMinimapNextColor = new ZTHsvFloatColor(0.298, 0.998, 0.998);
private static ZTHsvFloatColor maxMinimapNextColor = new ZTHsvFloatColor(0.302, 1, 1);
///
/// 小方格色块偏移
///
private static ZTPoint[] houseColorBlockOffset = new ZTPoint[] {
new ZTPoint(2,2),
new ZTPoint(2,3),
new ZTPoint(15,14),
new ZTPoint(15,15),
};
///
/// 房间是否开放
///
///
///
public static bool HouseIsOpen(Image image, 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;
}
private static Hsv minMonsterHsv = new Hsv(165, 247, 175);
private static Hsv maxMonsterHsv = new Hsv(173, 255, 230);
private static ZTSize monsterBlockSize = new ZTSize(30, 30);
///
/// 查找所有怪的位置
///
///
///
public static ZTPoint[] FindMonster(Image image,ZTRectangle gameRect)
{
List rects = CVHelper.FindBlocks(image, minMonsterHsv, maxMonsterHsv, monsterBlockSize);
ZTPoint[] monsterPoints = new ZTPoint[rects.Count];
for (int i = 0; i < rects.Count; i++)
{
monsterPoints[i] = rects[i].GetCenterPoint().Add(gameRect.Start);
}
return monsterPoints;
}
public static ZTSize minDoorBlockSize = new ZTSize(25, 25);//门的最小大小
public static Hsv minUpDoorColor = new Hsv(17, 254, 254);
public static Hsv maxUpDoorColor = new Hsv(19, 255, 255);
public static Hsv minRightDoorColor = new Hsv(143, 254, 254);
public static Hsv maxRightDoorColor = new Hsv(145, 255, 255);
public static Hsv minBottomDoorColor = new Hsv(17, 254, 254);
public static Hsv maxBottomDoorColor = new Hsv(19, 255, 255);
public static Hsv minLeftDoorColor = new Hsv(107, 254, 254);
public static Hsv maxLeftDoorColor = new Hsv(109, 255, 255);
public static Hsv minRealBottomDoorColor = new Hsv(35, 254, 254);
public static Hsv maxRealBottomDoorColor = new Hsv(37, 255, 255);
///
/// 查找门
///
///
///
public static ZTPoint FindDoor(out Direction targetDirection, Image image, Direction[] directions, ZTRectangle gameRect)
{
targetDirection = Direction.None;
Int32 height = gameRect.End.Y - gameRect.Start.Y;
Int32 width = gameRect.End.X - gameRect.Start.X;
Int32 yHalf = height / 2;
Int32 xHalf = width / 2;
ZTRectangle limitRect = ZTRectangle.Empty;
Hsv minDoorHsvColor = default(Hsv), maxDoorHsvColor = default(Hsv);
for (int doorIndex = 0; doorIndex < directions.Length; doorIndex++)
{
targetDirection = directions[doorIndex];
switch (targetDirection)
{
case Direction.Up:
minDoorHsvColor = minUpDoorColor;
maxDoorHsvColor = maxUpDoorColor;
limitRect = new ZTRectangle(0, 0, width, yHalf);
break;
case Direction.Right:
minDoorHsvColor = minRightDoorColor;
maxDoorHsvColor = maxRightDoorColor;
limitRect = new ZTRectangle(xHalf, 0, width, height);
break;
case Direction.Bottom:
minDoorHsvColor = minBottomDoorColor;
maxDoorHsvColor = maxBottomDoorColor;
limitRect = new ZTRectangle(0, yHalf, width, height);
break;
case Direction.Left:
minDoorHsvColor = minLeftDoorColor;
maxDoorHsvColor = maxLeftDoorColor;
limitRect = new ZTRectangle(0, 0, xHalf, height);
break;
}
List doors = CVHelper.FindBlocks(image, minDoorHsvColor, maxDoorHsvColor, minDoorBlockSize);
if (doors.Count <= 0)
{
continue;
}
ZTPoint doorPosition = ZTPoint.Empty;
for (int i = 0; i < doors.Count; i++)
{
doorPosition = new ZTPoint(doors[i].Start.X + (doors[i].End.X - doors[i].Start.X) / 2, doors[i].Start.Y + (doors[i].End.Y - doors[i].Start.Y) / 2);
if (doorPosition.X >= limitRect.Start.X &&
doorPosition.X <= limitRect.End.X &&
doorPosition.Y >= limitRect.Start.Y &&
doorPosition.Y <= limitRect.End.Y)
{
return doorPosition + gameRect.Start;
}
}
}
return ZTPoint.Empty;
}
///
/// 地图右上角素喃文字
///
public static ColorArray MapTopSunan = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1401,72,230,200,155$1381,69,230,200,155$1380,68,0,0,0$1385,68,0,0,0$1386,68,230,200,155$1386,67,0,0,0$1387,67,0,0,0$1387,68,0,0,0$1391,68,0,0,0$1391,69,230,200,155$1392,69,0,0,0$1393,69,230,200,155$1393,68,0,0,0$1396,69,0,0,0$1395,69,230,200,155$1397,69,230,200,155$1399,68,0,0,0$1401,68,0,0,0$1404,69,0,0,0$1404,72,0,0,0$1403,72,230,200,155$1402,72,0,0,0$1400,72,0,0,0$1399,72,230,200,155$1398,72,0,0,0$1397,72,230,200,155$1396,72,0,0,0$1395,72,230,200,155$1394,72,0,0,0$1393,72,230,200,155$1392,72,0,0,0$1381,79,0,0,0$1382,79,230,200,155$1383,79,0,0,0$1385,79,230,200,155$1387,79,0,0,0$1390,79,230,200,155$1391,79,0,0,0$1396,79,0,0,0$1397,79,230,200,155$1398,79,0,0,0$1397,80,0,0,0$1401,79,0,0,0$1402,79,230,200,155$1402,80,0,0,0$1403,80,0,0,0$1403,79,230,200,155$1404,79,0,0,0$1404,80,0,0,0");
///
/// 是否进入素喃
///
///
///
///
public static bool IsInSunan(ZTRectangle gameRect)
{
Image image = ScreenCapture.Instance.CaptureScreenReturnImage();
ZTRectangle limit = new ZTRectangle(gameRect.End.X - 130, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y + 60);
ZTRectangle position = ZTRectangle.Empty;
return CVHelper.FindColorArray(out position, image, MapTopSunan, limit);
}
///
/// 地图右上角时空之门文字
///
public static ColorArray MapTopShikongzhimen = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1187,48,230,200,155$1177,46,230,200,155$1180,46,230,200,155$1180,55,230,200,155$1177,55,230,200,155$1184,56,230,200,155$1186,56,230,200,155$1186,45,230,200,155$1189,48,230,200,155$1193,45,230,200,155$1196,48,230,200,155$1199,47,230,200,155$1199,48,230,200,155$1201,48,230,200,155$1209,48,230,200,155$1204,45,230,200,155$1212,45,230,200,155$1213,46,230,200,155$1215,45,230,200,155$1221,45,230,200,155$1221,56,230,200,155$1219,56,230,200,155$1212,56,230,200,155$1210,56,230,200,155$1205,56,230,200,155$1199,56,230,200,155$1189,56,230,200,155$1194,55,230,200,155");
///
/// 是否进入时空之门
///
///
///
///
public static bool IsInShikongzhimen(ZTRectangle gameRect)
{
Image image = ScreenCapture.Instance.CaptureScreenReturnImage();
ZTRectangle limit = new ZTRectangle(gameRect.End.X - 210, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y + 60);
ZTRectangle position = ZTRectangle.Empty;
return CVHelper.FindColorArray(out position, image, MapTopShikongzhimen, limit);
}
///
/// 选择进那个副本界面的下方space区域
///
public static ColorArray ChoiceTaskPage_0 = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "873,736,201,176,126$855,736,17,15,11$854,736,17,15,11$851,736,206,181,130$858,736,206,181,130$860,736,10,9,6$862,736,17,15,11$865,736,204,178,128$868,736,17,15,11$869,736,17,15,11$876,736,17,15,11$880,736,203,178,128$883,736,17,15,11$888,736,208,182,131$888,738,208,182,131$884,738,52,45,33$879,738,179,156,113$874,738,55,48,35$871,738,12,11,8$865,738,158,139,100$862,738,208,182,131$859,738,50,43,31$854,738,52,45,33$850,738,208,182,131$850,740,208,182,131$852,740,128,112,80$854,740,208,182,131$858,740,201,176,127$859,740,50,43,31$862,740,208,182,131$867,740,89,78,56$869,740,208,182,131$876,740,208,182,131$881,740,21,18,13$884,740,208,182,131$886,740,145,127,91$887,742,208,182,131$884,742,17,15,11$880,742,208,182,131$877,742,17,15,11$874,742,158,138,99$870,742,17,15,11$865,742,208,182,131$862,742,17,15,11$859,742,50,43,31$858,742,208,182,131$855,742,17,15,11$851,742,208,182,131");
public static ColorArray ChoiceTaskPage_1 = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "889,793,119,104,75$872,788,208,182,131$935,786,203,177,128$939,793,208,182,131$868,795,208,182,131$879,792,208,182,131$889,793,119,104,75$916,796,17,15,11$916,796,17,15,11$916,796,17,15,11$916,796,17,15,11");
///
/// 是否打开选择副本界面
///
///
///
///
public static bool IsInChoiceTaskPage(Image image, ZTRectangle gameRect)
{
ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 600, gameRect.End.Y - 35, gameRect.Start.X + 800, gameRect.End.Y);
ZTRectangle position = ZTRectangle.Empty;
if (CVHelper.FindColorArray(out position, image, ChoiceTaskPage_0, gameRect))
{
return true;
}
return CVHelper.FindColorArray(out position, image, ChoiceTaskPage_1, gameRect);
}
///
/// 凛冬难度选择向右的箭头
///
public static ColorArray LindongRightGreenArrow = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "574,612,0,160,245$577,612,0,213,255$574,596,29,77,189$574,604,15,114,217$574,605,0,101,208$574,611,0,154,241$577,611,0,212,255$577,604,37,185,253$578,604,37,187,253$589,604,37,170,249$590,604,37,163,247$591,604,33,151,242");
///
/// 凛冬难度选择向左的箭头
///
public static ColorArray LindongLeftGreenArrow = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "495,605,0,145,243$495,597,74,151,252$494,597,74,152,255$494,605,0,151,248$496,605,0,131,233$496,612,0,196,255$497,612,0,173,251$481,604,36,158,246$482,604,37,166,248");
///
/// 是否打开选择了凛冬副本
///
///
///
///
public static bool IsInChoiceLindong(Image image, ZTRectangle gameRect, out bool choiceNanduDir)
{
choiceNanduDir = true;
ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 400, gameRect.End.Y - 200, gameRect.Start.X + 630, gameRect.End.Y - 90);
ZTRectangle position = ZTRectangle.Empty;
if (CVHelper.FindColorArray(out position, image, LindongRightGreenArrow, limit))
{
choiceNanduDir = true;
return true;
}
if (CVHelper.FindColorArray(out position, image, LindongLeftGreenArrow, limit))
{
choiceNanduDir = false;
return true;
}
return false;
}
///
/// 凛冬难度,1¬5级
///
private static ColorArray[] LindongNandu = new ColorArray[] {
ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "591,625,157,0,17$537,625,255,255,255$551,625,0,93,157$564,625,93,0,157$577,625,150,0,126"),
ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "577,625,150,0,126$537,625,93,157,0$551,625,255,255,255$564,625,93,0,157$590,625,157,0,17"),
ColorArray.FromHsvFloatString(0.002f,0.002f,0.002f,"591,625,157,0,17$538,625,93,157,0$551,625,0,93,157$564,625,255,255,255$577,625,150,0,126"),
ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "577,625,255,255,255$538,625,93,157,0$551,625,0,93,157$564,625,93,0,157$590,625,157,0,17"),
ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "590,625,255,255,255$537,625,93,157,0$551,625,0,93,157$564,625,93,0,157$577,625,150,0,126")
};
///
/// 查找凛冬难度
///
///
///
///
///
public static bool GetChoiceLingdongNandu(out Int32 choiceNandu,Image image, ZTRectangle gameRect)
{
ZTRectangle limit = new ZTRectangle(gameRect.Start.X + 400, gameRect.End.Y - 150, gameRect.Start.X + 650, gameRect.End.Y-90);
ZTRectangle position = ZTRectangle.Empty;
for (int i = 0; i < LindongNandu.Length; i++)
{
if (CVHelper.FindColorArray(out position, image, LindongNandu[i], limit))
{
choiceNandu = i + 1;
return true;
}
}
choiceNandu = 0;
return false;
}
///
/// 小地图时空之门文字
///
public static ColorArray ShikongzhimenText = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.002f, "1162,37,230,200,155$1150,35,230,200,155$1153,35,230,200,155$1153,39,230,200,155$1150,39,230,200,155$1150,43,230,200,155$1152,43,230,200,155$1153,44,230,200,155$1159,45,230,200,155$1159,37,230,200,155$1159,34,230,200,155$1155,37,230,200,155$1162,36,230,200,155$1172,36,230,200,155$1172,37,230,200,155$1171,41,230,200,155$1163,41,230,200,155$1162,45,230,200,155$1167,43,230,200,155$1172,45,230,200,155$1181,45,230,200,155$1185,45,230,200,155$1185,37,230,200,155$1189,34,230,200,155$1194,34,230,200,155$1194,45,230,200,155");
///
/// 是否时空之门地图
///
///
///
///
public static bool IsShikongzhimen(Image image, ZTRectangle gameRect)
{
ZTRectangle limit = new ZTRectangle(gameRect.End.X-200, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y +80);
ZTRectangle position = ZTRectangle.Empty;
return CVHelper.FindColorArray(out position, image, ShikongzhimenText, limit);
}
public static ColorArray LingdongRoomText = ColorArray.FromHsvFloatString(0.002f, 0.002f, 0.3f, "1144,18,204,193,167$1140,19,204,193,167$1148,19,204,193,167$1153,18,204,193,167$1153,19,204,193,167$1158,19,204,193,167$1160,25,204,193,167$1158,29,204,193,167$1157,29,204,193,167$1148,29,204,193,167$1144,29,204,193,167$1143,29,204,193,167$1140,29,204,193,167$1138,27,204,193,167");
///
/// 是否存在凛冬房间上的文字
///
///
///
///
public static bool ExistLingdongText(Image image, ZTRectangle gameRect)
{
ZTRectangle limit = new ZTRectangle(gameRect.End.X - 200, gameRect.Start.Y, gameRect.End.X, gameRect.Start.Y + 40);
ZTRectangle position = ZTRectangle.Empty;
return CVHelper.FindColorArray(out position, image, LingdongRoomText, limit);
}
}
}