RequestExMagicSkillUseGround.java 3.1 KB

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