L2Object.java 23 KB

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