RequestExMagicSkillUseGround.java 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.gameserver.datatables.SkillTable;
  18. import com.l2jserver.gameserver.model.L2Skill;
  19. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  20. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  21. import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
  22. import com.l2jserver.gameserver.util.Util;
  23. import com.l2jserver.util.Point3D;
  24. /**
  25. * Fromat:(ch) dddddc
  26. * @author -Wooden-
  27. */
  28. public final class RequestExMagicSkillUseGround extends L2GameClientPacket
  29. {
  30. private static final String _C__D0_2F_REQUESTEXMAGICSKILLUSEGROUND = "[C] D0:2F RequestExMagicSkillUseGround";
  31. private static Logger _log = Logger.getLogger(RequestExMagicSkillUseGround.class.getName());
  32. private int _x;
  33. private int _y;
  34. private int _z;
  35. private int _skillId;
  36. private boolean _ctrlPressed;
  37. private boolean _shiftPressed;
  38. @Override
  39. protected void readImpl()
  40. {
  41. _x = readD();
  42. _y = readD();
  43. _z = readD();
  44. _skillId = readD();
  45. _ctrlPressed = readD() != 0;
  46. _shiftPressed = readC() != 0;
  47. }
  48. /**
  49. * @see com.l2jserver.util.network.BaseRecievePacket.ClientBasePacket#runImpl()
  50. */
  51. @Override
  52. protected void runImpl()
  53. {
  54. // Get the current L2PcInstance of the player
  55. L2PcInstance activeChar = getClient().getActiveChar();
  56. if (activeChar == null)
  57. return;
  58. // Get the level of the used skill
  59. int level = activeChar.getSkillLevel(_skillId);
  60. if (level <= 0)
  61. {
  62. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  63. return;
  64. }
  65. // Get the L2Skill template corresponding to the skillID received from the client
  66. L2Skill skill = SkillTable.getInstance().getInfo(_skillId, level);
  67. // Check the validity of the skill
  68. if (skill != null)
  69. {
  70. activeChar.setCurrentSkillWorldPosition(new Point3D(_x , _y, _z));
  71. // normally magicskilluse packet turns char client side but for these skills, it doesn't (even with correct target)
  72. activeChar.setHeading(Util.calculateHeadingFrom(activeChar.getX(), activeChar.getY(), _x , _y));
  73. activeChar.broadcastPacket(new ValidateLocation(activeChar));
  74. activeChar.useMagic(skill, _ctrlPressed, _shiftPressed);
  75. }
  76. else
  77. {
  78. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  79. _log.warning("No skill found with id " + _skillId + " and level " + level + " !!");
  80. }
  81. }
  82. /**
  83. * @see com.l2jserver.gameserver.BasePacket#getType()
  84. */
  85. @Override
  86. public String getType()
  87. {
  88. return _C__D0_2F_REQUESTEXMAGICSKILLUSEGROUND;
  89. }
  90. }