RequestMagicSkillUse.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.clientpackets;
  16. import java.util.logging.Logger;
  17. import net.sf.l2j.Config;
  18. import net.sf.l2j.gameserver.datatables.SkillTable;
  19. import net.sf.l2j.gameserver.model.L2Skill;
  20. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  21. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  22. /**
  23. * This class ...
  24. *
  25. * @version $Revision: 1.7.2.1.2.3 $ $Date: 2005/03/27 15:29:30 $
  26. */
  27. public final class RequestMagicSkillUse extends L2GameClientPacket
  28. {
  29. private static final String _C__2F_REQUESTMAGICSKILLUSE = "[C] 2F RequestMagicSkillUse";
  30. private static Logger _log = Logger.getLogger(RequestMagicSkillUse.class.getName());
  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. L2PcInstance activeChar = getClient().getActiveChar();
  46. if (activeChar == null)
  47. return;
  48. // Get the level of the used skill
  49. int level = activeChar.getSkillLevel(_magicId);
  50. if (level <= 0)
  51. {
  52. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  53. return;
  54. }
  55. if (activeChar.isOutOfControl())
  56. {
  57. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  58. return;
  59. }
  60. // Get the L2Skill template corresponding to the skillID received from the client
  61. L2Skill skill = SkillTable.getInstance().getInfo(_magicId, level);
  62. // Check the validity of the skill
  63. if (skill != null)
  64. {
  65. // _log.fine(" skill:"+skill.getName() + " level:"+skill.getLevel() + " passive:"+skill.isPassive());
  66. // _log.fine(" range:"+skill.getCastRange()+" targettype:"+skill.getTargetType()+" optype:"+skill.getOperateType()+" power:"+skill.getPower());
  67. // _log.fine(" reusedelay:"+skill.getReuseDelay()+" hittime:"+skill.getHitTime());
  68. // _log.fine(" currentState:"+activeChar.getCurrentState()); //for debug
  69. // If Alternate rule Karma punishment is set to true, forbid skill Return to player with Karma
  70. if (skill.getSkillType() == L2Skill.SkillType.RECALL && !Config.ALT_GAME_KARMA_PLAYER_CAN_TELEPORT && activeChar.getKarma() > 0)
  71. return;
  72. // activeChar.stopMove();
  73. activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
  74. }
  75. else
  76. {
  77. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  78. _log.warning("No skill found!!");
  79. }
  80. }
  81. /* (non-Javadoc)
  82. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  83. */
  84. @Override
  85. public String getType()
  86. {
  87. return _C__2F_REQUESTMAGICSKILLUSE;
  88. }
  89. }