L2Decoy.java 3.9 KB

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