Guest User

Untitled

a guest
Jul 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.96 KB | None | 0 0
  1.         public List<Location> getPathToEx( Creature selfPos, Creature targetPos, int minDist, int maxDist )
  2.         {
  3.  
  4.             if ( selfPos.Z != targetPos.Z ) return null;
  5.  
  6.             int currentDist = (int)selfPos.DistanceTo(targetPos.Location);
  7.  
  8.             if ( currentDist == maxDist ) return null;
  9.  
  10.             int dxMin = 0;
  11.             int dxMax = 0;
  12.             int dyMin = 0;
  13.             int dyMax = 0;
  14.  
  15.             if ((selfPos.X - targetPos.X) <= 0) dxMin = maxDist;
  16.             else dxMin = 0;
  17.  
  18.             if ((selfPos.X - targetPos.X) >= 0) dxMax = maxDist;
  19.             else dxMax = 0;
  20.  
  21.             if ((selfPos.Y - targetPos.Y) <= 0) dyMin = maxDist;
  22.             else dyMin = 0;
  23.  
  24.             if ((selfPos.Y - targetPos.Y) >= 0) dyMax = maxDist;
  25.             else dyMax = 0;
  26.  
  27.             int tile = 0;
  28.  
  29.             List<Location> minWalkPos = new List<Location>();
  30.             List<Location> tmpPos = new List<Location>();
  31.  
  32.             int minWalkDist = 100;
  33.             int maxTaxi = -1;
  34.    
  35.             int tmpDist = -1;
  36.             int tmpWalkDist = -1;
  37.             int tmpMaxTaxi = -1;
  38.    
  39.             int tryDist = maxDist;
  40.    
  41.             List<point> pointlist = new List<point>();
  42.  
  43.             while (tryDist >= minDist)
  44.             {
  45.  
  46.                 foreach (int y in Enumerable.Range(targetPos.Y - dyMin,targetPos.Y + dyMax+1))
  47.                 {                  
  48.                     foreach (int x in Enumerable.Range(targetPos.Y - dyMin,targetPos.Y + dyMax+1))
  49.                     {
  50.                         tmpDist = Math.Max(Math.Abs(targetPos.X - x),Math.Abs(targetPos.Y - y));
  51.                         if (tmpDist == tryDist) pointlist.Add(new point(x,y,(int)Player.Z));
  52.  
  53.                     }
  54.                 }
  55.  
  56.  
  57.                 while (pointlist.Count() > 0)
  58.                 {
  59.                     point p = pointlist.First();
  60.                     int x = p.x;
  61.                     int y = p.y;
  62.  
  63.                     tmpWalkDist = Math.Abs(selfPos.X - x) + Math.Abs(selfPos.Y - y);
  64.  
  65.                     tmpPos.Add(new Location(x,y,(int)Player.Z));
  66.  
  67.                     tmpMaxTaxi = Math.Abs(targetPos.X - x) + Math.Abs(targetPos.Y - y);
  68.  
  69.                     if ((tmpWalkDist < minDist && tmpMaxTaxi+1 >= maxTaxi) || (tmpMaxTaxi >= tmpWalkDist && tmpWalkDist > maxTaxi) || minWalkDist == 100)
  70.                     {
  71.                         if (!tmpPos.Equals(selfPos))
  72.                         {
  73.                             if (IsTileWalkable(x,y,(int)Player.Z))
  74.                             {
  75.                                 minWalkDist = tmpWalkDist;
  76.                                 minWalkPos =tmpPos;
  77.                                 maxTaxi =tmpMaxTaxi;
  78.  
  79.                             }
  80.                         }
  81.  
  82.                     }
  83.                 }
  84.             }          
  85.  
  86.             if (minWalkDist != 100) return minWalkPos;
  87.            
  88.             tryDist -= 1;
  89.  
  90.             return null;
  91.  
  92.         }
Add Comment
Please, Sign In to add comment