AdminRide.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2004-2015 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack 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 DataPack 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 handlers.admincommandhandlers;
  20. import com.l2jserver.gameserver.data.xml.impl.TransformData;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.network.SystemMessageId;
  24. /**
  25. * @author
  26. */
  27. public class AdminRide implements IAdminCommandHandler
  28. {
  29. private static final String[] ADMIN_COMMANDS =
  30. {
  31. "admin_ride_horse",
  32. "admin_ride_bike",
  33. "admin_ride_wyvern",
  34. "admin_ride_strider",
  35. "admin_unride_wyvern",
  36. "admin_unride_strider",
  37. "admin_unride",
  38. "admin_ride_wolf",
  39. "admin_unride_wolf",
  40. };
  41. private int _petRideId;
  42. private static final int PURPLE_MANED_HORSE_TRANSFORMATION_ID = 106;
  43. private static final int JET_BIKE_TRANSFORMATION_ID = 20001;
  44. @Override
  45. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  46. {
  47. L2PcInstance player = getRideTarget(activeChar);
  48. if (player == null)
  49. {
  50. return false;
  51. }
  52. if (command.startsWith("admin_ride"))
  53. {
  54. if (player.isMounted() || player.hasSummon())
  55. {
  56. activeChar.sendMessage("Target already have a summon.");
  57. return false;
  58. }
  59. if (command.startsWith("admin_ride_wyvern"))
  60. {
  61. _petRideId = 12621;
  62. }
  63. else if (command.startsWith("admin_ride_strider"))
  64. {
  65. _petRideId = 12526;
  66. }
  67. else if (command.startsWith("admin_ride_wolf"))
  68. {
  69. _petRideId = 16041;
  70. }
  71. else if (command.startsWith("admin_ride_horse")) // handled using transformation
  72. {
  73. if (player.isTransformed() || player.isInStance())
  74. {
  75. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
  76. }
  77. else
  78. {
  79. TransformData.getInstance().transformPlayer(PURPLE_MANED_HORSE_TRANSFORMATION_ID, player);
  80. }
  81. return true;
  82. }
  83. else if (command.startsWith("admin_ride_bike")) // handled using transformation
  84. {
  85. if (player.isTransformed() || player.isInStance())
  86. {
  87. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
  88. }
  89. else
  90. {
  91. TransformData.getInstance().transformPlayer(JET_BIKE_TRANSFORMATION_ID, player);
  92. }
  93. return true;
  94. }
  95. else
  96. {
  97. activeChar.sendMessage("Command '" + command + "' not recognized");
  98. return false;
  99. }
  100. player.mount(_petRideId, 0, false);
  101. return false;
  102. }
  103. else if (command.startsWith("admin_unride"))
  104. {
  105. if (player.getTransformationId() == PURPLE_MANED_HORSE_TRANSFORMATION_ID)
  106. {
  107. player.untransform();
  108. }
  109. if (player.getTransformationId() == JET_BIKE_TRANSFORMATION_ID)
  110. {
  111. player.untransform();
  112. }
  113. else
  114. {
  115. player.dismount();
  116. }
  117. }
  118. return true;
  119. }
  120. private L2PcInstance getRideTarget(L2PcInstance activeChar)
  121. {
  122. L2PcInstance player = null;
  123. if ((activeChar.getTarget() == null) || (activeChar.getTarget().getObjectId() == activeChar.getObjectId()) || !(activeChar.getTarget() instanceof L2PcInstance))
  124. {
  125. player = activeChar;
  126. }
  127. else
  128. {
  129. player = (L2PcInstance) activeChar.getTarget();
  130. }
  131. return player;
  132. }
  133. @Override
  134. public String[] getAdminCommandList()
  135. {
  136. return ADMIN_COMMANDS;
  137. }
  138. }