L2Object.java 23 KB

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