Guest User

Untitled

a guest
Dec 11th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. package org.dementhium.model.map.region;
  2.  
  3. import org.dementhium.model.Location;
  4. import org.dementhium.model.map.GameObject;
  5. import org.dementhium.model.map.Region;
  6.  
  7. public class DynamicRegion {
  8.  
  9. private int[][][][] regionCoords;
  10.  
  11. public DynamicRegion(int regionId) {
  12. regionCoords = new int[4][8][8][4];
  13. }
  14.  
  15. public int getMask(int plane, int localX, int localY) {
  16. int xoffset = localX/8;
  17. int yoffset = localY/8;
  18. int rotation = regionCoords[plane][xoffset][yoffset][3];
  19. if(rotation != 0)
  20. return 0;
  21. int realRegionX = regionCoords[plane][xoffset][yoffset][0];
  22. int realRegionY = regionCoords[plane][xoffset][yoffset][1];
  23. if(realRegionX == 0|| realRegionY == 0)
  24. return -1;
  25. int realRegionId = (((realRegionX / 8) << 8) + (realRegionY / 8));
  26. int baseX = (realRegionId >> 8) << 6, baseY = (realRegionId & 0xff) << 6;
  27. int coordX = baseX + localX;
  28. int coordY = baseY + localY;
  29. int regionX = coordX >> 3;
  30. int regionY = coordY >> 3;
  31. int regionOffsetX = (regionX - ((regionX/8) * 8));
  32. int regionOffsetY = (regionY - ((regionY/8) * 8));
  33. int realRegionOffsetX = (realRegionX - ((realRegionX/8) * 8));
  34. int realRegionOffsetY = (realRegionY - ((realRegionY/8) * 8));
  35. int realLocalX = (realRegionOffsetX * 8) + (localX - (regionOffsetX*8));
  36. int realLocalY = (realRegionOffsetY * 8) + (localY - (regionOffsetY*8));
  37. return Region.getClippingMask(baseX+realLocalX, baseY+realLocalY, regionCoords[plane][xoffset][yoffset][2]);
  38. }
  39.  
  40. public GameObject getObject(int objectId, int localX, int localY, int height) {
  41. int xoffset = localX/8;
  42. int yoffset = localY/8;
  43. int realRegionX = regionCoords[height][xoffset][yoffset][0];
  44. int realRegionY = regionCoords[height][xoffset][yoffset][1];
  45. if(realRegionX == 0|| realRegionY == 0)
  46. return null;
  47. int realRegionId = (((realRegionX / 8) << 8) + (realRegionY / 8));
  48. int baseX = (realRegionId >> 8) << 6, baseY = (realRegionId & 0xff) << 6;
  49. int coordX = baseX + localX;
  50. int coordY = baseY + localY;
  51. int regionX = coordX >> 3;
  52. int regionY = coordY >> 3;
  53. int regionOffsetX = (regionX - ((regionX/8) * 8));
  54. int regionOffsetY = (regionY - ((regionY/8) * 8));
  55. int realRegionOffsetX = (realRegionX - ((realRegionX/8) * 8));
  56. int realRegionOffsetY = (realRegionY - ((realRegionY/8) * 8));
  57. int realLocalX = (realRegionOffsetX * 8) + (localX - (regionOffsetX*8));
  58. int realLocalY = (realRegionOffsetY * 8) + (localY - (regionOffsetY*8));
  59. return Location.locate(baseX+realLocalX, baseY+realLocalY, regionCoords[height][xoffset][yoffset][2]).getGameObject(objectId);
  60. }
  61.  
  62. public int[][][][] getRegionCoords() {
  63. return regionCoords;
  64. }
  65.  
  66. public void setRegionCoords(int[][][][] regionCoords) {
  67. this.regionCoords = regionCoords;
  68. }
  69. }
Add Comment
Please, Sign In to add comment