using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace RichCreator.Utility.Structs
|
{
|
/// <summary>
|
/// 路径信息
|
/// </summary>
|
public class HousePathInfo
|
{
|
public HousePathInfo()
|
{
|
Obstacles = new List<ZTPolygon>();
|
LocationPoints = new List<ParametersPoint>();
|
FindPathPoints = new List<ZTPoint>();
|
LoopLines = new List<ZTLinePoint>();
|
FindPathLines = new List<ZTLinePoint>();
|
|
}
|
|
public HousePathInfo(Int32 width,Int32 height):this()
|
{
|
this.Width = width;
|
this.Height = height;
|
}
|
|
|
#region Propertys
|
/// <summary>
|
/// 宽
|
/// </summary>
|
public int Width { get; set; }
|
|
/// <summary>
|
/// 高
|
/// </summary>
|
public int Height { get; set; }
|
|
|
|
|
/// <summary>
|
/// 障碍物
|
/// </summary>
|
public List<ZTPolygon> Obstacles { get; set; }
|
|
|
/// <summary>
|
/// 定位点
|
/// </summary>
|
public List<ParametersPoint> LocationPoints { get; set; }
|
|
|
/// <summary>
|
/// 寻路点
|
/// </summary>
|
public List<ZTPoint> FindPathPoints{ get; set; }
|
|
|
/// <summary>
|
/// 循逻线
|
/// </summary>
|
public List<ZTLinePoint> LoopLines { get; set; }
|
|
/// <summary>
|
/// 寻路线
|
/// </summary>
|
public List<ZTLinePoint> FindPathLines { get; set; }
|
|
#endregion
|
|
|
#region Editor
|
/// <summary>
|
/// 添加障碍物
|
/// </summary>
|
/// <returns></returns>
|
public bool AddObstacle(ZTPolygon obstacle)
|
{
|
Int32 index = 0;
|
if (ExistsObstacle(out index, obstacle))
|
{
|
return false;
|
}
|
this.Obstacles.Add(obstacle);
|
return true;
|
}
|
|
/// <summary>
|
/// 删除障碍物
|
/// </summary>
|
/// <param name="obstacle"></param>
|
/// <returns></returns>
|
public void RemoveObstacle(ZTPolygon obstacle)
|
{
|
Int32 index = 0;
|
if (!ExistsObstacle(out index, obstacle))
|
{
|
return;
|
}
|
|
this.Obstacles.RemoveAt(index);
|
return;
|
}
|
|
/// <summary>
|
/// 是否存在障碍物
|
/// </summary>
|
/// <param name="obstacle"></param>
|
/// <returns></returns>
|
private bool ExistsObstacle(out Int32 index,ZTPolygon obstacle)
|
{
|
index = 0;
|
for (int i = 0; i < Obstacles.Count; i++)
|
{
|
if (Obstacles[i] == obstacle)
|
{
|
index = i;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/// <summary>
|
/// 添加定位点
|
/// </summary>
|
/// <param name="point"></param>
|
/// <param name="parameters"></param>
|
/// <returns></returns>
|
public bool AddLocationPosition(ParametersPoint point)
|
{
|
if (this.LocationPoints.Exists((p) => { return point.Point == p.Point; }))
|
{
|
return false;
|
}
|
|
this.LocationPoints.Add(point);
|
return true;
|
}
|
|
/// <summary>
|
/// 清空定位点
|
/// </summary>
|
/// <returns></returns>
|
public void ClearLocationPosiltion()
|
{
|
this.LocationPoints.Clear();
|
}
|
|
|
/// <summary>
|
/// 添加寻路点
|
/// </summary>
|
/// <param name="point"></param>
|
/// <returns></returns>
|
public bool AddFindPathPoint(ZTPoint point)
|
{
|
Int32 index = 0;
|
if (ExistsFindPathPoint(out index, point))
|
{
|
return false;
|
}
|
|
this.FindPathPoints.Add(point);
|
return true;
|
}
|
|
/// <summary>
|
/// 删除寻路点
|
/// </summary>
|
/// <param name="point"></param>
|
/// <returns></returns>
|
public bool RemoveFindPathPoint(ZTPoint point)
|
{
|
Int32 index = 0;
|
if (!ExistsFindPathPoint(out index,point))
|
{
|
return true;
|
}
|
|
//查询巡逻线和寻路线是否有用到此点
|
if (ExistsPointInAllLine(point))
|
{
|
return false;
|
}
|
|
this.FindPathPoints.RemoveAt(index);
|
return true;
|
}
|
|
/// <summary>
|
/// 是否存在指定寻路点
|
/// </summary>
|
/// <param name="index"></param>
|
/// <param name="point"></param>
|
/// <returns></returns>
|
private bool ExistsFindPathPoint(out Int32 index, ZTPoint point)
|
{
|
index = 0;
|
for (int i = 0; i < this.FindPathPoints.Count; i++)
|
{
|
if (this.FindPathPoints[i] == point)
|
{
|
index = i;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 添加巡逻线
|
/// </summary>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
public bool AddLoopLine(ZTLinePoint line)
|
{
|
Int32 index = 0;
|
if (ExistsLoopLine(out index, line))
|
{
|
return false;
|
}
|
if (line.P1 == line.P2)
|
{
|
return false;
|
}
|
this.LoopLines.Add(line);
|
return true;
|
}
|
|
/// <summary>
|
/// 删除巡逻线
|
/// </summary>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
public bool RemoveLoopLine(ZTLinePoint line)
|
{
|
Int32 index = 0;
|
if (!ExistsLoopLine(out index, line))
|
{
|
return true;
|
}
|
this.LoopLines.RemoveAt(index);
|
return true;
|
}
|
|
/// <summary>
|
/// 是否存在巡逻线
|
/// </summary>
|
/// <param name="index"></param>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
private bool ExistsLoopLine(out Int32 index, ZTLinePoint line)
|
{
|
index = 0;
|
for (int i = 0; i < this.LoopLines.Count; i++)
|
{
|
if (this.LoopLines[i] == line)
|
{
|
index = i;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
|
/// <summary>
|
/// 添加寻路线
|
/// </summary>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
public bool AddFindPathLine(ZTLinePoint line)
|
{
|
Int32 index = 0;
|
if (ExistsFindPathLine(out index, line))
|
{
|
return false;
|
}
|
this.FindPathLines.Add(line);
|
return true;
|
}
|
|
/// <summary>
|
/// 删除寻路线
|
/// </summary>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
public bool RemoveFindPathLine(ZTLinePoint line)
|
{
|
Int32 index = 0;
|
if (!ExistsFindPathLine(out index, line))
|
{
|
return true;
|
}
|
this.FindPathLines.RemoveAt(index);
|
return true;
|
}
|
|
/// <summary>
|
/// 是否存在寻路线
|
/// </summary>
|
/// <param name="index"></param>
|
/// <param name="line"></param>
|
/// <returns></returns>
|
private bool ExistsFindPathLine(out Int32 index, ZTLinePoint line)
|
{
|
index = 0;
|
for (int i = 0; i < this.FindPathLines.Count; i++)
|
{
|
if (this.FindPathLines[i] == line)
|
{
|
index = i;
|
return true;
|
}
|
}
|
return false;
|
}
|
|
/// <summary>
|
/// 巡逻线或寻路线中是否存在某点
|
/// </summary>
|
/// <param name="point"></param>
|
/// <returns></returns>
|
private bool ExistsPointInAllLine(ZTPoint point)
|
{
|
for (int i = 0; i < this.LoopLines.Count; i++)
|
{
|
if (this.LoopLines[i].P1 == point || this.LoopLines[i].P2 == point)
|
{
|
return true;
|
}
|
}
|
|
for (int i = 0; i < this.FindPathLines.Count; i++)
|
{
|
if (this.FindPathLines[i].P1 == point || this.FindPathLines[i].P2 == point)
|
{
|
return true;
|
}
|
}
|
return false;
|
}
|
#endregion
|
|
|
|
/// <summary>
|
/// 获取json
|
/// </summary>
|
/// <returns></returns>
|
public string ToJsonString()
|
{
|
string json = ZTImage.Json.JsonBuilder.ToJsonString(this);
|
return json;
|
}
|
|
/// <summary>
|
/// 从json字符串生成对象
|
/// </summary>
|
/// <param name="json"></param>
|
/// <returns></returns>
|
public static HousePathInfo FromJsonString(string json)
|
{
|
return ZTImage.Json.JsonParser.ToObject<HousePathInfo>(json);
|
}
|
|
|
/// <summary>
|
/// 寻找巡逻路线
|
/// </summary>
|
/// <param name="rolePosition"></param>
|
public static void FindLoopPath(ZTPoint rolePosition)
|
{
|
|
}
|
|
/// <summary>
|
/// 两点之间寻路
|
/// </summary>
|
/// <param name="start"></param>
|
/// <param name="end"></param>
|
public static void FindPath(ZTPoint start, ZTPoint end)
|
{
|
|
}
|
|
|
}
|
|
}
|