RequestMagicSkillUse.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. skill = activeChar.getTransformSkill(_magicId);
  59. if (skill == null)
  60. {
  61. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  62. _log.warning("Skill Id " + _magicId + " not found in player : " + activeChar);
  63. return;
  64. }
  65. }
  66. }
  67. // Avoid Use of Skills in AirShip.
  68. if (activeChar.isPlayable() && activeChar.isInAirShip())
  69. {
  70. activeChar.sendPacket(SystemMessageId.ACTION_PROHIBITED_WHILE_MOUNTED_OR_ON_AN_AIRSHIP);
  71. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  72. return;
  73. }
  74. if ((activeChar.isTransformed() || activeChar.isInStance()) && !activeChar.hasTransformSkill(skill.getId()))
  75. {
  76. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  77. return;
  78. }
  79. // If Alternate rule Karma punishment is set to true, forbid skill Return to player with Karma
  80. if (!Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && (activeChar.getKarma() > 0) && skill.hasEffectType(L2EffectType.TELEPORT))
  81. {
  82. return;
  83. }
  84. // players mounted on pets cannot use any toggle skills
  85. if (skill.isToggle() && activeChar.isMounted())
  86. {
  87. return;
  88. }
  89. // Stop if use self-buff (except if on AirShip or Boat).
  90. if ((skill.isContinuous() && !skill.isDebuff() && (skill.getTargetType() == L2TargetType.SELF)) && (!activeChar.isInAirShip() || !activeChar.isInBoat()))
  91. {
  92. activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, activeChar.getLocation());
  93. }
  94. activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
  95. }
  96. @Override
  97. public String getType()
  98. {
  99. return _C__39_REQUESTMAGICSKILLUSE;
  100. }
  101. }