2
0

L2SkillMount.java 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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 com.l2jserver.gameserver.skills.l2skills;
  16. import com.l2jserver.gameserver.model.L2Object;
  17. import com.l2jserver.gameserver.model.L2Skill;
  18. import com.l2jserver.gameserver.model.StatsSet;
  19. import com.l2jserver.gameserver.model.actor.L2Character;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.model.entity.TvTEvent;
  22. import com.l2jserver.gameserver.network.SystemMessageId;
  23. public class L2SkillMount extends L2Skill
  24. {
  25. private final int _npcId;
  26. private final int _itemId;
  27. public L2SkillMount(StatsSet set)
  28. {
  29. super(set);
  30. _npcId = set.getInteger("npcId", 0);
  31. _itemId = set.getInteger("itemId", 0);
  32. }
  33. @Override
  34. public void useSkill(L2Character caster, L2Object[] targets)
  35. {
  36. if (!(caster instanceof L2PcInstance))
  37. {
  38. return;
  39. }
  40. if (!TvTEvent.onItemSummon(caster.getObjectId()))
  41. {
  42. return;
  43. }
  44. L2PcInstance activePlayer = (L2PcInstance) caster;
  45. if (!activePlayer.getFloodProtectors().getItemPetSummon().tryPerformAction("mount"))
  46. {
  47. return;
  48. }
  49. // Dismount Action
  50. if (_npcId == 0)
  51. {
  52. activePlayer.dismount();
  53. return;
  54. }
  55. if (activePlayer.isSitting())
  56. {
  57. activePlayer.sendPacket(SystemMessageId.CANT_MOVE_SITTING);
  58. return;
  59. }
  60. if (activePlayer.inObserverMode())
  61. {
  62. return;
  63. }
  64. if (activePlayer.isInOlympiadMode())
  65. {
  66. activePlayer.sendPacket(SystemMessageId.THIS_ITEM_IS_NOT_AVAILABLE_FOR_THE_OLYMPIAD_EVENT);
  67. return;
  68. }
  69. if ((activePlayer.getPet() != null) || activePlayer.isMounted())
  70. {
  71. activePlayer.sendPacket(SystemMessageId.YOU_ALREADY_HAVE_A_PET);
  72. return;
  73. }
  74. if (activePlayer.isAttackingNow())
  75. {
  76. activePlayer.sendPacket(SystemMessageId.YOU_CANNOT_SUMMON_IN_COMBAT);
  77. return;
  78. }
  79. if (activePlayer.isCursedWeaponEquipped())
  80. {
  81. return;
  82. }
  83. activePlayer.mount(_npcId, _itemId, false);
  84. }
  85. }