2
0

L2Decoy.java 3.9 KB

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