MagicSkillUse.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.serverpackets;
  20. import java.util.Arrays;
  21. import java.util.Collections;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.model.Location;
  24. import com.l2jserver.gameserver.model.actor.L2Character;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.interfaces.IPositionable;
  27. /**
  28. * MagicSkillUse server packet implementation.
  29. * @author UnAfraid, NosBit
  30. */
  31. public final class MagicSkillUse extends L2GameServerPacket
  32. {
  33. private final int _skillId;
  34. private final int _skillLevel;
  35. private final int _hitTime;
  36. private final int _reuseDelay;
  37. private final L2Character _activeChar;
  38. private final L2Character _target;
  39. private final List<Integer> _unknown = Collections.emptyList();
  40. private final List<Location> _groundLocations;
  41. public MagicSkillUse(L2Character cha, L2Character target, int skillId, int skillLevel, int hitTime, int reuseDelay)
  42. {
  43. _activeChar = cha;
  44. _target = target;
  45. _skillId = skillId;
  46. _skillLevel = skillLevel;
  47. _hitTime = hitTime;
  48. _reuseDelay = reuseDelay;
  49. Location skillWorldPos = null;
  50. if (cha.isPlayer())
  51. {
  52. final L2PcInstance player = cha.getActingPlayer();
  53. if (player.getCurrentSkillWorldPosition() != null)
  54. {
  55. skillWorldPos = player.getCurrentSkillWorldPosition();
  56. }
  57. }
  58. _groundLocations = skillWorldPos != null ? Arrays.asList(skillWorldPos) : Collections.<Location> emptyList();
  59. }
  60. public MagicSkillUse(L2Character cha, int skillId, int skillLevel, int hitTime, int reuseDelay)
  61. {
  62. this(cha, cha, skillId, skillLevel, hitTime, reuseDelay);
  63. }
  64. @Override
  65. protected final void writeImpl()
  66. {
  67. writeC(0x48);
  68. writeD(_activeChar.getObjectId());
  69. writeD(_target.getObjectId());
  70. writeD(_skillId);
  71. writeD(_skillLevel);
  72. writeD(_hitTime);
  73. writeD(_reuseDelay);
  74. writeLoc(_activeChar);
  75. writeH(_unknown.size()); // TODO: Implement me!
  76. for (int unknown : _unknown)
  77. {
  78. writeH(unknown);
  79. }
  80. writeH(_groundLocations.size());
  81. for (IPositionable target : _groundLocations)
  82. {
  83. writeLoc(target);
  84. }
  85. writeLoc(_target);
  86. }
  87. }