Advertisement
Pauler

l2j dimensions v0.2

Aug 13th, 2013
847
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.94 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P gameserver
  3. Index: java/com/l2jpes/gameserver/model/actor/knownlist/PlayerKnownList.java
  4. ===================================================================
  5. --- java/com/l2jpes/gameserver/model/actor/knownlist/PlayerKnownList.java (revision 17)
  6. +++ java/com/l2jpes/gameserver/model/actor/knownlist/PlayerKnownList.java (working copy)
  7. @@ -35,6 +35,9 @@
  8. if (object instanceof L2PlayerInstance && ((L2PlayerInstance) object).inObserverMode())
  9. continue;
  10.  
  11. + if (object.getDimensionId() != getActiveChar().getDimensionId())
  12. + continue;
  13. +
  14. sendInfoFrom(object);
  15. }
  16. }
  17. Index: java/com/l2jpes/gameserver/handler/voicedcommandhandlers/DimensionCmd.java
  18. ===================================================================
  19. --- java/com/l2jpes/gameserver/handler/voicedcommandhandlers/DimensionCmd.java (revision 0)
  20. +++ java/com/l2jpes/gameserver/handler/voicedcommandhandlers/DimensionCmd.java (working copy)
  21. @@ -0,0 +1,104 @@
  22. +/*
  23. + * This program is free software: you can redistribute it and/or modify it under
  24. + * the terms of the GNU General Public License as published by the Free Software
  25. + * Foundation, either version 3 of the License, or (at your option) any later
  26. + * version.
  27. + *
  28. + * This program is distributed in the hope that it will be useful, but WITHOUT
  29. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  30. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  31. + * details.
  32. + *
  33. + * You should have received a copy of the GNU General Public License along with
  34. + * this program. If not, see <http://www.gnu.org/licenses/>.
  35. + */
  36. +package com.l2jpes.gameserver.handler.voicedcommandhandlers;
  37. +
  38. +import com.l2jpes.Config;
  39. +import com.l2jpes.gameserver.handler.impl.IVoicedCommandHandler;
  40. +import com.l2jpes.gameserver.model.L2Object;
  41. +import com.l2jpes.gameserver.model.L2World;
  42. +import com.l2jpes.gameserver.model.actor.instance.L2PlayerInstance;
  43. +import com.l2jpes.gameserver.network.serverpackets.NpcHtmlMessage;
  44. +
  45. +/**
  46. + * @author Pauler
  47. + */
  48. +public class DimensionCmd implements IVoicedCommandHandler
  49. +{
  50. +
  51. + private String[] commands = {
  52. + "dimension"
  53. + };
  54. +
  55. + @Override
  56. + public boolean useVoicedCommand(String command, L2PlayerInstance player, String[] commandParams)
  57. + {
  58. + if (Config.ENABLE_DIMENSION_COMMAND) {
  59. + if ((Config.DIMENSION_COMMAND_ADMIN_ONLY && player.isGM()) || !Config.DIMENSION_COMMAND_ADMIN_ONLY) {
  60. + if (commandParams != null) {
  61. + int dimensionId;
  62. +
  63. + try {
  64. + dimensionId = Integer.parseInt(commandParams[0]);
  65. + }catch(NumberFormatException e) {
  66. + player.sendMessage("You have to type a valid id.");
  67. + return false;
  68. + }
  69. +
  70. + if (dimensionId <= Config.MAX_DIMENSIONS) {
  71. + if (player.getDimensionId() != dimensionId) {
  72. + changeDimension(player, dimensionId);
  73. + player.sendMessage("You are transfered to dimension " + dimensionId + ".");
  74. + }else{
  75. + player.sendMessage("You already are in this dimension.");
  76. + }
  77. + }else
  78. + player.sendMessage("There are only " + Config.MAX_DIMENSIONS + " dimensions.");
  79. + }else{
  80. + NpcHtmlMessage msg = new NpcHtmlMessage(20);
  81. + msg.setHtml(showWindow(player));
  82. + msg.replace("%objectId%", String.valueOf(20));
  83. + player.sendPacket(msg);
  84. + }
  85. + }
  86. + }
  87. +
  88. + return true;
  89. + }
  90. +
  91. + private static void changeDimension(L2PlayerInstance player, int dimensionId) {
  92. + player.setDimensionId(dimensionId);
  93. + player.teleToLocation(player.getX(), player.getY(), player.getZ(), 0);
  94. + }
  95. +
  96. + private static String showWindow(L2PlayerInstance player) {
  97. + StringBuilder st = new StringBuilder();
  98. +
  99. + st.append("<html><head><title>L2JPes Open Source - Dimensions</title></head><body>");
  100. + for (int i = 1; i < Config.MAX_DIMENSIONS + 1; i++) {
  101. + st.append("<a action=\"bypass -h dimension " + i + "\" width=204 height=20>Dimension(" + i + ")-> " + getObjectCount(i) + " Objects.</a><br>");
  102. + }
  103. + st.append("</body></html>");
  104. +
  105. + return st.toString();
  106. + }
  107. +
  108. + private static int getObjectCount(int dimensionId) {
  109. + int objectCount = 0;
  110. +
  111. + for (L2Object obj:L2World.getInstance().getAllVisibleObjects().values()) {
  112. + if (obj.getDimensionId() == dimensionId)
  113. + objectCount++;
  114. + }
  115. +
  116. + return objectCount;
  117. + }
  118. +
  119. + @Override
  120. + public String[] getVoicedCommandList()
  121. + {
  122. + return commands;
  123. + }
  124. +
  125. +}
  126. Index: java/com/l2jpes/gameserver/network/clientpackets/Action.java
  127. ===================================================================
  128. --- java/com/l2jpes/gameserver/network/clientpackets/Action.java (revision 13)
  129. +++ java/com/l2jpes/gameserver/network/clientpackets/Action.java (working copy)
  130. @@ -72,6 +72,11 @@
  131. return;
  132. }
  133.  
  134. + if (obj.getDimensionId() != activeChar.getDimensionId()) {
  135. + activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  136. + return;
  137. + }
  138. +
  139. if (!activeChar.isGM() && activeChar.isOutOfControl())
  140. {
  141. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  142. Index: java/com/l2jpes/gameserver/handler/admincommandhandlers/AdminSpawn.java
  143. ===================================================================
  144. --- java/com/l2jpes/gameserver/handler/admincommandhandlers/AdminSpawn.java (revision 14)
  145. +++ java/com/l2jpes/gameserver/handler/admincommandhandlers/AdminSpawn.java (working copy)
  146. @@ -267,6 +267,7 @@
  147. spawn.setLocz(target.getZ());
  148. spawn.setHeading(activeChar.getHeading());
  149. spawn.setRespawnDelay(respawnTime);
  150. + spawn.setDimensionId(activeChar.getDimensionId());
  151.  
  152. if (RaidBossSpawnManager.getInstance().getValidTemplate(spawn.getNpcId()) != null)
  153. {
  154. Index: java/com/l2jpes/gameserver/datatables/SpawnTable.java
  155. ===================================================================
  156. --- java/com/l2jpes/gameserver/datatables/SpawnTable.java (revision 5)
  157. +++ java/com/l2jpes/gameserver/datatables/SpawnTable.java (working copy)
  158. @@ -94,6 +94,11 @@
  159. spawnDat.setHeading(rset.getInt("heading"));
  160. spawnDat.setRespawnDelay(rset.getInt("respawn_delay"));
  161.  
  162. + if (rset.getInt("dimensionid") == 0)
  163. + spawnDat.setDimensionId(1);
  164. + else
  165. + spawnDat.setDimensionId(rset.getInt("dimensionid"));
  166. +
  167. switch (rset.getInt("periodOfDay"))
  168. {
  169. case 0: // default
  170. @@ -141,13 +146,14 @@
  171. {
  172. try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  173. {
  174. - PreparedStatement statement = con.prepareStatement("INSERT INTO spawnlist (npc_templateid,locx,locy,locz,heading,respawn_delay) values(?,?,?,?,?,?)");
  175. + PreparedStatement statement = con.prepareStatement("INSERT INTO spawnlist (npc_templateid,locx,locy,locz,heading,respawn_delay,dimensionid) values(?,?,?,?,?,?,?)");
  176. statement.setInt(1, spawn.getNpcId());
  177. statement.setInt(2, spawn.getLocx());
  178. statement.setInt(3, spawn.getLocy());
  179. statement.setInt(4, spawn.getLocz());
  180. statement.setInt(5, spawn.getHeading());
  181. statement.setInt(6, spawn.getRespawnDelay() / 1000);
  182. + statement.setInt(7, spawn.getDimensionId());
  183. statement.execute();
  184. statement.close();
  185. }
  186. Index: java/com/l2jpes/gameserver/handler/skillhandlers/Continuous.java
  187. ===================================================================
  188. --- java/com/l2jpes/gameserver/handler/skillhandlers/Continuous.java (revision 14)
  189. +++ java/com/l2jpes/gameserver/handler/skillhandlers/Continuous.java (working copy)
  190. @@ -78,6 +78,10 @@
  191. if (!(obj instanceof L2Character))
  192. continue;
  193.  
  194. + if (obj.getDimensionId() != activeChar.getDimensionId()) {
  195. + continue;
  196. + }
  197. +
  198. L2Character target = ((L2Character) obj);
  199. if (Formulas.calcSkillReflect(target, skill) == Formulas.SKILL_REFLECT_SUCCEED)
  200. target = activeChar;
  201. Index: java/com/l2jpes/gameserver/network/clientpackets/RequestBypassToServer.java
  202. ===================================================================
  203. --- java/com/l2jpes/gameserver/network/clientpackets/RequestBypassToServer.java (revision 14)
  204. +++ java/com/l2jpes/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
  205. @@ -186,6 +186,17 @@
  206. return;
  207. }
  208. }
  209. + else if (_command.startsWith("dimension")) {
  210. + StringTokenizer st = new StringTokenizer(_command);
  211. +
  212. + st.nextToken();
  213. +
  214. + int dimensionId = Integer.parseInt(st.nextToken());
  215. +
  216. + activeChar.sendMessage("You are transfered to dimension " + dimensionId + ".");
  217. + activeChar.setDimensionId(dimensionId);
  218. + activeChar.teleToLocation(activeChar.getX(), activeChar.getY(), activeChar.getZ(), 0);
  219. + }
  220. }
  221. catch (Exception e)
  222. {
  223. Index: java/com/l2jpes/Config.java
  224. ===================================================================
  225. --- java/com/l2jpes/Config.java (revision 16)
  226. +++ java/com/l2jpes/Config.java (working copy)
  227. @@ -644,6 +644,10 @@
  228. public static boolean ENABLE_ONLINE_COMMAND;
  229. public static boolean ENABLE_ONLINE_PARAM;
  230.  
  231. + public static boolean ENABLE_DIMENSION_COMMAND;
  232. + public static boolean DIMENSION_COMMAND_ADMIN_ONLY;
  233. + public static int MAX_DIMENSIONS;
  234. +
  235. // --------------------------------------------------
  236. // Those "hidden" settings haven't configs to avoid admins to fuck their server
  237. // You still can experiment changing values here. But don't say I didn't warn you.
  238. @@ -1323,6 +1327,10 @@
  239.  
  240. ENABLE_ONLINE_COMMAND = general.getProperty("EnableOnlineCmd", false);
  241. ENABLE_ONLINE_PARAM = general.getProperty("EnableOnlineParam", false);
  242. +
  243. + ENABLE_DIMENSION_COMMAND = general.getProperty("EnableDimensionCmd", false);
  244. + DIMENSION_COMMAND_ADMIN_ONLY = general.getProperty("AdminOnlyDimensionCommand", false);
  245. + MAX_DIMENSIONS = general.getProperty("MaxDimensions", 20);
  246. }
  247. else if (Server.serverMode == Server.MODE_LOGINSERVER)
  248. {
  249. Index: java/com/l2jpes/gameserver/model/L2Object.java
  250. ===================================================================
  251. --- java/com/l2jpes/gameserver/model/L2Object.java (revision 13)
  252. +++ java/com/l2jpes/gameserver/model/L2Object.java (working copy)
  253. @@ -33,6 +33,7 @@
  254. private int _objectId; // Object identifier
  255. private ObjectPoly _poly;
  256. private ObjectPosition _position;
  257. + private int dimensionId = 1;
  258.  
  259. public L2Object(int objectId)
  260. {
  261. @@ -344,4 +345,12 @@
  262. {
  263. return (getClass().getSimpleName() + ":" + getName() + "[" + getObjectId() + "]");
  264. }
  265. +
  266. + public int getDimensionId() {
  267. + return dimensionId;
  268. + }
  269. +
  270. + public void setDimensionId(int dimensionId) {
  271. + this.dimensionId = dimensionId;
  272. + }
  273. }
  274. \ No newline at end of file
  275. Index: java/com/l2jpes/gameserver/handler/VoicedCommandHandler.java
  276. ===================================================================
  277. --- java/com/l2jpes/gameserver/handler/VoicedCommandHandler.java (revision 16)
  278. +++ java/com/l2jpes/gameserver/handler/VoicedCommandHandler.java (working copy)
  279. @@ -20,6 +20,7 @@
  280.  
  281. import com.l2jpes.Config;
  282. import com.l2jpes.gameserver.handler.impl.IVoicedCommandHandler;
  283. +import com.l2jpes.gameserver.handler.voicedcommandhandlers.DimensionCmd;
  284. import com.l2jpes.gameserver.handler.voicedcommandhandlers.L2JPesCmd;
  285. import com.l2jpes.gameserver.handler.voicedcommandhandlers.OnlineCmd;
  286.  
  287. @@ -38,6 +39,7 @@
  288. _datatable = new TIntObjectHashMap<>();
  289. registerVoicedCommandHandler(new L2JPesCmd());
  290. registerVoicedCommandHandler(new OnlineCmd());
  291. + registerVoicedCommandHandler(new DimensionCmd());
  292. }
  293.  
  294. private void registerVoicedCommandHandler(IVoicedCommandHandler handler)
  295. Index: java/com/l2jpes/gameserver/model/actor/knownlist/ObjectKnownList.java
  296. ===================================================================
  297. --- java/com/l2jpes/gameserver/model/actor/knownlist/ObjectKnownList.java (revision 5)
  298. +++ java/com/l2jpes/gameserver/model/actor/knownlist/ObjectKnownList.java (working copy)
  299. @@ -48,6 +48,10 @@
  300. if (!Util.checkIfInShortRadius(getDistanceToWatchObject(object), _activeObject, object, true))
  301. return false;
  302.  
  303. + // Check if they are at different dimensions
  304. + if (object.getDimensionId() != getActiveObject().getDimensionId())
  305. + return false;
  306. +
  307. return _knownObjects.put(object.getObjectId(), object) == null;
  308. }
  309.  
  310. Index: java/com/l2jpes/gameserver/model/L2Spawn.java
  311. ===================================================================
  312. --- java/com/l2jpes/gameserver/model/L2Spawn.java (revision 5)
  313. +++ java/com/l2jpes/gameserver/model/L2Spawn.java (working copy)
  314. @@ -75,6 +75,8 @@
  315. private L2Npc _lastSpawn;
  316. private static List<SpawnListener> _spawnListeners = new ArrayList<>();
  317.  
  318. + private int _dimensionid = 1;
  319. +
  320. /** The task launching the function doSpawn() */
  321. class SpawnTask implements Runnable
  322. {
  323. @@ -276,11 +278,11 @@
  324. }
  325.  
  326. /**
  327. - * Create the initial spawning and set _doRespawn to True.
  328. + * Create the initial spawning and set _doRespawn to True.
  329. */
  330. public void init()
  331. {
  332. - doSpawn();
  333. + doSpawn().setDimensionId(getDimensionId());
  334. _doRespawn = true;
  335. }
  336.  
  337. @@ -489,6 +491,14 @@
  338. return _template;
  339. }
  340.  
  341. + public int getDimensionId() {
  342. + return _dimensionid;
  343. + }
  344. +
  345. + public void setDimensionId(int dimensionId) {
  346. + _dimensionid = dimensionId;
  347. + }
  348. +
  349. @Override
  350. public String toString()
  351. {
  352. Index: config/general.properties
  353. ===================================================================
  354. --- config/general.properties (revision 16)
  355. +++ config/general.properties (working copy)
  356. @@ -308,4 +308,16 @@
  357. # By enabling this a player can check if someone is online by
  358. # writing the another player's name after the command
  359. # EnableOnlineCmd must be set to true
  360. -EnableOnlineParam = False
  361. \ No newline at end of file
  362. +EnableOnlineParam = False
  363. +
  364. +# Enable .dimension command.
  365. +# Default: False
  366. +EnableDimensionCmd = False
  367. +
  368. +# By enabling this you allow only GMs to use the .dimension command
  369. +# EnableDimensionCmd must be set to true
  370. +AdminOnlyDimensionCommand = False
  371. +
  372. +# Max number of available dimensions
  373. +# Default: 20
  374. +MaxDimensions = 20
  375. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement