Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<Location> getPathToEx( Creature selfPos, Creature targetPos, int minDist, int maxDist )
- {
- if ( selfPos.Z != targetPos.Z ) return null;
- int currentDist = (int)selfPos.DistanceTo(targetPos.Location);
- if ( currentDist == maxDist ) return null;
- int dxMin = 0;
- int dxMax = 0;
- int dyMin = 0;
- int dyMax = 0;
- if ((selfPos.X - targetPos.X) <= 0) dxMin = maxDist;
- else dxMin = 0;
- if ((selfPos.X - targetPos.X) >= 0) dxMax = maxDist;
- else dxMax = 0;
- if ((selfPos.Y - targetPos.Y) <= 0) dyMin = maxDist;
- else dyMin = 0;
- if ((selfPos.Y - targetPos.Y) >= 0) dyMax = maxDist;
- else dyMax = 0;
- int tile = 0;
- List<Location> minWalkPos = new List<Location>();
- List<Location> tmpPos = new List<Location>();
- int minWalkDist = 100;
- int maxTaxi = -1;
- int tmpDist = -1;
- int tmpWalkDist = -1;
- int tmpMaxTaxi = -1;
- int tryDist = maxDist;
- List<point> pointlist = new List<point>();
- while (tryDist >= minDist)
- {
- foreach (int y in Enumerable.Range(targetPos.Y - dyMin,targetPos.Y + dyMax+1))
- {
- foreach (int x in Enumerable.Range(targetPos.Y - dyMin,targetPos.Y + dyMax+1))
- {
- tmpDist = Math.Max(Math.Abs(targetPos.X - x),Math.Abs(targetPos.Y - y));
- if (tmpDist == tryDist) pointlist.Add(new point(x,y,(int)Player.Z));
- }
- }
- while (pointlist.Count() > 0)
- {
- point p = pointlist.First();
- int x = p.x;
- int y = p.y;
- tmpWalkDist = Math.Abs(selfPos.X - x) + Math.Abs(selfPos.Y - y);
- tmpPos.Add(new Location(x,y,(int)Player.Z));
- tmpMaxTaxi = Math.Abs(targetPos.X - x) + Math.Abs(targetPos.Y - y);
- if ((tmpWalkDist < minDist && tmpMaxTaxi+1 >= maxTaxi) || (tmpMaxTaxi >= tmpWalkDist && tmpWalkDist > maxTaxi) || minWalkDist == 100)
- {
- if (!tmpPos.Equals(selfPos))
- {
- if (IsTileWalkable(x,y,(int)Player.Z))
- {
- minWalkDist = tmpWalkDist;
- minWalkPos =tmpPos;
- maxTaxi =tmpMaxTaxi;
- }
- }
- }
- }
- }
- if (minWalkDist != 100) return minWalkPos;
- tryDist -= 1;
- return null;
- }
Add Comment
Please, Sign In to add comment