Attack.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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.serverpackets;
  16. import net.sf.l2j.gameserver.model.L2Character;
  17. import net.sf.l2j.gameserver.model.L2Object;
  18. /**
  19. * sample
  20. * 06 8f19904b 2522d04b 00000000 80 950c0000 4af50000 08f2ffff 0000 - 0 damage (missed 0x80)
  21. * 06 85071048 bc0e504b 32000000 10 fc41ffff fd240200 a6f5ffff 0100 bc0e504b 33000000 10 3....
  22. * format
  23. * dddc dddh (ddc)
  24. *
  25. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
  26. */
  27. public class Attack extends L2GameServerPacket
  28. {
  29. private class Hit
  30. {
  31. protected int _targetId;
  32. protected int _damage;
  33. protected int _flags;
  34. Hit(L2Object target, int damage, boolean miss, boolean crit, boolean shld)
  35. {
  36. _targetId = target.getObjectId();
  37. _damage = damage;
  38. if (soulshot) _flags |= 0x10 | _grade;
  39. if (crit) _flags |= 0x20;
  40. if (shld) _flags |= 0x40;
  41. if (miss) _flags |= 0x80;
  42. }
  43. }
  44. // dh
  45. private static final String _S__06_ATTACK = "[S] 33 Attack";
  46. protected final int _attackerObjId;
  47. public final boolean soulshot;
  48. protected int _grade;
  49. private int _x;
  50. private int _y;
  51. private int _z;
  52. private Hit[] _hits;
  53. /**
  54. * @param attacker the attacker L2Character
  55. * @param ss true if useing SoulShots
  56. */
  57. public Attack(L2Character attacker, boolean ss, int grade)
  58. {
  59. _attackerObjId = attacker.getObjectId();
  60. soulshot = ss;
  61. _grade = grade;
  62. _x = attacker.getX();
  63. _y = attacker.getY();
  64. _z = attacker.getZ();
  65. _hits = new Hit[0];
  66. }
  67. /**
  68. * Add this hit (target, damage, miss, critical, shield) to the Server-Client packet Attack.<BR><BR>
  69. */
  70. public void addHit(L2Object target, int damage, boolean miss, boolean crit, boolean shld)
  71. {
  72. // Get the last position in the hits table
  73. int pos = _hits.length;
  74. // Create a new Hit object
  75. Hit[] tmp = new Hit[pos+1];
  76. // Add the new Hit object to hits table
  77. for (int i=0; i < _hits.length; i++)
  78. tmp[i] = _hits[i];
  79. tmp[pos] = new Hit(target, damage, miss, crit, shld);
  80. _hits = tmp;
  81. }
  82. /**
  83. * Return True if the Server-Client packet Attack conatins at least 1 hit.<BR><BR>
  84. */
  85. public boolean hasHits()
  86. {
  87. return _hits.length > 0;
  88. }
  89. @Override
  90. protected final void writeImpl()
  91. {
  92. writeC(0x33);
  93. writeD(_attackerObjId);
  94. writeD(_hits[0]._targetId);
  95. writeD(_hits[0]._damage);
  96. writeC(_hits[0]._flags);
  97. writeD(_x);
  98. writeD(_y);
  99. writeD(_z);
  100. writeH(_hits.length-1);
  101. for (int i=1; i < _hits.length; i++)
  102. {
  103. writeD(_hits[i]._targetId);
  104. writeD(_hits[i]._damage);
  105. writeC(_hits[i]._flags);
  106. }
  107. }
  108. /* (non-Javadoc)
  109. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  110. */
  111. @Override
  112. public String getType()
  113. {
  114. return _S__06_ATTACK;
  115. }
  116. }