GeoData.java 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.model.L2Object;
  19. import com.l2jserver.gameserver.model.L2Spawn;
  20. import com.l2jserver.gameserver.model.Location;
  21. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  22. import com.l2jserver.gameserver.util.Point3D;
  23. /**
  24. * @author -Nemesiss-
  25. */
  26. public class GeoData
  27. {
  28. private static final Logger _log = Logger.getLogger(GeoData.class.getName());
  29. protected GeoData()
  30. {
  31. //
  32. }
  33. /**
  34. * Instantiates a new geodata.
  35. * @param disabled the disabled
  36. */
  37. protected GeoData(final boolean disabled)
  38. {
  39. if (disabled)
  40. {
  41. _log.info("Geodata Engine: Disabled.");
  42. }
  43. }
  44. /**
  45. * Gets the type.
  46. * @param x the x coordinate
  47. * @param y the y coordinate
  48. * @return the geodata block type
  49. */
  50. public short getType(int x, int y)
  51. {
  52. return 0;
  53. }
  54. /**
  55. * Gets the height.
  56. * @param x the x coordinate
  57. * @param y the y coordinate
  58. * @param z the z coordinate
  59. * @return the height
  60. */
  61. public short getHeight(int x, int y, int z)
  62. {
  63. return (short) z;
  64. }
  65. /**
  66. * Gets the spawn height.
  67. * @param x the x coordinate
  68. * @param y the y coordinate
  69. * @param zmin the minimum z coordinate
  70. * @param zmax the the maximum z coordinate
  71. * @param spawn the spawn
  72. * @return the spawn height
  73. */
  74. public short getSpawnHeight(int x, int y, int zmin, int zmax, L2Spawn spawn)
  75. {
  76. return (short) zmin;
  77. }
  78. /**
  79. * Geodata position.
  80. * @param x the x coordinate
  81. * @param y the y coordinate
  82. * @return the string
  83. */
  84. public String geoPosition(int x, int y)
  85. {
  86. return "";
  87. }
  88. /**
  89. * Can see target.
  90. * @param cha the character
  91. * @param target the target
  92. * @return {@code true} if the character can see the target (LOS), {@code false} otherwise
  93. */
  94. public boolean canSeeTarget(L2Object cha, L2Object target)
  95. {
  96. // If geodata is off do simple check :]
  97. // Don't allow casting on players on different dungeon levels etc
  98. return (Math.abs(target.getZ() - cha.getZ()) < 1000);
  99. }
  100. /**
  101. * Can see target.
  102. * @param cha the character
  103. * @param worldPosition the world position
  104. * @return {@code true} if the character can see the target at the given world position, {@code false} otherwise
  105. */
  106. public boolean canSeeTarget(L2Object cha, Point3D worldPosition)
  107. {
  108. // If geodata is off do simple check :]
  109. // Don't allow casting on players on different dungeon levels etc
  110. return Math.abs(worldPosition.getZ() - cha.getZ()) < 1000;
  111. }
  112. /**
  113. * Can see target.
  114. * @param x the x coordinate
  115. * @param y the y coordinate
  116. * @param z the z coordinate
  117. * @param tx the target's x coordinate
  118. * @param ty the target's y coordinate
  119. * @param tz the target's z coordinate
  120. * @return {@code true} if there is line of sight between the given coordinate sets, {@code false} otherwise
  121. */
  122. public boolean canSeeTarget(int x, int y, int z, int tx, int ty, int tz)
  123. {
  124. // If geodata is off do simple check :]
  125. // Don't allow casting on players on different dungeon levels etc
  126. return (Math.abs(z - tz) < 1000);
  127. }
  128. /**
  129. * Can see target debug.
  130. * @param gm the Game Master
  131. * @param target the target
  132. * @return {@code true} if the Game Master can see the target target (LOS), {@code false} otherwise
  133. */
  134. public boolean canSeeTargetDebug(L2PcInstance gm, L2Object target)
  135. {
  136. return true;
  137. }
  138. /**
  139. * Gets the NSWE.
  140. * @param x the x coordinate
  141. * @param y the y coordinate
  142. * @param z the z coordinate
  143. * @return the geodata NSWE (0-15)
  144. */
  145. public short getNSWE(int x, int y, int z)
  146. {
  147. return 15;
  148. }
  149. /**
  150. * Gets the height and NSWE.
  151. * @param x the x coordinate
  152. * @param y the y coordinate
  153. * @param z the z coordinate
  154. * @return the height and NSWE
  155. */
  156. public short getHeightAndNSWE(int x, int y, int z)
  157. {
  158. return (short) ((z << 1) | 15);
  159. }
  160. /**
  161. * Move check.
  162. * @param x the x coordinate
  163. * @param y the y coordinate
  164. * @param z the z coordinate
  165. * @param tx the target's x coordinate
  166. * @param ty the target's y coordinate
  167. * @param tz the target's z coordinate
  168. * @param instanceId the instance id
  169. * @return the last Location (x,y,z) where player can walk - just before wall
  170. */
  171. public Location moveCheck(int x, int y, int z, int tx, int ty, int tz, int instanceId)
  172. {
  173. return new Location(tx, ty, tz);
  174. }
  175. /**
  176. * Can move from to target.
  177. * @param x the x coordinate
  178. * @param y the y coordinate
  179. * @param z the z coordinate
  180. * @param tx the target's x coordinate
  181. * @param ty the target's y coordinate
  182. * @param tz the target's z coordinate
  183. * @param instanceId the instance id
  184. * @return {@code true} if the character at x,y,z can move to tx,ty,tz, {@code false} otherwise
  185. */
  186. public boolean canMoveFromToTarget(int x, int y, int z, int tx, int ty, int tz, int instanceId)
  187. {
  188. return true;
  189. }
  190. /**
  191. * Adds the geodata data bug.
  192. * @param gm the Game Master
  193. * @param comment the comment
  194. */
  195. public void addGeoDataBug(L2PcInstance gm, String comment)
  196. {
  197. // Do Nothing
  198. }
  199. /**
  200. * Unload geodata.
  201. * @param rx the region x coordinate
  202. * @param ry the region y coordinate
  203. */
  204. public static void unloadGeodata(byte rx, byte ry)
  205. {
  206. }
  207. /**
  208. * Load a geodata file.
  209. * @param rx the region x coordinate
  210. * @param ry the region y coordinate
  211. * @return {@code true} if successful, {@code false} otherwise
  212. */
  213. public static boolean loadGeodataFile(byte rx, byte ry)
  214. {
  215. return false;
  216. }
  217. /**
  218. * Checks for geodata.
  219. * @param x the x coordinate
  220. * @param y the y coordinate
  221. * @return {@code true} if there is geodata for the given coordinates, {@code false} otherwise
  222. */
  223. public boolean hasGeo(int x, int y)
  224. {
  225. return false;
  226. }
  227. /**
  228. * Gets the single instance of GeoData.
  229. * @return single instance of GeoData
  230. */
  231. public static GeoData getInstance()
  232. {
  233. return SingletonHolder._instance;
  234. }
  235. private static class SingletonHolder
  236. {
  237. protected static final GeoData _instance = Config.GEODATA > 0 ? GeoEngine.getInstance() : new GeoData(true);
  238. }
  239. }