L2Object.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package com.l2jserver.gameserver.model;
  16. import com.l2jserver.gameserver.handler.ActionHandler;
  17. import com.l2jserver.gameserver.handler.ActionShiftHandler;
  18. import com.l2jserver.gameserver.handler.IActionHandler;
  19. import com.l2jserver.gameserver.idfactory.IdFactory;
  20. import com.l2jserver.gameserver.instancemanager.InstanceManager;
  21. import com.l2jserver.gameserver.model.actor.L2Attackable;
  22. import com.l2jserver.gameserver.model.actor.L2Character;
  23. import com.l2jserver.gameserver.model.actor.L2Npc;
  24. import com.l2jserver.gameserver.model.actor.L2Playable;
  25. import com.l2jserver.gameserver.model.actor.L2Summon;
  26. import com.l2jserver.gameserver.model.actor.instance.L2DoorInstance;
  27. import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
  28. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  29. import com.l2jserver.gameserver.model.actor.instance.L2PetInstance;
  30. import com.l2jserver.gameserver.model.actor.instance.L2TrapInstance;
  31. import com.l2jserver.gameserver.model.actor.knownlist.ObjectKnownList;
  32. import com.l2jserver.gameserver.model.actor.poly.ObjectPoly;
  33. import com.l2jserver.gameserver.model.actor.position.ObjectPosition;
  34. import com.l2jserver.gameserver.model.entity.Instance;
  35. import com.l2jserver.gameserver.model.items.instance.L2ItemInstance;
  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
  42. * to interact (PC, NPC, Item...)<BR><BR>
  43. *
  44. * L2Object :<BR><BR>
  45. * <li>L2Character</li>
  46. * <li>L2ItemInstance</li>
  47. */
  48. public abstract class L2Object
  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. public L2Object(int objectId)
  59. {
  60. setInstanceType(InstanceType.L2Object);
  61. _objectId = objectId;
  62. initKnownList();
  63. initPosition();
  64. }
  65. public static enum InstanceType
  66. {
  67. L2Object(null),
  68. L2ItemInstance(L2Object),
  69. L2Character(L2Object),
  70. L2Npc(L2Character),
  71. L2Playable(L2Character),
  72. L2Summon(L2Playable),
  73. L2Decoy(L2Character),
  74. L2Trap(L2Character),
  75. L2PcInstance(L2Playable),
  76. L2NpcInstance(L2Npc),
  77. L2MerchantInstance(L2NpcInstance),
  78. L2WarehouseInstance(L2NpcInstance),
  79. L2StaticObjectInstance(L2Character),
  80. L2DoorInstance(L2Character),
  81. L2NpcWalkerInstance(L2Npc),
  82. L2TerrainObjectInstance(L2Npc),
  83. L2EffectPointInstance(L2Npc),
  84. // Summons, Pets, Decoys and Traps
  85. L2ServitorInstance(L2Summon),
  86. L2SiegeSummonInstance(L2ServitorInstance),
  87. L2MerchantSummonInstance(L2ServitorInstance),
  88. L2PetInstance(L2Summon),
  89. L2BabyPetInstance(L2PetInstance),
  90. L2DecoyInstance(L2Decoy),
  91. L2TrapInstance(L2Trap),
  92. // Attackable
  93. L2Attackable(L2Npc),
  94. L2GuardInstance(L2Attackable),
  95. L2QuestGuardInstance(L2GuardInstance),
  96. L2MonsterInstance(L2Attackable),
  97. L2ChestInstance(L2MonsterInstance),
  98. L2ControllableMobInstance(L2MonsterInstance),
  99. L2FeedableBeastInstance(L2MonsterInstance),
  100. L2TamedBeastInstance(L2FeedableBeastInstance),
  101. L2FriendlyMobInstance(L2Attackable),
  102. L2PenaltyMonsterInstance(L2MonsterInstance),
  103. L2RiftInvaderInstance(L2MonsterInstance),
  104. L2RaidBossInstance(L2MonsterInstance),
  105. L2GrandBossInstance(L2RaidBossInstance),
  106. // FlyMobs
  107. L2FlyNpcInstance(L2NpcInstance),
  108. L2FlyMonsterInstance(L2MonsterInstance),
  109. L2FlyRaidBossInstance(L2RaidBossInstance),
  110. L2FlyTerrainObjectInstance(L2Npc),
  111. // Sepulchers
  112. L2SepulcherNpcInstance(L2NpcInstance),
  113. L2SepulcherMonsterInstance(L2MonsterInstance),
  114. // Festival
  115. L2FestivalGiudeInstance(L2Npc),
  116. L2FestivalMonsterInstance(L2MonsterInstance),
  117. // Vehicles
  118. L2Vehicle(L2Character),
  119. L2BoatInstance(L2Vehicle),
  120. L2AirShipInstance(L2Vehicle),
  121. L2ControllableAirShipInstance(L2AirShipInstance),
  122. // Siege
  123. L2DefenderInstance(L2Attackable),
  124. L2ArtefactInstance(L2NpcInstance),
  125. L2ControlTowerInstance(L2Npc),
  126. L2FlameTowerInstance(L2Npc),
  127. L2SiegeFlagInstance(L2Npc),
  128. L2SiegeNpcInstance(L2Npc),
  129. // Fort Siege
  130. L2FortBallistaInstance(L2Npc),
  131. L2FortCommanderInstance(L2DefenderInstance),
  132. // Castle NPCs
  133. L2CastleBlacksmithInstance(L2NpcInstance),
  134. L2CastleChamberlainInstance(L2MerchantInstance),
  135. L2CastleMagicianInstance(L2NpcInstance),
  136. L2CastleTeleporterInstance(L2Npc),
  137. L2CastleWarehouseInstance(L2WarehouseInstance),
  138. L2MercManagerInstance(L2MerchantInstance),
  139. // Fort NPCs
  140. L2FortEnvoyInstance(L2Npc),
  141. L2FortLogisticsInstance(L2MerchantInstance),
  142. L2FortManagerInstance(L2MerchantInstance),
  143. L2FortSiegeNpcInstance(L2NpcWalkerInstance),
  144. L2FortSupportCaptainInstance(L2MerchantInstance),
  145. // Seven Signs
  146. L2CabaleBufferInstance(L2Npc),
  147. L2SignsPriestInstance(L2Npc),
  148. L2DawnPriestInstance(L2SignsPriestInstance),
  149. L2DuskPriestInstance(L2SignsPriestInstance),
  150. L2DungeonGatekeeperInstance(L2Npc),
  151. // City NPCs
  152. L2AdventurerInstance(L2NpcInstance),
  153. L2AuctioneerInstance(L2Npc),
  154. L2ClanHallManagerInstance(L2MerchantInstance),
  155. L2ClanTraderInstance(L2Npc),
  156. L2FameManagerInstance(L2Npc),
  157. L2FishermanInstance(L2MerchantInstance),
  158. L2ManorManagerInstance(L2MerchantInstance),
  159. L2MercenaryManagerInstance(L2Npc),
  160. L2ObservationInstance(L2Npc),
  161. L2OlympiadManagerInstance(L2Npc),
  162. L2PetManagerInstance(L2MerchantInstance),
  163. L2RaceManagerInstance(L2Npc),
  164. L2SymbolMakerInstance(L2Npc),
  165. L2TeleporterInstance(L2Npc),
  166. L2TotemInstance(L2NpcInstance),
  167. L2TownPetInstance(L2Npc),
  168. L2TrainerInstance(L2NpcInstance),
  169. L2TrainerHealersInstance(L2TrainerInstance),
  170. L2TransformManagerInstance(L2MerchantInstance),
  171. L2VillageMasterInstance(L2NpcInstance),
  172. L2WyvernManagerInstance(L2NpcInstance),
  173. L2XmassTreeInstance(L2NpcInstance),
  174. // Doormens
  175. L2DoormenInstance(L2NpcInstance),
  176. L2CastleDoormenInstance(L2DoormenInstance),
  177. L2FortDoormenInstance(L2DoormenInstance),
  178. L2ClanHallDoormenInstance(L2DoormenInstance),
  179. // Custom
  180. L2ClassMasterInstance(L2NpcInstance),
  181. L2NpcBufferInstance(L2Npc),
  182. L2TvTEventNpcInstance(L2Npc),
  183. L2WeddingManagerInstance(L2Npc),
  184. L2EventMobInstance(L2Npc),
  185. L2BirthdayCakeInstance(L2Npc);
  186. private final InstanceType _parent;
  187. private final long _typeL;
  188. private final long _typeH;
  189. private final long _maskL;
  190. private final long _maskH;
  191. private InstanceType(InstanceType parent)
  192. {
  193. _parent = parent;
  194. final int high = this.ordinal() - (Long.SIZE - 1);
  195. if (high < 0)
  196. {
  197. _typeL = 1L << this.ordinal();
  198. _typeH = 0;
  199. }
  200. else
  201. {
  202. _typeL = 0;
  203. _typeH = 1L << high;
  204. }
  205. if (_typeL < 0 || _typeH < 0)
  206. throw new Error("Too many instance types, failed to load " + this.name());
  207. if (parent != null)
  208. {
  209. _maskL = _typeL | parent._maskL;
  210. _maskH = _typeH | parent._maskH;
  211. }
  212. else
  213. {
  214. _maskL = _typeL;
  215. _maskH = _typeH;
  216. }
  217. }
  218. public final InstanceType getParent()
  219. {
  220. return _parent;
  221. }
  222. public final boolean isType(InstanceType it)
  223. {
  224. return (_maskL & it._typeL) > 0 || (_maskH & it._typeH) > 0;
  225. }
  226. public final boolean isTypes(InstanceType... it)
  227. {
  228. for (InstanceType i : it)
  229. {
  230. if (isType(i))
  231. return true;
  232. }
  233. return false;
  234. }
  235. }
  236. protected final void setInstanceType(InstanceType i)
  237. {
  238. _instanceType = i;
  239. }
  240. public final InstanceType getInstanceType()
  241. {
  242. return _instanceType;
  243. }
  244. public final boolean isInstanceType(InstanceType i)
  245. {
  246. return _instanceType.isType(i);
  247. }
  248. public final boolean isInstanceTypes(InstanceType... i)
  249. {
  250. return _instanceType.isTypes(i);
  251. }
  252. public final void onAction(L2PcInstance player)
  253. {
  254. onAction(player, true);
  255. }
  256. public void onAction(L2PcInstance player, boolean interact)
  257. {
  258. IActionHandler handler = ActionHandler.getInstance().getHandler(getInstanceType());
  259. if (handler != null)
  260. handler.action(player, this, interact);
  261. player.sendPacket(ActionFailed.STATIC_PACKET);
  262. }
  263. public void onActionShift(L2PcInstance player)
  264. {
  265. IActionHandler handler = ActionShiftHandler.getInstance().getHandler(getInstanceType());
  266. if (handler != null)
  267. handler.action(player, this, true);
  268. player.sendPacket(ActionFailed.STATIC_PACKET);
  269. }
  270. public void onForcedAttack(L2PcInstance player)
  271. {
  272. player.sendPacket(ActionFailed.STATIC_PACKET);
  273. }
  274. /**
  275. * Do Nothing.<BR><BR>
  276. *
  277. * <B><U> Overridden in </U> :</B><BR><BR>
  278. * <li> L2GuardInstance : Set the home location of its L2GuardInstance </li>
  279. * <li> L2Attackable : Reset the Spoiled flag </li><BR><BR>
  280. *
  281. */
  282. public void onSpawn()
  283. {
  284. }
  285. // Position - Should remove to fully move to L2ObjectPosition
  286. public final void setXYZ(int x, int y, int z)
  287. {
  288. getPosition().setXYZ(x, y, z);
  289. }
  290. public final void setXYZInvisible(int x, int y, int z)
  291. {
  292. getPosition().setXYZInvisible(x, y, z);
  293. }
  294. public final int getX()
  295. {
  296. assert getPosition().getWorldRegion() != null || _isVisible;
  297. return getPosition().getX();
  298. }
  299. /**
  300. * @return The id of the instance zone the object is in - id 0 is global
  301. * since everything like dropped items, mobs, players can be in a instanciated area, it must be in l2object
  302. */
  303. public int getInstanceId()
  304. {
  305. return _instanceId;
  306. }
  307. /**
  308. * @param instanceId The id of the instance zone the object is in - id 0 is global
  309. */
  310. public void setInstanceId(int instanceId)
  311. {
  312. if (_instanceId == instanceId)
  313. return;
  314. Instance oldI = InstanceManager.getInstance().getInstance(_instanceId);
  315. Instance newI = InstanceManager.getInstance().getInstance(instanceId);
  316. if (newI == null)
  317. return;
  318. if (this instanceof L2PcInstance)
  319. {
  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. sendPacket(new ExSendUIEvent(this, true, true, startTime, endTime, oldI.getTimerText()));
  329. else
  330. sendPacket(new ExSendUIEvent(this, true, false, endTime - startTime, 0, oldI.getTimerText()));
  331. }
  332. }
  333. if (instanceId > 0)
  334. {
  335. newI.addPlayer(getObjectId());
  336. if (newI.isShowTimer())
  337. {
  338. int startTime = (int) ((System.currentTimeMillis() - newI.getInstanceStartTime()) / 1000);
  339. int endTime = (int) ((newI.getInstanceEndTime() - newI.getInstanceStartTime()) / 1000);
  340. if (newI.isTimerIncrease())
  341. sendPacket(new ExSendUIEvent(this, false, true, startTime, endTime, newI.getTimerText()));
  342. else
  343. sendPacket(new ExSendUIEvent(this, false, false, endTime - startTime, 0, newI.getTimerText()));
  344. }
  345. }
  346. if (((L2PcInstance)this).getPet() != null)
  347. ((L2PcInstance)this).getPet().setInstanceId(instanceId);
  348. }
  349. else if (this instanceof L2Npc)
  350. {
  351. if (_instanceId > 0 && oldI != null)
  352. oldI.removeNpc(((L2Npc)this));
  353. if (instanceId > 0)
  354. newI.addNpc(((L2Npc)this));
  355. }
  356. _instanceId = instanceId;
  357. // If we change it for visible objects, me must clear & revalidates knownlists
  358. if (_isVisible && _knownList != null)
  359. {
  360. if (this instanceof L2PcInstance)
  361. {
  362. // We don't want some ugly looking disappear/appear effects, so don't update
  363. // the knownlist here, but players usually enter instancezones through teleporting
  364. // and the teleport will do the revalidation for us.
  365. }
  366. else
  367. {
  368. decayMe();
  369. spawnMe();
  370. }
  371. }
  372. }
  373. public final int getY()
  374. {
  375. assert getPosition().getWorldRegion() != null || _isVisible;
  376. return getPosition().getY();
  377. }
  378. public final int getZ()
  379. {
  380. assert getPosition().getWorldRegion() != null || _isVisible;
  381. return getPosition().getZ();
  382. }
  383. /**
  384. * Remove a L2Object from the world.<BR><BR>
  385. *
  386. * <B><U> Actions</U> :</B><BR><BR>
  387. * <li>Remove the L2Object from the world</li><BR><BR>
  388. *
  389. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T REMOVE the object from _allObjects of L2World </B></FONT><BR>
  390. * <FONT COLOR=#FF0000><B> <U>Caution</U> : This method DOESN'T SEND Server->Client packets to players</B></FONT><BR><BR>
  391. *
  392. * <B><U> Assert </U> :</B><BR><BR>
  393. * <li> _worldRegion != null <I>(L2Object is visible at the beginning)</I></li><BR><BR>
  394. *
  395. * <B><U> Example of use </U> :</B><BR><BR>
  396. * <li> Delete NPC/PC or Unsummon</li><BR><BR>
  397. *
  398. */
  399. public void decayMe()
  400. {
  401. assert getPosition().getWorldRegion() != null;
  402. L2WorldRegion reg = getPosition().getWorldRegion();
  403. synchronized (this)
  404. {
  405. _isVisible = false;
  406. getPosition().setWorldRegion(null);
  407. }
  408. // this can synchronize on others instances, so it's out of
  409. // synchronized, to avoid deadlocks
  410. // Remove the L2Object from the world
  411. L2World.getInstance().removeVisibleObject(this, reg);
  412. L2World.getInstance().removeObject(this);
  413. }
  414. public void refreshID()
  415. {
  416. L2World.getInstance().removeObject(this);
  417. IdFactory.getInstance().releaseId(getObjectId());
  418. _objectId = IdFactory.getInstance().getNextId();
  419. }
  420. /**
  421. * Init the position of a L2Object spawn and add it in the world as a visible object.<BR><BR>
  422. *
  423. * <B><U> Actions</U> :</B><BR><BR>
  424. * <li>Set the x,y,z position of the L2Object spawn and update its _worldregion </li>
  425. * <li>Add the L2Object spawn in the _allobjects of L2World </li>
  426. * <li>Add the L2Object spawn to _visibleObjects of its L2WorldRegion</li>
  427. * <li>Add the L2Object spawn in the world as a <B>visible</B> object</li><BR><BR>
  428. *
  429. * <B><U> Assert </U> :</B><BR><BR>
  430. * <li> _worldRegion == null <I>(L2Object is invisible at the beginning)</I></li><BR><BR>
  431. *
  432. * <B><U> Example of use </U> :</B><BR><BR>
  433. * <li> Create Door</li>
  434. * <li> Spawn : Monster, Minion, CTs, Summon...</li><BR>
  435. *
  436. */
  437. public final void spawnMe()
  438. {
  439. assert getPosition().getWorldRegion() == null && getPosition().getWorldPosition().getX() != 0 && getPosition().getWorldPosition().getY() != 0 && getPosition().getWorldPosition().getZ() != 0;
  440. synchronized (this)
  441. {
  442. // Set the x,y,z position of the L2Object spawn and update its _worldregion
  443. _isVisible = true;
  444. getPosition().setWorldRegion(L2World.getInstance().getRegion(getPosition().getWorldPosition()));
  445. // Add the L2Object spawn in the _allobjects of L2World
  446. L2World.getInstance().storeObject(this);
  447. // Add the L2Object spawn to _visibleObjects and if necessary to _allplayers of its L2WorldRegion
  448. getPosition().getWorldRegion().addVisibleObject(this);
  449. }
  450. // this can synchronize on others instances, so it's out of
  451. // synchronized, to avoid deadlocks
  452. // Add the L2Object spawn in the world as a visible object
  453. L2World.getInstance().addVisibleObject(this, getPosition().getWorldRegion());
  454. onSpawn();
  455. }
  456. public final void spawnMe(int x, int y, int z)
  457. {
  458. assert getPosition().getWorldRegion() == null;
  459. synchronized (this)
  460. {
  461. // Set the x,y,z position of the L2Object spawn and update its _worldregion
  462. _isVisible = true;
  463. if (x > L2World.MAP_MAX_X) x = L2World.MAP_MAX_X - 5000;
  464. if (x < L2World.MAP_MIN_X) x = L2World.MAP_MIN_X + 5000;
  465. if (y > L2World.MAP_MAX_Y) y = L2World.MAP_MAX_Y - 5000;
  466. if (y < L2World.MAP_MIN_Y) y = L2World.MAP_MIN_Y + 5000;
  467. getPosition().setWorldPosition(x, y ,z);
  468. getPosition().setWorldRegion(L2World.getInstance().getRegion(getPosition().getWorldPosition()));
  469. // Add the L2Object spawn in the _allobjects of L2World
  470. }
  471. L2World.getInstance().storeObject(this);
  472. // these can synchronize on others instances, so they're out of
  473. // synchronized, to avoid deadlocks
  474. // Add the L2Object spawn to _visibleObjects and if necessary to _allplayers of its L2WorldRegion
  475. getPosition().getWorldRegion().addVisibleObject(this);
  476. // Add the L2Object spawn in the world as a visible object
  477. L2World.getInstance().addVisibleObject(this, getPosition().getWorldRegion());
  478. onSpawn();
  479. }
  480. public void toggleVisible()
  481. {
  482. if (isVisible())
  483. decayMe();
  484. else
  485. spawnMe();
  486. }
  487. public boolean isAttackable()
  488. {
  489. return false;
  490. }
  491. public abstract boolean isAutoAttackable(L2Character attacker);
  492. public boolean isMarker()
  493. {
  494. return false;
  495. }
  496. /**
  497. * Return the visibility state of the L2Object.
  498. * <B><U> Concept</U> :</B><BR><BR>
  499. * A L2Object is visible if <B>__IsVisible</B>=true and <B>_worldregion</B>!=null <BR><BR>
  500. * @return
  501. */
  502. public final boolean isVisible()
  503. {
  504. return getPosition().getWorldRegion() != null;
  505. }
  506. public final void setIsVisible(boolean value)
  507. {
  508. _isVisible = value;
  509. if (!_isVisible) getPosition().setWorldRegion(null);
  510. }
  511. public ObjectKnownList getKnownList()
  512. {
  513. return _knownList;
  514. }
  515. /**
  516. * Initializes the KnownList of the L2Object,
  517. * is overwritten in classes that require a different knownlist Type.
  518. *
  519. * Removes the need for instanceof checks.
  520. */
  521. public void initKnownList()
  522. {
  523. _knownList = new ObjectKnownList(this);
  524. }
  525. public final void setKnownList(ObjectKnownList value)
  526. {
  527. _knownList = value;
  528. }
  529. public final String getName()
  530. {
  531. return _name;
  532. }
  533. public void setName(String value)
  534. {
  535. _name = value;
  536. }
  537. public final int getObjectId()
  538. {
  539. return _objectId;
  540. }
  541. public final ObjectPoly getPoly()
  542. {
  543. if (_poly == null)
  544. _poly = new ObjectPoly(this);
  545. return _poly;
  546. }
  547. public ObjectPosition getPosition()
  548. {
  549. return _position;
  550. }
  551. /**
  552. * Initializes the Position class of the L2Object,
  553. * is overwritten in classes that require a different position Type.
  554. *
  555. * Removes the need for instanceof checks.
  556. */
  557. public void initPosition()
  558. {
  559. _position = new ObjectPosition(this);
  560. }
  561. public final void setObjectPosition(ObjectPosition value)
  562. {
  563. _position = value;
  564. }
  565. /**
  566. * @return reference to region this object is in.
  567. */
  568. public L2WorldRegion getWorldRegion()
  569. {
  570. return getPosition().getWorldRegion();
  571. }
  572. public L2PcInstance getActingPlayer()
  573. {
  574. return null;
  575. }
  576. /**
  577. * Sends the Server->Client info packet for the object.<br><br>
  578. * Is Overridden in:
  579. * <li>L2AirShipInstance</li>
  580. * <li>L2BoatInstance</li>
  581. * <li>L2DoorInstance</li>
  582. * <li>L2PcInstance</li>
  583. * <li>L2StaticObjectInstance</li>
  584. * <li>L2Decoy</li>
  585. * <li>L2Npc</li>
  586. * <li>L2Summon</li>
  587. * <li>L2Trap</li>
  588. * <li>L2ItemInstance</li>
  589. * @param activeChar
  590. */
  591. public void sendInfo(L2PcInstance activeChar)
  592. {
  593. }
  594. @Override
  595. public String toString()
  596. {
  597. return (getClass().getSimpleName() + ":"+getName()+"[" + getObjectId() + "]");
  598. }
  599. /**
  600. * Not Implemented.<BR><BR>
  601. *
  602. * <B><U> Overridden in </U> :</B><BR><BR>
  603. * <li> L2PcInstance</li><BR><BR>
  604. * @param mov
  605. */
  606. public void sendPacket(L2GameServerPacket mov)
  607. {
  608. // default implementation
  609. }
  610. /**
  611. * Not Implemented.<BR><BR>
  612. *
  613. * <B><U> Overridden in </U> :</B><BR><BR>
  614. * <li> L2PcInstance</li><BR><BR>
  615. * @param id
  616. */
  617. public void sendPacket(SystemMessageId id)
  618. {
  619. // default implementation
  620. }
  621. /**
  622. * @return {@code true} if object is instance of {@link L2PcInstance}
  623. */
  624. public boolean isPlayer()
  625. {
  626. return false;
  627. }
  628. /**
  629. * @return {@code true} if object is instance of {@link L2Playable}
  630. */
  631. public boolean isPlayable()
  632. {
  633. return false;
  634. }
  635. /**
  636. * @return {@code true} if object is instance of {@link L2Summon}
  637. */
  638. public boolean isSummon()
  639. {
  640. return false;
  641. }
  642. /**
  643. * @return {@code true} if object is instance of {@link L2PetInstance}
  644. */
  645. public boolean isPet()
  646. {
  647. return false;
  648. }
  649. /**
  650. * @return {@code true} if object is instance of {@link L2DoorInstance}
  651. */
  652. public boolean isDoor()
  653. {
  654. return false;
  655. }
  656. /**
  657. * @return {@code true} if object is instance of {@link L2Npc}
  658. */
  659. public boolean isNpc()
  660. {
  661. return false;
  662. }
  663. /**
  664. * @return {@code true} if object is instance of {@link L2Attackable}
  665. */
  666. public boolean isL2Attackable()
  667. {
  668. return false;
  669. }
  670. /**
  671. * @return {@code true} if object is instance of {@link L2MonsterInstance}
  672. */
  673. public boolean isMonster()
  674. {
  675. return false;
  676. }
  677. /**
  678. * @return {@code true} if object is instance of {@link L2TrapInstance}
  679. */
  680. public boolean isTrap()
  681. {
  682. return false;
  683. }
  684. /**
  685. * @return {@code true} if object is instance of {@link L2ItemInstance}
  686. */
  687. public boolean isItem()
  688. {
  689. return false;
  690. }
  691. }