Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 2.29 KB | None | 0 0
  1. public boolean checkIfDoorsBetween(int x, int y, int z, int tx, int ty, int tz, int instance)
  2.     {
  3.         int region;
  4.         try
  5.         {
  6.             region = MapRegionTable.getInstance().getMapRegion(x, y);
  7.         }
  8.         catch (Exception e)
  9.         {
  10.             return false;
  11.         }
  12.        
  13.         // there are quite many doors, maybe they should be splitted
  14.         for (L2DoorInstance doorInst : _staticItems.values())
  15.         {
  16.             if (doorInst.getMapRegion() != region)
  17.                 continue;
  18.             if (doorInst.getXMax() == 0)
  19.                 continue;
  20.            
  21.             // line segment goes through box
  22.             // first basic checks to stop most calculations short
  23.             // phase 1, x
  24.             if (x <= doorInst.getXMax() && tx >= doorInst.getXMin() || tx <= doorInst.getXMax() && x >= doorInst.getXMin())
  25.             {
  26.                 //phase 2, y
  27.                 if (y <= doorInst.getYMax() && ty >= doorInst.getYMin() || ty <= doorInst.getYMax() && y >= doorInst.getYMin())
  28.                 {
  29.                     // phase 3, basically only z remains but now we calculate it with another formula (by rage)
  30.                     // in some cases the direct line check (only) in the beginning isn't sufficient,
  31.                     // when char z changes a lot along the path
  32.                     if (doorInst.getCurrentHp() > 0 && !doorInst.getOpen(instance))
  33.                     {
  34.                         int px1 = doorInst.getXMin();
  35.                         int py1 = doorInst.getYMin();
  36.                         int pz1 = doorInst.getZMin();
  37.                         int px2 = doorInst.getXMax();
  38.                         int py2 = doorInst.getYMax();
  39.                         int pz2 = doorInst.getZMax();
  40.                        
  41.                         int l = tx - x;
  42.                         int m = ty - y;
  43.                         int n = tz - z;
  44.                        
  45.                         int dk;
  46.                        
  47.                         if ((dk = (doorInst.getA() * l + doorInst.getB() * m + doorInst.getC() * n)) == 0) continue; // Parallel
  48.                        
  49.                         float p = (float)(doorInst.getA() * x + doorInst.getB() * y + doorInst.getC() * z + doorInst.getD()) / (float)dk;
  50.                        
  51.                         int fx = (int)(x - l * p);
  52.                         int fy = (int)(y - m * p);
  53.                         int fz = (int)(z - n * p);
  54.                        
  55.                         if((Math.min(x,tx) <= fx && fx <= Math.max(x,tx)) &&
  56.                                 (Math.min(y,ty) <= fy && fy <= Math.max(y,ty)) &&
  57.                                 (Math.min(z,tz) <= fz && fz <= Math.max(z,tz)))
  58.                         {
  59.  
  60.                             if (((fx >= px1 && fx <= px2) || (fx >= px2 && fx <= px1)) &&
  61.                                     ((fy >= py1 && fy <= py2) || (fy >= py2 && fy <= py1)) &&
  62.                                     ((fz >= pz1 && fz <= pz2) || (fz >= pz2 && fz <= pz1)))
  63.                                 return true; // Door between
  64.                         }
  65.                     }
  66.                 }
  67.             }
  68.         }
  69.         return false;
  70.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement