Attack.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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.ArrayList;
  21. import java.util.Iterator;
  22. import java.util.List;
  23. import com.l2jserver.gameserver.model.Hit;
  24. import com.l2jserver.gameserver.model.Location;
  25. import com.l2jserver.gameserver.model.actor.L2Character;
  26. public class Attack extends L2GameServerPacket
  27. {
  28. private final int _attackerObjId;
  29. private final boolean _soulshot;
  30. private final int _ssGrade;
  31. private final Location _attackerLoc;
  32. private final Location _targetLoc;
  33. private final List<Hit> _hits = new ArrayList<>();
  34. /**
  35. * @param attacker
  36. * @param target
  37. * @param useShots
  38. * @param ssGrade
  39. */
  40. public Attack(L2Character attacker, L2Character target, boolean useShots, int ssGrade)
  41. {
  42. _attackerObjId = attacker.getObjectId();
  43. _soulshot = useShots;
  44. _ssGrade = ssGrade;
  45. _attackerLoc = new Location(attacker);
  46. _targetLoc = new Location(target);
  47. }
  48. /**
  49. * Adds hit to the attack (Attacks such as dual dagger/sword/fist has two hits)
  50. * @param target
  51. * @param damage
  52. * @param miss
  53. * @param crit
  54. * @param shld
  55. */
  56. public void addHit(L2Character target, int damage, boolean miss, boolean crit, byte shld)
  57. {
  58. _hits.add(new Hit(target, damage, miss, crit, shld, _soulshot, _ssGrade));
  59. }
  60. /**
  61. * @return {@code true} if current attack contains at least 1 hit.
  62. */
  63. public boolean hasHits()
  64. {
  65. return !_hits.isEmpty();
  66. }
  67. /**
  68. * @return {@code true} if attack has soul shot charged.
  69. */
  70. public boolean hasSoulshot()
  71. {
  72. return _soulshot;
  73. }
  74. /**
  75. * Writes current hit
  76. * @param hit
  77. */
  78. private void writeHit(Hit hit)
  79. {
  80. writeD(hit.getTargetId());
  81. writeD(hit.getDamage());
  82. writeC(hit.getFlags());
  83. }
  84. @Override
  85. protected final void writeImpl()
  86. {
  87. final Iterator<Hit> it = _hits.iterator();
  88. writeC(0x33);
  89. writeD(_attackerObjId);
  90. writeHit(it.next());
  91. writeLoc(_attackerLoc);
  92. writeH(_hits.size() - 1);
  93. while (it.hasNext())
  94. {
  95. writeHit(it.next());
  96. }
  97. writeLoc(_targetLoc);
  98. }
  99. }