RequestMagicSkillUse.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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.network.clientpackets;
  16. import java.util.logging.Logger;
  17. import com.l2jserver.Config;
  18. import com.l2jserver.gameserver.datatables.SkillTable;
  19. import com.l2jserver.gameserver.model.L2Skill;
  20. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  21. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  22. import com.l2jserver.gameserver.templates.skills.L2SkillType;
  23. /**
  24. * This class ...
  25. *
  26. * @version $Revision: 1.7.2.1.2.3 $ $Date: 2005/03/27 15:29:30 $
  27. */
  28. public final class RequestMagicSkillUse extends L2GameClientPacket
  29. {
  30. private static final String _C__2F_REQUESTMAGICSKILLUSE = "[C] 2F RequestMagicSkillUse";
  31. private static Logger _log = Logger.getLogger(RequestMagicSkillUse.class.getName());
  32. private int _magicId;
  33. private boolean _ctrlPressed;
  34. private boolean _shiftPressed;
  35. @Override
  36. protected void readImpl()
  37. {
  38. _magicId = readD(); // Identifier of the used skill
  39. _ctrlPressed = readD() != 0; // True if it's a ForceAttack : Ctrl pressed
  40. _shiftPressed = readC() != 0; // True if Shift pressed
  41. }
  42. @Override
  43. protected void runImpl()
  44. {
  45. // Get the current L2PcInstance of the player
  46. L2PcInstance activeChar = getClient().getActiveChar();
  47. if (activeChar == null)
  48. return;
  49. // Get the level of the used skill
  50. int level = activeChar.getSkillLevel(_magicId);
  51. if (level <= 0)
  52. {
  53. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  54. return;
  55. }
  56. // Get the L2Skill template corresponding to the skillID received from the client
  57. L2Skill skill = SkillTable.getInstance().getInfo(_magicId, level);
  58. // Check the validity of the skill
  59. if (skill != null)
  60. {
  61. if ((activeChar.isTransformed() || activeChar.isInStance())
  62. && !activeChar.containsAllowedTransformSkill(skill.getId()))
  63. {
  64. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  65. return;
  66. }
  67. // _log.fine(" skill:"+skill.getName() + " level:"+skill.getLevel() + " passive:"+skill.isPassive());
  68. // _log.fine(" range:"+skill.getCastRange()+" targettype:"+skill.getTargetType()+" optype:"+skill.getOperateType()+" power:"+skill.getPower());
  69. // _log.fine(" reusedelay:"+skill.getReuseDelay()+" hittime:"+skill.getHitTime());
  70. // _log.fine(" currentState:"+activeChar.getCurrentState()); //for debug
  71. // If Alternate rule Karma punishment is set to true, forbid skill Return to player with Karma
  72. if (skill.getSkillType() == L2SkillType.RECALL && !Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && activeChar.getKarma() > 0)
  73. return;
  74. // players mounted on pets cannot use any toggle skills
  75. if (skill.isToggle() && activeChar.isMounted())
  76. return;
  77. // activeChar.stopMove();
  78. activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
  79. }
  80. else
  81. {
  82. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  83. _log.warning("No skill found with id " + _magicId + " and level " + level + " !!");
  84. }
  85. }
  86. /* (non-Javadoc)
  87. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  88. */
  89. @Override
  90. public String getType()
  91. {
  92. return _C__2F_REQUESTMAGICSKILLUSE;
  93. }
  94. @Override
  95. protected boolean triggersOnActionRequest()
  96. {
  97. return true;
  98. }
  99. }