AdminRide.java 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 handlers.admincommandhandlers;
  16. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  17. import com.l2jserver.gameserver.instancemanager.TransformationManager;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. import com.l2jserver.gameserver.network.SystemMessageId;
  20. /**
  21. * @author
  22. */
  23. public class AdminRide implements IAdminCommandHandler
  24. {
  25. private static final String[] ADMIN_COMMANDS =
  26. {
  27. "admin_ride_horse",
  28. "admin_ride_bike",
  29. "admin_ride_wyvern",
  30. "admin_ride_strider",
  31. "admin_unride_wyvern",
  32. "admin_unride_strider",
  33. "admin_unride",
  34. "admin_ride_wolf",
  35. "admin_unride_wolf",
  36. };
  37. private int _petRideId;
  38. private static final int PURPLE_MANED_HORSE_TRANSFORMATION_ID = 106;
  39. private static final int JET_BIKE_TRANSFORMATION_ID = 20001;
  40. @Override
  41. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  42. {
  43. L2PcInstance player = getRideTarget(activeChar);
  44. if(player == null)
  45. return false;
  46. if (command.startsWith("admin_ride"))
  47. {
  48. if (player.isMounted() || player.getPet() != null)
  49. {
  50. activeChar.sendMessage("Target already have a pet.");
  51. return false;
  52. }
  53. if (command.startsWith("admin_ride_wyvern"))
  54. {
  55. _petRideId = 12621;
  56. }
  57. else if (command.startsWith("admin_ride_strider"))
  58. {
  59. _petRideId = 12526;
  60. }
  61. else if (command.startsWith("admin_ride_wolf"))
  62. {
  63. _petRideId = 16041;
  64. }
  65. else if (command.startsWith("admin_ride_horse")) // handled using transformation
  66. {
  67. if (player.isTransformed() || player.isInStance())
  68. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
  69. else
  70. TransformationManager.getInstance().transformPlayer(PURPLE_MANED_HORSE_TRANSFORMATION_ID, player);
  71. return true;
  72. }
  73. else if (command.startsWith("admin_ride_bike")) // handled using transformation
  74. {
  75. if (player.isTransformed() || player.isInStance())
  76. activeChar.sendPacket(SystemMessageId.YOU_ALREADY_POLYMORPHED_AND_CANNOT_POLYMORPH_AGAIN);
  77. else
  78. TransformationManager.getInstance().transformPlayer(JET_BIKE_TRANSFORMATION_ID, player);
  79. return true;
  80. }
  81. else
  82. {
  83. activeChar.sendMessage("Command '" + command + "' not recognized");
  84. return false;
  85. }
  86. player.mount(_petRideId, 0, false);
  87. return false;
  88. }
  89. else if (command.startsWith("admin_unride"))
  90. {
  91. if (player.getTransformationId() == PURPLE_MANED_HORSE_TRANSFORMATION_ID)
  92. player.untransform();
  93. if (player.getTransformationId() == JET_BIKE_TRANSFORMATION_ID)
  94. player.untransform();
  95. else
  96. player.dismount();
  97. }
  98. return true;
  99. }
  100. private L2PcInstance getRideTarget(L2PcInstance activeChar)
  101. {
  102. L2PcInstance player = null;
  103. if(activeChar.getTarget() == null
  104. || activeChar.getTarget().getObjectId() == activeChar.getObjectId()
  105. || !(activeChar.getTarget() instanceof L2PcInstance))
  106. player = activeChar;
  107. else
  108. player = (L2PcInstance)activeChar.getTarget();
  109. return player;
  110. }
  111. @Override
  112. public String[] getAdminCommandList()
  113. {
  114. return ADMIN_COMMANDS;
  115. }
  116. }