public MirResult MoveAndFireToPoint(MapInfo mapInfo, Point point, CancellationTokenSource cancellationTokenSource, int distance = 2) { return(MoveToPoint(mapInfo, point, cancellationTokenSource, distance, () => { bool move = true; var actionResult = MirAction.FindMaster(); //#TODO 判断 actionResult ,并输出日志 var masters = actionResult.Data; while (masters.Any()) { move = true; var master = masters.NearbyMaster(MirContext.Position); MirAction.AttackMaster(master, cancellationTokenSource); } var actionResult2 = MirAction.FindItems(); //#TODO 判断 actionResult ,并输出日志 var items = actionResult2.Data; while (items.Any()) { //#TODO ,需要判断物品所在位置被人怪站住的情况 var item = items.NearbyItem(MirContext.Position); MirAction.PickupItem(item); } return move; })); }
/// <summary> /// 走到坐标 /// </summary> /// <param name="mapInfo"></param> /// <param name="point"></param> /// <param name="cancellationTokenSource"></param> /// <param name="distance"></param> /// <returns></returns> public MirResult MoveToPoint(MapInfo mapInfo, Point point, CancellationTokenSource cancellationTokenSource, int distance = 2, Func <bool> func = null) { var position = MirContext.Position; //同一个地图判断 if (!position.MapInfo.Equals(mapInfo)) { return(new MirResult(Consts.NotSameMap, "不在同一个地图")); } //距离判断 if (CalculationDistance(position.Point, point) <= distance) { return(new MirResult()); } /** * 1.找到两个点的路径 * 2.循环路径,一个个点的走过去(需要考虑人怪卡位问题) */ string message = string.Empty; #region 1.找到两个点的路径 var findPath = FindPath(position, point); var pathPoints = findPath.Data; if (findPath.Success && !pathPoints.Any()) { return(new MirResult(Consts.AutoRoteFail, findPath.Message)); } #endregion #region 循环路径,一个个点的走过去(需要考虑人怪卡位问题) Point firstPoint = pathPoints.FirstOrDefault(); //Point secondPoint = null; MirDirection mirDirection = MirDirection.None; RunType runType = RunType.FastRun; //移动是否成功 bool moveState = false; bool reFindPath = false; //循环条件 //还有点位没有走到 //没有被取消 //同一个地图 //距离大于 distance while (firstPoint != null && !cancellationTokenSource.IsCancellationRequested && position.MapInfo.Equals(mapInfo) && CalculationDistance(position.Point, point) > distance) { try { #region 计算移动方向 mirDirection = CalculationDirection(position.Point, firstPoint); if (mirDirection == MirDirection.None) { pathPoints.Remove(firstPoint); //已经到达位置,需要重新计算路线 //findPath = FindPath(MirContext.Position, point); //if(findPath.Success && findPath.Data.Any()) //{ // pathPoints = findPath.Data; //} //else //{ // pathPoints = new List<Point>(); //} continue; } #endregion #region 计算移动方式 runType = CalculationRunType(position, firstPoint); #endregion #region 移动 var actionResult = MirAction.Move(mirDirection, runType); //#TODO 判断 actionResult 状态,并输入日志 moveState = actionResult.Data; if (moveState) { //更新最后移动时间 MirContext.LastMoveTime = new DateTime(); pathPoints.Remove(firstPoint); //打怪过程有移动过,这重新寻路 if (func != null) { reFindPath = func(); } } else { var nextPoint = GetNextPoint(position.Point, mirDirection, runType); //#TODO,如果是跑,需要再处理下 //移动失败,15秒内不走这个点 MirContext.AddBartPoint(nextPoint, position.MapInfo, DateTime.Now.AddSeconds(15)); if (LongTimeNotMove()) { //长时间被堵住,随用随机飞 } //被堵后,重新寻路 reFindPath = true; } if (reFindPath) { findPath = FindPath(MirContext.Position, point); if (findPath.Success && findPath.Data.Any()) { pathPoints = findPath.Data; } else { pathPoints = new List <Point>(); return(new MirResult(findPath.Code, findPath.Message)); } } #endregion } finally { firstPoint = pathPoints.FirstOrDefault(); position = MirContext.Position; } } #endregion return(new MirResult()); }