RequestMagicSkillUse.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2004-2015 L2J Server
  3. *
  4. * This file is part of L2J Server.
  5. *
  6. * L2J Server 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 Server 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 com.l2jserver.gameserver.network.clientpackets;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.ai.CtrlIntention;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. import com.l2jserver.gameserver.model.effects.L2EffectType;
  24. import com.l2jserver.gameserver.model.skills.Skill;
  25. import com.l2jserver.gameserver.model.skills.targets.L2TargetType;
  26. import com.l2jserver.gameserver.network.SystemMessageId;
  27. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  28. public final class RequestMagicSkillUse extends L2GameClientPacket
  29. {
  30. private static final String _C__39_REQUESTMAGICSKILLUSE = "[C] 39 RequestMagicSkillUse";
  31. private int _magicId;
  32. private boolean _ctrlPressed;
  33. private boolean _shiftPressed;
  34. @Override
  35. protected void readImpl()
  36. {
  37. _magicId = readD(); // Identifier of the used skill
  38. _ctrlPressed = readD() != 0; // True if it's a ForceAttack : Ctrl pressed
  39. _shiftPressed = readC() != 0; // True if Shift pressed
  40. }
  41. @Override
  42. protected void runImpl()
  43. {
  44. // Get the current L2PcInstance of the player
  45. final L2PcInstance activeChar = getActiveChar();
  46. if (activeChar == null)
  47. {
  48. return;
  49. }
  50. // Get the level of the used skill
  51. Skill skill = activeChar.getKnownSkill(_magicId);
  52. if (skill == null)
  53. {
  54. // Player doesn't know this skill, maybe it's the display Id.
  55. skill = activeChar.getCustomSkill(_magicId);
  56. if (skill == null)
  57. {
  58. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  59. _log.warning("Skill Id " + _magicId + " not found in player!");
  60. return;
  61. }
  62. }
  63. // Avoid Use of Skills in AirShip.
  64. if (activeChar.isPlayable() && activeChar.isInAirShip())
  65. {
  66. activeChar.sendPacket(SystemMessageId.ACTION_PROHIBITED_WHILE_MOUNTED_OR_ON_AN_AIRSHIP);
  67. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  68. return;
  69. }
  70. if ((activeChar.isTransformed() || activeChar.isInStance()) && !activeChar.hasTransformSkill(skill.getId()))
  71. {
  72. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  73. return;
  74. }
  75. // If Alternate rule Karma punishment is set to true, forbid skill Return to player with Karma
  76. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && (activeChar.getKarma() > 0) && skill.hasEffectType(L2EffectType.TELEPORT))
  77. {
  78. return;
  79. }
  80. // players mounted on pets cannot use any toggle skills
  81. if (skill.isToggle() && activeChar.isMounted())
  82. {
  83. return;
  84. }
  85. // Stop if use self-buff (except if on AirShip or Boat).
  86. if ((skill.isContinuous() && !skill.isDebuff() && (skill.getTargetType() == L2TargetType.SELF)) && (!activeChar.isInAirShip() || !activeChar.isInBoat()))
  87. {
  88. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, activeChar.getLocation());
  89. }
  90. activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
  91. }
  92. @Override
  93. public String getType()
  94. {
  95. return _C__39_REQUESTMAGICSKILLUSE;
  96. }
  97. }