L2Object.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. /*
  2. * Copyright (C) 2004-2013 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.model;
  20. import java.util.Map;
  21. import javolution.util.FastMap;
  22. import com.l2jserver.gameserver.handler.ActionHandler;
  23. import com.l2jserver.gameserver.handler.ActionShiftHandler;
  24. import com.l2jserver.gameserver.handler.IActionHandler;
  25. import com.l2jserver.gameserver.idfactory.IdFactory;
  26. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  27. import com.l2jserver.gameserver.model.actor.L2Character;
  28. import com.l2jserver.gameserver.model.actor.L2Npc;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  30. import com.l2jserver.gameserver.model.actor.knownlist.ObjectKnownList;
  31. import com.l2jserver.gameserver.model.actor.poly.ObjectPoly;
  32. import com.l2jserver.gameserver.model.actor.position.ObjectPosition;
  33. import com.l2jserver.gameserver.model.entity.Instance;
  34. import com.l2jserver.gameserver.model.interfaces.IIdentifiable;
  35. import com.l2jserver.gameserver.model.zone.ZoneId;
  36. import com.l2jserver.gameserver.network.SystemMessageId;
  37. import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
  38. import com.l2jserver.gameserver.network.serverpackets.ExSendUIEvent;
  39. import com.l2jserver.gameserver.network.serverpackets.L2GameServerPacket;
  40. /**
  41. * Mother class of all objects in the world which ones is it possible to interact (PC, NPC, Item...)<BR>
  42. * <BR>
  43. * L2Object :<BR>
  44. * <BR>
  45. * <li>L2Character</li> <li>L2ItemInstance</li>
  46. */
  47. public abstract class L2Object extends ObjectPosition implements IIdentifiable
  48. {
  49. private boolean _isVisible; // Object visibility
  50. private ObjectKnownList _knownList;
  51. private String _name;
  52. private int _objectId; // Object identifier
  53. private ObjectPoly _poly;
  54. private InstanceType _instanceType = null;
  55. private volatile Map<String, Object> _scripts;
  56. public L2Object(int objectId)
  57. {
  58. super();
  59. setInstanceType(InstanceType.L2Object);
  60. _objectId = objectId;
  61. initKnownList();
  62. setActiveObject(this);
  63. }
  64. public static enum InstanceType
  65. {
  66. L2Object(null),
  67. L2ItemInstance(L2Object),
  68. L2Character(L2Object),
  69. L2Npc(L2Character),
  70. L2Playable(L2Character),
  71. L2Summon(L2Playable),
  72. L2Decoy(L2Character),
  73. L2PcInstance(L2Playable),
  74. L2NpcInstance(L2Npc),
  75. L2MerchantInstance(L2NpcInstance),
  76. L2WarehouseInstance(L2NpcInstance),
  77. L2StaticObjectInstance(L2Character),
  78. L2DoorInstance(L2Character),
  79. L2TerrainObjectInstance(L2Npc),
  80. L2EffectPointInstance(L2Npc),
  81. // Summons, Pets, Decoys and Traps
  82. L2ServitorInstance(L2Summon),
  83. L2SiegeSummonInstance(L2ServitorInstance),
  84. L2MerchantSummonInstance(L2ServitorInstance),
  85. L2PetInstance(L2Summon),
  86. L2BabyPetInstance(L2PetInstance),
  87. L2DecoyInstance(L2Decoy),
  88. L2TrapInstance(L2Npc),
  89. // Attackable
  90. L2Attackable(L2Npc),
  91. L2GuardInstance(L2Attackable),
  92. L2QuestGuardInstance(L2GuardInstance),
  93. L2MonsterInstance(L2Attackable),
  94. L2ChestInstance(L2MonsterInstance),
  95. L2ControllableMobInstance(L2MonsterInstance),
  96. L2FeedableBeastInstance(L2MonsterInstance),
  97. L2TamedBeastInstance(L2FeedableBeastInstance),
  98. L2FriendlyMobInstance(L2Attackable),
  99. L2RiftInvaderInstance(L2MonsterInstance),
  100. L2RaidBossInstance(L2MonsterInstance),
  101. L2GrandBossInstance(L2RaidBossInstance),
  102. // FlyMobs
  103. L2FlyNpcInstance(L2NpcInstance),
  104. L2FlyMonsterInstance(L2MonsterInstance),
  105. L2FlyRaidBossInstance(L2RaidBossInstance),
  106. L2FlyTerrainObjectInstance(L2Npc),
  107. // Sepulchers
  108. L2SepulcherNpcInstance(L2NpcInstance),
  109. L2SepulcherMonsterInstance(L2MonsterInstance),
  110. // Festival
  111. L2FestivalGiudeInstance(L2Npc),
  112. L2FestivalMonsterInstance(L2MonsterInstance),
  113. // Vehicles
  114. L2Vehicle(L2Character),
  115. L2BoatInstance(L2Vehicle),
  116. L2AirShipInstance(L2Vehicle),
  117. L2ControllableAirShipInstance(L2AirShipInstance),
  118. // Siege
  119. L2DefenderInstance(L2Attackable),
  120. L2ArtefactInstance(L2NpcInstance),
  121. L2ControlTowerInstance(L2Npc),
  122. L2FlameTowerInstance(L2Npc),
  123. L2SiegeFlagInstance(L2Npc),
  124. L2SiegeNpcInstance(L2Npc),
  125. // Fort Siege
  126. L2FortBallistaInstance(L2Npc),
  127. L2FortCommanderInstance(L2DefenderInstance),
  128. // Castle NPCs
  129. L2CastleMagicianInstance(L2NpcInstance),
  130. // Fort NPCs
  131. L2FortEnvoyInstance(L2Npc),
  132. L2FortLogisticsInstance(L2MerchantInstance),
  133. L2FortManagerInstance(L2MerchantInstance),
  134. L2FortSiegeNpcInstance(L2Npc),
  135. L2FortSupportCaptainInstance(L2MerchantInstance),
  136. // Seven Signs
  137. L2SignsPriestInstance(L2Npc),
  138. L2DawnPriestInstance(L2SignsPriestInstance),
  139. L2DuskPriestInstance(L2SignsPriestInstance),
  140. L2DungeonGatekeeperInstance(L2Npc),
  141. // City NPCs
  142. L2AdventurerInstance(L2NpcInstance),
  143. L2AuctioneerInstance(L2Npc),
  144. L2ClanHallManagerInstance(L2MerchantInstance),
  145. L2FishermanInstance(L2MerchantInstance),
  146. L2ManorManagerInstance(L2MerchantInstance),
  147. L2ObservationInstance(L2Npc),
  148. L2OlympiadManagerInstance(L2Npc),
  149. L2PetManagerInstance(L2MerchantInstance),
  150. L2RaceManagerInstance(L2Npc),
  151. L2TeleporterInstance(L2Npc),
  152. L2TrainerInstance(L2NpcInstance),
  153. L2VillageMasterInstance(L2NpcInstance),
  154. // Doormens
  155. L2DoormenInstance(L2NpcInstance),
  156. L2CastleDoormenInstance(L2DoormenInstance),
  157. L2FortDoormenInstance(L2DoormenInstance),
  158. L2ClanHallDoormenInstance(L2DoormenInstance),
  159. // Custom
  160. L2ClassMasterInstance(L2NpcInstance),
  161. L2NpcBufferInstance(L2Npc),
  162. L2TvTEventNpcInstance(L2Npc),
  163. L2WeddingManagerInstance(L2Npc),
  164. L2EventMobInstance(L2Npc);
  165. private final InstanceType _parent;
  166. private final long _typeL;
  167. private final long _typeH;
  168. private final long _maskL;
  169. private final long _maskH;
  170. private InstanceType(InstanceType parent)
  171. {
  172. _parent = parent;
  173. final int high = ordinal() - (Long.SIZE - 1);
  174. if (high < 0)
  175. {
  176. _typeL = 1L << ordinal();
  177. _typeH = 0;
  178. }
  179. else
  180. {
  181. _typeL = 0;
  182. _typeH = 1L << high;
  183. }
  184. if ((_typeL < 0) || (_typeH < 0))
  185. {
  186. throw new Error("Too many instance types, failed to load " + name());
  187. }
  188. if (parent != null)
  189. {
  190. _maskL = _typeL | parent._maskL;
  191. _maskH = _typeH | parent._maskH;
  192. }
  193. else
  194. {
  195. _maskL = _typeL;
  196. _maskH = _typeH;
  197. }
  198. }
  199. public final InstanceType getParent()
  200. {
  201. return _parent;
  202. }
  203. public final boolean isType(InstanceType it)
  204. {
  205. return ((_maskL & it._typeL) > 0) || ((_maskH & it._typeH) > 0);
  206. }
  207. public final boolean isTypes(InstanceType... it)
  208. {
  209. for (InstanceType i : it)
  210. {
  211. if (isType(i))
  212. {
  213. return true;
  214. }
  215. }
  216. return false;
  217. }
  218. }
  219. protected final void setInstanceType(InstanceType i)
  220. {
  221. _instanceType = i;
  222. }
  223. public final InstanceType getInstanceType()
  224. {
  225. return _instanceType;
  226. }
  227. public final boolean isInstanceType(InstanceType i)
  228. {
  229. return _instanceType.isType(i);
  230. }
  231. public final boolean isInstanceTypes(InstanceType... i)
  232. {
  233. return _instanceType.isTypes(i);
  234. }
  235. public final void onAction(L2PcInstance player)
  236. {
  237. onAction(player, true);
  238. }
  239. public void onAction(L2PcInstance player, boolean interact)
  240. {
  241. IActionHandler handler = ActionHandler.getInstance().getHandler(getInstanceType());
  242. if (handler != null)
  243. {
  244. handler.action(player, this, interact);
  245. }
  246. player.sendPacket(ActionFailed.STATIC_PACKET);
  247. }
  248. public void onActionShift(L2PcInstance player)
  249. {
  250. IActionHandler handler = ActionShiftHandler.getInstance().getHandler(getInstanceType());
  251. if (handler != null)
  252. {
  253. handler.action(player, this, true);
  254. }
  255. player.sendPacket(ActionFailed.STATIC_PACKET);
  256. }
  257. public void onForcedAttack(L2PcInstance player)
  258. {
  259. player.sendPacket(ActionFailed.STATIC_PACKET);
  260. }
  261. /**
  262. * Do Nothing.<BR>
  263. * <BR>
  264. * <B><U> Overridden in </U> :</B><BR>
  265. * <BR>
  266. * <li>L2GuardInstance : Set the home location of its L2GuardInstance</li> <li>L2Attackable : Reset the Spoiled flag</li><BR>
  267. * <BR>
  268. */
  269. public void onSpawn()
  270. {
  271. }
  272. /**
  273. * UnAfraid: TODO: Add listener here.
  274. * @param instanceId The id of the instance zone the object is in - id 0 is global
  275. */
  276. @Override
  277. public void setInstanceId(int instanceId)
  278. {
  279. if ((instanceId < 0) || (getInstanceId() == instanceId))
  280. {
  281. return;
  282. }
  283. Instance oldI = InstanceManager.getInstance().getInstance(getInstanceId());
  284. Instance newI = InstanceManager.getInstance().getInstance(instanceId);
  285. if (newI == null)
  286. {
  287. return;
  288. }
  289. if (isPlayer())
  290. {
  291. L2PcInstance player = getActingPlayer();
  292. if ((getInstanceId() > 0) && (oldI != null))
  293. {
  294. oldI.removePlayer(getObjectId());
  295. if (oldI.isShowTimer())
  296. {
  297. int startTime = (int) ((System.currentTimeMillis() - oldI.getInstanceStartTime()) / 1000);
  298. int endTime = (int) ((oldI.getInstanceEndTime() - oldI.getInstanceStartTime()) / 1000);
  299. if (oldI.isTimerIncrease())
  300. {
  301. sendPacket(new ExSendUIEvent(getActingPlayer(), true, true, startTime, endTime, oldI.getTimerText()));
  302. }
  303. else
  304. {
  305. sendPacket(new ExSendUIEvent(getActingPlayer(), true, false, endTime - startTime, 0, oldI.getTimerText()));
  306. }
  307. }
  308. }
  309. if (instanceId > 0)
  310. {
  311. newI.addPlayer(getObjectId());
  312. if (newI.isShowTimer())
  313. {
  314. int startTime = (int) ((System.currentTimeMillis() - newI.getInstanceStartTime()) / 1000);
  315. int endTime = (int) ((newI.getInstanceEndTime() - newI.getInstanceStartTime()) / 1000);
  316. if (newI.isTimerIncrease())
  317. {
  318. sendPacket(new ExSendUIEvent(getActingPlayer(), false, true, startTime, endTime, newI.getTimerText()));
  319. }
  320. else
  321. {
  322. sendPacket(new ExSendUIEvent(getActingPlayer(), false, false, endTime - startTime, 0, newI.getTimerText()));
  323. }
  324. }
  325. }
  326. if (player.hasSummon())
  327. {
  328. player.getSummon().setInstanceId(instanceId);
  329. }
  330. }
  331. else if (isNpc())
  332. {
  333. L2Npc npc = (L2Npc) this;
  334. if ((getInstanceId() > 0) && (oldI != null))
  335. {
  336. oldI.removeNpc(npc);
  337. }
  338. if (instanceId > 0)
  339. {
  340. newI.addNpc(npc);
  341. }
  342. }
  343. super.setInstanceId(instanceId);
  344. // If we change it for visible objects, me must clear & revalidates knownlists
  345. if (_isVisible && (_knownList != null))
  346. {
  347. if (isPlayer())
  348. {
  349. // We don't want some ugly looking disappear/appear effects, so don't update
  350. // the knownlist here, but players usually enter instancezones through teleporting
  351. // and the teleport will do the revalidation for us.
  352. }
  353. else
  354. {
  355. decayMe();
  356. spawnMe();
  357. }
  358. }
  359. }
  360. /**
  361. * Remove a L2Object from the world.<BR>
  362. * <BR>
  363. * <B><U> Actions</U> :</B><BR>
  364. * <BR>
  365. * <li>Remove the L2Object from the world</li><BR>
  366. * <BR>
  367. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  368. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR>
  369. * <BR>
  370. * <B><U> Assert </U> :</B><BR>
  371. * <BR>
  372. * <li>_worldRegion != null <I>(L2Object is visible at the beginning)</I></li><BR>
  373. * <BR>
  374. * <B><U> Example of use </U> :</B><BR>
  375. * <BR>
  376. * <li>Delete NPC/PC or Unsummon</li><BR>
  377. * <BR>
  378. */
  379. public void decayMe()
  380. {
  381. assert getWorldRegion() != null;
  382. L2WorldRegion reg = getWorldRegion();
  383. synchronized (this)
  384. {
  385. _isVisible = false;
  386. setWorldRegion(null);
  387. }
  388. // this can synchronize on others instances, so it's out of
  389. // synchronized, to avoid deadlocks
  390. // Remove the L2Object from the world
  391. L2World.getInstance().removeVisibleObject(this, reg);
  392. L2World.getInstance().removeObject(this);
  393. }
  394. public void refreshID()
  395. {
  396. L2World.getInstance().removeObject(this);
  397. IdFactory.getInstance().releaseId(getObjectId());
  398. _objectId = IdFactory.getInstance().getNextId();
  399. }
  400. /**
  401. * Init the position of a L2Object spawn and add it in the world as a visible object.<BR>
  402. * <BR>
  403. * <B><U> Actions</U> :</B><BR>
  404. * <BR>
  405. * <li>Set the x,y,z position of the L2Object spawn and update its _worldregion</li> <li>Add the L2Object spawn in the _allobjects of L2World</li> <li>Add the L2Object spawn to _visibleObjects of its L2WorldRegion</li> <li>Add the L2Object spawn in the world as a <B>visible</B> object</li><BR>
  406. * <BR>
  407. * <B><U> Assert </U> :</B><BR>
  408. * <BR>
  409. * <li>_worldRegion == null <I>(L2Object is invisible at the beginning)</I></li><BR>
  410. * <BR>
  411. * <B><U> Example of use </U> :</B><BR>
  412. * <BR>
  413. * <li>Create Door</li> <li>Spawn : Monster, Minion, CTs, Summon...</li><BR>
  414. */
  415. public final void spawnMe()
  416. {
  417. assert (getWorldRegion() == null) && (getWorldPosition().getX() != 0) && (getWorldPosition().getY() != 0) && (getWorldPosition().getZ() != 0);
  418. synchronized (this)
  419. {
  420. // Set the x,y,z position of the L2Object spawn and update its _worldregion
  421. _isVisible = true;
  422. setWorldRegion(L2World.getInstance().getRegion(getWorldPosition()));
  423. // Add the L2Object spawn in the _allobjects of L2World
  424. L2World.getInstance().storeObject(this);
  425. // Add the L2Object spawn to _visibleObjects and if necessary to _allplayers of its L2WorldRegion
  426. getWorldRegion().addVisibleObject(this);
  427. }
  428. // this can synchronize on others instances, so it's out of
  429. // synchronized, to avoid deadlocks
  430. // Add the L2Object spawn in the world as a visible object
  431. L2World.getInstance().addVisibleObject(this, getWorldRegion());
  432. onSpawn();
  433. }
  434. public final void spawnMe(int x, int y, int z)
  435. {
  436. assert getWorldRegion() == null;
  437. synchronized (this)
  438. {
  439. // Set the x,y,z position of the L2Object spawn and update its _worldregion
  440. _isVisible = true;
  441. if (x > L2World.MAP_MAX_X)
  442. {
  443. x = L2World.MAP_MAX_X - 5000;
  444. }
  445. if (x < L2World.MAP_MIN_X)
  446. {
  447. x = L2World.MAP_MIN_X + 5000;
  448. }
  449. if (y > L2World.MAP_MAX_Y)
  450. {
  451. y = L2World.MAP_MAX_Y - 5000;
  452. }
  453. if (y < L2World.MAP_MIN_Y)
  454. {
  455. y = L2World.MAP_MIN_Y + 5000;
  456. }
  457. setXYZ(x, y, z);
  458. setWorldRegion(L2World.getInstance().getRegion(getWorldPosition()));
  459. // Add the L2Object spawn in the _allobjects of L2World
  460. }
  461. L2World.getInstance().storeObject(this);
  462. // these can synchronize on others instances, so they're out of
  463. // synchronized, to avoid deadlocks
  464. // Add the L2Object spawn to _visibleObjects and if necessary to _allplayers of its L2WorldRegion
  465. getWorldRegion().addVisibleObject(this);
  466. // Add the L2Object spawn in the world as a visible object
  467. L2World.getInstance().addVisibleObject(this, getWorldRegion());
  468. onSpawn();
  469. }
  470. public void toggleVisible()
  471. {
  472. if (isVisible())
  473. {
  474. decayMe();
  475. }
  476. else
  477. {
  478. spawnMe();
  479. }
  480. }
  481. public boolean isAttackable()
  482. {
  483. return false;
  484. }
  485. public abstract boolean isAutoAttackable(L2Character attacker);
  486. /**
  487. * Return the visibility state of the L2Object. <B><U> Concept</U> :</B><BR>
  488. * <BR>
  489. * A L2Object is visible if <B>__IsVisible</B>=true and <B>_worldregion</B>!=null <BR>
  490. * <BR>
  491. * @return
  492. */
  493. public final boolean isVisible()
  494. {
  495. return getWorldRegion() != null;
  496. }
  497. public final void setIsVisible(boolean value)
  498. {
  499. _isVisible = value;
  500. if (!_isVisible)
  501. {
  502. setWorldRegion(null);
  503. }
  504. }
  505. public ObjectKnownList getKnownList()
  506. {
  507. return _knownList;
  508. }
  509. /**
  510. * Initializes the KnownList of the L2Object, is overwritten in classes that require a different knownlist Type. Removes the need for instanceof checks.
  511. */
  512. public void initKnownList()
  513. {
  514. _knownList = new ObjectKnownList(this);
  515. }
  516. public final void setKnownList(ObjectKnownList value)
  517. {
  518. _knownList = value;
  519. }
  520. public final String getName()
  521. {
  522. return _name;
  523. }
  524. public void setName(String value)
  525. {
  526. _name = value;
  527. }
  528. public final int getObjectId()
  529. {
  530. return _objectId;
  531. }
  532. public final ObjectPoly getPoly()
  533. {
  534. if (_poly == null)
  535. {
  536. _poly = new ObjectPoly(this);
  537. }
  538. return _poly;
  539. }
  540. public L2PcInstance getActingPlayer()
  541. {
  542. return null;
  543. }
  544. /**
  545. * Sends the Server->Client info packet for the object. <br>
  546. * Is Overridden in:
  547. * <ul>
  548. * <li>L2AirShipInstance</li>
  549. * <li>L2BoatInstance</li>
  550. * <li>L2DoorInstance</li>
  551. * <li>L2PcInstance</li>
  552. * <li>L2StaticObjectInstance</li>
  553. * <li>L2Decoy</li>
  554. * <li>L2Npc</li>
  555. * <li>L2Summon</li>
  556. * <li>L2Trap</li>
  557. * <li>L2ItemInstance</li>
  558. * </ul>
  559. * @param activeChar
  560. */
  561. public void sendInfo(L2PcInstance activeChar)
  562. {
  563. }
  564. /**
  565. * Not Implemented.<BR>
  566. * <BR>
  567. * <B><U> Overridden in </U> :</B><BR>
  568. * <BR>
  569. * <li>L2PcInstance</li><BR>
  570. * <BR>
  571. * @param mov
  572. */
  573. public void sendPacket(L2GameServerPacket mov)
  574. {
  575. // default implementation
  576. }
  577. /**
  578. * Not Implemented.<BR>
  579. * <BR>
  580. * <B><U> Overridden in </U> :</B><BR>
  581. * <BR>
  582. * <li>L2PcInstance</li><BR>
  583. * <BR>
  584. * @param id
  585. */
  586. public void sendPacket(SystemMessageId id)
  587. {
  588. // default implementation
  589. }
  590. /**
  591. * @return {@code true} if object is instance of L2PcInstance
  592. */
  593. public boolean isPlayer()
  594. {
  595. return false;
  596. }
  597. /**
  598. * @return {@code true} if object is instance of L2Playable
  599. */
  600. public boolean isPlayable()
  601. {
  602. return false;
  603. }
  604. /**
  605. * @return {@code true} if object is instance of L2Summon
  606. */
  607. public boolean isSummon()
  608. {
  609. return false;
  610. }
  611. /**
  612. * @return {@code true} if object is instance of L2PetInstance
  613. */
  614. public boolean isPet()
  615. {
  616. return false;
  617. }
  618. /**
  619. * @return {@code true} if object is instance of L2ServitorInstance
  620. */
  621. public boolean isServitor()
  622. {
  623. return false;
  624. }
  625. /**
  626. * @return {@code true} if object is instance of L2Attackable
  627. */
  628. public boolean isCharacter()
  629. {
  630. return false;
  631. }
  632. /**
  633. * @return {@code true} if object is instance of L2DoorInstance
  634. */
  635. public boolean isDoor()
  636. {
  637. return false;
  638. }
  639. /**
  640. * @return {@code true} if object is instance of L2Npc
  641. */
  642. public boolean isNpc()
  643. {
  644. return false;
  645. }
  646. /**
  647. * @return {@code true} if object is instance of L2Attackable
  648. */
  649. public boolean isL2Attackable()
  650. {
  651. return false;
  652. }
  653. /**
  654. * @return {@code true} if object is instance of L2MonsterInstance
  655. */
  656. public boolean isMonster()
  657. {
  658. return false;
  659. }
  660. /**
  661. * @return {@code true} if object is instance of L2TrapInstance
  662. */
  663. public boolean isTrap()
  664. {
  665. return false;
  666. }
  667. /**
  668. * @return {@code true} if object is instance of L2ItemInstance
  669. */
  670. public boolean isItem()
  671. {
  672. return false;
  673. }
  674. /**
  675. * @return {@code true} if object Npc Walker or Vehicle
  676. */
  677. public boolean isWalker()
  678. {
  679. return false;
  680. }
  681. /**
  682. * @return {@code true} if object Can be targeted
  683. */
  684. public boolean isTargetable()
  685. {
  686. return true;
  687. }
  688. /**
  689. * Check if the object is in the given zone Id.
  690. * @param zone the zone Id to check
  691. * @return {@code true} if the object is in that zone Id
  692. */
  693. public boolean isInsideZone(ZoneId zone)
  694. {
  695. return false;
  696. }
  697. /**
  698. * Check if current object has charged shot.
  699. * @param type of the shot to be checked.
  700. * @return {@code true} if the object has charged shot
  701. */
  702. public boolean isChargedShot(ShotType type)
  703. {
  704. return false;
  705. }
  706. /**
  707. * Charging shot into the current object.
  708. * @param type of the shot to be charged.
  709. * @param charged
  710. */
  711. public void setChargedShot(ShotType type, boolean charged)
  712. {
  713. }
  714. /**
  715. * Try to recharge a shot.
  716. * @param physical skill are using Soul shots.
  717. * @param magical skill are using Spirit shots.
  718. */
  719. public void rechargeShots(boolean physical, boolean magical)
  720. {
  721. }
  722. /**
  723. * @param <T>
  724. * @param script
  725. * @return
  726. */
  727. public final <T> T addScript(T script)
  728. {
  729. if (_scripts == null)
  730. {
  731. // Double-checked locking
  732. synchronized (this)
  733. {
  734. if (_scripts == null)
  735. {
  736. _scripts = new FastMap<String, Object>().shared();
  737. }
  738. }
  739. }
  740. _scripts.put(script.getClass().getName(), script);
  741. return script;
  742. }
  743. /**
  744. * @param <T>
  745. * @param script
  746. * @return
  747. */
  748. @SuppressWarnings("unchecked")
  749. public final <T> T removeScript(Class<T> script)
  750. {
  751. if (_scripts == null)
  752. {
  753. return null;
  754. }
  755. return (T) _scripts.remove(script.getName());
  756. }
  757. /**
  758. * @param <T>
  759. * @param script
  760. * @return
  761. */
  762. @SuppressWarnings("unchecked")
  763. public final <T> T getScript(Class<T> script)
  764. {
  765. if (_scripts == null)
  766. {
  767. return null;
  768. }
  769. return (T) _scripts.get(script.getName());
  770. }
  771. public void removeStatusListener(L2Character object)
  772. {
  773. }
  774. @Override
  775. public String toString()
  776. {
  777. return (getClass().getSimpleName() + ":" + getName() + "[" + getObjectId() + "]");
  778. }
  779. }