L2Object.java 21 KB

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