L2Decoy.java 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 net.sf.l2j.gameserver.model;
  16. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  17. import net.sf.l2j.gameserver.serverpackets.MyTargetSelected;
  18. import net.sf.l2j.gameserver.serverpackets.NpcInfo;
  19. import net.sf.l2j.gameserver.taskmanager.DecayTaskManager;
  20. import net.sf.l2j.gameserver.templates.L2CharTemplate;
  21. import net.sf.l2j.gameserver.templates.L2NpcTemplate;
  22. import net.sf.l2j.gameserver.templates.L2Weapon;
  23. public abstract class L2Decoy extends L2Character
  24. {
  25. private L2PcInstance _owner;
  26. public L2Decoy(int objectId, L2CharTemplate template, L2PcInstance owner)
  27. {
  28. super(objectId, template);
  29. getKnownList();
  30. getStat();
  31. getStatus();
  32. _owner = owner;
  33. setXYZInvisible(owner.getX(), owner.getY(), owner.getZ());
  34. }
  35. @Override
  36. public void onSpawn()
  37. {
  38. super.onSpawn();
  39. this.getOwner().sendPacket(new NpcInfo(this));
  40. }
  41. @Override
  42. public void onAction(L2PcInstance player)
  43. {
  44. player.setTarget(this);
  45. MyTargetSelected my = new MyTargetSelected(getObjectId(), player.getLevel()
  46. - getLevel());
  47. player.sendPacket(my);
  48. }
  49. @Override
  50. public void updateAbnormalEffect()
  51. {
  52. for (L2PcInstance player : getKnownList().getKnownPlayers().values())
  53. player.sendPacket(new NpcInfo(this));
  54. }
  55. public void stopDecay()
  56. {
  57. DecayTaskManager.getInstance().cancelDecayTask(this);
  58. }
  59. @Override
  60. public void onDecay()
  61. {
  62. deleteMe(_owner);
  63. }
  64. @Override
  65. public boolean isAutoAttackable(L2Character attacker)
  66. {
  67. return _owner.isAutoAttackable(attacker);
  68. }
  69. @Override
  70. public L2ItemInstance getActiveWeaponInstance()
  71. {
  72. return null;
  73. }
  74. @Override
  75. public L2Weapon getActiveWeaponItem()
  76. {
  77. return null;
  78. }
  79. @Override
  80. public L2ItemInstance getSecondaryWeaponInstance()
  81. {
  82. return null;
  83. }
  84. @Override
  85. public L2Weapon getSecondaryWeaponItem()
  86. {
  87. return null;
  88. }
  89. public final int getNpcId()
  90. {
  91. return getTemplate().npcId;
  92. }
  93. @Override
  94. public int getLevel()
  95. {
  96. return getTemplate().level;
  97. }
  98. public void deleteMe(L2PcInstance owner)
  99. {
  100. decayMe();
  101. getKnownList().removeAllKnownObjects();
  102. owner.setDecoy(null);
  103. }
  104. public synchronized void unSummon(L2PcInstance owner)
  105. {
  106. if (isVisible() && !isDead())
  107. {
  108. if (getWorldRegion() != null)
  109. getWorldRegion().removeFromZones(this);
  110. owner.setDecoy(null);
  111. decayMe();
  112. getKnownList().removeAllKnownObjects();
  113. }
  114. }
  115. public final L2PcInstance getOwner()
  116. {
  117. return _owner;
  118. }
  119. @Override
  120. public L2NpcTemplate getTemplate()
  121. {
  122. return (L2NpcTemplate) super.getTemplate();
  123. }
  124. }