Mount.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 net.sf.l2j.gameserver.handler.usercommandhandlers;
  16. import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  17. import net.sf.l2j.gameserver.model.L2Character;
  18. import net.sf.l2j.gameserver.model.L2Summon;
  19. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  20. import net.sf.l2j.gameserver.network.SystemMessageId;
  21. import net.sf.l2j.gameserver.serverpackets.SystemMessage;
  22. /**
  23. * Support for /mount command.
  24. * @author Tempy
  25. */
  26. public class Mount implements IUserCommandHandler
  27. {
  28. private static final int[] COMMAND_IDS = { 61 };
  29. /* (non-Javadoc)
  30. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#useUserCommand(int, net.sf.l2j.gameserver.model.L2PcInstance)
  31. */
  32. public synchronized boolean useUserCommand(int id, L2PcInstance activeChar)
  33. {
  34. if (id != COMMAND_IDS[0])
  35. return false;
  36. L2Summon pet = activeChar.getPet();
  37. if ((pet != null) && pet.isMountable() && !activeChar.isMounted())
  38. {
  39. if (activeChar.isTransformed())
  40. {
  41. // You cannot mount a steed while transformed.
  42. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_TRANSFORMED);
  43. activeChar.sendPacket(msg);
  44. return false;
  45. }
  46. else if (activeChar.isParalyzed())
  47. {
  48. // You cannot mount a steed while petrified.
  49. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_PETRIFIED);
  50. activeChar.sendPacket(msg);
  51. return false;
  52. }
  53. else if (activeChar.isDead())
  54. {
  55. // You cannot mount a steed while dead.
  56. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_DEAD);
  57. activeChar.sendPacket(msg);
  58. return false;
  59. }
  60. else if (activeChar.isFishing())
  61. {
  62. // You cannot mount a steed while fishing.
  63. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_FISHING);
  64. activeChar.sendPacket(msg);
  65. return false;
  66. }
  67. else if (activeChar.isInDuel())
  68. {
  69. // You cannot mount a steed while in a duel.
  70. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_IN_A_DUEL);
  71. activeChar.sendPacket(msg);
  72. return false;
  73. }
  74. else if (activeChar.isSitting())
  75. {
  76. // You cannot mount a steed while sitting.
  77. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_SITTING);
  78. activeChar.sendPacket(msg);
  79. return false;
  80. }
  81. else if (activeChar.isCastingNow())
  82. {
  83. // You cannot mount a steed while skill casting.
  84. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_SKILL_CASTING);
  85. activeChar.sendPacket(msg);
  86. return false;
  87. }
  88. else if (activeChar.isCursedWeaponEquipped())
  89. {
  90. // You cannot mount a steed while a cursed weapon is equipped.
  91. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_A_CURSED_WEAPON_IS_EQUIPPED);
  92. activeChar.sendPacket(msg);
  93. return false;
  94. }
  95. /**
  96. * TODO: Add Siege Flag Restriction,
  97. else if (activeChar.isFlagEquipped())
  98. {
  99. // You cannot mount a steed while holding a flag.
  100. SystemMessage msg = new SystemMessage(SystemMessageId.YOU_CANNOT_MOUNT_A_STEED_WHILE_HOLDING_A_FLAG);
  101. activeChar.sendPacket(msg);
  102. }
  103. */
  104. else if (activeChar.isInCombat() || activeChar.getPvpFlag() != 0)
  105. {
  106. // A pet cannot be ridden while player is in battle.
  107. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CANT_BE_RIDDEN_WHILE_IN_BATTLE);
  108. activeChar.sendPacket(msg);
  109. return false;
  110. }
  111. else if (activeChar.isRentedPet())
  112. {
  113. activeChar.stopRentPet();
  114. return false;
  115. }
  116. else if (activeChar.isMoving()
  117. || activeChar.isInsideZone(L2Character.ZONE_WATER))
  118. {
  119. // A strider can be ridden only when player is standing.
  120. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_CAN_BE_RIDDEN_ONLY_WHILE_STANDING);
  121. activeChar.sendPacket(msg);
  122. return false;
  123. }
  124. else if (pet.isInCombat())
  125. {
  126. // A strider in battle cannot be ridden.
  127. SystemMessage msg = new SystemMessage(SystemMessageId.STRIDER_IN_BATLLE_CANT_BE_RIDDEN);
  128. activeChar.sendPacket(msg);
  129. return false;
  130. }
  131. else if (pet.isDead())
  132. {
  133. // A dead strider cannot be ridden.
  134. SystemMessage msg = new SystemMessage(SystemMessageId.DEAD_STRIDER_CANT_BE_RIDDEN);
  135. activeChar.sendPacket(msg);
  136. return false;
  137. }
  138. else
  139. activeChar.mount(pet);
  140. }
  141. return true;
  142. }
  143. /* (non-Javadoc)
  144. * @see net.sf.l2j.gameserver.handler.IUserCommandHandler#getUserCommandList()
  145. */
  146. public int[] getUserCommandList()
  147. {
  148. return COMMAND_IDS;
  149. }
  150. }