AbstractNpcInfo.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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.Config;
  17. import com.l2jserver.gameserver.datatables.ClanTable;
  18. import com.l2jserver.gameserver.instancemanager.TownManager;
  19. import com.l2jserver.gameserver.model.L2Clan;
  20. import com.l2jserver.gameserver.model.actor.L2Character;
  21. import com.l2jserver.gameserver.model.actor.L2Npc;
  22. import com.l2jserver.gameserver.model.actor.L2Summon;
  23. import com.l2jserver.gameserver.model.actor.L2Trap;
  24. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  25. import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.skills.AbnormalEffect;
  28. /**
  29. * This class ...
  30. *
  31. * @version $Revision: 1.7.2.4.2.9 $ $Date: 2005/04/11 10:05:54 $
  32. */
  33. public abstract class AbstractNpcInfo extends L2GameServerPacket
  34. {
  35. // ddddddddddddddddddffffdddcccccSSddd dddddc
  36. // ddddddddddddddddddffffdddcccccSSddd dddddccffd
  37. private static final String _S__22_NPCINFO = "[S] 0c NpcInfo";
  38. protected int _x, _y, _z, _heading;
  39. protected int _idTemplate;
  40. protected boolean _isAttackable, _isSummoned;
  41. protected int _mAtkSpd, _pAtkSpd;
  42. /**
  43. * Run speed, swimming run speed and flying run speed
  44. */
  45. protected int _runSpd;
  46. /**
  47. * Walking speed, swimming walking speed and flying walking speed
  48. */
  49. protected int _walkSpd;
  50. protected int _rhand, _lhand, _chest, _enchantEffect;
  51. protected double _collisionHeight, _collisionRadius;
  52. protected String _name = "";
  53. protected String _title = "";
  54. public AbstractNpcInfo(L2Character cha)
  55. {
  56. _isSummoned = cha.isShowSummonAnimation();
  57. _x = cha.getX();
  58. _y = cha.getY();
  59. _z = cha.getZ();
  60. _heading = cha.getHeading();
  61. _mAtkSpd = cha.getMAtkSpd();
  62. _pAtkSpd = cha.getPAtkSpd();
  63. _runSpd = cha.getTemplate().baseRunSpd;
  64. _walkSpd = cha.getTemplate().baseWalkSpd;
  65. }
  66. /* (non-Javadoc)
  67. * @see com.l2jserver.gameserver.serverpackets.ServerBasePacket#getType()
  68. */
  69. @Override
  70. public String getType()
  71. {
  72. return _S__22_NPCINFO;
  73. }
  74. /**
  75. * Packet for Npcs
  76. */
  77. public static class NpcInfo extends AbstractNpcInfo
  78. {
  79. private L2Npc _npc;
  80. private int _clanCrest = 0;
  81. private int _allyCrest = 0;
  82. private int _allyId = 0;
  83. private int _clanId = 0;
  84. private int _displayEffect = 0;
  85. public NpcInfo(L2Npc cha, L2Character attacker)
  86. {
  87. super(cha);
  88. _npc = cha;
  89. _idTemplate = cha.getTemplate().idTemplate; // On every subclass
  90. _rhand = cha.getRightHandItem(); // On every subclass
  91. _lhand = cha.getLeftHandItem(); // On every subclass
  92. _enchantEffect = cha.getEnchantEffect();
  93. _collisionHeight = cha.getCollisionHeight();// On every subclass
  94. _collisionRadius = cha.getCollisionRadius();// On every subclass
  95. _isAttackable = cha.isAutoAttackable(attacker);
  96. if (cha.getTemplate().serverSideName)
  97. _name = cha.getName();// On every subclass
  98. if (Config.L2JMOD_CHAMPION_ENABLE && cha.isChampion())
  99. _title = (Config.L2JMOD_CHAMP_TITLE); // On every subclass
  100. else if (cha.getTemplate().serverSideTitle)
  101. _title = cha.getTemplate().title; // On every subclass
  102. else
  103. _title = cha.getTitle(); // On every subclass
  104. if (Config.SHOW_NPC_LVL && _npc instanceof L2MonsterInstance)
  105. {
  106. String t = "Lv " + cha.getLevel() + (cha.getAggroRange() > 0 ? "*" : "");
  107. if (_title != null)
  108. t += " " + _title;
  109. _title = t;
  110. }
  111. // npc crest of owning clan/ally of castle
  112. if (cha instanceof L2NpcInstance && cha.isInsideZone(L2Character.ZONE_TOWN) && (Config.SHOW_CREST_WITHOUT_QUEST || cha.getCastle().getShowNpcCrest()) && cha.getCastle().getOwnerId() != 0)
  113. {
  114. int townId = TownManager.getTown(_x, _y, _z).getTownId();
  115. if (townId != 33 && townId != 22)
  116. {
  117. L2Clan clan = ClanTable.getInstance().getClan(cha.getCastle().getOwnerId());
  118. _clanCrest = clan.getCrestId();
  119. _clanId = clan.getClanId();
  120. _allyCrest = clan.getAllyCrestId();
  121. _allyId = clan.getAllyId();
  122. }
  123. }
  124. _displayEffect = cha.getDisplayEffect();
  125. }
  126. @Override
  127. protected void writeImpl()
  128. {
  129. writeC(0x0c);
  130. writeD(_npc.getObjectId());
  131. writeD(_idTemplate + 1000000); // npctype id
  132. writeD(_isAttackable ? 1 : 0);
  133. writeD(_x);
  134. writeD(_y);
  135. writeD(_z);
  136. writeD(_heading);
  137. writeD(0x00);
  138. writeD(_mAtkSpd);
  139. writeD(_pAtkSpd);
  140. writeD(_runSpd);
  141. writeD(_walkSpd);
  142. writeD(_runSpd); // swim run speed
  143. writeD(_walkSpd); // swim walk speed
  144. writeD(_runSpd); // swim run speed
  145. writeD(_walkSpd); // swim walk speed
  146. writeD(_runSpd); // fly run speed
  147. writeD(_walkSpd); // fly run speed
  148. writeF(_npc.getMovementSpeedMultiplier());
  149. writeF(_npc.getAttackSpeedMultiplier());
  150. writeF(_collisionRadius);
  151. writeF(_collisionHeight);
  152. writeD(_rhand); // right hand weapon
  153. writeD(_chest);
  154. writeD(_lhand); // left hand weapon
  155. writeC(1); // name above char 1=true ... ??
  156. writeC(_npc.isRunning() ? 1 : 0);
  157. writeC(_npc.isInCombat() ? 1 : 0);
  158. writeC(_npc.isAlikeDead() ? 1 : 0);
  159. writeC(_isSummoned ? 2 : 0); // 0=teleported 1=default 2=summoned
  160. writeS(_name);
  161. writeS(_title);
  162. writeD(0x00); // Title color 0=client default
  163. writeD(0x00); //pvp flag
  164. writeD(0x00); // karma
  165. writeD(_npc.getAbnormalEffect()); // C2
  166. writeD(_clanId); //clan id
  167. writeD(_clanCrest); //crest id
  168. writeD(_allyId); // ally id
  169. writeD(_allyCrest); // all crest
  170. writeC(_npc.isFlying() ? 2 : 0); // C2
  171. writeC(0x00); // title color 0=client
  172. writeF(_collisionRadius);
  173. writeF(_collisionHeight);
  174. writeD(_enchantEffect); // C4
  175. writeD(_npc.isFlying() ? 1 : 0); // C6
  176. writeD(0x00);
  177. writeD(_npc.getColorEffect());// CT1.5 Pet form and skills, Color effect
  178. writeC(_npc.isHideName() ? 0x00 : 0x01);
  179. writeC(_npc.isHideName() ? 0x00 : 0x01);
  180. writeD(_npc.getSpecialEffect());
  181. writeD(_displayEffect);
  182. }
  183. }
  184. public static class TrapInfo extends AbstractNpcInfo
  185. {
  186. private L2Trap _trap;
  187. public TrapInfo(L2Trap cha, L2Character attacker)
  188. {
  189. super(cha);
  190. _trap = cha;
  191. _idTemplate = cha.getTemplate().idTemplate;
  192. _isAttackable = cha.isAutoAttackable(attacker);
  193. _rhand = 0;
  194. _lhand = 0;
  195. _collisionHeight = _trap.getTemplate().fCollisionHeight;
  196. _collisionRadius = _trap.getTemplate().fCollisionRadius;
  197. if (cha.getTemplate().serverSideName)
  198. _name = cha.getName();
  199. _title = cha.getOwner() != null ? cha.getOwner().getName() : "";
  200. _runSpd = _trap.getRunSpeed();
  201. _walkSpd = _trap.getWalkSpeed();
  202. }
  203. @Override
  204. protected void writeImpl()
  205. {
  206. writeC(0x0c);
  207. writeD(_trap.getObjectId());
  208. writeD(_idTemplate + 1000000); // npctype id
  209. writeD(_isAttackable ? 1 : 0);
  210. writeD(_x);
  211. writeD(_y);
  212. writeD(_z);
  213. writeD(_heading);
  214. writeD(0x00);
  215. writeD(_mAtkSpd);
  216. writeD(_pAtkSpd);
  217. writeD(_runSpd);
  218. writeD(_walkSpd);
  219. writeD(_runSpd); // swim run speed
  220. writeD(_walkSpd); // swim walk speed
  221. writeD(_runSpd); // fly run speed
  222. writeD(_walkSpd); // fly walk speed
  223. writeD(_runSpd); // fly run speed
  224. writeD(_walkSpd); // fly walk speed
  225. writeF(_trap.getMovementSpeedMultiplier());
  226. writeF(_trap.getAttackSpeedMultiplier());
  227. writeF(_collisionRadius);
  228. writeF(_collisionHeight);
  229. writeD(_rhand); // right hand weapon
  230. writeD(_chest);
  231. writeD(_lhand); // left hand weapon
  232. writeC(1); // name above char 1=true ... ??
  233. writeC(1);
  234. writeC(_trap.isInCombat() ? 1 : 0);
  235. writeC(_trap.isAlikeDead() ? 1 : 0);
  236. writeC(_isSummoned ? 2 : 0); // 0=teleported 1=default 2=summoned
  237. writeS(_name);
  238. writeS(_title);
  239. writeD(0x00); // title color 0 = client default
  240. writeD(_trap.getPvpFlag());
  241. writeD(_trap.getKarma());
  242. writeD(_trap.getAbnormalEffect()); // C2
  243. writeD(0x00); //clan id
  244. writeD(0x00); //crest id
  245. writeD(0000); // C2
  246. writeD(0000); // C2
  247. writeC(0000); // C2
  248. writeC(0x00); // Title color 0=client default
  249. writeF(_collisionRadius);
  250. writeF(_collisionHeight);
  251. writeD(0x00); // C4
  252. writeD(0x00); // C6
  253. writeD(0x00);
  254. writeD(0);//CT1.5 Pet form and skills
  255. writeC(0x01);
  256. writeC(0x01);
  257. writeD(0x00);
  258. }
  259. }
  260. /**
  261. * Packet for summons
  262. */
  263. public static class SummonInfo extends AbstractNpcInfo
  264. {
  265. private L2Summon _summon;
  266. private int _form = 0;
  267. private int _val = 0;
  268. public SummonInfo(L2Summon cha, L2Character attacker, int val)
  269. {
  270. super(cha);
  271. _summon = cha;
  272. _val = val;
  273. if (_summon.isShowSummonAnimation())
  274. _val = 2; //override for spawn
  275. int npcId = cha.getTemplate().npcId;
  276. if (npcId == 16041 || npcId == 16042)
  277. {
  278. if (cha.getLevel() > 84)
  279. _form = 3;
  280. else if (cha.getLevel() > 79)
  281. _form = 2;
  282. else if (cha.getLevel() > 74)
  283. _form = 1;
  284. }
  285. else if (npcId == 16025 || npcId == 16037)
  286. {
  287. if (cha.getLevel() > 69)
  288. _form = 3;
  289. else if (cha.getLevel() > 64)
  290. _form = 2;
  291. else if (cha.getLevel() > 59)
  292. _form = 1;
  293. }
  294. // fields not set on AbstractNpcInfo
  295. _isAttackable = cha.isAutoAttackable(attacker);
  296. _rhand = cha.getWeapon();
  297. _lhand = 0;
  298. _chest = cha.getArmor();
  299. _enchantEffect = cha.getTemplate().enchantEffect;
  300. _name = cha.getName();
  301. _title = cha.getOwner() != null ? ((!cha.getOwner().isOnline()) ? "" : cha.getOwner().getName()) : ""; // when owner online, summon will show in title owner name
  302. _idTemplate = cha.getTemplate().idTemplate;
  303. _collisionHeight = cha.getTemplate().fCollisionHeight;
  304. _collisionRadius = cha.getTemplate().fCollisionRadius;
  305. _invisible = cha.getOwner() != null ? cha.getOwner().getAppearance().getInvisible() : false;
  306. }
  307. @Override
  308. protected void writeImpl()
  309. {
  310. boolean gmSeeInvis = false;
  311. if (_invisible)
  312. {
  313. L2PcInstance tmp = getClient().getActiveChar();
  314. if (tmp != null && tmp.isGM())
  315. gmSeeInvis = true;
  316. }
  317. writeC(0x0c);
  318. writeD(_summon.getObjectId());
  319. writeD(_idTemplate + 1000000); // npctype id
  320. writeD(_isAttackable ? 1 : 0);
  321. writeD(_x);
  322. writeD(_y);
  323. writeD(_z);
  324. writeD(_heading);
  325. writeD(0x00);
  326. writeD(_mAtkSpd);
  327. writeD(_pAtkSpd);
  328. writeD(_runSpd);
  329. writeD(_walkSpd);
  330. writeD(_runSpd); // swim run speed
  331. writeD(_walkSpd); // swim walk speed
  332. writeD(_runSpd); // fly run speed
  333. writeD(_walkSpd); // fly walk speed
  334. writeD(_runSpd); // fly run speed
  335. writeD(_walkSpd); // fly walk speed
  336. writeF(_summon.getMovementSpeedMultiplier());
  337. writeF(_summon.getAttackSpeedMultiplier());
  338. writeF(_collisionRadius);
  339. writeF(_collisionHeight);
  340. writeD(_rhand); // right hand weapon
  341. writeD(_chest);
  342. writeD(_lhand); // left hand weapon
  343. writeC(1); // name above char 1=true ... ??
  344. writeC(1); // always running 1=running 0=walking
  345. writeC(_summon.isInCombat() ? 1 : 0);
  346. writeC(_summon.isAlikeDead() ? 1 : 0);
  347. writeC(_val); // 0=teleported 1=default 2=summoned
  348. writeS(_name);
  349. writeS(_title);
  350. writeD(0x01);// Title color 0=client default
  351. writeD(_summon.getPvpFlag());
  352. writeD(_summon.getKarma());
  353. writeD(gmSeeInvis ? _summon.getAbnormalEffect() | AbnormalEffect.STEALTH.getMask() : _summon.getAbnormalEffect());
  354. writeD(0x00); //clan id
  355. writeD(0x00); //crest id
  356. writeD(0000); // C2
  357. writeD(0000); // C2
  358. writeC(0000); // C2
  359. writeC(_summon.getTeam());// Title color 0=client default
  360. writeF(_collisionRadius);
  361. writeF(_collisionHeight);
  362. writeD(_enchantEffect); // C4
  363. writeD(0x00); // C6
  364. writeD(0x00);
  365. writeD(_form); //CT1.5 Pet form and skills
  366. writeC(0x01);
  367. writeC(0x01);
  368. writeD(_summon.getSpecialEffect());
  369. }
  370. }
  371. }