NpcInfo.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * This program is free software; you can redistribute it and/or modify
  3. * it under the terms of the GNU General Public License as published by
  4. * the Free Software Foundation; either version 2, or (at your option)
  5. * any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. * 02111-1307, USA.
  16. *
  17. * http://www.gnu.org/copyleft/gpl.html
  18. */
  19. package net.sf.l2j.gameserver.serverpackets;
  20. import net.sf.l2j.Config;
  21. import net.sf.l2j.gameserver.model.L2Character;
  22. import net.sf.l2j.gameserver.model.L2Summon;
  23. import net.sf.l2j.gameserver.model.actor.instance.L2MonsterInstance;
  24. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  25. import net.sf.l2j.gameserver.model.actor.instance.L2PetInstance;
  26. /**
  27. * This class ...
  28. *
  29. * @version $Revision: 1.7.2.4.2.9 $ $Date: 2005/04/11 10:05:54 $
  30. */
  31. public class NpcInfo extends L2GameServerPacket
  32. {
  33. // ddddddddddddddddddffffdddcccccSSddd dddddc
  34. // ddddddddddddddddddffffdddcccccSSddd dddddccffd
  35. private static final String _S__22_NPCINFO = "[S] 16 NpcInfo";
  36. private L2Character _activeChar;
  37. private int _x, _y, _z, _heading;
  38. private int _idTemplate;
  39. private boolean _isAttackable, _isSummoned;
  40. private int _mAtkSpd, _pAtkSpd;
  41. private int _runSpd, _walkSpd, _swimRunSpd, _swimWalkSpd, _flRunSpd, _flWalkSpd, _flyRunSpd, _flyWalkSpd;
  42. private int _rhand, _lhand;
  43. private int _collisionHeight, _collisionRadius;
  44. private String _name = "";
  45. private String _title = "";
  46. /**
  47. * @param _characters
  48. */
  49. public NpcInfo(L2NpcInstance cha, L2Character attacker)
  50. {
  51. _activeChar = cha;
  52. _idTemplate = cha.getTemplate().idTemplate;
  53. _isAttackable = cha.isAutoAttackable(attacker);
  54. _rhand = cha.getRightHandItem();
  55. _lhand = cha.getLeftHandItem();
  56. _isSummoned = false;
  57. _collisionHeight = cha.getCollisionHeight();
  58. _collisionRadius = cha.getCollisionRadius();
  59. if (cha.getTemplate().serverSideName)
  60. _name = cha.getTemplate().name;
  61. if(Config.L2JMOD_CHAMPION_ENABLE && cha.isChampion())
  62. _title = ("Champion");
  63. else if (cha.getTemplate().serverSideTitle)
  64. _title = cha.getTemplate().title;
  65. else
  66. _title = cha.getTitle();
  67. if (Config.SHOW_NPC_LVL && _activeChar instanceof L2MonsterInstance)
  68. {
  69. String t = "Lv " + cha.getLevel() + (cha.getAggroRange() > 0 ? "*" : "");
  70. if (_title != null)
  71. t += " " + _title;
  72. _title = t;
  73. }
  74. _x = _activeChar.getX();
  75. _y = _activeChar.getY();
  76. _z = _activeChar.getZ();
  77. _heading = _activeChar.getHeading();
  78. _mAtkSpd = _activeChar.getMAtkSpd();
  79. _pAtkSpd = _activeChar.getPAtkSpd();
  80. _runSpd = _activeChar.getRunSpeed();
  81. _walkSpd = _activeChar.getWalkSpeed();
  82. _swimRunSpd = _flRunSpd = _flyRunSpd = _runSpd;
  83. _swimWalkSpd = _flWalkSpd = _flyWalkSpd = _walkSpd;
  84. }
  85. public NpcInfo(L2Summon cha, L2Character attacker)
  86. {
  87. _activeChar = cha;
  88. _idTemplate = cha.getTemplate().idTemplate;
  89. _isAttackable = cha.isAutoAttackable(attacker); //(cha.getKarma() > 0);
  90. _rhand = 0;
  91. _lhand = 0;
  92. _isSummoned = cha.isShowSummonAnimation();
  93. _collisionHeight = _activeChar.getTemplate().collisionHeight;
  94. _collisionRadius = _activeChar.getTemplate().collisionRadius;
  95. if (cha.getTemplate().serverSideName || cha instanceof L2PetInstance)
  96. {
  97. _name = _activeChar.getName();
  98. _title = cha.getTitle();
  99. }
  100. _x = _activeChar.getX();
  101. _y = _activeChar.getY();
  102. _z = _activeChar.getZ();
  103. _heading = _activeChar.getHeading();
  104. _mAtkSpd = _activeChar.getMAtkSpd();
  105. _pAtkSpd = _activeChar.getPAtkSpd();
  106. _runSpd = _activeChar.getRunSpeed();
  107. _walkSpd = _activeChar.getWalkSpeed();
  108. _swimRunSpd = _flRunSpd = _flyRunSpd = _runSpd;
  109. _swimWalkSpd = _flWalkSpd = _flyWalkSpd = _walkSpd;
  110. }
  111. @Override
  112. protected final void writeImpl()
  113. {
  114. if (_activeChar instanceof L2Summon)
  115. if (((L2Summon)_activeChar).getOwner() != null
  116. && ((L2Summon)_activeChar).getOwner().getAppearance().getInvisible())
  117. return;
  118. writeC(0x16);
  119. writeD(_activeChar.getObjectId());
  120. writeD(_idTemplate+1000000); // npctype id
  121. writeD(_isAttackable ? 1 : 0);
  122. writeD(_x);
  123. writeD(_y);
  124. writeD(_z);
  125. writeD(_heading);
  126. writeD(0x00);
  127. writeD(_mAtkSpd);
  128. writeD(_pAtkSpd);
  129. writeD(_runSpd);
  130. writeD(_walkSpd);
  131. writeD(_swimRunSpd/*0x32*/); // swimspeed
  132. writeD(_swimWalkSpd/*0x32*/); // swimspeed
  133. writeD(_flRunSpd);
  134. writeD(_flWalkSpd);
  135. writeD(_flyRunSpd);
  136. writeD(_flyWalkSpd);
  137. writeF(1.1/*_activeChar.getProperMultiplier()*/);
  138. //writeF(1/*_activeChar.getAttackSpeedMultiplier()*/);
  139. writeF(_pAtkSpd/277.478340719);
  140. writeF(_collisionRadius);
  141. writeF(_collisionHeight);
  142. writeD(_rhand); // right hand weapon
  143. writeD(0);
  144. writeD(_lhand); // left hand weapon
  145. writeC(1); // name above char 1=true ... ??
  146. writeC(_activeChar.isRunning() ? 1 : 0);
  147. writeC(_activeChar.isInCombat() ? 1 : 0);
  148. writeC(_activeChar.isAlikeDead() ? 1 : 0);
  149. writeC(_isSummoned ? 2 : 0); // invisible ?? 0=false 1=true 2=summoned (only works if model has a summon animation)
  150. writeS(_name);
  151. writeS(_title);
  152. writeD(0);
  153. writeD(0);
  154. writeD(0000); // hmm karma ??
  155. writeD(_activeChar.getAbnormalEffect()); // C2
  156. writeD(0000); // C2
  157. writeD(0000); // C2
  158. writeD(0000); // C2
  159. writeD(0000); // C2
  160. writeC(0000); // C2
  161. writeC(0x00); // C3 team circle 1-blue, 2-red
  162. writeF(_collisionRadius);
  163. writeF(_collisionHeight);
  164. writeD(0x00); // C4
  165. writeD(0x00); // C6
  166. }
  167. /* (non-Javadoc)
  168. * @see net.sf.l2j.gameserver.serverpackets.ServerBasePacket#getType()
  169. */
  170. @Override
  171. public String getType()
  172. {
  173. return _S__22_NPCINFO;
  174. }
  175. }