GeoData.java 6.9 KB

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