Attack.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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.serverpackets;
  16. import com.l2jserver.gameserver.model.L2Object;
  17. import com.l2jserver.gameserver.model.actor.L2Character;
  18. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  19. /**
  20. * sample
  21. * 06 8f19904b 2522d04b 00000000 80 950c0000 4af50000 08f2ffff 0000 - 0 damage (missed 0x80)
  22. * 06 85071048 bc0e504b 32000000 10 fc41ffff fd240200 a6f5ffff 0100 bc0e504b 33000000 10 3....
  23. * format
  24. * dddc dddh (ddc)
  25. *
  26. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/03/27 15:29:39 $
  27. */
  28. public class Attack extends L2GameServerPacket
  29. {
  30. public static final int HITFLAG_USESS = 0x10;
  31. public static final int HITFLAG_CRIT = 0x20;
  32. public static final int HITFLAG_SHLD = 0x40;
  33. public static final int HITFLAG_MISS = 0x80;
  34. public class Hit
  35. {
  36. protected final int _targetId;
  37. protected final int _damage;
  38. protected int _flags;
  39. Hit(L2Object target, int damage, boolean miss, boolean crit, byte shld)
  40. {
  41. _targetId = target.getObjectId();
  42. _damage = damage;
  43. if (miss)
  44. {
  45. _flags = HITFLAG_MISS;
  46. return;
  47. }
  48. if (soulshot)
  49. _flags = HITFLAG_USESS | Attack.this._ssGrade;
  50. if (crit)
  51. _flags |= HITFLAG_CRIT;
  52. // dirty fix for lags on olympiad
  53. if (shld > 0 && !(target instanceof L2PcInstance && ((L2PcInstance)target).isInOlympiadMode()))
  54. _flags |= HITFLAG_SHLD;
  55. // if (shld > 0)
  56. // _flags |= HITFLAG_SHLD;
  57. }
  58. }
  59. private static final String _S__06_ATTACK = "[S] 33 Attack";
  60. private final int _attackerObjId;
  61. private final int _targetObjId;
  62. public final boolean soulshot;
  63. public final int _ssGrade;
  64. private final int _x;
  65. private final int _y;
  66. private final int _z;
  67. private final int _tx;
  68. private final int _ty;
  69. private final int _tz;
  70. private Hit[] _hits;
  71. /**
  72. * @param attacker: the attacking L2Character<br>
  73. * @param target: the target L2Object<br>
  74. * @param useShots: true if soulshots used
  75. * @param ssGrade: the grade of the soulshots
  76. */
  77. public Attack(L2Character attacker, L2Object target, boolean useShots, int ssGrade)
  78. {
  79. _attackerObjId = attacker.getObjectId();
  80. _targetObjId = target.getObjectId();
  81. soulshot = useShots;
  82. _ssGrade = ssGrade;
  83. _x = attacker.getX();
  84. _y = attacker.getY();
  85. _z = attacker.getZ();
  86. _tx = target.getX();
  87. _ty = target.getY();
  88. _tz = target.getZ();
  89. }
  90. public Hit createHit(L2Object target, int damage, boolean miss, boolean crit, byte shld)
  91. {
  92. return new Hit( target, damage, miss, crit, shld );
  93. }
  94. public void hit(Hit... hits)
  95. {
  96. if (_hits == null)
  97. {
  98. _hits = hits;
  99. return;
  100. }
  101. // this will only happen with pole attacks
  102. Hit[] tmp = new Hit[hits.length + _hits.length];
  103. System.arraycopy(_hits, 0, tmp, 0, _hits.length);
  104. System.arraycopy(hits, 0, tmp, _hits.length, hits.length);
  105. _hits = tmp;
  106. }
  107. /**
  108. * Return True if the Server-Client packet Attack contains at least 1 hit.<BR><BR>
  109. */
  110. public boolean hasHits()
  111. {
  112. return _hits != null;
  113. }
  114. @Override
  115. protected final void writeImpl()
  116. {
  117. writeC(0x33);
  118. writeD(_attackerObjId);
  119. writeD(_targetObjId);
  120. writeD(_hits[0]._damage);
  121. writeC(_hits[0]._flags);
  122. writeD(_x);
  123. writeD(_y);
  124. writeD(_z);
  125. writeH(_hits.length - 1);
  126. // prevent sending useless packet while there is only one target.
  127. if (_hits.length > 1)
  128. {
  129. for (int i = 1; i < _hits.length; i++)
  130. {
  131. writeD(_hits[i]._targetId);
  132. writeD(_hits[i]._damage);
  133. writeC(_hits[i]._flags);
  134. }
  135. }
  136. writeD(_tx);
  137. writeD(_ty);
  138. writeD(_tz);
  139. }
  140. /* (non-Javadoc)
  141. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  142. */
  143. @Override
  144. public String getType()
  145. {
  146. return _S__06_ATTACK;
  147. }
  148. }