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 single instance of GeoData.
  46. * @return single instance of GeoData
  47. */
  48. public static GeoData getInstance()
  49. {
  50. return SingletonHolder._instance;
  51. }
  52. /**
  53. * Gets the type.
  54. * @param x the x coordinate
  55. * @param y the y coordinate
  56. * @return the geodata block type
  57. */
  58. public short getType(int x, int y)
  59. {
  60. return 0;
  61. }
  62. /**
  63. * Gets the height.
  64. * @param x the x coordinate
  65. * @param y the y coordinate
  66. * @param z the z coordinate
  67. * @return the height
  68. */
  69. public short getHeight(int x, int y, int z)
  70. {
  71. return (short) z;
  72. }
  73. /**
  74. * Gets the spawn height.
  75. * @param x the x coordinate
  76. * @param y the y coordinate
  77. * @param zmin the minimum z coordinate
  78. * @param zmax the the maximum z coordinate
  79. * @param spawn the spawn
  80. * @return the spawn height
  81. */
  82. public short getSpawnHeight(int x, int y, int zmin, int zmax, L2Spawn spawn)
  83. {
  84. return (short) zmin;
  85. }
  86. /**
  87. * Geodata position.
  88. * @param x the x coordinate
  89. * @param y the y coordinate
  90. * @return the string
  91. */
  92. public String geoPosition(int x, int y)
  93. {
  94. return "";
  95. }
  96. /**
  97. * Can see target.
  98. * @param cha the character
  99. * @param target the target
  100. * @return {@code true} if the character can see the target (LOS), {@code false} otherwise
  101. */
  102. public boolean canSeeTarget(L2Object cha, L2Object target)
  103. {
  104. //If geodata is off do simple check :]
  105. //Don't allow casting on players on different dungeon levels etc
  106. return (Math.abs(target.getZ() - cha.getZ()) < 1000);
  107. }
  108. /**
  109. * Can see target.
  110. * @param cha the character
  111. * @param worldPosition the world position
  112. * @return {@code true} if the character can see the target at the given world position, {@code false} otherwise
  113. */
  114. public boolean canSeeTarget(L2Object cha, Point3D worldPosition)
  115. {
  116. // If geodata is off do simple check :]
  117. // Don't allow casting on players on different dungeon levels etc
  118. return Math.abs(worldPosition.getZ() - cha.getZ()) < 1000;
  119. }
  120. /**
  121. * Can see target.
  122. * @param x the x coordinate
  123. * @param y the y coordinate
  124. * @param z the z coordinate
  125. * @param tx the target's x coordinate
  126. * @param ty the target's y coordinate
  127. * @param tz the target's z coordinate
  128. * @return {@code true} if there is line of sight between the given coordinate sets, {@code false} otherwise
  129. */
  130. public boolean canSeeTarget(int x, int y, int z, int tx, int ty, int tz)
  131. {
  132. // If geodata is off do simple check :]
  133. // Don't allow casting on players on different dungeon levels etc
  134. return (Math.abs(z - tz) < 1000);
  135. }
  136. /**
  137. * Can see target debug.
  138. * @param gm the Game Master
  139. * @param target the target
  140. * @return {@code true} if the Game Master can see the target target (LOS), {@code false} otherwise
  141. */
  142. public boolean canSeeTargetDebug(L2PcInstance gm, L2Object target)
  143. {
  144. return true;
  145. }
  146. /**
  147. * Gets the NSWE.
  148. * @param x the x coordinate
  149. * @param y the y coordinate
  150. * @param z the z coordinate
  151. * @return the geodata NSWE (0-15)
  152. */
  153. public short getNSWE(int x, int y, int z)
  154. {
  155. return 15;
  156. }
  157. /**
  158. * Gets the height and NSWE.
  159. * @param x the x coordinate
  160. * @param y the y coordinate
  161. * @param z the z coordinate
  162. * @return the height and NSWE
  163. */
  164. public short getHeightAndNSWE(int x, int y, int z)
  165. {
  166. return (short)((z << 1) | 15);
  167. }
  168. /**
  169. * Move check.
  170. * @param x the x coordinate
  171. * @param y the y coordinate
  172. * @param z the z coordinate
  173. * @param tx the target's x coordinate
  174. * @param ty the target's y coordinate
  175. * @param tz the target's z coordinate
  176. * @param instanceId the instance id
  177. * @return the last Location (x,y,z) where player can walk - just before wall
  178. */
  179. public Location moveCheck(int x, int y, int z, int tx, int ty, int tz, int instanceId)
  180. {
  181. return new Location(tx, ty, tz);
  182. }
  183. /**
  184. * Can move from to target.
  185. * @param x the x coordinate
  186. * @param y the y coordinate
  187. * @param z the z coordinate
  188. * @param tx the target's x coordinate
  189. * @param ty the target's y coordinate
  190. * @param tz the target's z coordinate
  191. * @param instanceId the instance id
  192. * @return {@code true} if the character at x,y,z can move to tx,ty,tz, {@code false} otherwise
  193. */
  194. public boolean canMoveFromToTarget(int x, int y, int z, int tx, int ty, int tz, int instanceId)
  195. {
  196. return true;
  197. }
  198. /**
  199. * Adds the geodata data bug.
  200. * @param gm the Game Master
  201. * @param comment the comment
  202. */
  203. public void addGeoDataBug(L2PcInstance gm, String comment)
  204. {
  205. //Do Nothing
  206. }
  207. /**
  208. * Unload geodata.
  209. * @param rx the region x coordinate
  210. * @param ry the region y coordinate
  211. */
  212. public static void unloadGeodata(byte rx, byte ry)
  213. {
  214. }
  215. /**
  216. * Load a geodata file.
  217. * @param rx the region x coordinate
  218. * @param ry the region y coordinate
  219. * @return {@code true} if successful, {@code false} otherwise
  220. */
  221. public static boolean loadGeodataFile(byte rx, byte ry)
  222. {
  223. return false;
  224. }
  225. /**
  226. * Checks for geodata.
  227. * @param x the x coordinate
  228. * @param y the y coordinate
  229. * @return {@code true} if there is geodata for the given coordinates, {@code false} otherwise
  230. */
  231. public boolean hasGeo(int x, int y)
  232. {
  233. return false;
  234. }
  235. private static class SingletonHolder
  236. {
  237. protected static final GeoData _instance = Config.GEODATA > 0 ? GeoEngine.getInstance() : new GeoData(true);
  238. }
  239. }