AbstractNpcInfo.java 12 KB

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